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 1x60ye-000Q7o-0J for pgsql-hackers@arkaria.postgresql.org; Mon, 14 Sep 2026 07:19:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1x60yd-00Bnes-2H for pgsql-hackers@arkaria.postgresql.org; Mon, 14 Sep 2026 07:19:43 +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 1x60yd-00Bnej-1K for pgsql-hackers@lists.postgresql.org; Mon, 14 Sep 2026 07:19:43 +0000 Received: from mail-pj2-x11.google.com ([2607:f8b0:4864:39::11]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1x60yb-00000000IWV-20yI for pgsql-hackers@lists.postgresql.org; Mon, 14 Sep 2026 07:19:42 +0000 Received: by mail-pj2-x11.google.com with SMTP id 98e67ed59e1d1-396ccc09d65so1638762a91.3 for ; Mon, 14 Sep 2026 00:19:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789370379; x=1789975179; darn=lists.postgresql.org; h=to:date:message-id:subject:mime-version:content-type:from:from:to :cc:subject:date:message-id:reply-to:content-type; bh=GPB73doweZfmcxUiZSbr4CJl1W+2g2TKM7edNLczGlA=; b=R33cFczu/9fy/Id/fYcK/DHs5bcDICxmyH2QARlldcXsGFpTOW0g5WFM+yCgDsfDpa scuKoyZVUWOJguul9VP2uFTAqGmzXpqpdCQUFGB8rGenKtYz03z9CV06EcBMcwttWqGv LRhQWgnjLrAx5VUtsILXNww+OV8HtG1sNDk60xk3BD4zMAyqDb0Fw6TJ24rUSWgZCeRs CvYi4+asQRtRF4kpHmONOqgpcG9MZPTY9Fg2urU2qWs1RVREvVOLJMCsz3xwYmTh++UZ N+IlAgCqAHT3YZ+Nib50pujLr4yZwNJKukzr8OVOOntrIIV7/6bwze5pYeYaVMeTdBMT T67A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789370380; x=1789975180; h=to:date:message-id:subject:mime-version:content-type:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=GPB73doweZfmcxUiZSbr4CJl1W+2g2TKM7edNLczGlA=; b=Sz6dTdttubIUlt8nqn7d/OfpXYTiDakPeYH/sJKhXZISH13VvqL+LT+Ur/T1ck5Hca IGycBtBJNnzRnTXLSbEZL4S2hLnvu4t7oqPhzWF1IQCGWVia0c6MC+ZZ1KMGpl4clhZd lzftYJcbtmfo8yabQTO66dlgdx2pARQ58ZZ52gzc24+DFChk17P8Ri6UufSiT6Zb/NOj +5xbIFPNczKtrzbFezd0DyDxLv1v8sd4KkNskSSwzcroi//ZAYfhCAyoE6Y/1bl6E/Qe WLjlshgfeXHOHWesbJU0fsLqIzDJ01rKbYE+eMRFG/rhm9aEALuJvRa/+RLpWMyj127u JA9A== X-Gm-Message-State: AFuF++l3euTkqCL43N19f2HJR9VnO2RYzX1mTanTGvzZL5wiBWiCubes CX20xTWn/DnZZy1+zsZNZF5/Jw+sXAWEz8dfCjQLrKhaxU2hBdUgoMLVspT8OhgJ X-Gm-Gg: AYBFou12DnQevIm3G6z95WbbThe7IjmgK6f94H4D+vV0un+dnKC1DVoMcNwkdKyFTfp d3n0IhJ0bkX+3j7ZXWLwH5tHfbDTP1TwdEZypR5KpCk1x9h7IRsZmQmeB7fHkXQpxWv9uaQzYKV 3xtP1VwFCHVM5kYs9ZJjy/tytyzaOB9i3trDjS19bB2xpSWxiniX3Xi+4LSZ+IXLJpm5l4YYQHS Vu2qERPnMNrCbrlb4oBoa0mcRDZcNSIwk636XXILLMxeX0ZUn2z5vfd0vkt5PjrNKrGRrUoAh7M ITJVigzkN3GiMCiooMghVgvhAVZS4eaeTXoKTlDg5/lLtj87HmGVzQA3SHcpXjYV+0pXVsMcZHO nMibNgt9yVPD0zH/ZjFWq4Bdl+m+xBjvLofBFx9y94tKy93UbHhsKD62EfNh0OY9PyZA/mbeWu7 G0CS90NAQxkAkNIELzCxt/SGx106qZO4tZSQmMkDO6SCchkUq27qcQ0mYstnNn9JQuDuYYlmVVA 1+rSqTv X-Received: by 2002:a17:90b:2c88:b0:398:e969:87ef with SMTP id 98e67ed59e1d1-39dec0f773fmr3119857a91.24.1789370379484; Mon, 14 Sep 2026 00:19:39 -0700 (PDT) Received: from smtpclient.apple ([185.135.79.125]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39d994cc978sm19298192a91.9.2026.09.14.00.19.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Sep 2026 00:19:38 -0700 (PDT) From: Chao Li Content-Type: multipart/mixed; boundary="Apple-Mail=_021F9626-A4CB-42DC-AE30-0D0412313A78" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.700.51.1.1\)) Subject: Fix unnecessary shared memory page allocation in CalculateShmemSize() Message-Id: Date: Mon, 14 Sep 2026 15:19:03 +0800 To: pgsql-hackers 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 --Apple-Mail=_021F9626-A4CB-42DC-AE30-0D0412313A78 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Hi, I just noticed this item when I went through my TODO list today. I = remember finding this issue a few months ago, but at that time, only = bugs new to PG19 were being processed, so I put it on my TODO list. 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)); ``` 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)); ``` I put the comment within the if clause because I remember Tom once = mentioning that this would be the preferred style. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/ --Apple-Mail=_021F9626-A4CB-42DC-AE30-0D0412313A78 Content-Disposition: attachment; filename=v1-0001-Avoid-extra-shared-memory-page-in-CalculateShmemS.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="v1-0001-Avoid-extra-shared-memory-page-in-CalculateShmemS.patch" Content-Transfer-Encoding: quoted-printable =46rom=20a1023326b5895f2820424f96612c2fd945d5f424=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20"Chao=20Li=20(Evan)"=20=0A= Date:=20Mon,=2014=20Sep=202026=2015:16:20=20+0800=0ASubject:=20[PATCH=20= v1]=20Avoid=20extra=20shared-memory=20page=20in=20CalculateShmemSize()=0A= =0ACalculateShmemSize()=20rounds=20the=20requested=20shared-memory=20= size=20up=20to=20a=0Amultiple=20of=208192=20bytes.=20When=20the=20size=20= is=20already=20aligned,=20however,=20the=0Acalculation=20adds=20another=20= 8192=20bytes=20unnecessarily.=0A=0AOnly=20add=20the=20padding=20when=20= the=20size=20is=20not=20already=20a=20multiple=20of=208192.=0A=0AAuthor:=20= Chao=20Li=20=0A---=0A=20src/backend/storage/ipc/ipci.c=20= |=205=20+++--=0A=201=20file=20changed,=203=20insertions(+),=202=20= deletions(-)=0A=0Adiff=20--git=20a/src/backend/storage/ipc/ipci.c=20= b/src/backend/storage/ipc/ipci.c=0Aindex=20e149a738c8d..3a221b88f37=20= 100644=0A---=20a/src/backend/storage/ipc/ipci.c=0A+++=20= b/src/backend/storage/ipc/ipci.c=0A@@=20-73,8=20+73,9=20@@=20= CalculateShmemSize(void)=0A=20=09/*=20include=20additional=20requested=20= shmem=20from=20preload=20libraries=20*/=0A=20=09size=20=3D=20= add_size(size,=20total_addin_request);=0A=20=0A-=09/*=20might=20as=20= well=20round=20it=20off=20to=20a=20multiple=20of=20a=20typical=20page=20= size=20*/=0A-=09size=20=3D=20add_size(size,=208192=20-=20(size=20%=20= 8192));=0A+=09if=20(size=20%=208192=20!=3D=200)=0A+=09=09/*=20might=20as=20= well=20round=20it=20off=20to=20a=20multiple=20of=20a=20typical=20page=20= size=20*/=0A+=09=09size=20=3D=20add_size(size,=208192=20-=20(size=20%=20= 8192));=0A=20=0A=20=09return=20size;=0A=20}=0A--=20=0A2.50.1=20(Apple=20= Git-155)=0A=0A= --Apple-Mail=_021F9626-A4CB-42DC-AE30-0D0412313A78--