Re: Add palloc_aligned() to allow arbitrary power of 2 memory alignment
David Rowley <dgrowleyml@gmail.com>
From: David Rowley <dgrowleyml@gmail.com>
To: Andres Freund <andres@anarazel.de>
Cc: PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>
Date: 2022-11-16T10:56:26Z
Lists: pgsql-hackers
Attachments
- v2-0001-Add-allocator-support-for-larger-allocation-align.patch (text/plain) patch v2-0001
- v2-0002-Test-code-to-exercise-palloc_aligned-and-repalloc.patch (text/plain) patch v2-0002
On Wed, 16 Nov 2022 at 08:19, Andres Freund <andres@anarazel.de> wrote: > We already rely on memory context returning MAXIMUM_ALIGNOF aligned > allocations. Adding the special case, I think, means that the we could safely > over-allocate by "only" > alignto + sizeof(MemoryChunk) - MAXIMUM_ALIGNOF > > Which would be a reasonable win for small allocations with a small > > MAXIMUM_ALIGNOF alignment. But I don't think that'll be a very common case? Seems reasonable. Subtracting MAXIMUM_ALIGNOF doesn't add any additional run-time cost since it will be constant folded with the sizeof(MemoryChunk). I've attached an updated patch. The 0002 is just intended to exercise these allocations a little bit, it's not intended for commit. I was using that to ensure valgrind does not complain about anything. It seems happy now. David
Commits
-
Add palloc_aligned() to allow aligned memory allocations
- 439f61757f05 16.0 landed