Improvements and refactoring in shmem.c

From: Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Improvements and refactoring in shmem.c
Date: 2026-01-29 09:56:32
Message-ID: CAExHW5uNRB9oT4pdo54qAo025MXFX4MfYrD9K15OCqe-ExnNvg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi All,

PFA two patches for $subject.

0001: Adds assertions to InitShmemAccess() and InitShmemAllocation
which indicate the conditions, EXEC_BACKEND and IsUnderPostmaster,
these functions are expected to be called. I found these annotations
to be useful when modifying these functions to handle multiple Shmem
segments required by buffer pool resizing project [1].

0002: We use two different methods to pass ShmemIndex and ShmemLock
respectively to new backends even though both the structures are
allocated before creating named structures in the shared memory. This
patch consistently uses the same method - passing via PGShmemHeader.
Further the patch gets rid of InitShmemAllocation and moves that code
inside InitShmemAccess() itself. Maybe that's overkill but at least we
would be able to call InitShmemAllocation() from InitShmemAccess() and
declare first as static within shmem.c. That way we avoid a minor risk
of InitShmemAllocation() being called twice.

We may achieve consistency by passing ShmemIndex through
BackendParameter, but I haven't tried that.

[1] https://www.postgresql.org/message-id/cnthxg2eekacrejyeonuhiaezc7vd7o2uowlsbenxqfkjwgvwj%40qgzu6eoqrglb

--
Best Wishes,
Ashutosh Bapat

Attachment Content-Type Size
v20260129-0001-Clarify-Shmem-access-by-Postmaster-and-sta.patch text/x-patch 1.8 KB
v20260129-0002-Move-shmem-allocation-lock-into-shared-mem.patch text/x-patch 6.2 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Langote 2026-01-29 10:04:17 Re: Batching in executor
Previous Message Dean Rasheed 2026-01-29 09:37:20 Re: ABI Compliance Checker GSoC Project