Files
hakmem/build.sh
Moe Charm (CI) 83bb8624f6 Tiny: fix remote sentinel leak → SEGV; add defense-in-depth; PoolTLS: refill-boundary remote drain; build UX help; quickstart docs
Summary
- Fix SEGV root cause in Tiny random_mixed: TINY_REMOTE_SENTINEL leaked from Remote queue into freelist/TLS SLL.
- Clear/guard sentinel at the single boundary where Remote merges to freelist.
- Add minimal defense-in-depth in freelist_pop and TLS SLL pop.
- Silence verbose prints behind debug gates to reduce noise in release runs.
- Pool TLS: integrate Remote Queue drain at refill boundary to avoid unnecessary backend carve/OS calls when possible.
- DX: strengthen build.sh with help/list/verify and add docs/BUILDING_QUICKSTART.md.

Details
- core/superslab/superslab_inline.h: guard head/node against TINY_REMOTE_SENTINEL; sanitize node[0] when splicing local chain; only print diagnostics when debug guard is enabled.
- core/slab_handle.h: freelist_pop breaks on sentinel head (fail-fast under strict).
- core/tiny_alloc_fast_inline.h: TLS SLL pop breaks on sentinel head (rare branch).
- core/tiny_superslab_free.inc.h: sentinel scan log behind debug guard.
- core/pool_refill.c: try pool_remote_pop_chain() before backend carve in pool_refill_and_alloc().
- core/tiny_adaptive_sizing.c: default adaptive logs off; enable via HAKMEM_ADAPTIVE_LOG=1.
- build.sh: add help/list/verify; EXTRA_MAKEFLAGS passthrough; echo pinned flags.
- docs/BUILDING_QUICKSTART.md: add one‑pager for targets/flags/env/perf/strace.

Verification (high level)
- Tiny random_mixed 10k 256/1024: SEGV resolved; runs complete.
- Pool TLS 1T/4T perf: HAKMEM >= system (≈ +0.7% 1T, ≈ +2.9% 4T); syscall counts ~10–13.

Known issues (to address next)
- Tiny random_mixed perf is weak vs system:
  - 1T/500k/256: cycles/op ≈ 240 vs ~47 (≈5× slower), IPC ≈0.92, branch‑miss ≈11%.
  - 1T/500k/1024: cycles/op ≈ 149 vs ~53 (≈2.8× slower), IPC ≈0.82, branch‑miss ≈10.5%.
  - Hypothesis: frequent SuperSlab path for class7 (fast_cap=0), branchy refill/adopt, and hot-path divergence.
- Proposed next steps:
  - Introduce fast_cap>0 for class7 (bounded TLS SLL) and a simpler batch refill.
  - Add env‑gated Remote Side OFF for 1T A/B (reduce side-table and guards).
  - Revisit likely/unlikely and unify adopt boundary sequencing (drain→bind→acquire) for Tiny.
2025-11-09 16:49:34 +09:00

115 lines
3.4 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# build.sh - Unified build wrapper (Phase 7 + Pool TLS) with discoverable help
#
# Quick use:
# ./build.sh bench_pool_tls_hakmem # Recommended target
# ./build.sh help # Show usage/hints/ENV
# ./build.sh verify bench_pool_tls_hakmem # Check freshness
#
# Notes:
# - Flags are pinned to avoid drift (see below). You can pass extra make flags via
# EXTRA_MAKEFLAGS, e.g. EXTRA_MAKEFLAGS="HAKMEM_DEBUG_VERBOSE=1" ./build.sh <target>
# - Arena ENV (Pool TLS): HAKMEM_POOL_TLS_ARENA_MB_INIT/MAX/GROWTH_LEVELS
# - See also: docs/BUILDING_QUICKSTART.md
set -euo pipefail
TARGET="${1:-bench_mid_large_mt_hakmem}"
usage() {
cat <<'USAGE'
=========================================
HAKMEM Build Script (help)
=========================================
Usage:
./build.sh <target>
./build.sh help # Show this help
./build.sh list # Show common targets
./build.sh verify <bin> # Verify binary freshness
Common targets (curated):
- bench_random_mixed_hakmem
- bench_pool_tls_hakmem
- bench_mid_large_mt_hakmem
- larson_hakmem
Pinned build flags (by default):
POOL_TLS_PHASE1=1 HEADER_CLASSIDX=1 AGGRESSIVE_INLINE=1 PREWARM_TLS=1 POOL_TLS_PREWARM=1
Extra flags (optional):
Use environment var EXTRA_MAKEFLAGS, e.g.:
EXTRA_MAKEFLAGS="HAKMEM_DEBUG_VERBOSE=1" ./build.sh bench_pool_tls_hakmem
EXTRA_MAKEFLAGS="HAKMEM_TINY_SAFE_FREE=1" ./build.sh bench_random_mixed_hakmem
Pool TLS Arena ENV (A/B friendly):
export HAKMEM_POOL_TLS_ARENA_MB_INIT=2 # default 1
export HAKMEM_POOL_TLS_ARENA_MB_MAX=16 # default 8
export HAKMEM_POOL_TLS_ARENA_GROWTH_LEVELS=4 # default 3
Verify & perf tips:
make print-flags
./verify_build.sh <bin>
perf stat -e cycles,instructions,branches,branch-misses,cache-misses -r 3 -- ./<bin> ...
strace -e trace=mmap,madvise,munmap -c ./<bin> ...
USAGE
}
list_targets() {
cat <<'LIST'
Common build targets:
bench_random_mixed_hakmem # Tiny 1T mixed
bench_pool_tls_hakmem # Pool TLS (852KB)
bench_mid_large_mt_hakmem # Mid-Large MT (832KB)
larson_hakmem # Larson mixed
bench_random_mixed_system # glibc baseline
bench_pool_tls_system # glibc baseline (PoolTLS workload)
bench_mid_large_mt_system # glibc baseline (Mid-Large workload)
LIST
}
if [[ "${TARGET}" == "help" || "${TARGET}" == "-h" || "${TARGET}" == "--help" ]]; then
usage
exit 0
fi
if [[ "${TARGET}" == "list" ]]; then
list_targets
exit 0
fi
if [[ "${TARGET}" == "verify" ]]; then
BIN="${2:-}"
if [[ -z "${BIN}" ]]; then
echo "Usage: ./build.sh verify <binary>" >&2
exit 2
fi
./verify_build.sh "${BIN}"
exit 0
fi
echo "========================================="
echo " HAKMEM Build Script"
echo " Target: ${TARGET}"
echo " Flags: POOL_TLS_PHASE1=1 POOL_TLS_PREWARM=1 HEADER_CLASSIDX=1 AGGRESSIVE_INLINE=1 PREWARM_TLS=1 ${EXTRA_MAKEFLAGS:-}"
echo "========================================="
# Always clean to avoid stale objects when toggling flags
make clean >/dev/null 2>&1 || true
# Phase 7 + Pool TLS defaults (pinned) + user extras
make \
POOL_TLS_PHASE1=1 \
POOL_TLS_PREWARM=1 \
HEADER_CLASSIDX=1 \
AGGRESSIVE_INLINE=1 \
PREWARM_TLS=1 \
${EXTRA_MAKEFLAGS:-} \
"${TARGET}"
echo ""
echo "========================================="
echo " ✅ Build successful"
echo " Run: ./${TARGET}"
echo " Tip: ./build.sh help # flags, ENV, targets"
echo "========================================="