Fix tiny lane success handling for TinyHeap routes
This commit is contained in:
@ -6,7 +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_heap_env_box.h" // TinyHeap front gate (C7 / multi-class)
|
||||
#include "tiny_heap_box.h" // TinyHeapBox alloc/free helpers
|
||||
#include "tiny_c7_hotbox.h" // tiny_c7_alloc_fast wrapper
|
||||
|
||||
#ifdef HAKMEM_POOL_TLS_PHASE1
|
||||
@ -70,6 +71,9 @@ inline void* hak_alloc_at(size_t size, hak_callsite_t site) {
|
||||
// Phase 16: Dynamic Tiny max size (ENV: HAKMEM_TINY_MAX_CLASS)
|
||||
// Default: 1023B (C0-C7), reduced to 255B (C0-C5) when Small-Mid enabled
|
||||
// Phase 17-1: Auto-adjusted to avoid overlap with Small-Mid
|
||||
int tiny_class_idx = -1;
|
||||
int tiny_heap_route = 0;
|
||||
int tiny_tried = 0;
|
||||
if (__builtin_expect(size <= tiny_get_max_size(), 1)) {
|
||||
#if HAKMEM_DEBUG_TIMING
|
||||
HKM_TIME_START(t_tiny);
|
||||
@ -86,12 +90,21 @@ inline void* hak_alloc_at(size_t size, hak_callsite_t site) {
|
||||
HKM_TIME_END(HKM_CAT_TINY_ALLOC, t_tiny);
|
||||
#endif
|
||||
// PERF_OPT: likely hint - tiny allocations usually succeed (hot path)
|
||||
tiny_class_idx = hak_tiny_size_to_class(size);
|
||||
tiny_heap_route = (tiny_class_idx >= 0 && tiny_heap_class_route_enabled(tiny_class_idx));
|
||||
tiny_tried = 1;
|
||||
|
||||
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; }
|
||||
// TinyHeap route is also "Tiny lane success" (C7 or other enabled classes)
|
||||
if (__builtin_expect(tiny_heap_route, 0)) {
|
||||
void* th_ptr = NULL;
|
||||
if (tiny_class_idx == 7 && tiny_c7_hot_enabled()) {
|
||||
th_ptr = tiny_c7_alloc_fast(size);
|
||||
} else {
|
||||
th_ptr = tiny_heap_alloc_class_fast(tiny_heap_ctx_for_thread(), tiny_class_idx, size);
|
||||
}
|
||||
if (th_ptr) { hkm_ace_track_alloc(); return th_ptr; }
|
||||
}
|
||||
|
||||
// PHASE 7 CRITICAL FIX: No malloc fallback for Tiny failures
|
||||
@ -227,7 +240,7 @@ inline void* hak_alloc_at(size_t size, hak_callsite_t site) {
|
||||
#endif
|
||||
ptr = hak_os_map_boundary(size, site_id);
|
||||
} else {
|
||||
// LANE_TINY failed - this is a design bug!
|
||||
// LANE_TINY failed - treat TinyHeap route as normal fallback, legacy Tiny failure is a 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());
|
||||
@ -240,8 +253,15 @@ inline void* hak_alloc_at(size_t size, hak_callsite_t site) {
|
||||
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);
|
||||
if (tiny_heap_route) {
|
||||
if (!HAKMEM_BUILD_RELEASE && count < 3) {
|
||||
fprintf(stderr, "[HAKMEM] TinyHeap route fallback size=%zu class=%d (Tiny lane bypass)\n",
|
||||
size, tiny_class_idx);
|
||||
}
|
||||
} else {
|
||||
if (tiny_tried && count < 10) {
|
||||
fprintf(stderr, "[HAKMEM] BUG: Tiny lane failed for size=%zu (should not happen)\n", size);
|
||||
}
|
||||
}
|
||||
errno = ENOMEM;
|
||||
return NULL;
|
||||
|
||||
Reference in New Issue
Block a user