Phase 12: Shared SuperSlab Pool implementation (WIP - runtime crash)
## Summary
Implemented Phase 12 Shared SuperSlab Pool (mimalloc-style) to address
SuperSlab allocation churn (877 SuperSlabs → 100-200 target).
## Implementation (ChatGPT + Claude)
1. **Metadata changes** (superslab_types.h):
- Added class_idx to TinySlabMeta (per-slab dynamic class)
- Removed size_class from SuperSlab (no longer per-SuperSlab)
- Changed owner_tid (16-bit) → owner_tid_low (8-bit)
2. **Shared Pool** (hakmem_shared_pool.{h,c}):
- Global pool shared by all size classes
- shared_pool_acquire_slab() - Get free slab for class_idx
- shared_pool_release_slab() - Return slab when empty
- Per-class hints for fast path optimization
3. **Integration** (23 files modified):
- Updated all ss->size_class → meta->class_idx
- Updated all meta->owner_tid → meta->owner_tid_low
- superslab_refill() now uses shared pool
- Free path releases empty slabs back to pool
4. **Build system** (Makefile):
- Added hakmem_shared_pool.o to OBJS_BASE and TINY_BENCH_OBJS_BASE
## Status: ⚠️ Build OK, Runtime CRASH
**Build**: ✅ SUCCESS
- All 23 files compile without errors
- Only warnings: superslab_allocate type mismatch (legacy code)
**Runtime**: ❌ SEGFAULT
- Crash location: sll_refill_small_from_ss()
- Exit code: 139 (SIGSEGV)
- Test case: ./bench_random_mixed_hakmem 1000 256 42
## Known Issues
1. **SEGFAULT in refill path** - Likely shared_pool_acquire_slab() issue
2. **Legacy superslab_allocate()** still exists (type mismatch warning)
3. **Remaining TODOs** from design doc:
- SuperSlab physical layout integration
- slab_handle.h cleanup
- Remove old per-class head implementation
## Next Steps
1. Debug SEGFAULT (gdb backtrace shows sll_refill_small_from_ss)
2. Fix shared_pool_acquire_slab() or superslab_init_slab()
3. Basic functionality test (1K → 100K iterations)
4. Measure SuperSlab count reduction (877 → 100-200)
5. Performance benchmark (+650-860% expected)
## Files Changed (25 files)
core/box/free_local_box.c
core/box/free_remote_box.c
core/box/front_gate_classifier.c
core/hakmem_super_registry.c
core/hakmem_tiny.c
core/hakmem_tiny_bg_spill.c
core/hakmem_tiny_free.inc
core/hakmem_tiny_lifecycle.inc
core/hakmem_tiny_magazine.c
core/hakmem_tiny_query.c
core/hakmem_tiny_refill.inc.h
core/hakmem_tiny_superslab.c
core/hakmem_tiny_superslab.h
core/hakmem_tiny_tls_ops.h
core/slab_handle.h
core/superslab/superslab_inline.h
core/superslab/superslab_types.h
core/tiny_debug.h
core/tiny_free_fast.inc.h
core/tiny_free_magazine.inc.h
core/tiny_remote.c
core/tiny_superslab_alloc.inc.h
core/tiny_superslab_free.inc.h
Makefile
## New Files (3 files)
PHASE12_SHARED_SUPERSLAB_POOL_DESIGN.md
core/hakmem_shared_pool.c
core/hakmem_shared_pool.h
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: ChatGPT <chatgpt@openai.com>
This commit is contained in:
@ -70,7 +70,7 @@ static void tiny_remote_track_log_mismatch(const char* stage,
|
||||
uint32_t tid,
|
||||
const char* prev_stage) {
|
||||
if (!__builtin_expect(g_debug_remote_guard, 0)) return;
|
||||
uint16_t cls = ss ? (uint16_t)ss->size_class : 0;
|
||||
uint16_t cls = 0;
|
||||
uintptr_t base = ss ? (uintptr_t)ss : 0;
|
||||
size_t ss_size = ss ? ((size_t)1ULL << ss->lg_size) : 0;
|
||||
fprintf(stderr,
|
||||
@ -278,7 +278,7 @@ int tiny_remote_guard_allow_local_push(SuperSlab* ss,
|
||||
if (__builtin_expect(g_disable_remote_guard, 0)) return 1;
|
||||
} while (0);
|
||||
if (!__builtin_expect(g_debug_remote_guard, 0)) return 1;
|
||||
uint32_t owner = __atomic_load_n(&meta->owner_tid, __ATOMIC_RELAXED);
|
||||
uint32_t owner = (uint32_t)meta->owner_tid_low;
|
||||
if (owner == self_tid && owner != 0) {
|
||||
return 1;
|
||||
}
|
||||
@ -338,7 +338,7 @@ static void tiny_remote_watch_emit(const char* stage,
|
||||
size_t sz = (size_t)1ULL << ss->lg_size;
|
||||
uint32_t combined = (code & 0xFFFFu) | ((stage_hash & 0xFFFFu) << 16);
|
||||
aux = tiny_remote_pack_diag(combined, base, sz, (uintptr_t)node);
|
||||
cls = (uint16_t)ss->size_class;
|
||||
cls = 0;
|
||||
} else {
|
||||
aux = ((uintptr_t)(code & 0xFFFFu) << 32) | (uintptr_t)(stage_hash & 0xFFFFu);
|
||||
}
|
||||
@ -350,13 +350,12 @@ static void tiny_remote_watch_emit(const char* stage,
|
||||
if (ss && slab_idx >= 0 && slab_idx < ss_slabs_capacity(ss)) {
|
||||
TinySlabMeta* meta = &ss->slabs[slab_idx];
|
||||
fprintf(stderr,
|
||||
"[REMOTE_WATCH] stage=%s code=0x%04x cls=%u slab=%d node=%p owner=%u used=%u freelist=%p tid=0x%08x first_tid=0x%08x\n",
|
||||
"[REMOTE_WATCH] stage=%s code=0x%04x slab=%d node=%p owner_tid_low=%u used=%u freelist=%p tid=0x%08x first_tid=0x%08x\n",
|
||||
stage ? stage : "(null)",
|
||||
(unsigned)code,
|
||||
ss->size_class,
|
||||
slab_idx,
|
||||
node,
|
||||
meta->owner_tid,
|
||||
(unsigned)meta->owner_tid_low,
|
||||
(unsigned)meta->used,
|
||||
meta->freelist,
|
||||
tid,
|
||||
@ -433,8 +432,7 @@ static void tiny_remote_dump_queue_sample(SuperSlab* ss, int slab_idx) {
|
||||
uintptr_t head = atomic_load_explicit(&ss->remote_heads[slab_idx], memory_order_relaxed);
|
||||
unsigned rc = atomic_load_explicit(&ss->remote_counts[slab_idx], memory_order_relaxed);
|
||||
fprintf(stderr,
|
||||
"[REMOTE_QUEUE] cls=%u slab=%d head=%p rc=%u\n",
|
||||
ss->size_class,
|
||||
"[REMOTE_QUEUE] slab=%d head=%p rc=%u\n",
|
||||
slab_idx,
|
||||
(void*)head,
|
||||
rc);
|
||||
@ -554,16 +552,15 @@ void tiny_remote_side_set(struct SuperSlab* ss, int slab_idx, void* node, uintpt
|
||||
uintptr_t observed = atomic_load_explicit((_Atomic uintptr_t*)node, memory_order_relaxed);
|
||||
tiny_remote_report_corruption("dup_push", node, observed);
|
||||
uintptr_t aux = tiny_remote_pack_diag(0xA212u, base, ss_size, (uintptr_t)node);
|
||||
tiny_debug_ring_record(TINY_RING_EVENT_REMOTE_INVALID, (uint16_t)ss->size_class, node, aux);
|
||||
tiny_debug_ring_record(TINY_RING_EVENT_REMOTE_INVALID, 0, node, aux);
|
||||
TinySlabMeta* meta = &ss->slabs[slab_idx];
|
||||
fprintf(stderr,
|
||||
"[REMOTE_DUP_PUSH] cls=%u slab=%d node=%p next=%p observed=0x%016" PRIxPTR " owner=%u rc=%u head=%p\n",
|
||||
ss->size_class,
|
||||
"[REMOTE_DUP_PUSH] slab=%d node=%p next=%p observed=0x%016" PRIxPTR " owner_tid_low=%u rc=%u head=%p\n",
|
||||
slab_idx,
|
||||
node,
|
||||
(void*)next,
|
||||
observed,
|
||||
meta->owner_tid,
|
||||
(unsigned)meta->owner_tid_low,
|
||||
(unsigned)atomic_load_explicit(&ss->remote_counts[slab_idx], memory_order_relaxed),
|
||||
(void*)atomic_load_explicit(&ss->remote_heads[slab_idx], memory_order_relaxed));
|
||||
tiny_remote_watch_note("dup_push", ss, slab_idx, node, 0xA234u, 0, 1);
|
||||
|
||||
Reference in New Issue
Block a user