Kaffe Memory Manager

Chris Pedley cp114 at york.ac.uk
Wed Feb 7 07:42:23 PST 2001


So does that mean that if you choose a large initial
value for the heap, and make that the heap total as
well (so that the heap never grows) that the
block array will need reallocating on the first
call to gc_block_alloc?  If this is the case then
I think there is a bug here.

The calculation used to get the new number of
blocks is:

nblocks = (nblocks * (gc_heap_limit >> gc_pgbits))
   / n_live;

n_live is initially 0, so you get an Arithmetic
Exception.  Is it valid to simply fix this by
checking with n_live==0, and if it is just removing
the divisor from this calculation?

On Tue, 6 Feb 2001, Jason Baker wrote:

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