Fix C7 warm/TLS Release path and unify debug instrumentation
This commit is contained in:
@ -18,6 +18,7 @@
|
||||
#include "tiny_box_geometry.h"
|
||||
#include "superslab/superslab_inline.h" // Provides hak_super_lookup() and SUPERSLAB_MAGIC
|
||||
#include "box/tls_sll_box.h"
|
||||
#include "box/c7_meta_used_counter_box.h"
|
||||
#include "box/tiny_header_box.h" // Header Box: Single Source of Truth for header operations
|
||||
#include "box/tiny_front_config_box.h" // Phase 7-Step6-Fix: Config macros for dead code elimination
|
||||
#include "hakmem_tiny_integrity.h"
|
||||
@ -94,6 +95,39 @@ static inline void tiny_debug_validate_node_base(int class_idx, void* node, cons
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline void c7_log_used_assign_cap(TinySlabMeta* meta,
|
||||
int class_idx,
|
||||
const char* tag) {
|
||||
if (__builtin_expect(class_idx != 7, 1)) {
|
||||
return;
|
||||
}
|
||||
#if HAKMEM_BUILD_RELEASE
|
||||
static _Atomic uint32_t rel_logs = 0;
|
||||
uint32_t n = atomic_fetch_add_explicit(&rel_logs, 1, memory_order_relaxed);
|
||||
if (n < 4) {
|
||||
fprintf(stderr,
|
||||
"[REL_C7_USED_ASSIGN] tag=%s used=%u cap=%u carved=%u freelist=%p\n",
|
||||
tag,
|
||||
(unsigned)meta->used,
|
||||
(unsigned)meta->capacity,
|
||||
(unsigned)meta->carved,
|
||||
meta->freelist);
|
||||
}
|
||||
#else
|
||||
static _Atomic uint32_t dbg_logs = 0;
|
||||
uint32_t n = atomic_fetch_add_explicit(&dbg_logs, 1, memory_order_relaxed);
|
||||
if (n < 4) {
|
||||
fprintf(stderr,
|
||||
"[DBG_C7_USED_ASSIGN] tag=%s used=%u cap=%u carved=%u freelist=%p\n",
|
||||
tag,
|
||||
(unsigned)meta->used,
|
||||
(unsigned)meta->capacity,
|
||||
(unsigned)meta->carved,
|
||||
meta->freelist);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// ========= superslab_tls_bump_fast =========
|
||||
//
|
||||
// Ultra bump shadow: current slabが freelist 空で carved<capacity のとき、
|
||||
@ -141,6 +175,11 @@ static inline void* superslab_tls_bump_fast(int class_idx) {
|
||||
|
||||
meta->carved = (uint16_t)(carved + (uint16_t)chunk);
|
||||
meta->used = (uint16_t)(meta->used + (uint16_t)chunk);
|
||||
if (class_idx == 7) {
|
||||
for (uint32_t i = 0; i < chunk; ++i) {
|
||||
c7_meta_used_note(class_idx, C7_META_USED_SRC_FRONT);
|
||||
}
|
||||
}
|
||||
ss_active_add(tls->ss, chunk);
|
||||
#if HAKMEM_DEBUG_COUNTERS
|
||||
g_bump_arms[class_idx]++;
|
||||
@ -365,8 +404,10 @@ int sll_refill_small_from_ss(int class_idx, int max_take)
|
||||
|
||||
meta->freelist = next_raw;
|
||||
meta->used++;
|
||||
c7_meta_used_note(class_idx, C7_META_USED_SRC_FRONT);
|
||||
if (__builtin_expect(meta->used > meta->capacity, 0)) {
|
||||
// 異常検出時はロールバックして終了(fail-fast 回避のため静かに中断)
|
||||
c7_log_used_assign_cap(meta, class_idx, "FREELIST_OVERRUN");
|
||||
meta->used = meta->capacity;
|
||||
break;
|
||||
}
|
||||
@ -414,7 +455,9 @@ int sll_refill_small_from_ss(int class_idx, int max_take)
|
||||
|
||||
meta->carved++;
|
||||
meta->used++;
|
||||
c7_meta_used_note(class_idx, C7_META_USED_SRC_FRONT);
|
||||
if (__builtin_expect(meta->used > meta->capacity, 0)) {
|
||||
c7_log_used_assign_cap(meta, class_idx, "CARVE_OVERRUN");
|
||||
meta->used = meta->capacity;
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user