lkml.org 
[lkml]   [2004]   [Dec]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: 2.6.9, 64bit, 4GB memory => panics ...
On Sun, 5 Dec 2004, Rudolf Usselmann wrote:

> // -------------------------- eat mem ---------------------------------
>
> #include "stdio.h"
> #include "stdlib.h"
>
> int main() {
>
> int mem[10000];

Array of integers, you probably want int *mem[10000] if anything.

> int i, n;
>
> for(i=0;i<2000;i++) {
> printf("Doing alloc %0d ...\n",i);
> mem[i] = (int)malloc(1024*1024*1024);

Wrongly assigning pointer to signed integer, casting can sometimes be
evil.

> if(mem[i] == NULL)
> printf("Malloc failed ...\n");
> else
> for(n=0;n<(1024*1024*1024);n=n+640) mem[i] = n;

You lose the pointer value here and do not touch the allocated memory,
which means that the VM isn't forced to commit the memory you allocated.
You also want to be looking at the Committed_AS and Mapped fields of
/proc/meminfo

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 14:08    [W:0.055 / U:0.084 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site