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.94.2) (envelope-from ) id 1uCXQh-00GUfd-JN for pgsql-hackers@arkaria.postgresql.org; Wed, 07 May 2025 05:34:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uCXQg-00BokV-Fs for pgsql-hackers@arkaria.postgresql.org; Wed, 07 May 2025 05:34:50 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uCXQg-00Bojz-5e for pgsql-hackers@lists.postgresql.org; Wed, 07 May 2025 05:34:50 +0000 Received: from bramsgout01.huawei.com ([119.8.89.135]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uCXQc-000Zbp-2H for pgsql-hackers@postgresql.org; Wed, 07 May 2025 05:34:49 +0000 Received: from mail.maildlp.com (unknown [172.18.210.252]) by bramsgout01.huawei.com (SkyGuard) with ESMTPS id 4ZskTg0byPz3NNyy for ; Wed, 7 May 2025 13:34:15 +0800 (CST) Received: from ytopeml500002.china.huawei.com (unknown [7.184.16.163]) by mail.maildlp.com (Postfix) with ESMTPS id 1647314011B for ; Wed, 7 May 2025 13:34:40 +0800 (CST) Received: from ytopeml500001.china.huawei.com (7.184.16.223) by ytopeml500002.china.huawei.com (7.184.16.163) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Wed, 7 May 2025 01:34:37 -0400 Received: from ytopeml500001.china.huawei.com ([7.184.16.223]) by ytopeml500001.china.huawei.com ([7.184.16.223]) with mapi id 15.01.2507.039; Wed, 7 May 2025 01:34:37 -0400 From: Jack Ng To: Dmitry Dolgov <9erthalion6@gmail.com> CC: Ashutosh Bapat , "pgsql-hackers@postgresql.org" , Robert Haas , Ni Ku Subject: RE: Changing shared_buffers without restart Thread-Topic: Changing shared_buffers without restart Thread-Index: AQHbl7DrFzUaSyTydEunWI983IaxOrNc1X6AgGMtZVaABTbmwIAAlRyAgAEig+A= Date: Wed, 7 May 2025 05:34:37 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-CA, zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.48.242.13] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > all the possible scenarios. But now I'm reworking it along the lines sugg= ested > by Thomas, and will address those as well. Thanks! Thanks for the info, Dmitry. Just want to confirm my understanding of Thomas' suggestion and your discus= sions... I think the simpler and more portable solution goes something like= the following?=20 * For each BP resource segment (main, desc, buffers, etc): 1. create an anonymous file as backing 2. mmap a large reserved shared memory area with PROTO_READ/WRITE + MAP= _NORESERVE using the anon fd 3. use ftruncate to back the in-use region (and maybe posix_fallocate t= oo to avoid SIGBUS on alloc failure during first-touch), but no need to cre= ate a memory mapping for it 4. also no need to create a separate mapping for the reserved region (a= lready covered by the mapping created in 2.) |-- Memory mapping (MAP_NORESERVE) for BUFFER --| |-- In-use region --|----- Reserved region -----| * During resize, simply calculate the new size and call ftruncate on each s= egment to adjust memory accordingly, no need to mmap/munmap or modify any m= emory mapping. I tried this approach with a test program (with huge pages), and both expan= d and shrink seem to work as expected --for shrink, the memory is freed rig= ht after the resize ftruncate. Regards, Jack Ng