Phase 9-2: Remove Legacy Backend & Unify to Shared Pool (50M ops/s)
- Removed Legacy Backend fallback; Shared Pool is now the sole backend. - Removed Soft Cap limit in Shared Pool to allow full memory management. - Implemented EMPTY slab recycling with batched meta->used decrement in remote drain. - Updated tiny_free_local_box to return is_empty status for safe recycling. - Fixed race condition in release path by removing from legacy list early. - Achieved 50.3M ops/s in WS8192 benchmark (+200% vs baseline).
This commit is contained in:
@ -19,11 +19,11 @@ void tiny_failfast_log(const char* stage,
|
||||
void* ptr,
|
||||
void* prev);
|
||||
|
||||
void tiny_free_local_box(SuperSlab* ss, int slab_idx, TinySlabMeta* meta, void* ptr, uint32_t my_tid) {
|
||||
int tiny_free_local_box(SuperSlab* ss, int slab_idx, TinySlabMeta* meta, void* ptr, uint32_t my_tid) {
|
||||
extern _Atomic uint64_t g_free_local_box_calls;
|
||||
atomic_fetch_add_explicit(&g_free_local_box_calls, 1, memory_order_relaxed);
|
||||
if (!(ss && ss->magic == SUPERSLAB_MAGIC)) return;
|
||||
if (slab_idx < 0 || slab_idx >= ss_slabs_capacity(ss)) return;
|
||||
if (!(ss && ss->magic == SUPERSLAB_MAGIC)) return 0;
|
||||
if (slab_idx < 0 || slab_idx >= ss_slabs_capacity(ss)) return 0;
|
||||
(void)my_tid;
|
||||
|
||||
// ✅ Phase E1-CORRECT: ALL classes have headers, calculate BASE pointer once
|
||||
@ -177,11 +177,16 @@ void tiny_free_local_box(SuperSlab* ss, int slab_idx, TinySlabMeta* meta, void*
|
||||
|
||||
// Track local free (debug helpers may be no-op)
|
||||
tiny_remote_track_on_local_free(ss, slab_idx, ptr, "local_free", my_tid);
|
||||
meta->used--;
|
||||
|
||||
// BUGFIX Phase 9-2: Use atomic_fetch_sub to detect 1->0 transition reliably
|
||||
// meta->used--; // old
|
||||
uint16_t prev_used = atomic_fetch_sub_explicit(&meta->used, 1, memory_order_release);
|
||||
int is_empty = (prev_used == 1); // Transitioned from 1 to 0
|
||||
|
||||
ss_active_dec_one(ss);
|
||||
|
||||
// Phase 12-1.1: EMPTY slab detection (immediate reuse optimization)
|
||||
if (meta->used == 0) {
|
||||
if (is_empty) {
|
||||
// Slab became EMPTY → mark for highest-priority reuse
|
||||
ss_mark_slab_empty(ss, slab_idx);
|
||||
|
||||
@ -206,4 +211,6 @@ void tiny_free_local_box(SuperSlab* ss, int slab_idx, TinySlabMeta* meta, void*
|
||||
uint8_t cls0 = (meta && meta->class_idx < TINY_NUM_CLASSES) ? meta->class_idx : 0;
|
||||
tiny_free_publish_first_free((int)cls0, ss, slab_idx);
|
||||
}
|
||||
|
||||
return is_empty;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user