Skip to content

Commit 73f897b

Browse files
committed
Fix checkpointer shared memory allocation
Use Min(NBuffers, MAX_CHECKPOINT_REQUESTS) instead of NBuffers in CheckpointerShmemSize() to match the actual array size limit set in CheckpointerShmemInit(). This prevents wasting shared memory when NBuffers > MAX_CHECKPOINT_REQUESTS. Also, fix the comment. Reported-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://postgr.es/m/1439188.1754506714%40sss.pgh.pa.us Author: Xuneng Zhou <xunengzhou@gmail.com> Co-authored-by: Alexander Korotkov <aekorotkov@gmail.com>
1 parent 098c27d commit 73f897b

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/backend/postmaster/checkpointer.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -874,11 +874,14 @@ CheckpointerShmemSize(void)
874874
Size size;
875875

876876
/*
877-
* Currently, the size of the requests[] array is arbitrarily set equal to
878-
* NBuffers. This may prove too large or small ...
877+
* The size of the requests[] array is arbitrarily set equal to NBuffers.
878+
* But there is a cap of MAX_CHECKPOINT_REQUESTS to prevent accumulating
879+
* too many checkpoint requests in the ring buffer.
879880
*/
880881
size = offsetof(CheckpointerShmemStruct, requests);
881-
size = add_size(size, mul_size(NBuffers, sizeof(CheckpointerRequest)));
882+
size = add_size(size, mul_size(Min(NBuffers,
883+
MAX_CHECKPOINT_REQUESTS),
884+
sizeof(CheckpointerRequest)));
882885

883886
return size;
884887
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy