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 1x672s-0002G9-0H for pgsql-hackers@arkaria.postgresql.org; Mon, 14 Sep 2026 13:48:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1x672r-00DDzP-0m for pgsql-hackers@arkaria.postgresql.org; Mon, 14 Sep 2026 13:48:29 +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 1x672q-00DDv3-2l for pgsql-hackers@lists.postgresql.org; Mon, 14 Sep 2026 13:48:28 +0000 Received: from mail-qk1-x729.google.com ([2607:f8b0:4864:20::729]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1x672p-000000001Wm-185E for pgsql-hackers@lists.postgresql.org; Mon, 14 Sep 2026 13:48:27 +0000 Received: by mail-qk1-x729.google.com with SMTP id af79cd13be357-936623c6dd3so448905685a.0 for ; Mon, 14 Sep 2026 06:48:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789393706; x=1789998506; darn=lists.postgresql.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=z6nxbC+vAhdCOS8N64ww54ilsEd+CMXY78j1JBVow4Y=; b=b7MPw/Mm0vR8elH+67i/0M4ARxvEAAjkkBZs7ZgewGOgp30d10e3jrPhFFqM/zMvk7 ZX9owl6Icy/n5vFtZFB1tkf7WFDqU7F+PFh3d+JMSKCQFkncMVLeHOmAt3I0ANbno1XL LM0xMo/IG0PLxwgCSgfC1y4M25nkNuTIrluvQQ6BxNshypJnBSQc2CDa9hnm76swNCEi oTZCM4ncnweQ8h3odkNrUE+TdkIyevC1GQDjMpv68oIDwj/gkdQ+CGeKOV0W3nm+KOP+ teKP83/uK9JNaoLf4CeydHkDme2Kr0XGwqc24yWk6HDffjHsoDdSyT4OPisojnJpeWD+ 5Qww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789393706; x=1789998506; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=z6nxbC+vAhdCOS8N64ww54ilsEd+CMXY78j1JBVow4Y=; b=P3116rxtUCWmFPSNC3f0v1uRfkJ/i0/2/zZ5PA+QRz5jUt3Q/mzDsuOxOPTXbr+Ayf ONztdtjUZfXbV1tE0ORQ1T0501LZsc5ukpWi0bVmbEUDbrLh03tY/aVhW3Wi8Djf19B5 t4IpJ8XkFNGKER7EhjDnmGRxT9ovcMGvswvl8rrSPhSKQbeMVJo7M6AY8syDH/5zI07o MZJ9RwaPhd3FRWIGmZ0O9c2uKDHC5kuXrzOnrPcHM8SXvQ+tCmBW20edwHJNAZeQ1hgK 2Z+iuR0sBODnWAUyNMIVjQ1ChAcj6BHLxojRb9z+BpM6Lo83hOmWo+VE3lynKoPO0Gzq /7Ig== X-Gm-Message-State: AFuF++krs8LRsD7Yoo/PKEvIp3j0RP1/dGJzs5giJZvzngSQqwHCplQA jbb1PRrPGupWrsMmJVZEiND0I58X5L1MbSzRNEAkAOag6hwWqCR1C0oO X-Gm-Gg: AYBFou1VB2FjzLNui4G85yaKwsGFN4Z+RDBfiX45RPB5+ad2DoMFHCQPgZS5Rex5ncQ c5lmFXfdEwYmTQ2EIzxUNmItdYB9zOFC5Zhi07SZJpdmAuh20iMtCUnSKP2mHMk70c1lQbJ6UJN AMDwmeVd2MnjsbpK/irUEHiUXsl7wZ90pyVOZJWU/BViqwyZa+oXn/HueqT7QrH2AlbbcRpcWbE CfM9As6mkfsJ4nZlMf+DINbYksOUjzTb1D61al2iFA3JQGcDPRoADULI4ziTx87vdZQTmVhpDBz vd3iI8aN0QMvGK+OEa89JOaX25toOGI1EmUUS9VSn+/pa03DibipVC0qbJ1o56FXKTNfBtdw5oP fwoQ+r4GMoQwYr1Eqtie2SVDr4WTKuW0JTtIPx+SMio1VPiY7bja9RRVqLdbaQcv9Jy1rdlSlW+ +ylrBMItdBds5pRwpTmOPy5M/f8bnFGDHmCBGi3Xp5xubtROxJJFBnkJtMdM9Vrr5puL6EE+f/v Q0rzd3JPiVxpXrfUDoSOg884zuMq5QcEyUCou1fvoxzgGtxBfZGlVVYrIlL44aya9ZgrFxxdCgO I+YhGliMvk57r5y/fXW4Zv8qVAQ= X-Received: by 2002:a05:620a:40d1:b0:939:f861:8836 with SMTP id af79cd13be357-93a18601143mr643061085a.20.1789393706046; Mon, 14 Sep 2026 06:48:26 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-9120f4b699bsm95832396d6.37.2026.09.14.06.48.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Sep 2026 06:48:24 -0700 (PDT) Date: Mon, 14 Sep 2026 08:48:22 -0500 From: Nathan Bossart To: Chao Li Cc: pgsql-hackers Subject: Re: Fix unnecessary shared memory page allocation in CalculateShmemSize() Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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