Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1x6Hw5-0008vl-2V for pgsql-hackers@arkaria.postgresql.org; Tue, 15 Sep 2026 01:26:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1x6Hw5-00GWDg-0Z for pgsql-hackers@arkaria.postgresql.org; Tue, 15 Sep 2026 01:26:13 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1x6Hw4-00GWDY-2w for pgsql-hackers@lists.postgresql.org; Tue, 15 Sep 2026 01:26:12 +0000 Received: from mail-pz2-x24.google.com ([2607:f8b0:4864:3b::24]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1x6Hw2-000000006rJ-0LyP for pgsql-hackers@lists.postgresql.org; Tue, 15 Sep 2026 01:26:11 +0000 Received: by mail-pz2-x24.google.com with SMTP id 41be03b00d2f7-cc4d04d73b8so2077784a12.1 for ; Mon, 14 Sep 2026 18:26:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789435569; x=1790040369; darn=lists.postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:content-type:from:to:cc :subject:date:message-id:reply-to:content-type; bh=98Xdgx+Vht9nfB2S2xm3NpPzD0tOIwHbfRFI5M3wMmU=; b=F2mkFBLzJAcU+Cu3xKi2V36YMD0HKimbuIszV2moyaRooDr69JjHs7MLk71JbP9Vts 1nSmMDAVxSfZGMX1HIuog1LzEq8+sj2A9d5eTbzgiZl7ugZUpp+YCvSMBH06ZizoJHGw LzMUS/Ut885OxjKuqCFF9/8LPZPdoWJPquNfqECA7nYCy2qzB3Q0fF4KEVXPE8omVq3y tlOEQPIHVHPdrRs1zWpUGesXM8o06t0jMfTE2sCuXbfqqdCwKJ7D9Dn75zOFM+gfkor5 CCYr+YDjGgpkLfQgcoe3DPP6woKBx7hfeTXi12IyMVfdlZmiRj4n6mc77D0Cfac+xuCL CfaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789435569; x=1790040369; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:content-type:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=98Xdgx+Vht9nfB2S2xm3NpPzD0tOIwHbfRFI5M3wMmU=; b=Q7l6RsJqOe6de7RbbFUFewa5PBTqon/Xg7BMT0T2rXR1fZBEGhhXL2RUwRu4opZEJ3 GrpkFM7APfWzEiNZVG0i/0QAvfSq9D74bJg1SafQilbcBN8Iru6jgfQ4vqFo5d9rHMRn fAZJHYLfF0lmF40FGQQaxH31RB/vtZ/KcPeb1APOF3JgggHF55p8xF6VeGFSRLPn9aBJ E5mmqvNTd/B1p1Tmi2SJ0NjjH69uJErE4jI4t9jGZV/tqHkW6qr8FKxT2XOw4P28sXBR AgIIG91im3bv7+kTWk7Hu/7GlBRoL0Wh4j9wT9glUSA5OVBKirYsBbXYjhR2HO7UA0Dy 8fDA== X-Gm-Message-State: AFuF++n3fVF18+7j1S/s3X5+EhzwOPsPpr2XkqZKTpXS2+5tM2iffd5c VgThsjkC/T9wBJ1eMa/04DWK89QG+V/ys9YvmyogcPV1q0OdFZkS036E X-Gm-Gg: AYBFou0djWYwd0NYnyJqtpJYv3nKEkdQtf5KzJ7D39sneXqB7pFkkptFlWELjKCMegp 30A8N355lt1OwFENJR7dCjzLMRl+Qmbo2TM251AidWmiBRbqcA0oTMzImNv9rG3vxlmObYKGDva IfBNw8cxpfzYIw2s8OCakfjH7UtgyyWZLho7zg11mlJvKsPb/nbd1+yUPFP6OcyGaK2Mfja8XGW 57UGoPMWHWoo7MOGYoJokQ3r9ne6nRb8FaiLZGitzhqW0WevPeRCynHr/ISsD0LcEqRbSlucemx g1AUKRlz9v2RFfbBDs/u6rOC2wz39Tjv9vvOsw0wcf9cT36Sbosjnf2lmdaxoxG9PZz68Lkgt+W Q0Tjmy7cH9SRADKZYHCs3sNkNQYaz12qgSq1rfMvWbD0GuW+gQFu7T8/uZWvLerF77ELsbwECyI dQ3u7+Maku/slb1JN4QUc7/ntA4slz3UcPgBYPLcPUGn5TbTD02JY68xugL7RdlEiaQP1X/nEse OEfmbUG X-Received: by 2002:a17:90b:5784:b0:39d:f7dc:61e4 with SMTP id 98e67ed59e1d1-39df7dc6273mr5955122a91.9.1789435568875; Mon, 14 Sep 2026 18:26:08 -0700 (PDT) Received: from smtpclient.apple ([185.135.79.161]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39dfda24dcbsm1926974a91.5.2026.09.14.18.26.07 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Sep 2026 18:26:08 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.700.51.1.1\)) Subject: Re: Fix unnecessary shared memory page allocation in CalculateShmemSize() From: Chao Li In-Reply-To: Date: Tue, 15 Sep 2026 09:25:33 +0800 Cc: pgsql-hackers Content-Transfer-Encoding: quoted-printable Message-Id: <88D043BA-2198-44E8-B9B6-D45DF6B5A76A@gmail.com> References: To: Nathan Bossart X-Mailer: Apple Mail (2.3864.700.51.1.1) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Sep 14, 2026, at 21:48, Nathan Bossart = wrote: >=20 > 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 =3D add_size(size, 8192 - (size % 8192)); >> ``` >>=20 >> 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 !=3D 0) >> /* might as well round it off to a multiple of a typical page size */ >> size =3D add_size(size, 8192 - (size % 8192)); >> ``` >=20 > IMHO the current code is fine and is unlikely to cause problems for = users. >=20 > --=20 > 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/