[Python-Dev] pymalloc killer

Tim Peters tim.one@comcast.net
Fri, 29 Mar 2002 18:55:09 -0500


[Tim]
>> , and see whether B <= p < B + 256KB
>>    (which can again be collapsed into a tricksy one-compare test via
>>    exploiting unsigned arithmetic).

[David Abrahams]
> ...isn't this part just a little too complicated?

I don't think so, but I am making a speed/space tradeoff.

> If I understand correctly, arenas are 4K aligned pages.

Arenas are 256KB chunks with no known alignment.  They're carved into
4KB-aligned pages (also called "pools") of 4KB each.  Some number of the
leading and trailing memory addresses in an arena are sacrificed to get page
alignment in the smaller pieces (pools/pages).  A given pool is in turn
carved into some number of continguous, equal-sized, 8-byte aligned small
blocks.

> Given an address, when you find its pool header, you either find
> a valid arena header that covers all 4K subsequent addresses, or some
> alien memory.

True, after s/arena header/pool header/.

> I think you just have to look for the address of the pool header at the
> appropriate index in the vector.

It would consume too much memory (64x as much -- 2**18/2**12) to keep a
vector of all pool header addresses.  That's why I'm storing arena base
addresses instead.  We can't control or predict anything about the addresses
we get from the system malloc() when allocating arenas, so address
arithmetic tricks can't work to find arena base addresses.