Files
hakmem/core/hakmem_ace.c
Moe Charm (CI) 8feeb63c2b release: silence runtime logs and stabilize benches
- Fix HAKMEM_LOG gating to use  (numeric) so release builds compile out logs.
- Switch remaining prints to HAKMEM_LOG or guard with :
  - core/box/hak_core_init.inc.h (EVO sample warning, shutdown banner)
  - core/hakmem_config.c (config/feature prints)
  - core/hakmem.c (BigCache eviction prints)
  - core/hakmem_tiny_superslab.c (OOM, head init/expand, C7 init diagnostics)
  - core/hakmem_elo.c (init/evolution)
  - core/hakmem_batch.c (init/flush/stats)
  - core/hakmem_ace.c (33KB route diagnostics)
  - core/hakmem_ace_controller.c (ACE logs macro → no-op in release)
  - core/hakmem_site_rules.c (init banner)
  - core/box/hak_free_api.inc.h (unknown method error → release-gated)
- Rebuilt benches and verified quiet output for release:
  - bench_fixed_size_hakmem/system
  - bench_random_mixed_hakmem/system
  - bench_mid_large_mt_hakmem/system
  - bench_comprehensive_hakmem/system

Note: Kept debug logs available in debug builds and when explicitly toggled via env.
2025-11-11 01:47:06 +09:00

113 lines
4.4 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <stdio.h>
#include "hakmem_internal.h"
#include "hakmem_ace.h"
#include "hakmem_pool.h"
#include "hakmem_l25_pool.h"
#include "hakmem_ace_stats.h"
#include "hakmem_policy.h"
#include "hakmem_debug.h"
// Map size to MidPool/LargePool and allocate.
// Phase 6.21: Bridge classes (40KB, 52KB) now hardcoded, DYN1/DYN2 disabled
static inline size_t round_to_mid_class(size_t s, double wmax, const FrozenPolicy* pol) {
// Build candidate set: 2/4/8/16/32/40/52 KiB (Bridge classes now fixed)
size_t cand[7] = {
POOL_CLASS_2KB, POOL_CLASS_4KB, POOL_CLASS_8KB, POOL_CLASS_16KB, POOL_CLASS_32KB,
POOL_CLASS_40KB, POOL_CLASS_52KB // Phase 6.21: Bridge classes
};
// Legacy: DYN1/DYN2 support (currently disabled in Phase 6.21)
// Note: If DYN classes are re-enabled, they should override Bridge classes
if (pol) {
if (pol->mid_dyn1_bytes >= POOL_MIN_SIZE && pol->mid_dyn1_bytes <= POOL_MAX_SIZE) cand[5] = (size_t)pol->mid_dyn1_bytes;
if (pol->mid_dyn2_bytes >= POOL_MIN_SIZE && pol->mid_dyn2_bytes <= POOL_MAX_SIZE) cand[6] = (size_t)pol->mid_dyn2_bytes;
}
// Choose the smallest c >= s that also satisfies c ≤ wmax*s
size_t best = 0; // 0 = not found
for (int i = 0; i < 7; i++) {
size_t c = cand[i];
if (c == 0) continue;
if (c < s) continue;
if ((double)c > wmax * (double)s) continue;
if (best == 0 || c < best) best = c;
}
return best;
}
static inline size_t round_to_large_class(size_t s, double wmax) {
const size_t classes[L25_NUM_CLASSES] = {
L25_CLASS_64KB, L25_CLASS_128KB, L25_CLASS_256KB, L25_CLASS_512KB, L25_CLASS_1MB
};
for (int i = 0; i < L25_NUM_CLASSES; i++) {
size_t c = classes[i];
if (s <= c) {
if ((double)c <= wmax * (double)s) return c;
return 0; // not allowed → fallback
}
}
return 0; // above 1MB
}
void* hkm_ace_alloc(size_t size, uintptr_t site_id, const FrozenPolicy* pol) {
double wmax_mid = (pol ? pol->w_max_mid : 1.33);
double wmax_large = (pol ? pol->w_max_large : 1.25);
// MidPool: 252KiB (Phase 6.21: with Bridge classes for W_MAX rounding)
if (size >= 33000 && size <= 34000) {
#if !HAKMEM_BUILD_RELEASE
fprintf(stderr, "[ACE] Processing 33KB: size=%zu, POOL_MAX_SIZE=%d\n", size, POOL_MAX_SIZE);
#endif
}
if (size <= POOL_MAX_SIZE) {
size_t r = round_to_mid_class(size, wmax_mid, pol);
if (size >= 33000 && size <= 34000) {
#if !HAKMEM_BUILD_RELEASE
fprintf(stderr, "[ACE] round_to_mid_class returned: %zu (0 means no valid class)\n", r);
#endif
}
if (r != 0) {
// Debug: Log 33KB allocation routing (only in debug builds)
#ifdef HAKMEM_DEBUG_VERBOSE
if (size >= 33000 && size <= 34000) {
HAKMEM_LOG("[ACE] 33KB alloc: size=%zu → rounded=%zu (class 5: 40KB)\n", size, r);
}
#endif
if (size >= 33000 && size <= 34000) {
#if !HAKMEM_BUILD_RELEASE
fprintf(stderr, "[ACE] Calling hak_pool_try_alloc with size=%zu\n", r);
#endif
}
HKM_TIME_START(t_mid_get);
void* p = hak_pool_try_alloc(r, site_id);
HKM_TIME_END(HKM_CAT_POOL_GET, t_mid_get);
hkm_ace_stat_mid_attempt(p != NULL);
if (p) return p;
}
// If rounding not allowed or miss, fallthrough to large class rounding below
}
// LargePool: 64KiB1MiB (with W_MAX rounding)
if (size <= L25_MAX_SIZE) {
size_t r = round_to_large_class(size, wmax_large);
if (r != 0) {
HKM_TIME_START(t_l25_get);
void* p = hak_l25_pool_try_alloc(r, site_id);
HKM_TIME_END(HKM_CAT_L25_GET, t_l25_get);
hkm_ace_stat_large_attempt(p != NULL);
if (p) return p;
}
} else if (size > POOL_MAX_SIZE && size < L25_MIN_SIZE) {
// Gap 3264KiB: try rounding up to 64KiB if permitted
// size_t r = round_to_large_class(L25_MIN_SIZE, wmax_large); // check 64KiB vs size (unused)
if ((double)L25_MIN_SIZE <= wmax_large * (double)size) {
HKM_TIME_START(t_l25_get2);
void* p = hak_l25_pool_try_alloc(L25_MIN_SIZE, site_id);
HKM_TIME_END(HKM_CAT_L25_GET, t_l25_get2);
hkm_ace_stat_large_attempt(p != NULL);
if (p) return p;
}
}
hkm_ace_stat_l1_fallback();
return NULL; // Miss: let caller fallback to malloc
}