growing and shrinking ObjectMemory

Lex Spoon lex at cc.gatech.edu
Fri Mar 2 23:09:15 UTC 2001


Bert Freudenberg <bert at isg.cs.uni-magdeburg.de> wrote:
> On Fri, 2 Mar 2001, Lex Spoon wrote:
> 
> > 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?). 
> 
> Why is this preferable over just allocating the old way? Even if I start
> squeak with -memory 128m it takes up only like 14M of real memory. As I
> read your code, it does not actually grow/shrink the memory.
> 
> Btw, did you actually try to alloc a 400M Array with your change?
> 

You're right, although I think Linux is stricter about overcommitting
malloc-ed memory than it is about mmap-ed memory.

Anyway, after a little thought, I came up with the below code which can
release memory that's no longer used.  The trick used is to munmap()
unusued portions and then to mmap() them back again in order that the
region of memory stays contiguous.  At least on Linux this seems to work
okay.

To test it, I allocated and freed a few 100M string's and watched
Linux's free(1) report increase and decrease.  I also ran a loop 1000
times that allocates a 10M String, frees it, and runs a garbage collect,
and everything seems to be fine.


-Lex

-------------- next part --------------
A non-text attachment was scrubbed...
Name: sqUnixMemory.c
Type: application/octet-stream
Size: 4870 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20010302/32db8ab4/sqUnixMemory.obj


More information about the Squeak-dev mailing list