#include "miscadmin.h"
#include "utils/sb_region.h"
+typedef struct sb_heap sb_heap;
+typedef struct sb_span sb_span;
+
/*
* Metadata for an ordinary superblock, a large memory allocation, or a "span
* of spans".
#define SB_SCLASS_SPAN_LARGE 1
#define SB_NUM_SIZE_CLASSES lengthof(sb_size_classes)
+/*
+ * Superblocks are binned by how full they are. Generally, each fullness
+ * class corresponds to one quartile, but the superblock being used for
+ * allocations is always at the head of the list for fullness class 1,
+ * regardless of how full it really is.
+ *
+ * For large objects, we just stick all of the allocations in fullness class
+ * 0. Since we can just return the space directly to the free page manager,
+ * we don't really need them on a list at all, except that if someone wants
+ * to bulk release everything allocated using this sb_allocator, we have no
+ * other way of finding them.
+ */
+#define SB_FULLNESS_CLASSES 4
+
+/*
+ * An sb_heap represents a set of allocations of a given size class.
+ * There can be multiple heaps for the same size class for contention
+ * avoidance.
+ */
+struct sb_heap
+{
+ relptr(LWLock) lock;
+ relptr(sb_span) spans[SB_FULLNESS_CLASSES];
+};
+
+/*
+ * An sb_allocator is basically just a group of heaps, one per size class.
+ * If locking is required, then we've also got an array of LWLocks, one per
+ * heap.
+ */
+struct sb_allocator
+{
+ bool private;
+ relptr(LWLock) locks;
+ sb_heap heaps[lengthof(sb_size_classes)];
+};
+
/* Helper functions. */
static char *sb_alloc_guts(char *base, sb_region *region,
sb_allocator *a, int size_class);
#include "storage/lwlock.h"
#include "utils/relptr.h"
-typedef struct sb_span sb_span;
-
-/*
- * Superblocks are binned by how full they are. Generally, each fullness
- * class corresponds to one quartile, but the superblock being used for
- * allocations is always at the head of the list for fullness class 1,
- * regardless of how full it really is.
- *
- * For large objects, we just stick all of the allocations in fullness class
- * 0. Since we can just return the space directly to the free page manager,
- * we don't really need them on a list at all, except that if someone wants
- * to bulk release everything allocated using this sb_allocator, we have no
- * other way of finding them.
- */
-#define SB_FULLNESS_CLASSES 4
-
-/*
- * An sb_heap represents a set of allocations of a given size class.
- * There can be multiple heaps for the same size class for contention
- * avoidance.
- */
-typedef struct sb_heap
-{
- relptr(LWLock) lock;
- relptr(sb_span) spans[SB_FULLNESS_CLASSES];
-} sb_heap;
-
-/*
- * An sb_allocator is basically just a group of heaps, one per size class.
- * If locking is required, then we've also got an array of LWLocks, one per
- * heap.
- */
-typedef struct sb_allocator
-{
- bool private;
- relptr(LWLock) locks;
- sb_heap heaps[FLEXIBLE_ARRAY_MEMBER];
-} sb_allocator;
-
-/* Pages per superblock (in units of FPM_PAGE_SIZE). */
-#define SB_PAGES_PER_SUPERBLOCK 16
+typedef struct sb_allocator sb_allocator;
/* Allocation options. */
#define SB_ALLOC_HUGE 0x0001 /* allow >=1GB */
#include "utils/sb_alloc.h"
#include "utils/sb_map.h"
+/* Pages per superblock (in units of FPM_PAGE_SIZE). */
+#define SB_PAGES_PER_SUPERBLOCK 16
+
/*
* An sb_region is a backend-private object used to track allocatable regions
* of memory, either backend-private or shared.