From 7b3fb9e98301c6d08cf827e98c1254131b190c2b Mon Sep 17 00:00:00 2001 From: David Christensen Date: Fri, 19 Jan 2024 12:56:56 -0500 Subject: [PATCH v3 28/28] feature: teach FSM about reserved page space --- src/backend/storage/freespace/freespace.c | 2 +- src/include/storage/fsm_internals.h | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/backend/storage/freespace/freespace.c b/src/backend/storage/freespace/freespace.c index 323c652a9d..6ce7517cdd 100644 --- a/src/backend/storage/freespace/freespace.c +++ b/src/backend/storage/freespace/freespace.c @@ -72,7 +72,7 @@ * this means that 4096 bytes is the smallest BLCKSZ that we can get away * with a 3-level tree, and 512 is the smallest we support. */ -#define FSM_TREE_DEPTH ((SlotsPerFSMPage >= 1626) ? 3 : 4) +#define FSM_TREE_DEPTH ((MinSlotsPerFSMPage >= 1626) ? 3 : 4) #define FSM_ROOT_LEVEL (FSM_TREE_DEPTH - 1) #define FSM_BOTTOM_LEVEL 0 diff --git a/src/include/storage/fsm_internals.h b/src/include/storage/fsm_internals.h index 195fb7804a..da0351aa41 100644 --- a/src/include/storage/fsm_internals.h +++ b/src/include/storage/fsm_internals.h @@ -48,7 +48,7 @@ typedef FSMPageData *FSMPage; * Number of non-leaf and leaf nodes, and nodes in total, on an FSM page. * These definitions are internal to fsmpage.c. */ -#define NodesPerPage (PageUsableSpaceMax - \ +#define NodesPerPage (PageUsableSpace - \ offsetof(FSMPageData, fp_nodes)) #define NonLeafNodesPerPage (BLCKSZ / 2 - 1) @@ -60,6 +60,14 @@ typedef FSMPageData *FSMPage; */ #define SlotsPerFSMPage LeafNodesPerPage +/* + * MinSlotsPerFSMPage is required so we can properly choose the tree level + * based on the minimum known number of slots on the page; the actual number + * could be more, but is not a compile-time constant, so the FSM_TREE_DEPTH + * logic uses this value instead to make the compiler happy. + */ +#define MinSlotsPerFSMPage (BLCKSZ - SizeOfPageHeaderData - MaxReservedPageSize - offsetof(FSMPageData, fp_nodes) - NonLeafNodesPerPage) + /* Prototypes for functions in fsmpage.c */ extern int fsm_search_avail(Buffer buf, uint8 minvalue, bool advancenext, bool exclusive_lock_held); -- 2.40.1