From: Teodor Sigaev Date: Mon, 20 Mar 2017 15:48:46 +0000 (+0300) Subject: Revert unintentional change in increasing usage count during pin of buffers, X-Git-Tag: REL_10_BETA1~591 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9cf6033281fdaf938b826545a643f951086d8671;p=postgresql Revert unintentional change in increasing usage count during pin of buffers, this makes buffer access strategy have no effect. Change was a part of commit 48354581a49c30f5757c203415aa8412d85b0f70 during 9.6 release cycle, so backpath to 9.6 Reported-by: Jim Nasby Author: Alexander Korotkov Reviewed-by: Jim Nasby, Andres Freund https://commitfest.postgresql.org/13/1029/ --- diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 2ca2ab9753..2109cbf858 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -1595,9 +1595,21 @@ PinBuffer(BufferDesc *buf, BufferAccessStrategy strategy) /* increase refcount */ buf_state += BUF_REFCOUNT_ONE; - /* increase usagecount unless already max */ - if (BUF_STATE_GET_USAGECOUNT(buf_state) != BM_MAX_USAGE_COUNT) - buf_state += BUF_USAGECOUNT_ONE; + if (strategy == NULL) + { + /* Default case: increase usagecount unless already max. */ + if (BUF_STATE_GET_USAGECOUNT(buf_state) < BM_MAX_USAGE_COUNT) + buf_state += BUF_USAGECOUNT_ONE; + } + else + { + /* + * Ring buffers shouldn't evict others from pool. Thus we + * don't make usagecount more than 1. + */ + if (BUF_STATE_GET_USAGECOUNT(buf_state) == 0) + buf_state += BUF_USAGECOUNT_ONE; + } if (pg_atomic_compare_exchange_u32(&buf->state, &old_buf_state, buf_state))