From 7bcfa3f08be436a4b7ff34cf96c2dd12e6d0680c Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Sat, 25 Aug 2018 15:43:50 -0400 Subject: [PATCH] tune slab metadata allocation --- malloc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/malloc.c b/malloc.c index d516f25..9414ac9 100644 --- a/malloc.c +++ b/malloc.c @@ -206,7 +206,7 @@ static size_t get_metadata_max(size_t slab_size) { } static struct slab_metadata *alloc_metadata(struct size_class *c, size_t slab_size) { - if (c->metadata_count == c->metadata_allocated) { + if (unlikely(c->metadata_count == c->metadata_allocated)) { size_t metadata_max = get_metadata_max(slab_size); if (c->metadata_count == metadata_max) { return NULL; @@ -649,7 +649,7 @@ COLD static void init_slow_path(void) { if (c->slab_info == NULL) { fatal_error("failed to allocate slab metadata"); } - c->metadata_allocated = 32; + c->metadata_allocated = PAGE_SIZE / sizeof(struct slab_metadata); if (mprotect(c->slab_info, c->metadata_allocated * sizeof(struct slab_metadata), PROT_READ|PROT_WRITE)) { fatal_error("failed to allocate initial slab info"); }