Subject: Re: Release postmaster working memory context in slotsync worker

From: Tom Lane <[email-masked]>
Date: Fri, 27 Feb 2026 12:58:47 -0500

Andres Freund <[email-masked]> writes:
> On 2026-02-28 01:25:12 +0900, Fujii Masao wrote:
>> Child processes do not need the postmaster's working memory context and
>> release it at the start of their main function. However, the slotsync worker
>> appears to have missed this step.

> Obviously this inconsistency is not good.  However:
> I think we should consider *not* releasing postmaster memory. Freeing the
> memory actually can lead to an *increase* in memory usage and a slight
> *decrease* in connection startup performance. The reason for that is that with
> fork, memory allocated in postmaster is handled by copy-on-write in the
> children.

Meh.  I think that's optimizing for the wrong thing.  To my mind the
point of releasing that context is to be sure that child processes
don't have access to postmaster-private data.  Admittedly, we're not
doing anything as drastic as zeroing out the memory, but it'll soon
be overwritten as the child starts up and populates its caches.

			regards, tom lane

---

From: Fujii Masao <[email-masked]>
Date: Wed, 18 Mar 2026 15:31:23 +0900

On Sat, Feb 28, 2026 at 2:58 AM Tom Lane <[email-masked]> wrote:
> don't have access to postmaster-private data.

Okay, I've included this point in the commit message of the patch.

> Admittedly, we're not

Yes.

Attached is a rebased version of the patch. I'm thinking to commit it.

Regards,

-- 
Fujii Masao

---

From: Fujii Masao <[email-masked]>
Date: Mon, 6 Apr 2026 23:09:49 +0900

On Thu, Mar 19, 2026 at 5:16 PM Chao Li <[email-masked]> wrote:
> Still, the current phrasing seems a bit too strong to me. Strictly speaking, the memory is already inherited at fork time, so this is not making access impossible in an absolute sense. What this patch really does is remove the inherited PostmasterContext, so the child no longer retains that postmaster-private data through that context.
>
> Maybe we could phrase in some way like: "so that it no longer retains access to postmaster-private data through PostmasterContext”.

Thanks for the review! I've pushed the patch.
Per your and Tiancheng's suggestions, I just used "prevent unintended use"
in the commit message.

Regards,

-- 
Fujii Masao