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>
88 lines
2.8 KiB
C
88 lines
2.8 KiB
C
#include "tiny_ultra_page_arena.h"
|
|
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <stdatomic.h>
|
|
|
|
__thread TinyUltraPageStats g_tiny_ultra_page_stats = {0};
|
|
|
|
// Global aggregated stats for all threads (learning layer / observer 用)
|
|
static _Atomic uint64_t g_tiny_ultra_page_global_refills[TINY_NUM_CLASSES];
|
|
|
|
void tiny_ultra_page_on_refill(int class_idx, SuperSlab* ss)
|
|
{
|
|
(void)ss; // いまは統計のみ。将来 PageArena/LRU で利用予定。
|
|
|
|
if (class_idx < 0 || class_idx >= TINY_NUM_CLASSES) {
|
|
return;
|
|
}
|
|
|
|
g_tiny_ultra_page_stats.superslab_refills[class_idx]++;
|
|
// 学習層から参照しやすいように、軽量なグローバル集計も行う。
|
|
atomic_fetch_add_explicit(&g_tiny_ultra_page_global_refills[class_idx],
|
|
1,
|
|
memory_order_relaxed);
|
|
}
|
|
|
|
void tiny_ultra_page_stats_snapshot(uint64_t refills[TINY_NUM_CLASSES],
|
|
int reset)
|
|
{
|
|
if (!refills) {
|
|
return;
|
|
}
|
|
|
|
for (int cls = 0; cls < TINY_NUM_CLASSES; cls++) {
|
|
refills[cls] = g_tiny_ultra_page_stats.superslab_refills[cls];
|
|
}
|
|
|
|
if (reset) {
|
|
for (int cls = 0; cls < TINY_NUM_CLASSES; cls++) {
|
|
g_tiny_ultra_page_stats.superslab_refills[cls] = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
void tiny_ultra_page_global_stats_snapshot(uint64_t refills[TINY_NUM_CLASSES],
|
|
int reset)
|
|
{
|
|
if (!refills) {
|
|
return;
|
|
}
|
|
|
|
for (int cls = 0; cls < TINY_NUM_CLASSES; cls++) {
|
|
refills[cls] = atomic_load_explicit(&g_tiny_ultra_page_global_refills[cls],
|
|
memory_order_relaxed);
|
|
}
|
|
|
|
if (reset) {
|
|
for (int cls = 0; cls < TINY_NUM_CLASSES; cls++) {
|
|
atomic_store_explicit(&g_tiny_ultra_page_global_refills[cls],
|
|
0,
|
|
memory_order_relaxed);
|
|
}
|
|
}
|
|
}
|
|
|
|
// オプション: Ultra backend 統計をプロセス終了時に 1 回だけダンプ
|
|
// ENV: HAKMEM_TINY_ULTRA_PAGE_DUMP=1 で有効化(デフォルト: 無効)
|
|
static void tiny_ultra_page_dump_stats(void) __attribute__((destructor));
|
|
static void tiny_ultra_page_dump_stats(void)
|
|
{
|
|
const char* dump = getenv("HAKMEM_TINY_ULTRA_PAGE_DUMP");
|
|
if (!dump || !*dump || *dump == '0') {
|
|
return;
|
|
}
|
|
|
|
uint64_t refills[TINY_NUM_CLASSES] = {0};
|
|
// 終了時ダンプではグローバル集計を使うことで、マルチスレッド環境でも全体像を掴みやすくする。
|
|
tiny_ultra_page_global_stats_snapshot(refills, 0);
|
|
|
|
fprintf(stderr, "[ULTRA_PAGE_STATS] class superslab_refills\n");
|
|
for (int c = 0; c < TINY_NUM_CLASSES; c++) {
|
|
if (refills[c] != 0) {
|
|
fprintf(stderr, " C%d: %llu\n",
|
|
c, (unsigned long long)refills[c]);
|
|
}
|
|
}
|
|
}
|