lkml.org 
[lkml]   [2000]   [Mar]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: Overcomittable memory
> Date: 	Fri, 17 Mar 2000 16:33:09 +0100
> From: Jamie Lokier <lk@tantalophile.demon.co.uk>
>
> Andreas Bombe wrote:
> > Allocated and touched.
> >
> > int i;
> > char *ptr = malloc(1024);
> > if (!ptr) thats_tough();
> > for (i = 0; i < 1024; i++) ptr[i] = 0;
> >
> > Only then you can be sure that this memory is there, because malloc
> > gave you a pointer and the for loop didn't get you killed. This works
> > because we sabotage COW through this, forcing a copy of the global COW
> > zero page[1] if the malloc returns newly allocated pages (and doesn't
> > reuse existing ones, in which case memory is there already). And you
> > should also touch your stack, while you're at it.
>
> Even this doesn't work if you've got duplicate page merging switched on
> :-)

This also introduces a race condition into your program: if another
process does the exact same thing, both mallocs can still succeed even
if there isn't enough memory for both, then when they try to touch the
memory one of them dies.

Brad


-
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/

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