- Notifications
You must be signed in to change notification settings - Fork5.2k
Commit5e89985
committed
bufmgr: Don't lock buffer header in StrategyGetBuffer()
Previously StrategyGetBuffer() acquired the buffer header spinlock for everybuffer, whether it was reusable or not. If reusable, it'd be returned, withthe lock held, to GetVictimBuffer(), which then would pin the buffer withPinBuffer_Locked(). That's somewhat violating the spirit of the guidelines forholding spinlocks (i.e. that they are only held for a few lines of consecutivecode) and necessitates using PinBuffer_Locked(), which scales worse thanPinBuffer() due to holding the spinlock. This alone makes it worth changingthe code.However, the main reason to change this is that a future commit will makePinBuffer_Locked() slower (due to making UnlockBufHdr() slower), to gainscalability for the much more common case of pinning a pre-existing buffer. Bypinning the buffer with a single atomic operation, iff the buffer is reusable,we avoid any potential regression for miss-heavy workloads. There strictly arefewer atomic operations for each potential buffer after this change.The price for this improvement is that freelist.c needs two CAS loops andneeds to be able to set up the resource accounting for pinned buffers. Thelatter is achieved by exposing a new function for that purpose from bufmgr.c,that seems better than exposing the entire private refcount infrastructure.The improvement seems worth the complexity.Reviewed-by: Robert Haas <robertmhaas@gmail.com>Reviewed-by: Matthias van de Meent <boekewurm+postgres@gmail.com>Discussion:https://postgr.es/m/fvfmkr5kk4nyex56ejgxj3uzi63isfxovp2biecb4bspbjrze7@az2pljabhnff1 parent3baae90 commit5e89985
File tree
3 files changed
+132
-66
lines changed- src
- backend/storage/buffer
- include/storage
3 files changed
+132
-66
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
518 | 518 | | |
519 | 519 | | |
520 | 520 | | |
521 | | - | |
522 | 521 | | |
523 | 522 | | |
524 | 523 | | |
| |||
2326 | 2325 | | |
2327 | 2326 | | |
2328 | 2327 | | |
2329 | | - | |
2330 | | - | |
| 2328 | + | |
| 2329 | + | |
2331 | 2330 | | |
2332 | 2331 | | |
2333 | 2332 | | |
| |||
2336 | 2335 | | |
2337 | 2336 | | |
2338 | 2337 | | |
2339 | | - | |
2340 | | - | |
| 2338 | + | |
| 2339 | + | |
2341 | 2340 | | |
2342 | 2341 | | |
2343 | 2342 | | |
2344 | 2343 | | |
2345 | | - | |
2346 | | - | |
2347 | | - | |
2348 | | - | |
2349 | | - | |
2350 | 2344 | | |
2351 | 2345 | | |
2352 | 2346 | | |
| |||
3118 | 3112 | | |
3119 | 3113 | | |
3120 | 3114 | | |
3121 | | - | |
| 3115 | + | |
3122 | 3116 | | |
3123 | 3117 | | |
3124 | 3118 | | |
| |||
3150 | 3144 | | |
3151 | 3145 | | |
3152 | 3146 | | |
| 3147 | + | |
| 3148 | + | |
| 3149 | + | |
| 3150 | + | |
3153 | 3151 | | |
3154 | 3152 | | |
3155 | | - | |
3156 | | - | |
3157 | | - | |
3158 | 3153 | | |
3159 | 3154 | | |
3160 | 3155 | | |
| |||
3183 | 3178 | | |
3184 | 3179 | | |
3185 | 3180 | | |
3186 | | - | |
3187 | | - | |
3188 | 3181 | | |
3189 | 3182 | | |
3190 | 3183 | | |
| |||
3209 | 3202 | | |
3210 | 3203 | | |
3211 | 3204 | | |
3212 | | - | |
3213 | | - | |
3214 | | - | |
3215 | | - | |
3216 | | - | |
3217 | | - | |
| 3205 | + | |
3218 | 3206 | | |
3219 | 3207 | | |
3220 | 3208 | | |
| |||
3332 | 3320 | | |
3333 | 3321 | | |
3334 | 3322 | | |
| 3323 | + | |
| 3324 | + | |
| 3325 | + | |
| 3326 | + | |
| 3327 | + | |
| 3328 | + | |
| 3329 | + | |
| 3330 | + | |
| 3331 | + | |
| 3332 | + | |
| 3333 | + | |
3335 | 3334 | | |
3336 | 3335 | | |
3337 | 3336 | | |
| |||
6288 | 6287 | | |
6289 | 6288 | | |
6290 | 6289 | | |
6291 | | - | |
| 6290 | + | |
6292 | 6291 | | |
6293 | 6292 | | |
6294 | 6293 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
159 | 159 | | |
160 | 160 | | |
161 | 161 | | |
162 | | - | |
| 162 | + | |
163 | 163 | | |
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
167 | | - | |
168 | | - | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
169 | 172 | | |
170 | 173 | | |
171 | 174 | | |
172 | 175 | | |
173 | 176 | | |
174 | 177 | | |
175 | 178 | | |
176 | | - | |
177 | 179 | | |
178 | 180 | | |
179 | 181 | | |
| |||
228 | 230 | | |
229 | 231 | | |
230 | 232 | | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
231 | 236 | | |
232 | 237 | | |
233 | 238 | | |
234 | | - | |
235 | | - | |
| 239 | + | |
| 240 | + | |
236 | 241 | | |
237 | | - | |
238 | | - | |
239 | | - | |
| 242 | + | |
| 243 | + | |
240 | 244 | | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
241 | 275 | | |
242 | 276 | | |
243 | 277 | | |
244 | 278 | | |
245 | | - | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
246 | 285 | | |
247 | 286 | | |
248 | 287 | | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
254 | 303 | | |
| 304 | + | |
255 | 305 | | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | 306 | | |
270 | 307 | | |
271 | 308 | | |
| |||
614 | 651 | | |
615 | 652 | | |
616 | 653 | | |
617 | | - | |
| 654 | + | |
| 655 | + | |
618 | 656 | | |
619 | 657 | | |
620 | 658 | | |
621 | 659 | | |
622 | 660 | | |
623 | 661 | | |
| 662 | + | |
624 | 663 | | |
625 | 664 | | |
626 | 665 | | |
| |||
637 | 676 | | |
638 | 677 | | |
639 | 678 | | |
| 679 | + | |
| 680 | + | |
640 | 681 | | |
641 | | - | |
642 | | - | |
643 | | - | |
644 | | - | |
645 | | - | |
646 | | - | |
647 | | - | |
| 682 | + | |
| 683 | + | |
648 | 684 | | |
649 | | - | |
650 | | - | |
651 | | - | |
652 | | - | |
| 685 | + | |
| 686 | + | |
653 | 687 | | |
654 | | - | |
655 | | - | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
656 | 720 | | |
657 | | - | |
658 | 721 | | |
659 | 722 | | |
660 | 723 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
371 | 371 | | |
372 | 372 | | |
373 | 373 | | |
| 374 | + | |
| 375 | + | |
374 | 376 | | |
375 | 377 | | |
376 | 378 | | |
| |||
425 | 427 | | |
426 | 428 | | |
427 | 429 | | |
| 430 | + | |
| 431 | + | |
428 | 432 | | |
429 | 433 | | |
430 | 434 | | |
| |||
0 commit comments
Comments
(0)