diff --git a/src/backend/storage/buffer/freelist.c b/src/backend/storage/buffer/freelist.c index 3e62448..af7215f 100644 --- a/src/backend/storage/buffer/freelist.c +++ b/src/backend/storage/buffer/freelist.c @@ -218,12 +218,21 @@ StrategyGetBuffer(BufferAccessStrategy strategy, bool *lock_held) } /* - * StrategyFreeBuffer: put a buffer on the freelist + * StrategyFreeBuffer: put a buffer on the freelist, unless we're busy */ void StrategyFreeBuffer(volatile BufferDesc *buf) { - LWLockAcquire(BufFreelistLock, LW_EXCLUSIVE); + /* + * The buffer is already invalidated and is now an allocation target. + * Adding buffers back onto the freelist is an optimisation only, + * so we can decide to skip this step if the lock is busy. + * This improves the speed of dropping indexes and tables on a busy system. + * If the system is busy the newly invalidated buffers will be reallocated + * within one clock sweep. + */ + if (!LWLockConditionalAcquire(BufFreelistLock, LW_EXCLUSIVE)) + return; /* * It is possible that we are told to put something in the freelist that