PostgreSQL Source Code  git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
fsm_internals.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * fsm_internals.h
4  * internal functions for free space map
5  *
6  *
7  * Portions Copyright (c) 1996-2024, 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  */
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  */
43 } FSMPageData;
44 
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 minvalue, 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 */
int Buffer
Definition: buf.h:23
Pointer Page
Definition: bufpage.h:81
#define FLEXIBLE_ARRAY_MEMBER
Definition: c.h:413
unsigned char uint8
Definition: c.h:490
FSMPageData * FSMPage
Definition: fsm_internals.h:45
uint8 fsm_get_avail(Page page, int slot)
Definition: fsmpage.c:122
bool fsm_rebuild_page(Page page)
Definition: fsmpage.c:342
uint8 fsm_get_max_avail(Page page)
Definition: fsmpage.c:138
bool fsm_set_avail(Page page, int slot, uint8 value)
Definition: fsmpage.c:63
bool fsm_truncate_avail(Page page, int nslots)
Definition: fsmpage.c:313
int fsm_search_avail(Buffer buf, uint8 minvalue, bool advancenext, bool exclusive_lock_held)
Definition: fsmpage.c:158
static struct @160 value
static char * buf
Definition: pg_test_fsync.c:72