L.S.,
I am studying the GC because I'd like to fight memory fragmentation.
It seems to me that mmap could really solve the problem of
fragmentation best. When I look at the code however, I have a few
questions, I couldn't find answers on on the site or in the code.
1.
Unused hblks are only unmapped after they have not been used for some
time. What is the reason to not unmap them as soon as they become
free? Costs?
2.
Unmapped hblks are not really unmapped, but remapped as inaccessible.
(PROT_NONE). What is the reason for this?
3.
Later, unmapped blocks might be merged with adjacent free blocks by
GC_merge_unmapped(). Why not unmap them all and map a new block when
needed?
4.
If it were possible to just unmap blocks and use mmap for new blocks,
then the fragmentation would completely vanish, it that true?
5.
Doing 4. would probably lead to many heap segments, as it would of
course be necessary to let mmap decide about the addresses, is that a
hard problem, to avoid at all costs?
I do have some thoughts about the answers to these questions of
course, but I might be completely wrong. To me, it seems that the
collector tries to maintain a more or less consecutive heap, reusing
blocks and filling up the gaps as efficiently as possible. So here is
my meta-question:
6. What if one would not try to be efficient but just let mmap do its
work, at least for large blocks, how would that change the answers to
the questions above? Would it enable a solution for the fragmentation
problem?
Erik