Hi all, this is my first post to this group.
I spent some time before deciding on which forum this request could be sent. I finally decided for “Install/Boot/Login” because the answer to my problem could be related to installation / tuning / kernel rebuild, so this might be the right place.
Please excuse me if I am wrong!
I am trying to understand how exactly memory management in linux (OpenSUSE 11.2) works.
I have compiled the following program (memorytest.c):
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char **argv)
{
long int n=0;
int *x;
if (argc != 2) exit (0);
else {
int mem = atoi(argv[1]);
while(1)
{
x = (int*) malloc (mem); // no point in testing if not zero:
// I'll know that from the segmfault :-)
printf("
n=%ld x=%p", n, x);
*(x+20) = 123456; // just to use the allocated memory
// (or to trigger the segmfault)
n++;
sleep(1); // wait a little and let me see what's happening
} // while
} // else
return 0;
}
on a linux workstation running 64bit OpenSuse, with 24 GB RAM.
I run the program with
memorytest 1073751800
thus allocating memory 1 GB per cycle.
The program output is
n=0 x=0x7f751b1cd010
n=1 x=0x7f74db1ca010
n=2 x=0x7f749b1c7010
n=3 x=0x7f745b1c4010
<…omissis…>
n=21 x=0x7f6fdb18e010
n=22 x=0x7f6f9b18b010
n=23 x=0x7f6f5b188010
n=24 x=0x7f6f1b185010
Segmentation fault
The program stops after allocating 24 GB, that is the physical memory
limit: why does it not go as far as 64 bit allocation allows? I’d expect
it to continue allocating memory (and paging) till all the paging memory
is exhausted, or virtual space addressing is saturated, whichever
the first.
Also consider that the same code works with no problem on a Mac Pro, continuing to allocate memory on and on (till you are bored and stop the program).
What’s going on? Can someone enlighten me please?
I need all that memory (far more than the available physical RAM) so the problem is not just curiosity…
It is evident that linux is not allowing memory paging: how can I verify it and convince linux to work as I expect?
Thanks
Giorgio
PS This request was already posted to other forums, so please excuse me if you have already seen this help cry somewhere else…