Add TinyHeap class mask and extend routing

This commit is contained in:
Moe Charm (CI)
2025-12-07 22:49:28 +09:00
parent 9c68073557
commit a6991ec9e4
23 changed files with 433 additions and 211 deletions

View File

@ -6,6 +6,8 @@
#include "../hakmem_tiny.h" // For tiny_get_max_size() + hak_lane_classify.inc.h
#include "../hakmem_pool.h" // Phase 2: For hak_pool_try_alloc() (Pool lane 1025B-52KB)
#include "../hakmem_smallmid.h" // For Small-Mid Front Box (Phase 17-1)
#include "tiny_heap_env_box.h" // TinyHeap front gate (C7)
#include "tiny_c7_hotbox.h" // tiny_c7_alloc_fast wrapper
#ifdef HAKMEM_POOL_TLS_PHASE1
#include "../pool_tls.h"
@ -86,6 +88,12 @@ inline void* hak_alloc_at(size_t size, hak_callsite_t site) {
// PERF_OPT: likely hint - tiny allocations usually succeed (hot path)
if (__builtin_expect(tiny_ptr != NULL, 1)) { hkm_ace_track_alloc(); return tiny_ptr; }
// TinyHeap front (C7) は Tiny lane の成功として扱う
if (__builtin_expect(size == 1024 && tiny_c7_heap_mode_enabled(), 0)) {
void* c7_ptr = tiny_c7_alloc_fast(size);
if (c7_ptr) { hkm_ace_track_alloc(); return c7_ptr; }
}
// PHASE 7 CRITICAL FIX: No malloc fallback for Tiny failures
// If Tiny fails for size <= tiny_get_max_size(), let it flow to Mid/ACE layers
// This prevents mixed HAKMEM/libc allocation bugs
@ -222,6 +230,15 @@ inline void* hak_alloc_at(size_t size, hak_callsite_t site) {
// LANE_TINY failed - this is a design bug!
HAK_LANE_ASSERT_NO_FALLBACK(LANE_FALLBACK, size);
static _Atomic int oom_count = 0;
const int c7_heap_on = (size == 1024 && tiny_heap_box_enabled());
if (__builtin_expect(c7_heap_on, 0)) {
if (tiny_c7_hot_enabled()) {
void* retry = tiny_c7_alloc_fast(size);
if (retry) { hkm_ace_track_alloc(); return retry; }
}
errno = ENOMEM;
return NULL;
}
int count = atomic_fetch_add(&oom_count, 1);
if (count < 10) {
fprintf(stderr, "[HAKMEM] BUG: Tiny lane failed for size=%zu (should not happen)\n", size);