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 CAApHDvqYz4VkdTs41SVVYJUq=xUSDjL445RcMzyuivwgzcty7g@mail.gmail.com
Whole thread Raw
In response to Re: Add palloc_aligned() to allow arbitrary power of 2 memory alignment  (John Naylor <john.naylor@enterprisedb.com>)
List pgsql-hackers
On Mon, 14 Nov 2022 at 15:25, John Naylor <john.naylor@enterprisedb.com> wrote:
> - Assert((char *) chunk > (char *) block);
> + Assert((char *) chunk >= (char *) block);
>
> Is this related or independent?

It's related.  Because the code is doing:

MemoryChunkSetHdrMask(alignedchunk, unaligned, alignto,
  MCTX_ALIGNED_REDIRECT_ID);

Here the blockoffset gets set to the difference between alignedchunk
and unaligned. Typically when we call MemoryChunkSetHdrMask, the
blockoffset is always the difference between the block and
MemoryChunk, which is never 0 due to the block header fields.  Here it
can be the same pointer when the redirection MemoryChunk is stored on
the first byte of the palloc'd address.  This can happen if the
address returned by palloc + sizeof(MemoryChunk) is aligned to what we
need already.

David



pgsql-hackers by date:

Previous
From: Pavel Borisov
Date:
Subject: Re: Unit tests for SLRU
Next
From: Amit Kapila
Date:
Subject: Re: Assertion failure in SnapBuildInitialSnapshot()