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 1ubKph-00H2Xd-AO for pgsql-hackers@arkaria.postgresql.org; Mon, 14 Jul 2025 15:11:09 +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 1ubKpd-0098fF-6K for pgsql-hackers@arkaria.postgresql.org; Mon, 14 Jul 2025 15:11:05 +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.94.2) (envelope-from ) id 1ubKpc-0098f6-MB for pgsql-hackers@lists.postgresql.org; Mon, 14 Jul 2025 15:11:05 +0000 Received: from bramsgout03.huawei.com ([119.8.89.137]) by makus.postgresql.org with smtp (Exim 4.96) (envelope-from ) id 1ubKpW-007Fqf-2i for pgsql-hackers@postgresql.org; Mon, 14 Jul 2025 15:11:01 +0000 dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=PmUIw5BE6FWwJcf71FTiC6AjJkhr+G6p2ui/aie4OKM=; b=1bmW+LgQkWKuUkQPZg/vUfTtZWvp/2UEvuzPmOwzJQwiAeLZQUSo2u8RZrHlqYDK/dW8USaOr yGkhXLKQKWcPMkYEO/PhAISWsDlHhykRZoGEuAEiVNyupV/5NFpj8CpXFkXJgABjAAWCpWuIbAg dbtoqBftDhtmIYSKOygLiCk= Received: from mail.maildlp.com (unknown [172.18.210.252]) by bramsgout03.huawei.com (SkyGuard) with ESMTPS id 4bgm295pLLz1msdX; Mon, 14 Jul 2025 23:09:37 +0800 (CST) Received: from ytopeml100001.china.huawei.com (unknown [7.184.17.227]) by mail.maildlp.com (Postfix) with ESMTPS id 3CD52140275; Mon, 14 Jul 2025 23:10:52 +0800 (CST) Received: from ytopeml500001.china.huawei.com (7.184.16.223) by ytopeml100001.china.huawei.com (7.184.17.227) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Mon, 14 Jul 2025 11:10:50 -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; Mon, 14 Jul 2025 11:10:50 -0400 From: Jack Ng To: Andres Freund , Dmitry Dolgov <9erthalion6@gmail.com> CC: Thom Brown , Ashutosh Bapat , Tomas Vondra , Thomas Munro , PostgreSQL-development , Ni Ku Subject: RE: Changing shared_buffers without restart Thread-Topic: Changing shared_buffers without restart Thread-Index: AQHb4czjArbykOnCnUaEQCqOWcY4q7QfGxSAgAJTTACAAPSigIADCKUAgAAFeACAC1ixAIAArMiAgAA2XgCAAARBgIAACBkAgAAIcACAAAIegIAAOSQAgAADOQCAAAGrAIAAAZKAgAAGWACAAAVUAIAABgaA///AHlA= Date: Mon, 14 Jul 2025 15:10:50 +0000 Message-ID: <39b5afc524174c8a8fa6ef058676a596@huawei.com> 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.218.176.22] 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 If I understanding correctly, putting a new buffer in the freelist before u= pdating NBuffers could break existing logic that calls BufferIsValid(bufnum= ) and asserts bufnum <=3D NBuffers? (since a backend can grab the new buffe= r and checks its validity before the coordinator can add it to the freelist= .) But it seems updating NBuffers before adding new elements to the freelist c= ould be problematic too? Like if a new buffer is already chosen as a victi= m and then the coordinator adds it to the freelist, would that lead to "dou= ble-use"? (seems possible at least with current logic and serialization in = StrategyGetBuffer). If that's a valid concern, would something like this wo= rk? 1) initialize buffer headers, with a new state/flag to indicate "add-pendin= g" 2) update NBuffers -- add a check in clock-sweep logic for "add-pending" and skip them 3) put them onto the freelist 4) when a new element is grabbed from freelist, check for and reset add-pen= ding flag.=20 This ensure the new element is always obtained from the freelist first I th= ink. Jack >-----Original Message----- >From: Andres Freund >Sent: Monday, July 14, 2025 10:23 AM >To: Dmitry Dolgov <9erthalion6@gmail.com> >Cc: Thom Brown ; Ashutosh Bapat >; Tomas Vondra ; >Thomas Munro ; PostgreSQL-development hackers@postgresql.org>; Jack Ng ; Ni Ku > >Subject: Re: Changing shared_buffers without restart > >Hi, > >On 2025-07-14 16:01:50 +0200, Dmitry Dolgov wrote: >> > On Mon, Jul 14, 2025 at 09:42:46AM -0400, Andres Freund wrote: >> > What on earth would be the point of putting a buffer on the freelist >> > but not make it reachable by the clock sweep? To me that's just nonsen= sical. >> >> To clarify, we're not talking about this scenario as "that's how it >> would work after the resize". The point is that to expand shared >> buffers they need to be initialized, included into the whole buffer >> machinery (freelist, clock sweep, etc.) and NBuffers has to be updated. > >It seems pretty obvious to that the order has to be > >1) initialize buffer headers >2) update NBuffers >3) put them onto the freelist > >(with 3) hopefully becoming obsolete) > > >> Those steps are separated in time, and I'm currently trying to >> understand what are the consequences of performing them in different >> order and whether there are possible concurrency issues under various >> scenarios. Does this make more sense, or still not? > >I still don't understand why it'd ever make sense to put a buffer onto the= freelist >before updating NBuffers first. > >Greetings, > >Andres Freund