1 /*------------------------------------------------------------------------- 2 * 3 * fsm_internals.h 4 * internal functions for free space map 5 * 6 * 7 * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group 8 * Portions Copyright (c) 1994, Regents of the University of California 9 * 10 * src/include/storage/fsm_internals.h 11 * 12 *------------------------------------------------------------------------- 13 */ 14 #ifndef FSM_INTERNALS_H 15 #define FSM_INTERNALS_H 16 17 #include "storage/buf.h" 18 #include "storage/bufpage.h" 19 20 /* 21 * Structure of a FSM page. See src/backend/storage/freespace/README for 22 * details. 23 */ 24 typedef struct 25 { 26 /* 27 * fsm_search_avail() tries to spread the load of multiple backends by 28 * returning different pages to different backends in a round-robin 29 * fashion. fp_next_slot points to the next slot to be returned (assuming 30 * there's enough space on it for the request). It's defined as an int, 31 * because it's updated without an exclusive lock. uint16 would be more 32 * appropriate, but int is more likely to be atomically 33 * fetchable/storable. 34 */ 35 int fp_next_slot; 36 37 /* 38 * fp_nodes contains the binary tree, stored in array. The first 39 * NonLeafNodesPerPage elements are upper nodes, and the following 40 * LeafNodesPerPage elements are leaf nodes. Unused nodes are zero. 41 */ 42 uint8 fp_nodes[FLEXIBLE_ARRAY_MEMBER]; 43 } FSMPageData; 44 45 typedef FSMPageData *FSMPage; 46 47 /* 48 * Number of non-leaf and leaf nodes, and nodes in total, on an FSM page. 49 * These definitions are internal to fsmpage.c. 50 */ 51 #define NodesPerPage (BLCKSZ - MAXALIGN(SizeOfPageHeaderData) - \ 52 offsetof(FSMPageData, fp_nodes)) 53 54 #define NonLeafNodesPerPage (BLCKSZ / 2 - 1) 55 #define LeafNodesPerPage (NodesPerPage - NonLeafNodesPerPage) 56 57 /* 58 * Number of FSM "slots" on a FSM page. This is what should be used 59 * outside fsmpage.c. 60 */ 61 #define SlotsPerFSMPage LeafNodesPerPage 62 63 /* Prototypes for functions in fsmpage.c */ 64 extern int fsm_search_avail(Buffer buf, uint8 min_cat, bool advancenext, 65 bool exclusive_lock_held); 66 extern uint8 fsm_get_avail(Page page, int slot); 67 extern uint8 fsm_get_max_avail(Page page); 68 extern bool fsm_set_avail(Page page, int slot, uint8 value); 69 extern bool fsm_truncate_avail(Page page, int nslots); 70 extern bool fsm_rebuild_page(Page page); 71 72 #endif /* FSM_INTERNALS_H */ 73