- Notifications
You must be signed in to change notification settings - Fork5
Commit4835458
committed
Allow Pin/UnpinBuffer to operate in a lockfree manner.
Pinning/Unpinning a buffer is a very frequent operation; especially inread-mostly cache resident workloads. Benchmarking shows that in variousscenarios the spinlock protecting a buffer header's state becomes asignificant bottleneck. The problem can be reproduced with pgbench -S onlarger machines, but can be considerably worse for queries which touchthe same buffers over and over at a high frequency (e.g. nested loopsover a small inner table).To allow atomic operations to be used, cram BufferDesc's flags,usage_count, buf_hdr_lock, refcount into a single 32bit atomic variable;that allows to manipulate them together using 32bit compare-and-swapoperations. This requires reducing MAX_BACKENDS to 2^18-1 (which couldbe lifted by using a 64bit field, but it's not a realistic configurationatm).As not all operations can easily implemented in a lockfree manner,implement the previous buf_hdr_lock via a flag bit in the atomicvariable. That way we can continue to lock the header in places whereit's needed, but can get away without acquiring it in the more frequenthot-paths. There's some additional operations which can be done withoutthe lock, but aren't in this patch; but the most important places arecovered.As bufmgr.c now essentially re-implements spinlocks, abstract the delaylogic from s_lock.c into something more generic. It now has already twousers, and more are coming up; there's a follupw patch for lwlock.c atleast.This patch is based on a proof-of-concept written by me, which AlexanderKorotkov made into a fully working patch; the committed version is againrevised by me. Benchmarking and testing has, amongst others, beenprovided by Dilip Kumar, Alexander Korotkov, Robert Haas.On a large x86 system improvements for readonly pgbench, with a highclient count, of a factor of 8 have been observed.Author: Alexander Korotkov and Andres FreundDiscussion: 2400449.GjM57CE0Yg@dinodell1 parentcf223c3 commit4835458
File tree
10 files changed
+622
-357
lines changed- contrib/pg_buffercache
- src
- backend/storage
- buffer
- lmgr
- include
- postmaster
- storage
- tools/pgindent
10 files changed
+622
-357
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
148 | 148 | | |
149 | 149 | | |
150 | 150 | | |
151 | | - | |
| 151 | + | |
| 152 | + | |
152 | 153 | | |
153 | 154 | | |
154 | 155 | | |
155 | | - | |
| 156 | + | |
156 | 157 | | |
157 | 158 | | |
158 | 159 | | |
159 | 160 | | |
160 | 161 | | |
161 | 162 | | |
162 | 163 | | |
163 | | - | |
164 | | - | |
| 164 | + | |
| 165 | + | |
165 | 166 | | |
166 | | - | |
| 167 | + | |
167 | 168 | | |
168 | 169 | | |
169 | 170 | | |
170 | 171 | | |
171 | 172 | | |
172 | | - | |
| 173 | + | |
173 | 174 | | |
174 | 175 | | |
175 | 176 | | |
176 | 177 | | |
177 | | - | |
| 178 | + | |
178 | 179 | | |
179 | 180 | | |
180 | 181 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | 138 | | |
143 | | - | |
| 139 | + | |
| 140 | + | |
144 | 141 | | |
145 | 142 | | |
146 | 143 | | |
| |||
0 commit comments
Comments
(0)