Re: Add bump memory context type and use it for tuplesorts

From: Tomas Vondra <tomas(dot)vondra(at)enterprisedb(dot)com>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: David Rowley <dgrowleyml(at)gmail(dot)com>, John Naylor <johncnaylorls(at)gmail(dot)com>, Matthias van de Meent <boekewurm+postgres(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL Developers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Add bump memory context type and use it for tuplesorts
Date: 2024-04-07 21:27:18
Message-ID: 23b1110b-7b6f-4308-bade-55fd05578c4b@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 4/7/24 23:09, Andres Freund wrote:
> Hi,
>
> On 2024-04-07 22:35:47 +0200, Tomas Vondra wrote:
>> I haven't investigated, but I'd considering it works on 64-bit, I guess
>> it's not considering alignment somewhere. I can dig more if needed.
>
> I think I may the problem:
>
>
> #define KeeperBlock(set) ((BumpBlock *) ((char *) (set) + sizeof(BumpContext)))
> #define IsKeeperBlock(set, blk) (KeeperBlock(set) == (blk))
>
> BumpContextCreate():
> ...
> /* Fill in the initial block's block header */
> block = (BumpBlock *) (((char *) set) + MAXALIGN(sizeof(BumpContext)));
> /* determine the block size and initialize it */
> firstBlockSize = allocSize - MAXALIGN(sizeof(BumpContext));
> BumpBlockInit(set, block, firstBlockSize);
> ...
> ((MemoryContext) set)->mem_allocated = allocSize;
>
> void
> BumpCheck(MemoryContext context)
> ...
> if (IsKeeperBlock(bump, block))
> total_allocated += block->endptr - (char *) bump;
> ...
>
> I suspect that KeeperBlock() isn't returning true, because IsKeeperBlock misses
> the MAXALIGN(). I think that about fits with:
>
>> #4 0x008f0088 in BumpCheck (context=0x131e330) at bump.c:808
>> 808 Assert(total_allocated == context->mem_allocated);
>> (gdb) p total_allocated
>> $1 = 8120
>> (gdb) p context->mem_allocated
>> $2 = 8192
>

Yup, changing it to this:

#define KeeperBlock(set) ((BumpBlock *) ((char *) (set) +
MAXALIGN(sizeof(BumpContext))))

fixes the issue for me.

regards

--
Tomas Vondra
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Nazir Bilal Yavuz 2024-04-07 21:30:18 Re: Streaming I/O, vectored I/O (WIP)
Previous Message Tom Lane 2024-04-07 21:17:37 Re: pub/sub - specifying optional parameters without values.