Phase 3d-B: TLS Cache Merge - Unified g_tls_sll[] structure (+12-18% expected)
Merge separate g_tls_sll_head[] and g_tls_sll_count[] arrays into unified TinyTLSSLL struct to improve L1D cache locality. Expected performance gain: +12-18% from reducing cache line splits (2 loads → 1 load per operation). Changes: - core/hakmem_tiny.h: Add TinyTLSSLL type (16B aligned, head+count+pad) - core/hakmem_tiny.c: Replace separate arrays with g_tls_sll[8] - core/box/tls_sll_box.h: Update Box API (13 sites) for unified access - Updated 32+ files: All g_tls_sll_head[i] → g_tls_sll[i].head - Updated 32+ files: All g_tls_sll_count[i] → g_tls_sll[i].count - core/hakmem_tiny_integrity.h: Unified canary guards - core/box/integrity_box.c: Simplified canary validation - Makefile: Added core/box/tiny_sizeclass_hist_box.o to link Build: ✅ PASS (10K ops sanity test) Warnings: Only pre-existing LTO type mismatches (unrelated) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
67
core/box/tiny_near_empty_box.h
Normal file
67
core/box/tiny_near_empty_box.h
Normal file
@ -0,0 +1,67 @@
|
||||
// tiny_near_empty_box.h - Box: Tiny Near-Empty Slab Advisor (C2/C3)
|
||||
//
|
||||
// 目的:
|
||||
// - Tiny Superslab の free パスで「ほぼ空き slab」を検出する軽量な観測箱。
|
||||
// - いまは C2/C3 限定で、used/cap から near-empty な slab を検知して
|
||||
// カウンタを増やすだけ(SuperSlab/SharedPool の状態は一切変更しない)。
|
||||
// - Learner から near-empty 統計を見て CAP/キャッシュ/しきい値を調整する足場として使う。
|
||||
//
|
||||
// ENV:
|
||||
// - HAKMEM_TINY_SS_PACK_C23=1
|
||||
// → C2/C3 の near-empty 検出を有効化(既定0: 無効)。
|
||||
// - HAKMEM_TINY_NEAREMPTY_DUMP=1
|
||||
// → 終了時に [TINY_NEAR_EMPTY_STATS] を 1 回だけダンプ。
|
||||
// - HAKMEM_TINY_NEAREMPTY_PCT=P (1-99, default 25)
|
||||
// → near-empty 判定の使用率しきい値 (%).
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include "../hakmem_tiny_config.h" // TINY_NUM_CLASSES
|
||||
#include "../superslab/superslab_types.h" // TinySlabMeta, SuperSlab
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Per-class near-empty events(観測用カウンタ)
|
||||
extern _Atomic uint64_t g_tiny_near_empty_events[TINY_NUM_CLASSES];
|
||||
|
||||
// 現在のしきい値(%)を取得(1-99)
|
||||
int tiny_near_empty_get_pct(void);
|
||||
|
||||
// しきい値(%)を更新(1-99 範囲外の値は無視)
|
||||
void tiny_near_empty_set_pct(int pct);
|
||||
|
||||
// near-empty 検出(free パスから呼ばれるメインエントリ)。
|
||||
// - C2/C3 限定(現時点では 32B〜128B のホットクラスのみ)。
|
||||
// - used>0 かつ used/cap <= THRESH_PCT% のとき near-empty とみなして 1 カウント。
|
||||
// - SuperSlab/SharedPool の state には触らない(観測のみ)。
|
||||
static inline void tiny_near_empty_on_free(int class_idx,
|
||||
SuperSlab* ss,
|
||||
int slab_idx,
|
||||
TinySlabMeta* meta)
|
||||
{
|
||||
(void)ss;
|
||||
(void)slab_idx;
|
||||
if (!meta) {
|
||||
return;
|
||||
}
|
||||
extern int tiny_near_empty_enabled(void);
|
||||
extern void tiny_near_empty_on_free_impl(int class_idx, TinySlabMeta* meta);
|
||||
if (!tiny_near_empty_enabled()) {
|
||||
return;
|
||||
}
|
||||
tiny_near_empty_on_free_impl(class_idx, meta);
|
||||
}
|
||||
|
||||
// near-empty 統計のスナップショットを取得。
|
||||
// - events: 出力配列(NULL の場合は無視)
|
||||
// - reset!=0 のとき、読み取り後 0 にリセットする。
|
||||
void tiny_near_empty_stats_snapshot(uint64_t events[TINY_NUM_CLASSES],
|
||||
int reset);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user