Refactor: Split hakmem_tiny_superslab.c + unified backend exit point

Major refactoring to improve maintainability and debugging:

1. Split hakmem_tiny_superslab.c (1521 lines) into 7 focused files:
   - superslab_allocate.c: SuperSlab allocation/deallocation
   - superslab_backend.c: Backend allocation paths (legacy, shared)
   - superslab_ace.c: ACE (Adaptive Cache Engine) logic
   - superslab_slab.c: Slab initialization and bitmap management
   - superslab_cache.c: LRU cache and prewarm cache management
   - superslab_head.c: SuperSlabHead management and expansion
   - superslab_stats.c: Statistics tracking and debugging

2. Created hakmem_tiny_superslab_internal.h for shared declarations

3. Added superslab_return_block() as single exit point for header writing:
   - All backend allocations now go through this helper
   - Prevents bugs where headers are forgotten in some paths
   - Makes future debugging easier

4. Updated Makefile for new file structure

5. Added header writing to ss_legacy_backend_box.c and
   ss_unified_backend_box.c (though not currently linked)

Note: Header corruption bug in Larson benchmark still exists.
Class 1-6 allocations go through TLS refill/carve paths, not backend.
Further investigation needed.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Moe Charm (CI)
2025-11-29 05:13:04 +09:00
parent b52e1985e6
commit 6ac6f5ae1b
13 changed files with 1734 additions and 1542 deletions

View File

@ -5,6 +5,7 @@
#include "ss_allocation_box.h"
#include "hakmem_tiny_config.h"
#include "hakmem_tiny.h" // For tiny_self_u32
#include "../tiny_region_id.h" // For tiny_region_id_write_header
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
@ -88,7 +89,11 @@ void* hak_tiny_alloc_superslab_backend_hint(int class_idx)
g_ss_legacy_hint_ss[class_idx] = NULL;
}
#if HAKMEM_TINY_HEADER_CLASSIDX
return tiny_region_id_write_header(base, class_idx);
#else
return (void*)base;
#endif
}
// ============================================================================
@ -156,7 +161,11 @@ void* hak_tiny_alloc_superslab_backend_legacy(int class_idx)
hak_tiny_ss_hint_record(class_idx, chunk, slab_idx);
meta->used++;
atomic_fetch_add_explicit(&chunk->total_active_blocks, 1, memory_order_relaxed);
#if HAKMEM_TINY_HEADER_CLASSIDX
return tiny_region_id_write_header(base, class_idx);
#else
return (void*)base;
#endif
}
}
chunk = chunk->next_chunk;
@ -197,7 +206,11 @@ void* hak_tiny_alloc_superslab_backend_legacy(int class_idx)
hak_tiny_ss_hint_record(class_idx, new_chunk, slab_idx);
meta->used++;
atomic_fetch_add_explicit(&new_chunk->total_active_blocks, 1, memory_order_relaxed);
#if HAKMEM_TINY_HEADER_CLASSIDX
return tiny_region_id_write_header(base, class_idx);
#else
return (void*)base;
#endif
}
}