growing and shrinking ObjectMemory
Jan Bottorff
janb at pmatrix.com
Sun Mar 4 03:30:49 UTC 2001
> > > Awesome!! Attached is a quick implementation for anyone who wants to
> > > play with it in Unix. It mmap's 500 Megs from /dev/zero, which on most
> > > Unices will both work and will not actually waste the memory until it's
> > > used (at which point it's not really wasting, now is it?).
I seem to remember from ParcPlace days some OS's having a REALLY ugly issue
about demand committed memory.
It goes like this, you allocate a bunch of memory/address space that's
backed by demand zero filled memory. The call to this allocation works
fine, and your software "thinks" it has the memory. Time passes, and other
applications use up some swap space. Eventually, your app decided to
actually touch one of those pages it allocated way back when, and uh oh,
the swap file is full. So how do you not inform the app that memory it
allocated, is actually unavailable? If the original allocated had failed,
the program logic could probably cope. Is the VM prepared to get a swap
file full memory access fault anytime it might be writing to memory for the
first time?
After understanding this issue, I decided that demand committed memory was
a really bad idea, and the OS had better allocate swap space as part of the
memory commitment. Under Windows NT (and W2K) you can allocate address
space as a separate operation from allocating the backing swap space. This
makes it easy to allocate 500 MByte of address space, then move the
committed line up and down, while returning a meaningful status to the
memory expansion code.
As I remember, OS/2 and "some" Unix flavors had the ugly behavior of
letting you map zero demand pages, and then later changing it's mind about
the availability of those pages.
I also fuzzily remember a solution was to always write to any memory you
allocated that was demand committed, essentially forcing swaps space to be
created before you return from the allocation call. Of course this also can
cause ugly paging behavior from all those now dirty pages.
Note that all this is talking about writing apps that work most of the time
vs. apps that work all of the time. Most of the time, the demand committed
memory has available swap space to allocate, just not all the time.
- Jan
More information about the Squeak-dev
mailing list
|