Remove num_size_classes. For now, at least, it's a constant.
authorRobert Haas <rhaas@postgresql.org>
Thu, 10 Apr 2014 19:29:07 +0000 (19:29 +0000)
committerRobert Haas <rhaas@postgresql.org>
Thu, 10 Apr 2014 19:29:07 +0000 (19:29 +0000)
src/backend/utils/mmgr/sb_alloc.c
src/include/utils/sb_alloc.h

index 5220161f01cc4b0c54ba6e289ee686f1f896c37c..31d4eee7c9e43240bf9a90dfd71c8b6ad65bd9cc 100644 (file)
@@ -75,6 +75,7 @@ struct sb_span
  * the total allocations.
  */
 static const uint16 sb_size_classes[] = {
+       sizeof(sb_span), 0,                             /* special size classes */
        8, 16, 24, 32, 40, 48, 56, 64,  /* 8 classes separated by 8 bytes */
        80, 96, 112, 128,                               /* 4 classes separated by 16 bytes */
        160, 192, 224, 256,                             /* 4 classes separated by 32 bytes */
@@ -92,23 +93,21 @@ static const uint16 sb_size_classes[] = {
  * index into this array.
  */
 static char sb_size_class_map[] = {
-       0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11,
-       12, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15,
-       16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 17, 17, 17, 17,
+       2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 11, 11, 12, 12, 13, 13,
+       14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 17, 17, 17, 17,
        18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 19,
-       20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
-       21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+       20, 20, 20, 20, 20, 20, 20, 20, 21, 21, 21, 21, 21, 21, 21, 21,
        22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
-       23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23
+       23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+       24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+       25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25
 };
 #define SB_SIZE_CLASS_MAP_QUANTUM      8
 
 /* Special size classes. */
 #define SB_SCLASS_SPAN_OF_SPANS                        0
 #define SB_SCLASS_SPAN_LARGE                   1
-#define SB_SCLASS_FIRST_REGULAR                        2
-#define SB_NUM_SIZE_CLASSES \
-       (SB_SCLASS_FIRST_REGULAR + lengthof(sb_size_classes))
+#define SB_NUM_SIZE_CLASSES                            lengthof(sb_size_classes)
 
 /* Helper functions. */
 static char *sb_alloc_from_heap(char *base, sb_heap *heap,
@@ -129,7 +128,6 @@ static bool sb_try_to_steal_superblock(char *base, sb_allocator *a,
 sb_allocator *
 sb_create_private_allocator(void)
 {
-       uint16  num_size_classes = lengthof(sb_size_classes);
        Size    allocator_size;
        int             heapno;
        int             fclass;
@@ -137,7 +135,7 @@ sb_create_private_allocator(void)
        char   *base = NULL;
 
        allocator_size = offsetof(sb_allocator, heaps);
-       allocator_size += sizeof(sb_heap) * num_size_classes;
+       allocator_size += sizeof(sb_heap) * SB_NUM_SIZE_CLASSES;
        a = malloc(allocator_size);
        if (a == NULL)
                ereport(ERROR,
@@ -145,8 +143,7 @@ sb_create_private_allocator(void)
                                 errmsg("out of memory")));
 
        a->private = true;
-       a->num_size_classes = num_size_classes;
-       for (heapno = 0; heapno < num_size_classes; ++heapno)
+       for (heapno = 0; heapno < SB_NUM_SIZE_CLASSES; ++heapno)
        {
                sb_heap *heap = &a->heaps[heapno];
 
@@ -261,7 +258,6 @@ sb_alloc(sb_allocator *a, Size size, int flags)
        }
        Assert(size <= sb_size_classes[size_class]);
        Assert(size_class == 0 || size > sb_size_classes[size_class - 1]);
-       size_class += SB_SCLASS_FIRST_REGULAR;
 
        /* Attempt the actual allocation. */
        result = sb_alloc_guts(base, region, a, size_class);
@@ -297,7 +293,7 @@ sb_reset_allocator(sb_allocator *a)
         * Iterate through heaps back to front.  We do it this way so that
         * spans-of-spans are freed last.
         */
-       for (heapno = a->num_size_classes; heapno >= 0; --heapno)
+       for (heapno = SB_NUM_SIZE_CLASSES; heapno >= 0; --heapno)
        {
                sb_heap *heap = &a->heaps[heapno];
                Size    fclass;
@@ -469,18 +465,12 @@ sb_alloc_guts(char *base, sb_region *region, sb_allocator *a, int size_class)
        Size    nmax;
 
        /* Work out object size. */
+       Assert(size_class < SB_NUM_SIZE_CLASSES);
+       obsize = sb_size_classes[size_class];
        if (size_class == 0)
-       {
-               obsize = sizeof(sb_span);
                nmax = FPM_PAGE_SIZE / obsize;
-       }
        else
-       {
-               Assert(size_class >= SB_SCLASS_FIRST_REGULAR);
-               Assert(size_class < SB_NUM_SIZE_CLASSES);
-               obsize = sb_size_classes[size_class - SB_SCLASS_FIRST_REGULAR];
                nmax = (FPM_PAGE_SIZE * SB_PAGES_PER_SUPERBLOCK) / obsize;
-       }
 
        /* If locking is in use, acquire the lock. */
        if (lock != NULL)
index 0ed528b6d1274378986821194429c9e83be4d33b..cf303451361f6daf2ca5f768e7a4238c4b0acf63 100644 (file)
@@ -45,15 +45,13 @@ typedef struct sb_heap
 } sb_heap;
 
 /*
- * An sb_allocator is basically just a group of heaps, N per size class, where
- * N can be chosen by the user.  If locking is required, then we've also got
- * an array of LWLocks, one per 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;
-       uint16  heaps_per_size_class;
-       uint16  num_size_classes;
        relptr(LWLock) locks;
        sb_heap heaps[FLEXIBLE_ARRAY_MEMBER];
 } sb_allocator;