* 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 */
* 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,
sb_allocator *
sb_create_private_allocator(void)
{
- uint16 num_size_classes = lengthof(sb_size_classes);
Size allocator_size;
int heapno;
int fclass;
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,
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];
}
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);
* 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;
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)