Re: Add palloc_aligned() to allow arbitrary power of 2 memory alignment - Mailing list pgsql-hackers

From David Rowley
Subject Re: Add palloc_aligned() to allow arbitrary power of 2 memory alignment
Date
Msg-id CAApHDvqvFVd5LyKcNpY5cdBg5_ecZj=P7aNZwh2MMv+GK-7zEg@mail.gmail.com
Whole thread Raw
In response to Re: Add palloc_aligned() to allow arbitrary power of 2 memory alignment  (Andres Freund <andres@anarazel.de>)
Responses Re: Add palloc_aligned() to allow arbitrary power of 2 memory alignment
List pgsql-hackers
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

Attachment

pgsql-hackers by date:

Previous
From: Yugo NAGATA
Date:
Subject: Re: BUG #17434: CREATE/DROP DATABASE can be executed in the same transaction with other commands
Next
From: vignesh C
Date:
Subject: Re: PGDOCS - Logical replication GUCs - added some xrefs