From cd60db1c892b142355c4d30731e52db4ae2d3bba Mon Sep 17 00:00:00 2001 From: dzaima Date: Mon, 5 Jul 2021 02:52:42 +0300 Subject: [PATCH] optimize fast allocation path --- src/opt/mm_buddyTemplate.c | 10 ++++++++-- src/opt/mm_buddyTemplate.h | 8 ++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/opt/mm_buddyTemplate.c b/src/opt/mm_buddyTemplate.c index 7605371a..712619b4 100644 --- a/src/opt/mm_buddyTemplate.c +++ b/src/opt/mm_buddyTemplate.c @@ -15,7 +15,7 @@ AllocInfo* al; u64 alCap; u64 alSize; -NOINLINE EmptyValue* BN(makeEmpty)(u8 bucket) { // result->next is garbage +static void BN(guaranteeEmpty)(u8 bucket) { u8 cb = bucket; EmptyValue* c; while (true) { @@ -56,8 +56,14 @@ NOINLINE EmptyValue* BN(makeEmpty)(u8 bucket) { // result->next is garbage b->next = buckets[cb]; buckets[cb] = b; } - return c; + c->next = buckets[cb]; + buckets[cb] = c; } +NOINLINE void* BN(allocS)(i64 bucket, u8 type) { + BN(guaranteeEmpty)(bucket); + return BN(allocL)(bucket, type); +} + void BN(forHeap)(V2v f) { for (u64 i = 0; i < alSize; i++) { AllocInfo ci = al[i]; diff --git a/src/opt/mm_buddyTemplate.h b/src/opt/mm_buddyTemplate.h index 03f89be2..0182e8c5 100644 --- a/src/opt/mm_buddyTemplate.h +++ b/src/opt/mm_buddyTemplate.h @@ -12,7 +12,6 @@ extern AllocInfo* al; extern u64 alCap; extern u64 alSize; -extern NOINLINE EmptyValue* BN(makeEmpty)(u8 bucket); // result->next is garbage static void BN(free)(Value* x) { onFree(x); @@ -32,10 +31,11 @@ static void BN(free)(Value* x) { x->type = t_empty; } -static void* BN(allocL)(u8 bucket, u8 type) { +NOINLINE void* BN(allocS)(i64 bucket, u8 type); +static void* BN(allocL)(i64 bucket, u8 type) { EmptyValue* x = buckets[bucket]; - if (RARE(x==NULL)) x = BN(makeEmpty)(bucket); - else buckets[bucket] = x->next; + if (RARE(x==NULL)) return BN(allocS)(bucket, type); + buckets[bucket] = x->next; #ifdef USE_VALGRIND VALGRIND_MAKE_MEM_UNDEFINED(x, BSZ(bucket)); VALGRIND_MAKE_MEM_DEFINED(&x->mmInfo, 1);