1 /*-------------------------------------------------------------------------
4 * internal functions for free space map
7 * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * $PostgreSQL: pgsql/src/include/storage/fsm_internals.h,v 1.3 2009/06/11 14:49:12 momjian Exp $
12 *-------------------------------------------------------------------------
14 #ifndef FSM_INTERNALS_H
15 #define FSM_INTERNALS_H
17 #include "storage/buf.h"
18 #include "storage/bufpage.h"
19 #include "lib/stringinfo.h"
22 * Structure of a FSM page. See src/backend/storage/freespace/README for
28 * fsm_search_avail() tries to spread the load of multiple backends by
29 * returning different pages to different backends in a round-robin
30 * fashion. fp_next_slot points to the next slot to be returned (assuming
31 * there's enough space on it for the request). It's defined as an int,
32 * because it's updated without an exclusive lock. uint16 would be more
33 * appropriate, but int is more likely to be atomically
39 * fp_nodes contains the binary tree, stored in array. The first
40 * NonLeafNodesPerPage elements are upper nodes, and the following
41 * LeafNodesPerPage elements are leaf nodes. Unused nodes are zero.
46 typedef FSMPageData *FSMPage;
49 * Number of non-leaf and leaf nodes, and nodes in total, on an FSM page.
50 * These definitions are internal to fsmpage.c.
52 #define NodesPerPage (BLCKSZ - MAXALIGN(SizeOfPageHeaderData) - \
53 offsetof(FSMPageData, fp_nodes))
55 #define NonLeafNodesPerPage (BLCKSZ / 2 - 1)
56 #define LeafNodesPerPage (NodesPerPage - NonLeafNodesPerPage)
59 * Number of FSM "slots" on a FSM page. This is what should be used
62 #define SlotsPerFSMPage LeafNodesPerPage
64 /* Prototypes for functions in fsmpage.c */
65 extern int fsm_search_avail(Buffer buf, uint8 min_cat, bool advancenext,
66 bool exclusive_lock_held);
67 extern uint8 fsm_get_avail(Page page, int slot);
68 extern uint8 fsm_get_max_avail(Page page);
69 extern bool fsm_set_avail(Page page, int slot, uint8 value);
70 extern bool fsm_truncate_avail(Page page, int nslots);
71 extern bool fsm_rebuild_page(Page page);
73 #endif /* FSM_INTERNALS_H */