Move more stuff out of sb_alloc.h.
authorRobert Haas <rhaas@postgresql.org>
Fri, 9 May 2014 19:33:24 +0000 (15:33 -0400)
committerRobert Haas <rhaas@postgresql.org>
Fri, 9 May 2014 19:33:24 +0000 (15:33 -0400)
src/backend/utils/mmgr/sb_alloc.c
src/include/utils/sb_alloc.h
src/include/utils/sb_region.h

index ace9e56923ca00aa955c2cca172235589f39dcf0..334ffa0fc13d46abd3e5cb2221441e4485d0b656 100644 (file)
@@ -16,6 +16,9 @@
 #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".
@@ -114,6 +117,43 @@ static char sb_size_class_map[] = {
 #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);
index 50ef5c3703c0190a1efb56768d36078d37158917..8fe92832a2206308fc911d108c13dd7834b656c4 100644 (file)
 #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 */
index 5bb01f38195ba13b8919593951c3a777d7a59a38..6b2a5780226e281b9b3b6dd17e8714b64aa5def4 100644 (file)
@@ -21,6 +21,9 @@
 #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.