Re: Add palloc_aligned() to allow arbitrary power of 2 memory alignment

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: John Naylor <john(dot)naylor(at)enterprisedb(dot)com>
Cc: Andres Freund <andres(at)anarazel(dot)de>, PostgreSQL Developers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Add palloc_aligned() to allow arbitrary power of 2 memory alignment
Date: 2022-11-15 10:46:17
Message-ID: CAApHDvqYz4VkdTs41SVVYJUq=xUSDjL445RcMzyuivwgzcty7g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, 14 Nov 2022 at 15:25, John Naylor <john(dot)naylor(at)enterprisedb(dot)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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2022-11-15 10:50:00 Re: Assertion failure in SnapBuildInitialSnapshot()
Previous Message Pavel Borisov 2022-11-15 10:43:06 Re: Unit tests for SLRU