public inbox for [email protected]  
help / color / mirror / Atom feed
From: Heikki Linnakangas <[email protected]>
To: Matthias van de Meent <[email protected]>
Cc: Ashutosh Bapat <[email protected]>
Cc: Robert Haas <[email protected]>
Cc: Andres Freund <[email protected]>
Cc: pgsql-hackers <[email protected]>
Cc: [email protected]
Subject: Re: Better shared data structure management and resizable shared data structures
Date: Sun, 5 Apr 2026 18:50:11 +0300
Message-ID: <[email protected]> (raw)
In-Reply-To: <CAEze2WjgCROMMXY0+j8FFdm3iFcr7By-+6Mwiz=PgGSEydiW3A@mail.gmail.com>
References: <CAExHW5vM1bneLYfg0wGeAa=52UiJ3z4vKd3AJ72X8Fw6k3KKrg@mail.gmail.com>
	<[email protected]>
	<CAExHW5uTNWOSxJDWQAUnS0tZawob2_J3dRAtc67NHNZ98X4_xA@mail.gmail.com>
	<CAExHW5t439y61YD9bc7d5wZWHp6J=M43Qu3eEZOBPguZML7o2A@mail.gmail.com>
	<CAExHW5v5FVZbsO9sLzztMZ11C3hgGStE=HkkV2bQkCyncess4w@mail.gmail.com>
	<[email protected]>
	<CAExHW5tCC0T1ky=Jnq-AvMxa67Adaw7aQ4iQAO=BSdHcbSNBVg@mail.gmail.com>
	<[email protected]>
	<CAExHW5tS7GncN90oJWOSzW_3F1EHL9xwe59L7Req3nUVgmObUw@mail.gmail.com>
	<[email protected]>
	<CAEze2WhMOHVgH2Xeyzx=VEk-Ta_YnQUqT+TdBiv5Lx8ESn2WZA@mail.gmail.com>
	<CAExHW5s6h=c_q2m72Nvyj1ghMEhPkOBkeN5Htn7YR=1BrNN-Sw@mail.gmail.com>
	<[email protected]>
	<CAEze2WjQZff3znd6CtG-OBzYZMMqy5TyQSoAo=QTFT38tDndeQ@mail.gmail.com>
	<[email protected]>
	<CAEze2WjgCROMMXY0+j8FFdm3iFcr7By-+6Mwiz=PgGSEydiW3A@mail.gmail.com>

On 05/04/2026 02:17, Matthias van de Meent wrote:
>> +    pgss->extent = 0;
>> +    pgss->n_writers = 0;
>> +    pgss->gc_count = 0;
>> +    pgss->stats.dealloc = 0;
> 
> Shmem is said to be zero-initialized, should we remove the manual
> zero-initialization?

Yeah, perhaps. We already had initialization like this in many places, 
while others relied on the implicit initialization. Some places even do 
just this:

void
LogicalDecodingCtlShmemInit(void)
{
	bool		found;

	LogicalDecodingCtl = ShmemInitStruct("Logical decoding control",
										 LogicalDecodingCtlShmemSize(),
										 &found);

	if (!found)
		MemSet(LogicalDecodingCtl, 0, LogicalDecodingCtlShmemSize());
}

I think there are two directions we could go here:

1. Document that the memory is zeroed, and you can rely on it. Remove 
silly initializations like that in LogicalDecodingCtlShmemInit(). In 
other places the explicitly zero-initialization might have documentation 
value though.

2. Require the init functions to explicitly zero the memory. Document it 
and add valgrind checks.

I'm inclined to go with 1. But in the name of avoiding scope creep, not 
as part of these patches.

- Heikki






view thread (82+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
  Subject: Re: Better shared data structure management and resizable shared data structures
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox