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 CAApHDvqZNwLeKPNxyLi6avGmHLaJr38XsA+LS5UdrcNDgo+Z8Q@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 Tue, 15 Nov 2022 at 11:11, Andres Freund <andres@anarazel.de> wrote:
> Couldn't we reduce the amount of over-allocation by a small amount by special
> casing the already-aligned case? That's not going to be relevant for page size
> aligne allocations, but for smaller alignment values it could matter.

I don't quite follow this. How can we know the allocation is already
aligned without performing the allocation? To perform the allocation
we must tell palloc what size to allocate. So, we've already wasted
the space by the time we can tell if the allocation is aligned to what
we need.

Aside from that, there's already a special case for alignto <=
MAXIMUM_ALIGNOF.  But we know no palloc will ever return anything
aligned less than that in all cases, which is why that can work.

David



pgsql-hackers by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: Non-decimal integer literals
Next
From: Daniel Gustafsson
Date:
Subject: Re: Unit tests for SLRU