2
0

fsm_internals.h 2.3 KB

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