Re: Overcommitable memory??

From: Aaron Denney (wnoise@ugcs.caltech.edu)
Date: Fri Mar 17 2000 - 22:46:39 EST


On the linux-kernel mailing list, dwhysong@physics.ucsb.edu wrote:
> Sorry, you're wrong on this one. Even with /proc/sys/vm/overcommit_memory
> set to 0, you can easily have a task malloc() a region larger than the
> available virtual memory.
>
> Example:
>
> [root@sleepy dwhysong]# echo "0" > /proc/sys/vm/overcommit_memory
> [dwhysong@sleepy dwhysong]$ cat mem.c
> int main(int argc, char *argv[]) {
> char *a;
> unsigned n;
> n = atoi(argv[1]);
> a = (char *) malloc(1024*1024*n);
> printf("Allocating %u megabytes at %p\n",n,a);
> return(0);
> }
> [dwhysong@sleepy dwhysong]$ gcc mem.c -o mem
> [dwhysong@sleepy dwhysong]$ free
> total used free shared buffers cached
> Mem: 257788 98764 159024 19400 37708 32264
> -/+ buffers/cache: 28792 228996
> Swap: 642016 2200 639816
> [dwhysong@sleepy dwhysong]$ ./mem 800
> Allocating 800 megabytes at 0x40108008
> [dwhysong@sleepy dwhysong]$ ./mem 1000
> Allocating 1000 megabytes at (nil)
>
> So malloc() returns success when I ask for an 800 megabyte array on a
> machine with only ~640 megabytes of free virtual memory.

639816 + 228996 = 868812 = 848 Mb

-- 
Aaron Denney
-><-

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



This archive was generated by hypermail 2b29 : Thu Mar 23 2000 - 21:00:23 EST