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 1vWHgL-00GXIX-1D for pgsql-hackers@arkaria.postgresql.org; Thu, 18 Dec 2025 17:20:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vWHgK-0038VZ-10 for pgsql-hackers@arkaria.postgresql.org; Thu, 18 Dec 2025 17:20:53 +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.96) (envelope-from ) id 1vWHgJ-0038VQ-30 for pgsql-hackers@lists.postgresql.org; Thu, 18 Dec 2025 17:20:52 +0000 Received: from lahtoruutu.iki.fi ([185.185.170.37]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vWHgI-001Ru7-1L for pgsql-hackers@postgresql.org; Thu, 18 Dec 2025 17:20:52 +0000 Received: from [10.0.2.15] (unknown [130.41.208.2]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: hlinnaka) by lahtoruutu.iki.fi (Postfix) with ESMTPSA id 4dXHW05B2rz49PvR; Thu, 18 Dec 2025 19:20:44 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1766078445; 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=z/M1glTj/gbwgG9TPMPXqWTn+G4UiWVmXiUH3asmpVA=; b=X01oGOYtCZC1Q3vX5CnY5yRIBCv2ARUUf8J+kacTzmJJNeOXgS+NcnymuX0RPhh5k4XeBT T7x5zMswazKH4Yw82D/IBaWMvYhzoaop3n0twcKdVJ+tv5Sf5WCPi6/lubAxjaeauu4Xud MwOo1eRFAQMRS1eEWjJYAUz0vQmZpvXR3FAr9zAPCzSMBAL7O0qMFXSRWT0JijIWRRSse+ /IYrXV50BEZT8e/WyrGdEswp672KYGStRYaJvdI0ykX/UowwWMC0otJk0tb+WmXFeSg6jr 4jWy6V8NFA84XrLA7SVRU99qNOMN/Qt/IAKGihYmiH58Ppi4HYr0ZIxtkS3igQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1766078445; 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=z/M1glTj/gbwgG9TPMPXqWTn+G4UiWVmXiUH3asmpVA=; b=qY3pi2avsYb3l22t+IS11CHca1hIMySy6w0rd/2SpCs7F59u/99G5CZ5J6IrgGJ7BM32nG Px6W7kZr2C/sjpzFhBz2D9TJQCUUddS0INLCTSVeKx58tgMbzCGsaUdVbBSTrsSvrXFEyO WdrQPE1SwPVX+ylZuW1t2v8ihFXA0mN7sB4L/zTR88IdJfMfavCFuAlMI3SyKql8RecJNO L5u/nvbW4++OF03xVQ7TSKlay/mpAwEUFZfrDVsDUK1fAH2Hsar1+QaoXTMJ9izZoSfXWo Zgv3wcpZGw02/KPXV6RoMLiQGydcu2MI97a/pcZJyckH5D3KwWb3P/rH6oXCBg== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi ARC-Seal: i=1; a=rsa-sha256; d=iki.fi; s=lahtoruutu; cv=none; t=1766078445; b=jlhyYmpUu8dBmt8D3kf387o3K4GhDEUO/1oocKfU0XObz01vBxQvoWRxs4RdFQYSERKMT7 xDwbkZks4V6/Gd9FXXYp3YhvS4NMtjUwpgEX7q9da0wMmRKAwBYFhSuzm3b99I6/CZRKxd XZz8J6hRm/eqwILNO1yIJ3fifZgHyKOqVdL0i5swmtxESUxlP+TfDhwt1iKaHPOGbVk25h f/uuRFdkoKOHia3f++E7ieMbe2mO6sdum7L8okYc5DySRFBS2cNb3+C8NX8pilQrS2pUTW EgQ/PZG3etoS+IUlva4FBVwfhIv3Eoh1ZMNu5oKGWqx1ZITERbXaRLQedZTe6g== Message-ID: <1108f18d-cf7c-4f17-b29c-a119fe42f7e5@iki.fi> Date: Thu, 18 Dec 2025 19:20:38 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Buffer locking is special (hints, checksums, AIO writes) To: Andres Freund Cc: Melanie Plageman , Matthias van de Meent , pgsql-hackers@postgresql.org, Thomas Munro , Noah Misch , Robert Haas , Michael Paquier References: <3je3ahgf7rrmmurxo6hnlhg5d3ffwfrtjwjxd6jm5srlv5iebp@vxqk5qtgmowr> <3w7v3w6a57jnssokap4k7thoekig72flnyhd4wp3yftzdd7lm7@f6lpcfen6hr7> <6rgb2nvhyvnszz4ul3wfzlf5rheb2kkwrglthnna7qhe24onwr@vw27225tkyar> <3nce7i72ayzkunai6mkz24ckbxk74jodz4ua2chcdrwppxlxcd@w6x5kfkjrkru> Content-Language: en-US From: Heikki Linnakangas In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 18/12/2025 19:03, Andres Freund wrote: > Hi, > > On 2025-12-17 09:54:32 -0500, Andres Freund wrote: >> On 2025-12-17 11:25:50 +0200, Heikki Linnakangas wrote: >>> - LWLockWaitListLock() uses pg_atomic_read_u32() after spinning, >>> LockBufHdr() retries directly with pg_atomic_fetch_or_u32(). >> >> I think here LWLockWaitListLock() is likely right - but it seems like a change >> to LockBufHdr() that I would probably make in a separate commit? > > FWIW, I couldn't come up with a scenario where it makes a performance > difference - exclusive content locks just aren't *that* frequent. And because > of that the wait list lock doesn't have similar contention as some non-content > lwlocks (like XidGenLock). The most extreme workload I could think of was > pgbench hammering a single sequence across many sessions. While the exclusive > locks show up in wait events, the buffer header spinlock itself doesn't.. > > So I'm inclined to not change anything about this for now. Ok. My thinking was just that LockBufHdr() and LWLockWaitListLock() should be consistent with each other. Otherwise anyone reading the code will ask the question "why are they different?". They're the only two things using the spin delay mechanism in our codebase, in addition to actual spinlocks. BTW, I wonder if it would be worthwhile to have an inlineable fast-path of LockBufHdr() for the common case that the lock is free? I see that UnlockBufHdr() is already a static inline function. - Heikki