![]() |
![]() |
#1 |
Dec 2003
23×33 Posts |
![]()
On an Opteron box with 16 GiB of RAM, it refuses to use anything other than 8 MiB. I get this message when trying to use the menu:
Code:
Daytime available memory in MB (7): 16128 Please enter a value between 8 and 8. Daytime available memory in MB (7): 7 Please enter a value between 8 and 8. Contents of /proc/meminfo: Code:
MemTotal: 16254220 kB MemFree: 15555472 kB [...] SwapTotal: 18876364 kB SwapFree: 18876364 kB [...] ![]() Fortunately this doesn't break completely on 2.6 kernels with less than 8 GiB of memory, because of another bug. mprime subtracts 8 from the unsigned long value returned from physical_memory(). This the reason why it suggested 7 above. When the amount of memory seen by mprime is less than 8 MiB, the result wraps around and becomes a very large number. Don't fix the last bug. It may be handy if Linux 3.14 or so decides to give the amount of memory in MiB. ![]() This version should work on all kernels 2.0 and above. The function is defined in linux/prime.c line 489: Code:
unsigned long physical_memory (void) { FILE *fd; char mem[80]; fd = fopen ("/proc/meminfo", "r"); if (fd == NULL) return (1024); for ( ; ; ) { if (fscanf (fd, "%s", mem) == EOF) break; if (strcmp (mem, "MemTotal:") == 0) { fscanf (fd, "%s", mem); fclose (fd); return (atoi (mem) >> 10); } } fclose (fd); return (1024); } |
![]() |
![]() |
![]() |
#2 |
P90 years forever!
Aug 2002
Yeehaw, FL
100000101101112 Posts |
![]()
Does this code work instead? It was recommended by a user a month ago.
struct sysinfo sys_info; if (sysinfo(&sys_info) != 0) { return(1024); } return (sys_info.totalram >> 20); |
![]() |
![]() |
![]() |
#3 |
Aug 2002
26×5 Posts |
![]()
Programs shouldn't really rely on information from /proc files, since their format may change without warning.
Yes, using sysinfo is better, though its Linux specific. |
![]() |
![]() |
![]() |
#4 |
P90 years forever!
Aug 2002
Yeehaw, FL
53·67 Posts |
![]()
Is the totalram field in sysinfo 32 bits? If so, won't 16GB of memory still cause problems?
|
![]() |
![]() |
![]() |
#5 | |
Aug 2002
26×5 Posts |
![]() Quote:
The "mem_unit" field tells you how many bytes each unit of "totalram" designates. So if "mem_unit" is 1024, and "totalram" is 1024, then the true amount of ram is a MB. |
|
![]() |
![]() |
![]() |
#6 | |
Dec 2003
23·33 Posts |
![]() Quote:
There is some weirdness. When I compile the program on RHEL 4 with a 2.6 kernel, my test program return 0 on a RHEL 3 machine running a 2.4 kernel. If I compile it on the RHEL 3 machine, the program works on both. I don't have a Linux machine availiable with more than 16 GiB of RAM ![]() |
|
![]() |
![]() |
![]() |
#7 | |
Aug 2002
5008 Posts |
![]() Quote:
|
|
![]() |
![]() |
![]() |
#8 |
P90 years forever!
Aug 2002
Yeehaw, FL
53×67 Posts |
![]()
The code in v25 will be:
struct sysinfo sys_info; if (sysinfo(&sys_info) != 0) return (1024); /* Guess 1GB */ return ((unsigned long) ((double) sys_info.totalram * (double) sys_info.mem_unit / 1048576.0)); |
![]() |
![]() |
![]() |
Thread Tools | |
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Large memory usage | Unregistered | Information & Answers | 8 | 2010-05-14 23:45 |
Large-capacity memory | fivemack | Hardware | 17 | 2010-02-12 22:29 |
GMP-ECM on large memory systems ~ 60 Gb | Tom | GMP-ECM | 20 | 2007-12-21 18:57 |
Is there a large memory method? | nibble4bits | Miscellaneous Math | 21 | 2005-11-11 12:57 |
Use of large memory pages possible with newer linux kernels | Dresdenboy | Software | 3 | 2003-12-08 14:47 |