From: | Andres Freund <andres(at)anarazel(dot)de> |
---|---|
To: | pgsql-committers(at)postgresql(dot)org |
Subject: | pgsql: Lockless StrategyGetBuffer clock sweep hot path. |
Date: | 2014-12-25 17:34:53 |
Message-ID: | E1Y4CJJ-0006NW-6R@gemulon.postgresql.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-committers |
Lockless StrategyGetBuffer clock sweep hot path.
StrategyGetBuffer() has proven to be a bottleneck in a number of
buffer acquisition heavy workloads. To some degree this has already
been alleviated by 5d7962c6, but it still can be quite a heavy
bottleneck. The problem is that in unfortunate usage patterns a
single StrategyGetBuffer() call will have to look at a large number of
buffers - in turn making it likely that the process will be put to
sleep while still holding the spinlock.
Replace most of the usage of the buffer_strategy_lock spinlock for the
clock sweep by a atomic nextVictimBuffer variable. That variable,
modulo NBuffers, is the current hand of the clock sweep. The buffer
clock-sweep then only needs to acquire the spinlock after a
wraparound. And even then only in the process that did the wrapping
around. That alleviates nearly all the contention on the relevant
spinlock, although significant contention on the cacheline can still
exist.
Reviewed-By: Robert Haas and Amit Kapila
Discussion: 20141010160020(dot)GG6670(at)alap3(dot)anarazel(dot)de,
20141027133218(dot)GA2639(at)awork2(dot)anarazel(dot)de
Branch
------
master
Details
-------
http://git.postgresql.org/pg/commitdiff/d72731a70450b5e7084991b9caa15cb58a2820df
Modified Files
--------------
src/backend/postmaster/bgwriter.c | 4 +-
src/backend/storage/buffer/freelist.c | 253 +++++++++++++++++++++++----------
src/include/storage/buf_internals.h | 2 +-
3 files changed, 180 insertions(+), 79 deletions(-)
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2014-12-25 18:25:27 | pgsql: Temporarily revert "Move pg_lzcompress.c to src/common." |
Previous Message | Andres Freund | 2014-12-25 16:49:00 | pgsql: Add capability to suppress CONTEXT: messages to elog machinery. |