[Python-Dev] gc ideas -- sparse memory

"Martin v. Löwis" martin at v.loewis.de
Sat Dec 4 00:15:48 CET 2010

Am 03.12.2010 23:55, schrieb Dima Tisnek:
> How hard or reasonable would it be to free memory pages on OS level?

Very easy. Python already does that.

> [pcmiiw] Gabage collection within a generation involves moving live
> objects to compact the generation storage. This separates the memory
> region into 2 parts "live" and "cleared", the pointer to the beginning
> of the "cleared" part is where next allocation is going to happen.

I think you are talking about copying collectors here. This is not how
Python's garbage collection works.

> When this is done, does Python gc move the objects preserving order or
> does it try to populate garbaged slot with some live object
> disregarding order? Earlier case is more applicable, but latter case
> is a target for below too.

(C)Python's garbage collector is not moving objects at all.

> If we were to look at memory regions from the OS point of view, they
> are allocated as pages (or possibly as hugetlb pages). So if we are to
> compact something like this [LL__][_L__][____][L_LL][LFFF]  where []
> is a page, L is live object and _ is garbage and F is free memory,
> would it not make more sense to tell OS that [____] is not needed
> anymore, and not move some of the consequtive [L_LL][LFFF] at all, or
> at least not move those objects as far down the memory region?

See above. Python does no moving of objects whatsoever.


More information about the Python-Dev mailing list