[Gc] Questions on boehm-gc, fragmentation, and low memory
dej at inode.org
Wed Jul 8 10:48:28 PDT 2009
Fragmentation will be a problem.
The GC allocates objects of a given size on their own page. e.g. all objects
of 24 bytes will be allocated on one page, and objects of size 40 bytes will
be allocated on a different page.
So, if you have five objects of size 24, 32, 40, 48, 64 bytes then they
could all fit on one page in a naive allocator, but Boehm-GC will take up 5
pages. If you have many different object sizes then this could be a problem.
Whether this is a real problem or not is application-dependent. If you have
a lot of objects then the effect is not as bad.
The other thing to consider: garbage collectors are not as memory-efficient
as manual management no matter what you use. Garbage collectors don't run
continuously. Rather, the GC will amortize the cost of a collection across
multiple allocations by requesting memory from the OS before running another
collection. e.g. the algorithm might be: "run a collection, and then request
as much additional memory from the OS as I am currently using in the heap,
unless I have reclaimed more than half my memory". (I have no idea if this
is the real algorithm.) With this heuristic, you are using potentially twice
as much memory as you would otherwise. e.g. if there is 4MB of data in the
heap and you continually allocate and drop objects (Java container iterators
come to mind) then you could work up to 8MB, and then a collection brings
you back down to 4MB. But you are using worst-case twice as much memory as
you would be otherwise.
(And a copying collector could be much worse: worst-case, both the fromspace
and tospace must be represented by physical memory during a collection.)
On Wed, Jul 8, 2009 at 1:12 PM, Yann Frach <yann.frach at gmail.com> wrote:
> I'm working on embedded devices with low memory and I'm worried about
> heap fragmentation
> in a non-moving GC like boehm-gc. I have a few questions.
> - Does boehm-gc do something to avoid/minimize fragmentation ?
> - Is there any "moving"/compacting implementation of boehm gc, and if
> not, would it be possible ?
> - For people with experience in the embedded context, is it worthwhile to
> boehm-gc and how do you make it work as good as possible ?
> Thanks for your thoughts (and possibly pointers on more information) on
> Gc mailing list
> Gc at linux.hpl.hp.com
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Gc