=== Applying patches on top of PostgreSQL commit ID 06473f5a344df8c9594ead90a609b86f6724cff8 === /etc/rc.d/jail: WARNING: Per-jail configuration via jail_* variables is obsolete. Please consider migrating to /etc/jail.conf. Sun Sep 7 10:22:18 UTC 2025 On branch cf/5928 nothing to commit, working tree clean === using 'git am' to apply patch ./v14-0001-Use-consistent-naming-of-the-clock-sweep-algorit.patch === Applying: Use consistent naming of the clock-sweep algorithm. Using index info to reconstruct a base tree... M src/backend/storage/buffer/README M src/backend/storage/buffer/bufmgr.c M src/backend/storage/buffer/freelist.c M src/backend/storage/buffer/localbuf.c M src/include/storage/buf_internals.h Falling back to patching base and 3-way merge... Auto-merging src/include/storage/buf_internals.h Auto-merging src/backend/storage/buffer/freelist.c CONFLICT (content): Merge conflict in src/backend/storage/buffer/freelist.c Auto-merging src/backend/storage/buffer/bufmgr.c CONFLICT (content): Merge conflict in src/backend/storage/buffer/bufmgr.c Auto-merging src/backend/storage/buffer/README error: Failed to merge in the changes. hint: Use 'git am --show-current-patch=diff' to see the failed patch Patch failed at 0001 Use consistent naming of the clock-sweep algorithm. When you have resolved this problem, run "git am --continue". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort". Unstaged changes after reset: M src/backend/storage/buffer/bufmgr.c M src/backend/storage/buffer/freelist.c === using patch(1) to apply patch ./v14-0001-Use-consistent-naming-of-the-clock-sweep-algorit.patch === patching file src/backend/storage/buffer/README Hunk #1 FAILED at 211. 1 out of 1 hunk FAILED -- saving rejects to file src/backend/storage/buffer/README.rej patching file src/backend/storage/buffer/bufmgr.c Hunk #1 FAILED at 3608. Hunk #2 FAILED at 3658. Hunk #3 FAILED at 3679. 3 out of 3 hunks FAILED -- saving rejects to file src/backend/storage/buffer/bufmgr.c.rej patching file src/backend/storage/buffer/freelist.c Hunk #1 FAILED at 33. Hunk #2 FAILED at 51. Hunk #3 FAILED at 311. Hunk #4 FAILED at 511. Hunk #5 FAILED at 759. 5 out of 5 hunks FAILED -- saving rejects to file src/backend/storage/buffer/freelist.c.rej patching file src/backend/storage/buffer/localbuf.c Hunk #1 FAILED at 229. 1 out of 1 hunk FAILED -- saving rejects to file src/backend/storage/buffer/localbuf.c.rej patching file src/include/storage/buf_internals.h Hunk #1 FAILED at 80. 1 out of 1 hunk FAILED -- saving rejects to file src/include/storage/buf_internals.h.rej Removing src/backend/storage/buffer/README.rej Removing src/backend/storage/buffer/bufmgr.c.rej Removing src/backend/storage/buffer/freelist.c.rej Removing src/backend/storage/buffer/localbuf.c.rej Removing src/include/storage/buf_internals.h.rej === using 'git apply' to apply patch ./v14-0001-Use-consistent-naming-of-the-clock-sweep-algorit.patch === Applied patch to 'src/backend/storage/buffer/README' cleanly. Applied patch to 'src/backend/storage/buffer/bufmgr.c' with conflicts. Applied patch to 'src/backend/storage/buffer/freelist.c' with conflicts. Applied patch to 'src/backend/storage/buffer/localbuf.c' cleanly. Applied patch to 'src/include/storage/buf_internals.h' cleanly. U src/backend/storage/buffer/bufmgr.c U src/backend/storage/buffer/freelist.c diff --cc src/backend/storage/buffer/bufmgr.c index fe470de63f2,396b053b3fa..00000000000 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@@ -3635,8 -3658,8 +3635,13 @@@ BgBufferSync(WritebackContext *wb_conte uint32 new_recent_alloc; /* ++<<<<<<< ours + * Find out where the clock-sweep currently is, and how many buffer + * allocations have happened since our last call. ++======= + * Find out where the freelist clock-sweep currently is, and how many + * buffer allocations have happened since our last call. ++>>>>>>> theirs */ strategy_buf_id = StrategySyncStart(&strategy_passes, &recent_alloc); diff --cc src/backend/storage/buffer/freelist.c index 7d59a92bd1a,cd94a7d8a7b..00000000000 --- a/src/backend/storage/buffer/freelist.c +++ b/src/backend/storage/buffer/freelist.c @@@ -224,7 -249,69 +224,73 @@@ StrategyGetBuffer(BufferAccessStrategy */ pg_atomic_fetch_add_u32(&StrategyControl->numBufferAllocs, 1); ++<<<<<<< ours + /* Use the "clock sweep" algorithm to find a free buffer */ ++======= + /* + * First check, without acquiring the lock, whether there's buffers in the + * freelist. Since we otherwise don't require the spinlock in every + * StrategyGetBuffer() invocation, it'd be sad to acquire it here - + * uselessly in most cases. That obviously leaves a race where a buffer is + * put on the freelist but we don't see the store yet - but that's pretty + * harmless, it'll just get used during the next buffer acquisition. + * + * If there's buffers on the freelist, acquire the spinlock to pop one + * buffer of the freelist. Then check whether that buffer is usable and + * repeat if not. + * + * Note that the freeNext fields are considered to be protected by the + * buffer_strategy_lock not the individual buffer spinlocks, so it's OK to + * manipulate them without holding the spinlock. + */ + if (StrategyControl->firstFreeBuffer >= 0) + { + while (true) + { + /* Acquire the spinlock to remove element from the freelist */ + SpinLockAcquire(&StrategyControl->buffer_strategy_lock); + + if (StrategyControl->firstFreeBuffer < 0) + { + SpinLockRelease(&StrategyControl->buffer_strategy_lock); + break; + } + + buf = GetBufferDescriptor(StrategyControl->firstFreeBuffer); + Assert(buf->freeNext != FREENEXT_NOT_IN_LIST); + + /* Unconditionally remove buffer from freelist */ + StrategyControl->firstFreeBuffer = buf->freeNext; + buf->freeNext = FREENEXT_NOT_IN_LIST; + + /* + * Release the lock so someone else can access the freelist while + * we check out this buffer. + */ + SpinLockRelease(&StrategyControl->buffer_strategy_lock); + + /* + * If the buffer is pinned or has a nonzero usage_count, we cannot + * use it; discard it and retry. (This can only happen if VACUUM + * put a valid buffer in the freelist and then someone else used + * it before we got to it. It's probably impossible altogether as + * of 8.3, but we'd better check anyway.) + */ + local_buf_state = LockBufHdr(buf); + if (BUF_STATE_GET_REFCOUNT(local_buf_state) == 0 + && BUF_STATE_GET_USAGECOUNT(local_buf_state) == 0) + { + if (strategy != NULL) + AddBufferToRing(strategy, buf); + *buf_state = local_buf_state; + return buf; + } + UnlockBufHdr(buf, local_buf_state); + } + } + + /* Nothing on the freelist, so run the "clock-sweep" algorithm */ ++>>>>>>> theirs trycounter = NBuffers; for (;;) { @@@ -394,6 -504,13 +460,16 @@@ StrategyInitialize(bool init SpinLockInit(&StrategyControl->buffer_strategy_lock); ++<<<<<<< ours ++======= + /* + * Grab the whole linked list of free buffers for our strategy. We + * assume it was previously set up by BufferManagerShmemInit(). + */ + StrategyControl->firstFreeBuffer = 0; + StrategyControl->lastFreeBuffer = NBuffers - 1; + ++>>>>>>> theirs /* Initialize the clock-sweep pointer */ pg_atomic_init_u32(&StrategyControl->nextVictimBuffer, 0);