Re: Reducing relcache memory usage: deduping index shapes

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: Matthias van de Meent <boekewurm+postgres(at)gmail(dot)com>
Cc: Yilin Zhang <jiezhilove(at)126(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Andres Freund <andres(at)anarazel(dot)de>, David Geier <geidav(dot)pg(at)gmail(dot)com>
Subject: Re: Reducing relcache memory usage: deduping index shapes
Date: 2026-10-14 07:27:53
Message-ID: CAApHDvp_-zh5cdR_aNaUCXGHeddWC0b1a5kiJpC1cKdG0vx6DA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, 13 Oct 2026 at 07:22, Matthias van de Meent
<boekewurm+postgres(at)gmail(dot)com> wrote:
> 0004/0005: Adjust for Proxy -> System /SystemCxt rename

Here's a delta patch with various fixups for v4-0003

* Fixed inconsistent references to systemcxt.c file in README (In some
places this was spelt systemctx.c)
* Ended up renaming the file to systemctx.c (we're not very consistent
in general between cxt and ctx. MemoryContextMethodID enum uses ctx,
so I followed that example)
* Changed function names from SystemCxt* to SystemContext*. The struct
was called SystemContext. I felt the need to have consistency.
* Added missing accounting of mem_allocated in SystemContextRealloc().
* size_t is unsigned, so the format specifier for printf is %zu, not %zd
* Fixed bug in SystemContextRealloc() which would leak the old block
on realloc() failure. The dlist_delete_from_thoroughly() can't be
moved to after the realloc() as the dlist_member_check() can't access
the old block. The best I could come up with is just doing
dlist_push_tail() on the old block on failed realloc(). aset.c
doesn't have this issue as it doesn't use dlist and adjusts the linked
list pointers manually.
* Updated outdated references to the old "Proxy" name, one in comments
and some in typedefs.list
* Fixed incorrect direct use of sizeof(SystemContext) in
SystemContextCheck() (Similar to prior mistake in ProxyReset()).
* Renamed ExternalChunkGetBlock() macro to ChunkGetBlock(). Old name
would lead you to believe some chunks were not external.
* Added BlockGetChunk() and updated 3 places doing manual memory
address calculations.
* Fixed weird calculation of parameter in sentinel_ok() call. (I'm
aware of aset.c, slab.c and generation.c do this too, but it's still
weird)
* Added missing valgrind macros in SystemContextCheck(). Valgrind was
warning about accessing the MemoryChunk fields during the check.
* Adjusted README to mention the large per-chunk header being one
reason why cases that require many allocations aren't a good fit.
* Various comment adjustments.

I spent some time running this under Valgrind, accessing the memory of
a chunk made by SystemContextAlloc() and another after doing
SystemContextRealloc() on a chunk. Valgrind is correctly giving me
warnings when I access the byte before the pointer and when I access
the sentinel byte manually. I don't see any warnings when I access
bytes that are valid to access.

I'm not aware of any other issues.

David

Attachment Content-Type Size
v4-0002-fixup-MemCTX-Add-minimal-system-context-type.patch.txt text/plain 27.7 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Hayato Kuroda (Fujitsu) 2026-10-14 07:30:12 RE: Test publication.sql racing with subscription.sql might fail due to cache lookup error
Previous Message solai v 2026-10-14 07:23:44 Re: addFkRecurseReferencing use unassigned fkconstraint->fk_with_period value