pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Chao Li <li.evan.chao@gmail.com>
To: Nathan Bossart <nathandbossart@gmail.com>
Cc: pgsql-hackers <pgsql-hackers@lists.postgresql.org>
Subject: Re: Fix unnecessary shared memory page allocation in CalculateShmemSize()
Date: Tue, 15 Sep 2026 09:25:33 +0800
Message-ID: <88D043BA-2198-44E8-B9B6-D45DF6B5A76A@gmail.com> (raw)
In-Reply-To: <aqf7JjCW2aGozCq8@nathan>
References: <F132EBB6-47EB-4DF8-8C8D-3DE698265A2B@gmail.com>
	<aqf7JjCW2aGozCq8@nathan>



> On Sep 14, 2026, at 21:48, Nathan Bossart <nathandbossart@gmail.com> wrote:
> 
> On Mon, Sep 14, 2026 at 03:19:03PM +0800, Chao Li wrote:
>> This is a small issue, but it has been there for many years.
>> CalculateShmemSize() has logic to round size to a multiple of a typical
>> page size:
>> ```
>> /* might as well round it off to a multiple of a typical page size */
>> size = add_size(size, 8192 - (size % 8192));
>> ```
>> 
>> When size is already a multiple of 8192, this add_size() call is not
>> needed; it only results in an extra 8192 bytes being allocated in shared
>> memory. The fix is simple:
>> ```
>> if (size % 8192 != 0)
>> /* might as well round it off to a multiple of a typical page size */
>> size = add_size(size, 8192 - (size % 8192));
>> ```
> 
> IMHO the current code is fine and is unlikely to cause problems for users.
> 
> -- 
> nathan

I agree. Given the 100 KB added to the requested size, it should be extremely rare for this issue to be triggered. Even if it is, only an extra 8192 bytes are allocated, so users are unlikely to notice.

Still, it is a potential issue. It might not be worth back-patching, how about fixing it only on master?

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/










view thread (7+ messages)

Message-ID: <88D043BA-2198-44E8-B9B6-D45DF6B5A76A@gmail.com>
Permalink:  ../88D043BA-2198-44E8-B9B6-D45DF6B5A76A@gmail.com/
Also on:    postgresql.org/message-id/88D043BA-2198-44E8-B9B6-D45DF6B5A76A@gmail.com

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: li.evan.chao@gmail.com, nathandbossart@gmail.com
  Subject: Re: Fix unnecessary shared memory page allocation in CalculateShmemSize()
  In-Reply-To: <88D043BA-2198-44E8-B9B6-D45DF6B5A76A@gmail.com>
  References: <F132EBB6-47EB-4DF8-8C8D-3DE698265A2B@gmail.com> <aqf7JjCW2aGozCq8@nathan> <88D043BA-2198-44E8-B9B6-D45DF6B5A76A@gmail.com>

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

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