Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UJ8O4-0006TS-UE for pgsql-hackers@arkaria.postgresql.org; Fri, 22 Mar 2013 20:16:29 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UJ8O4-0004rI-DL for pgsql-hackers@arkaria.postgresql.org; Fri, 22 Mar 2013 20:16:28 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UJ8O3-0004rD-FF for pgsql-hackers@postgresql.org; Fri, 22 Mar 2013 20:16:27 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UJ8Nz-0001XC-NH for pgsql-hackers@postgresql.org; Fri, 22 Mar 2013 20:16:26 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.5/8.14.5) with ESMTP id r2MKGIM7029749; Fri, 22 Mar 2013 16:16:18 -0400 (EDT) From: Tom Lane To: Merlin Moncure cc: Atri Sharma , Greg Stark , Ants Aasma , Amit Kapila , PostgreSQL-development Subject: Re: Page replacement algorithm in buffer cache In-reply-to: References: <514bf302.84d5440a.43f2.ffffe411SMTPIN_ADDED_BROKEN@mx.google.com> <08BBC126-D375-4743-B9A6-D1320D05D5C7@gmail.com> <514c3395.487a420a.28d1.764eSMTPIN_ADDED_BROKEN@mx.google.com> <3985.1363960959@sss.pgh.pa.us> <29181.1363981925@sss.pgh.pa.us> Comments: In-reply-to Merlin Moncure message dated "Fri, 22 Mar 2013 15:09:09 -0500" Date: Fri, 22 Mar 2013 16:16:18 -0400 Message-ID: <29748.1363983378@sss.pgh.pa.us> X-Pg-Spam-Score: -4.4 (----) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org Merlin Moncure writes: > I think there is some very low hanging optimization fruit in the clock > sweep loop. first and foremost, I see no good reason why when > scanning pages we have to spin and wait on a buffer in order to > pedantically adjust usage_count. some simple refactoring there could > set it up so that a simple TAS (or even a TTAS with the first test in > front of the cache line lock as we done automatically in x86 IIRC) > could guard the buffer and, in the event of any lock detected, simply > move on to the next candidate without messing around with that buffer > at all. This could construed as a 'trylock' variant of a spinlock > and might help out with cases where an especially hot buffer is > locking up the sweep. This is exploiting the fact that from > StrategyGetBuffer we don't need a *particular* buffer, just *a* > buffer. Hm. You could argue in fact that if there's contention for the buffer header, that's proof that it's busy and shouldn't have its usage count decremented. So this seems okay from a logical standpoint. However, I'm not real sure that it's possible to do a conditional spinlock acquire that doesn't create just as much hardware-level contention as a full acquire (ie, TAS is about as bad whether it gets the lock or not). So the actual benefit is a bit less clear. regards, tom lane -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers