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
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
29
* by returning different pages to different backends in a round-robin
30
* fashion. fp_next_slot points to the next slot to be returned
31
* (assuming there's enough space on it for the request). It's defined
32
* as an int, because it's updated without an exclusive lock. uint16
33
* would be more 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 */