From 0504a7c998309056459c6cfae981c1f9e8d7a997 Mon Sep 17 00:00:00 2001 From: Anthonin Bonnefoy Date: Tue, 20 Jan 2026 10:47:37 +0100 Subject: Pass NBuffers as parameter to StrategyShmemSize When computing the necessary shared memory for the buffer pool, the NBuffer global variable is directly accessed. This prevents the possible auto-tuning of NBuffer as we can't accurately compute the additional memory from modifying NBuffer. This patch passes NBuffers as a parameter, allowing to call StrategyShmemSize with different values of NBuffers. --- src/backend/storage/buffer/buf_init.c | 2 +- src/backend/storage/buffer/freelist.c | 4 ++-- src/include/storage/buf_internals.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/backend/storage/buffer/buf_init.c b/src/backend/storage/buffer/buf_init.c index c0c223b2e32..6a57ab9cf30 100644 --- a/src/backend/storage/buffer/buf_init.c +++ b/src/backend/storage/buffer/buf_init.c @@ -163,7 +163,7 @@ BufferManagerShmemSize(void) size = add_size(size, mul_size(NBuffers, BLCKSZ)); /* size of stuff controlled by freelist.c */ - size = add_size(size, StrategyShmemSize()); + size = add_size(size, StrategyShmemSize(NBuffers)); /* size of I/O condition variables */ size = add_size(size, mul_size(NBuffers, diff --git a/src/backend/storage/buffer/freelist.c b/src/backend/storage/buffer/freelist.c index b7687836188..a8fe67ac766 100644 --- a/src/backend/storage/buffer/freelist.c +++ b/src/backend/storage/buffer/freelist.c @@ -377,12 +377,12 @@ StrategyNotifyBgWriter(int bgwprocno) * is also determined here. */ Size -StrategyShmemSize(void) +StrategyShmemSize(int num_buffers) { Size size = 0; /* size of lookup hash table ... see comment in StrategyInitialize */ - size = add_size(size, BufTableShmemSize(NBuffers + NUM_BUFFER_PARTITIONS)); + size = add_size(size, BufTableShmemSize(num_buffers + NUM_BUFFER_PARTITIONS)); /* size of the shared replacement strategy control block */ size = add_size(size, MAXALIGN(sizeof(BufferStrategyControl))); diff --git a/src/include/storage/buf_internals.h b/src/include/storage/buf_internals.h index 27f12502d19..cb1106df515 100644 --- a/src/include/storage/buf_internals.h +++ b/src/include/storage/buf_internals.h @@ -571,7 +571,7 @@ extern bool StrategyRejectBuffer(BufferAccessStrategy strategy, extern int StrategySyncStart(uint32 *complete_passes, uint32 *num_buf_alloc); extern void StrategyNotifyBgWriter(int bgwprocno); -extern Size StrategyShmemSize(void); +extern Size StrategyShmemSize(int num_buffers); extern void StrategyInitialize(bool init); /* buf_table.c */ -- 2.52.0