Infrastructure and build updates
- Update build configuration and flags - Add missing header files and dependencies - Update TLS list implementation with proper scoping - Fix various compilation warnings and issues - Update debug ring and tiny allocation infrastructure - Update benchmark results documentation Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
This commit is contained in:
@ -16,6 +16,8 @@
|
||||
#include "hakmem_tiny.h"
|
||||
#include "tiny_route.h"
|
||||
#include "tiny_alloc_fast_sfc.inc.h" // Box 5-NEW: SFC Layer
|
||||
#include "hakmem_tiny_fastcache.inc.h" // Array stack (FastCache) for C0–C3
|
||||
#include "hakmem_tiny_tls_list.h" // TLS List (for tiny_fast_refill_and_take)
|
||||
#include "tiny_region_id.h" // Phase 7: Header-based class_idx lookup
|
||||
#include "tiny_adaptive_sizing.h" // Phase 2b: Adaptive sizing
|
||||
#include "box/tls_sll_box.h" // Box TLS-SLL: C7-safe push/pop/splice
|
||||
@ -186,6 +188,20 @@ static inline void* tiny_alloc_fast_pop(int class_idx) {
|
||||
uint64_t start = tiny_profile_enabled() ? tiny_fast_rdtsc() : 0;
|
||||
#endif
|
||||
|
||||
// Phase 1: Try array stack (FastCache) first for hottest tiny classes (C0–C3)
|
||||
if (__builtin_expect(g_fastcache_enable && class_idx <= 3, 1)) {
|
||||
void* fc = fastcache_pop(class_idx);
|
||||
if (__builtin_expect(fc != NULL, 1)) {
|
||||
// Frontend FastCache hit
|
||||
extern unsigned long long g_front_fc_hit[];
|
||||
g_front_fc_hit[class_idx]++;
|
||||
return fc;
|
||||
} else {
|
||||
extern unsigned long long g_front_fc_miss[];
|
||||
g_front_fc_miss[class_idx]++;
|
||||
}
|
||||
}
|
||||
|
||||
// Box 5-NEW: Layer 0 - Try SFC first (if enabled)
|
||||
// Cache g_sfc_enabled in TLS to avoid global load on every allocation
|
||||
static __thread int sfc_check_done = 0;
|
||||
@ -457,34 +473,34 @@ static inline void* tiny_alloc_fast(size_t size) {
|
||||
}
|
||||
ROUTE_BEGIN(class_idx);
|
||||
|
||||
// 2. Fast path: TLS freelist pop (3-4 instructions, 95% hit rate)
|
||||
// CRITICAL: Use Box TLS-SLL API (static inline, same performance as macro but SAFE!)
|
||||
// The old macro had race condition: read head before pop → rbp=0xa0 SEGV
|
||||
void* ptr = NULL;
|
||||
tls_sll_pop(class_idx, &ptr);
|
||||
// 2. Fast path: Frontend pop (FastCache/SFC/SLL)
|
||||
// Try the consolidated fast pop path first (includes FastCache for C0–C3)
|
||||
void* ptr = tiny_alloc_fast_pop(class_idx);
|
||||
if (__builtin_expect(ptr != NULL, 1)) {
|
||||
// C7 (1024B, headerless): clear embedded next pointer before returning to user
|
||||
if (__builtin_expect(class_idx == 7, 0)) {
|
||||
*(void**)ptr = NULL;
|
||||
}
|
||||
// C7 (1024B, headerless) is never returned by tiny_alloc_fast_pop (returns NULL for C7)
|
||||
HAK_RET_ALLOC(class_idx, ptr);
|
||||
}
|
||||
|
||||
// 3. Miss: Refill from backend (Box 3: SuperSlab)
|
||||
// 3. Miss: Refill from TLS List/SuperSlab and take one into FastCache/front
|
||||
{
|
||||
// Use header-aware TLS List bulk transfer that prefers FastCache for C0–C3
|
||||
extern __thread TinyTLSList g_tls_lists[TINY_NUM_CLASSES];
|
||||
void* took = tiny_fast_refill_and_take(class_idx, &g_tls_lists[class_idx]);
|
||||
if (took) {
|
||||
HAK_RET_ALLOC(class_idx, took);
|
||||
}
|
||||
}
|
||||
|
||||
// 4. Still miss: Fallback to existing backend refill and retry
|
||||
int refilled = tiny_alloc_fast_refill(class_idx);
|
||||
if (__builtin_expect(refilled > 0, 1)) {
|
||||
// Refill success → retry pop using safe Box TLS-SLL API
|
||||
ptr = NULL;
|
||||
tls_sll_pop(class_idx, &ptr);
|
||||
ptr = tiny_alloc_fast_pop(class_idx);
|
||||
if (ptr) {
|
||||
if (__builtin_expect(class_idx == 7, 0)) {
|
||||
*(void**)ptr = NULL;
|
||||
}
|
||||
HAK_RET_ALLOC(class_idx, ptr);
|
||||
}
|
||||
}
|
||||
|
||||
// 4. Refill failure or still empty → slow path (OOM or new SuperSlab)
|
||||
// 5. Refill failure or still empty → slow path (OOM or new SuperSlab)
|
||||
// Box Boundary: Delegate to Slow Path (Box 3 backend)
|
||||
ptr = hak_tiny_alloc_slow(size, class_idx);
|
||||
if (ptr) {
|
||||
|
||||
Reference in New Issue
Block a user