Andres Freund <andres@anarazel.de> writes:
> Independently of this, we really should redefine StandardChunkHeader to
> be only the MemoryContext. There's no need to have size/requested_size
> part of StandardChunkHeader, given there's
> MemoryContextMethods->get_chunk_space().
Yeah, perhaps. The trick would be to get things laid out so that the
MemoryContext pointer is always immediately adjacent to the chunk data
(no padding between).
One could imagine redefining aset.c's chunk header along the lines of
typedef struct AllocSetChunkHeader
{ Size size; /* size of data space allocated in chunk */
#ifdef MEMORY_CONTEXT_CHECKING Size requested_size; /* original request size */
#if 32-bit-but-maxalign-is-8 Size padding; /* needed to avoid padding below */
#endif
#endif MemoryContext context; /* owning context */ /* there must not be any padding to reach a MAXALIGN
boundaryhere! */
} AllocSetChunkHeader;
where we'd possibly need some help from configure to implement that inner
#if condition, but it seems doable enough.
If the slab allocator would be happier with just a MemoryContext pointer
as chunk header, I think we should push in this direction rather than
invent some short-term hack.
regards, tom lane