Tiny: fix header/stride mismatch and harden refill paths
- Root cause: header-based class indexing (HEADER_CLASSIDX=1) wrote a 1-byte header during allocation, but linear carve/refill and initial slab capacity still used bare class block sizes. This mismatch could overrun slab usable space and corrupt freelists, causing reproducible SEGV at ~100k iters. Changes - Superslab: compute capacity with effective stride (block_size + header for classes 0..6; class7 remains headerless) in superslab_init_slab(). Add a debug-only bound check in superslab_alloc_from_slab() to fail fast if carve would exceed usable bytes. - Refill (non-P0 and P0): use header-aware stride for all linear carving and TLS window bump operations. Ensure alignment/validation in tiny_refill_opt.h also uses stride, not raw class size. - Drain: keep existing defense-in-depth for remote sentinel and sanitize nodes before splicing into freelist (already present). Notes - This unifies the memory layout across alloc/linear-carve/refill with a single stride definition and keeps class7 (1024B) headerless as designed. - Debug builds add fail-fast checks; release builds remain lean. Next - Re-run Tiny benches (256/1024B) in debug to confirm stability, then in release. If any remaining crash persists, bisect with HAKMEM_TINY_P0_BATCH_REFILL=0 to isolate P0 batch carve, and continue reducing branch-miss as planned.
This commit is contained in:
92
run_pool_bench.sh
Executable file
92
run_pool_bench.sh
Executable file
@ -0,0 +1,92 @@
|
||||
#!/usr/bin/env bash
|
||||
# run_pool_bench.sh - Pool TLS Phase 1.5a パフォーマンステスト
|
||||
#
|
||||
# Pool TLS の性能を System malloc / mimalloc と比較
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
echo "========================================="
|
||||
echo " 🧪 Pool TLS Phase 1.5a Benchmark"
|
||||
echo "========================================="
|
||||
echo ""
|
||||
|
||||
# 1. Build Pool TLS version
|
||||
echo "📦 Building Pool TLS Phase 1.5a..."
|
||||
./build_pool_tls.sh bench_mid_large_mt_hakmem >/dev/null 2>&1
|
||||
echo "✓ HAKMEM built"
|
||||
|
||||
# 2. Build System malloc version
|
||||
echo "📦 Building System malloc version..."
|
||||
./build.sh bench_mid_large_mt_system >/dev/null 2>&1
|
||||
echo "✓ System malloc built"
|
||||
|
||||
echo ""
|
||||
echo "========================================="
|
||||
echo " 📊 Running Benchmarks"
|
||||
echo "========================================="
|
||||
echo ""
|
||||
|
||||
# Test parameters
|
||||
THREADS=1
|
||||
CYCLES=100000
|
||||
WORKSET=256
|
||||
SEED=42
|
||||
|
||||
# Run HAKMEM
|
||||
echo "🔵 HAKMEM (Pool TLS Phase 1.5a)..."
|
||||
HAKMEM_OUTPUT=$(./bench_mid_large_mt_hakmem $THREADS $CYCLES $WORKSET $SEED 2>&1)
|
||||
HAKMEM_RESULT=$(echo "$HAKMEM_OUTPUT" | grep "Throughput" | awk '{print $3}')
|
||||
HAKMEM_TIME=$(echo "$HAKMEM_OUTPUT" | grep "Throughput" | awk '{print $NF}' | tr -d 's.')
|
||||
|
||||
# Run System
|
||||
echo "🟢 System malloc..."
|
||||
SYSTEM_OUTPUT=$(./bench_mid_large_mt_system $THREADS $CYCLES $WORKSET $SEED 2>&1)
|
||||
SYSTEM_RESULT=$(echo "$SYSTEM_OUTPUT" | grep "Throughput" | awk '{print $3}')
|
||||
SYSTEM_TIME=$(echo "$SYSTEM_OUTPUT" | grep "Throughput" | awk '{print $NF}' | tr -d 's.')
|
||||
|
||||
# Calculate performance ratio
|
||||
RATIO=$(echo "scale=2; $HAKMEM_RESULT / $SYSTEM_RESULT * 100" | bc)
|
||||
SPEEDUP=$(echo "scale=2; $HAKMEM_RESULT / $SYSTEM_RESULT" | bc)
|
||||
|
||||
# Determine status emoji
|
||||
if (( $(echo "$RATIO >= 100" | bc -l) )); then
|
||||
STATUS="🏆"
|
||||
VERDICT="HAKMEM WINS!"
|
||||
elif (( $(echo "$RATIO >= 80" | bc -l) )); then
|
||||
STATUS="✅"
|
||||
VERDICT="Competitive"
|
||||
elif (( $(echo "$RATIO >= 50" | bc -l) )); then
|
||||
STATUS="⚠️ "
|
||||
VERDICT="Below target"
|
||||
else
|
||||
STATUS="❌"
|
||||
VERDICT="Needs optimization"
|
||||
fi
|
||||
|
||||
# Pretty print results
|
||||
echo ""
|
||||
echo "========================================="
|
||||
echo " 📊 Performance Results"
|
||||
echo "========================================="
|
||||
printf "%-25s %12s ops/s (%.3fs)\n" "HAKMEM (Pool TLS):" "$HAKMEM_RESULT" "$HAKMEM_TIME"
|
||||
printf "%-25s %12s ops/s (%.3fs)\n" "System malloc:" "$SYSTEM_RESULT" "$SYSTEM_TIME"
|
||||
echo "----------------------------------------"
|
||||
printf "%-25s %11s%% (${SPEEDUP}x)\n" "Performance ratio:" "$RATIO"
|
||||
echo "========================================="
|
||||
echo " $STATUS $VERDICT"
|
||||
echo "========================================="
|
||||
echo ""
|
||||
|
||||
# Expected performance targets
|
||||
echo "📈 Pool TLS Phase 1.5a Targets:"
|
||||
echo " - Current: 1.0-2.0M ops/s (baseline)"
|
||||
echo " - Phase 1.5b: 5-15M ops/s (with optimizations)"
|
||||
echo " - Phase 2: 15-30M ops/s (full learning)"
|
||||
echo ""
|
||||
|
||||
# Exit code based on performance
|
||||
if (( $(echo "$RATIO >= 50" | bc -l) )); then
|
||||
exit 0
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user