Re: MemPools rewrite

From: Alex Rousskov <rousskov@dont-contact.us>
Date: Wed, 18 Oct 2000 15:12:41 -0600 (MDT)

On Wed, 18 Oct 2000, Andres Kroonmaa wrote:

> seems that I've missed that train. Why was it killed?

You cannot miss the train that never showed up :). As I said, the
initial code was never released. IIRC, the reasons I decided to kill the
initial design were:

        - no hard evidence of significant improvement over the simpler
          (current) design

        - higher complexity relative to the simpler (current) design

        - alignment concerns

        - chunk design still does not make variable string allocation
          convenient;
          the source pool still must be remembered for all objects

        - the current design can be used to pre-populate pools
          with sequentially pre-allocated objects, giving improvement
          that is probably close (in most cases) to that of a chunked
          design

> this alignment is one of the major sources of memory waste. This is
> a must for general purpose allocator I guess, but inside squid? Do we
> have any places where 8/16 byte alignment is really required?

Sure. If I want to allocate a "double" variable, it needs to be aligned.
Structures that contain doubles must be aligned appropriately. Many
platforms also require alignment for integers, AFAIK.

> I think we could add alignment value to MemPool struct or add another
> interface to memPoolCreate where we simply specify and round up
> requested size to given alignment requirement. Or we can round up this
> size with current api during a call to PoolCreate.
>
> I would like to align chunks on page boundaries, but I'd rather not
> hardwire 8/16 alignment into all object allocations.

I am not 100% sure, but I suspect that, in most cases, you will be safe
if the chunks are allocated with calloc or even malloc _and_ used to
store objects of equal size only. However,
        - I am not sure using malloc is safe on all platforms
        - if somebody tries to optimize mempools further (mmap or
          whatever), they may introduce alignment problems.

$0.02,

Alex.
Received on Wed Oct 18 2000 - 15:12:45 MDT

This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:12:51 MST