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 1uZtFd-009bcn-Fa for pgsql-hackers@arkaria.postgresql.org; Thu, 10 Jul 2025 15:31:57 +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 1uZtFb-00ECvj-3Q for pgsql-hackers@arkaria.postgresql.org; Thu, 10 Jul 2025 15:31:55 +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 1uZtFa-00ECuJ-Ph for pgsql-hackers@lists.postgresql.org; Thu, 10 Jul 2025 15:31:55 +0000 Received: from relay2-d.mail.gandi.net ([2001:4b98:dc4:8::222]) by makus.postgresql.org with smtp (Exim 4.96) (envelope-from ) id 1uZtFZ-006b4Z-1H for pgsql-hackers@lists.postgresql.org; Thu, 10 Jul 2025 15:31:54 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id A244F430B7; Thu, 10 Jul 2025 15:31:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vondra.me; s=gm1; t=1752161509; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NxVV4FAbMj1VEpm13AmV5efOQCXa5lMvmDDGigVvyJw=; b=Miq1iN3iq9KyQlN+w80ztwE49jPTQViRogQPdeGop+XDiMqrhXV7FY6cJ5eHK8zuYv4PD8 jyIeb04RspJk5SbTJ4LfUrGI8Eqsfs12dUin5UpckwExmx08EP4YtvfXqw4hTwm+958Gp/ 4S9xCfJzOM6yGXk8JoJkDxdCrUcBR38y/2QPePuep2fDo3jSF2LsQN4JZdSb2Ung7UAex6 pLC1W/fHMWDwkfMSYuewmxRWcI4yWfP1Zr61EHwT240wG+nhIS/1wJYdU6xy1+XJVOml7d +K98Idu0T3TYTnPRv9ORpwWHxgb6Z5nMlTtg57KX0SjRomGbYZBFTA7dthMbig== Message-ID: Date: Thu, 10 Jul 2025 17:31:45 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Adding basic NUMA awareness To: Andres Freund , Greg Burd Cc: Ashutosh Bapat , PostgreSQL Hackers , Dmitry Dolgov <9erthalion6@gmail.com> References: Content-Language: en-US From: Tomas Vondra In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdegtdekudcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhepkfffgggfuffvvehfhfgjtgfgsehtjeertddtvdejnecuhfhrohhmpefvohhmrghsucggohhnughrrgcuoehtohhmrghssehvohhnughrrgdrmhgvqeenucggtffrrghtthgvrhhnpeeludegieekgfelhffgffeuvdelteetveeghfdvieekfeduudduvdfhvedufefhveenucfkphepkeeirdegledrvdeftddrvddtieenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeekiedrgeelrddvfedtrddvtdeipdhhvghloheplgdutddrudefjedrtddrvdgnpdhmrghilhhfrhhomhepthhomhgrshesvhhonhgurhgrrdhmvgdpnhgspghrtghpthhtohephedprhgtphhtthhopegrnhgurhgvshesrghnrghrrgiivghlrdguvgdprhgtphhtthhopehgrhgvghessghurhgurdhmvgdprhgtphhtthhopegrshhhuhhtohhshhdrsggrphgrthdrohhsshesghhmrghilhdrtghomhdprhgtphhtthhopehpghhsqhhlqdhhrggtkhgvrhhssehlihhsthhsrdhpohhsthhgrhgvshhqlhdrohhrghdprhgtphhtthhopeelvghrthhhrghlihhonheisehgmhgrihhlrdgtohhm X-GND-Sasl: tomas@vondra.me List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 7/9/25 19:23, Andres Freund wrote: > Hi, > > On 2025-07-09 12:55:51 -0400, Greg Burd wrote: >> On Jul 9 2025, at 12:35 pm, Andres Freund wrote: >> >>> FWIW, I've started to wonder if we shouldn't just get rid of the freelist >>> entirely. While clocksweep is perhaps minutely slower in a single >>> thread than >>> the freelist, clock sweep scales *considerably* better [1]. As it's rather >>> rare to be bottlenecked on clock sweep speed for a single thread >>> (rather then >>> IO or memory copy overhead), I think it's worth favoring clock sweep. >> >> Hey Andres, thanks for spending time on this. I've worked before on >> freelist implementations (last one in LMDB) and I think you're onto >> something. I think it's an innovative idea and that the speed >> difference will either be lost in the noise or potentially entirely >> mitigated by avoiding duplicate work. > > Agreed. FWIW, just using clock sweep actually makes things like DROP TABLE > perform better because it doesn't need to maintain the freelist anymore... > > >>> Also needing to switch between getting buffers from the freelist and >>> the sweep >>> makes the code more expensive. I think just having the buffer in the sweep, >>> with a refcount / usagecount of zero would suffice. >> >> If you're not already coding this, I'll jump in. :) > > My experimental patch is literally a four character addition ;), namely adding > "0 &&" to the relevant code in StrategyGetBuffer(). > > Obviously a real patch would need to do some more work than that. Feel free > to take on that project, I am not planning on tackling that in near term. > > > There's other things around this that could use some attention. It's not hard > to see clock sweep be a bottleneck in concurrent workloads - partially due to > the shared maintenance of the clock hand. A NUMAed clock sweep would address > that. However, we also maintain StrategyControl->numBufferAllocs, which is a > significant contention point and would not necessarily be removed by a > NUMAificiation of the clock sweep. > Wouldn't it make sense to partition the numBufferAllocs too, though? I don't remember if my hacky experimental patch NUMA-partitioning did that or I just thought about doing that, but why wouldn't that be enough? Places that need the "total" count would have to sum the counters, but it seemed to me most of the places would be fine with the "local" count for that partition. If we also make sure to "sync" the clocksweeps so as to not work on just a single partition, that might be enough ... regards -- Tomas Vondra