On Fri, Jul 29, 2022 at 12:43:45PM -0400, Reid Thompson wrote:
> slab.c
> does not in SlabContextCreate(). Is this intentional, it seems to be an
> oversight to me.
>
> /* Finally, do the type-independent part of context creation */
> MemoryContextCreate((MemoryContext) slab,
> T_SlabContext,
> &SlabMethods,
> parent,
> name);
>
> return (MemoryContext) slab;
> }
IIUC this is because the header is tracked separately from the first
regular block, unlike aset.c. See the following comment:
/*
* Allocate the context header. Unlike aset.c, we never try to combine
* this with the first regular block; not worth the extra complication.
*/
You'll also notice that the "reset" and "free" functions in aset.c and
generation.c have special logic for "keeper" blocks. Here is a relevant
comment from AllocSetReset():
* Actually, this routine has some discretion about what to do.
* It should mark all allocated chunks freed, but it need not necessarily
* give back all the resources the set owns. Our actual implementation is
* that we give back all but the "keeper" block (which we must keep, since
* it shares a malloc chunk with the context header). In this way, we don't
* thrash malloc() when a context is repeatedly reset after small allocations,
* which is typical behavior for per-tuple contexts.
--
Nathan Bossart
Amazon Web Services: https://aws.amazon.com