Fix C7 warm/TLS Release path and unify debug instrumentation

This commit is contained in:
Moe Charm (CI)
2025-12-05 23:41:01 +09:00
parent 96c2988381
commit d17ec46628
29 changed files with 1314 additions and 123 deletions

View File

@ -6,11 +6,42 @@
#include "hakmem_env_cache.h" // Priority-2: ENV cache
#include "superslab/superslab_inline.h" // superslab_ref_get guard for TLS pins
#include "box/ss_release_guard_box.h" // Box: SuperSlab Release Guard
#include "box/ss_slab_reset_box.h" // Box: Reset slab metadata on reuse path
#include <stdlib.h>
#include <stdio.h>
#include <stdatomic.h>
static inline void c7_release_log_once(SuperSlab* ss, int slab_idx) {
#if HAKMEM_BUILD_RELEASE
static _Atomic uint32_t rel_c7_release_logs = 0;
uint32_t n = atomic_fetch_add_explicit(&rel_c7_release_logs, 1, memory_order_relaxed);
if (n < 8) {
TinySlabMeta* meta = &ss->slabs[slab_idx];
fprintf(stderr,
"[REL_C7_RELEASE] ss=%p slab=%d used=%u cap=%u carved=%u\n",
(void*)ss,
slab_idx,
(unsigned)meta->used,
(unsigned)meta->capacity,
(unsigned)meta->carved);
}
#else
static _Atomic uint32_t dbg_c7_release_logs = 0;
uint32_t n = atomic_fetch_add_explicit(&dbg_c7_release_logs, 1, memory_order_relaxed);
if (n < 8) {
TinySlabMeta* meta = &ss->slabs[slab_idx];
fprintf(stderr,
"[DBG_C7_RELEASE] ss=%p slab=%d used=%u cap=%u carved=%u\n",
(void*)ss,
slab_idx,
(unsigned)meta->used,
(unsigned)meta->capacity,
(unsigned)meta->carved);
}
#endif
}
void
shared_pool_release_slab(SuperSlab* ss, int slab_idx)
{
@ -75,6 +106,9 @@ shared_pool_release_slab(SuperSlab* ss, int slab_idx)
}
uint8_t class_idx = slab_meta->class_idx;
if (class_idx == 7) {
c7_release_log_once(ss, slab_idx);
}
// Guard: if SuperSlab is pinned (TLS/remote references), defer release to avoid
// class_map=255 while pointers are still in-flight.
@ -101,6 +135,39 @@ shared_pool_release_slab(SuperSlab* ss, int slab_idx)
}
#endif
if (class_idx == 7) {
ss_slab_reset_meta_for_tiny(ss, slab_idx, class_idx);
#if HAKMEM_BUILD_RELEASE
static _Atomic uint32_t rel_c7_reset_logs = 0;
uint32_t rn = atomic_fetch_add_explicit(&rel_c7_reset_logs, 1, memory_order_relaxed);
if (rn < 4) {
TinySlabMeta* m = &ss->slabs[slab_idx];
fprintf(stderr,
"[REL_C7_RELEASE_RESET] ss=%p slab=%d used=%u cap=%u carved=%u freelist=%p\n",
(void*)ss,
slab_idx,
(unsigned)m->used,
(unsigned)m->capacity,
(unsigned)m->carved,
m->freelist);
}
#else
static _Atomic uint32_t dbg_c7_reset_logs = 0;
uint32_t rn = atomic_fetch_add_explicit(&dbg_c7_reset_logs, 1, memory_order_relaxed);
if (rn < 4) {
TinySlabMeta* m = &ss->slabs[slab_idx];
fprintf(stderr,
"[DBG_C7_RELEASE_RESET] ss=%p slab=%d used=%u cap=%u carved=%u freelist=%p\n",
(void*)ss,
slab_idx,
(unsigned)m->used,
(unsigned)m->capacity,
(unsigned)m->carved,
m->freelist);
}
#endif
}
// Find SharedSSMeta for this SuperSlab
SharedSSMeta* sp_meta = NULL;
uint32_t count = atomic_load_explicit(&g_shared_pool.ss_meta_count, memory_order_relaxed);