Skip to content

Commit c59a00f

Browse files
akorotkovhopebo
authored andcommitted
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 <[email protected]> Discussion: https://postgr.es/m/1439188.1754506714%40sss.pgh.pa.us Author: Xuneng Zhou <[email protected]> Co-authored-by: Alexander Korotkov <[email protected]> (cherry picked from commit 6058900348059255a8a8da6df46ff8606ca1c612)
1 parent 0a5f6f7 commit c59a00f

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
@@ -884,11 +884,14 @@ CheckpointerShmemSize(void)
884884
Size size;
885885

886886
/*
887-
* Currently, the size of the requests[] array is arbitrarily set equal to
888-
* NBuffers. This may prove too large or small ...
887+
* The size of the requests[] array is arbitrarily set equal to NBuffers.
888+
* But there is a cap of MAX_CHECKPOINT_REQUESTS to prevent accumulating
889+
* too many checkpoint requests in the ring buffer.
889890
*/
890891
size = offsetof(CheckpointerShmemStruct, requests);
891-
size = add_size(size, mul_size(NBuffers, sizeof(CheckpointerRequest)));
892+
size = add_size(size, mul_size(Min(NBuffers,
893+
MAX_CHECKPOINT_REQUESTS),
894+
sizeof(CheckpointerRequest)));
892895

893896
return size;
894897
}

0 commit comments

Comments
 (0)