Boxify superslab registry, add bench profile, and document C7 hotpath experiments

This commit is contained in:
Moe Charm (CI)
2025-12-07 03:12:27 +09:00
parent 18faa6a1c4
commit fda6cd2e67
71 changed files with 2052 additions and 286 deletions

View File

@ -15,10 +15,7 @@
#include <string.h>
#include <strings.h>
#include <stdatomic.h>
#define C7_META_COUNTER_DEFINE
#include "core/box/c7_meta_used_counter_box.h"
#undef C7_META_COUNTER_DEFINE
#include "core/box/warm_pool_rel_counters_box.h"
#include <sys/resource.h>
#ifdef USE_HAKMEM
#include "hakmem.h"
@ -26,6 +23,9 @@
#include "core/box/c7_meta_used_counter_box.h"
#include "core/box/tiny_class_stats_box.h"
#include "core/box/tiny_class_policy_box.h"
#include "core/box/ss_stats_box.h"
#include "core/box/warm_pool_rel_counters_box.h"
#include "core/box/tiny_mem_stats_box.h"
// Box BenchMeta: Benchmark metadata management (bypass hakmem wrapper)
// Phase 15: Separate BenchMeta (slots array) from CoreAlloc (user workload)
@ -61,10 +61,30 @@ static inline int bench_is_c7_only_mode(void) {
return bench_mode_c7_only;
}
// C5/C6 専用ベンチモード (ENV: HAKMEM_BENCH_C5_ONLY / HAKMEM_BENCH_C6_ONLY)
static int bench_mode_c5_only = -1;
static int bench_mode_c6_only = -1;
static inline int bench_is_c5_only_mode(void) {
if (bench_mode_c5_only == -1) {
const char* e = getenv("HAKMEM_BENCH_C5_ONLY");
bench_mode_c5_only = (e && *e && *e != '0') ? 1 : 0;
}
return bench_mode_c5_only;
}
static inline int bench_is_c6_only_mode(void) {
if (bench_mode_c6_only == -1) {
const char* e = getenv("HAKMEM_BENCH_C6_ONLY");
bench_mode_c6_only = (e && *e && *e != '0') ? 1 : 0;
}
return bench_mode_c6_only;
}
int main(int argc, char** argv){
int cycles = (argc>1)? atoi(argv[1]) : 10000000; // total ops (10M for steady-state measurement)
int ws = (argc>2)? atoi(argv[2]) : 8192; // working-set slots
uint32_t seed = (argc>3)? (uint32_t)strtoul(argv[3],NULL,10) : 1234567u;
struct rusage ru0 = {0}, ru1 = {0};
getrusage(RUSAGE_SELF, &ru0);
// サイズレンジTiny-only / Non-Tiny-only の比較用)
// 既定: 16..1040 bytes元の挙動と同等
@ -97,8 +117,14 @@ int main(int argc, char** argv){
if (min_size < 1) min_size = 1;
if (max_size < min_size) max_size = min_size;
// C7 専用モード: サイズを C7 帯に固定(現行 C7 ブロックサイズ ≈ 1024B
if (bench_is_c7_only_mode()) {
// C5/C6/C7 専用モード: サイズを各クラス帯に固定
if (bench_is_c5_only_mode()) {
min_size = 256;
max_size = 256;
} else if (bench_is_c6_only_mode()) {
min_size = 512;
max_size = 512;
} else if (bench_is_c7_only_mode()) {
min_size = 1024;
max_size = 1024;
}
@ -238,10 +264,13 @@ int main(int argc, char** argv){
for (int i=0;i<ws;i++){ if (slots[i]) { free(slots[i]); slots[i]=NULL; } }
fprintf(stderr, "[TEST] Drain phase completed.\n");
uint64_t end = now_ns();
getrusage(RUSAGE_SELF, &ru1);
double sec = (double)(end-start)/1e9;
double tput = (double)cycles / (sec>0.0?sec:1e-9);
// Include params in output to avoid confusion about test conditions
printf("Throughput = %9.0f ops/s [iter=%d ws=%d] time=%.3fs\n", tput, cycles, ws, sec);
long rss_kb = ru1.ru_maxrss;
fprintf(stderr, "[RSS] max_kb=%ld\n", rss_kb);
(void)allocs; (void)frees;
// Box BenchMeta: Use __libc_free to bypass hakmem wrapper
@ -270,6 +299,14 @@ int main(int argc, char** argv){
tiny_class_stats_dump_global(stderr, "[CLASS_STATS_GLOBAL]");
}
const char* tiny_mem_dump_env = getenv("HAKMEM_TINY_MEM_DUMP");
if (tiny_mem_dump_env && *tiny_mem_dump_env && *tiny_mem_dump_env != '0') {
tiny_mem_stats_dump();
}
// Superslab/slab counters (ENV: HAKMEM_SS_STATS_DUMP=1)
ss_stats_dump_if_requested();
// Warm Pool Stats (ENV-gated: HAKMEM_WARM_POOL_STATS=1)
extern void tiny_warm_pool_print_stats_public(void);
tiny_warm_pool_print_stats_public();