Kaffe Memory Manager

Jason Baker jbaker at cs.utah.edu
Tue Feb 6 10:10:40 PST 2001


> 
> 
> I'm having some trouble understanding Kaffe's memory manager
> and there is one particular part that is confusing me a lot.
> In gc-mem.c, function gc_block_alloc (about line 881) appears:
> 	if (GCMEM2BLOCK(heap_addr + size) 
> 	    > ((gc_block *)gc_block_base) + nblocks
> 	    || heap_addr < gc_heap_base) {
>
> what is this test for?

The original plan was to do one of two things:  Either allocate a
gc_heap_limit sized chunk of address space up front with
mmap(...MAP_NORESERVE), or, on systems that don't support
MAP_NORESERVE, find a chunk of address space that no-one else would
allocate.  Either way, Kaffe's heap would be contiguous, and we could
store page metadata (gc_block structures) in an array indexed by the
page's offset from gc_heap_base.

For some reason, I tried to make the code more portable:  Allocate
a gc_block array to cover 125% of kaffe's maximum pages, and allocate
heap pages normally.  Since Kaffe is now competing with libc malloc,
our heap will not be contiguous.  If libc malloc allocates more that
25% of gc_heap_limit, the gc_block array is too small to index all
heap pages, and we have to grow the array.

The conditional above is true if any page we allocated has a block
index > nblocks or < 0.  In other words, it is true when we need to
reallocate the block array.

Jason


More information about the kaffe mailing list