90 lines
2.8 KiB
Bash
90 lines
2.8 KiB
Bash
|
|
#!/usr/bin/env bash
|
||
|
|
# sweep_mem_perf.sh - Sweep HAKMEM memory/performance knobs and measure results
|
||
|
|
# Usage: scripts/sweep_mem_perf.sh [tiny|mixed|both]
|
||
|
|
|
||
|
|
set -euo pipefail
|
||
|
|
MODE="${1:-both}"
|
||
|
|
|
||
|
|
bench_tiny() {
|
||
|
|
local REFILL_ONE=$1 SLLM=$2 TRIMMS=$3 FLUSH=$4 INT=$5
|
||
|
|
# Throughput run (short)
|
||
|
|
local out
|
||
|
|
out=$(HAKMEM_TINY_REFILL_ONE_ON_MISS=$REFILL_ONE \
|
||
|
|
HAKMEM_SLL_MULTIPLIER=$SLLM \
|
||
|
|
HAKMEM_TINY_IDLE_TRIM_MS=$TRIMMS \
|
||
|
|
HAKMEM_TINY_IDLE_FLUSH=$FLUSH \
|
||
|
|
HAKMEM_INT_ENGINE=$INT \
|
||
|
|
./bench_tiny_hot_hakmem 64 100 60000 2>/dev/null | tail -n 5)
|
||
|
|
local thr=$(echo "$out" | awk '/Throughput/{print $2}')
|
||
|
|
# Memory run (background)
|
||
|
|
HAKMEM_TINY_REFILL_ONE_ON_MISS=$REFILL_ONE \
|
||
|
|
HAKMEM_SLL_MULTIPLIER=$SLLM \
|
||
|
|
HAKMEM_TINY_IDLE_TRIM_MS=$TRIMMS \
|
||
|
|
HAKMEM_TINY_IDLE_FLUSH=$FLUSH \
|
||
|
|
HAKMEM_INT_ENGINE=$INT \
|
||
|
|
./bench_tiny_hot_hakmem 64 1000 400000000 >/dev/null 2>&1 &
|
||
|
|
local pid=$!
|
||
|
|
sleep 1
|
||
|
|
local rss_kb=0 vms_kb=0
|
||
|
|
if ps -p $pid >/dev/null 2>&1; then
|
||
|
|
rss_kb=$(awk '/VmRSS/{print $2}' /proc/$pid/status)
|
||
|
|
vms_kb=$(awk '/VmSize/{print $2}' /proc/$pid/status)
|
||
|
|
kill $pid 2>/dev/null || true
|
||
|
|
wait $pid 2>/dev/null || true
|
||
|
|
fi
|
||
|
|
echo "tiny,$REFILL_ONE,$SLLM,$TRIMMS,$FLUSH,$INT,$thr,$rss_kb,$vms_kb"
|
||
|
|
}
|
||
|
|
|
||
|
|
bench_mixed() {
|
||
|
|
local REFILL_ONE=$1 SLLM=$2 TRIMMS=$3 FLUSH=$4 INT=$5
|
||
|
|
# Throughput run (short)
|
||
|
|
local out
|
||
|
|
out=$(HAKMEM_TINY_REFILL_ONE_ON_MISS=$REFILL_ONE \
|
||
|
|
HAKMEM_SLL_MULTIPLIER=$SLLM \
|
||
|
|
HAKMEM_TINY_IDLE_TRIM_MS=$TRIMMS \
|
||
|
|
HAKMEM_TINY_IDLE_FLUSH=$FLUSH \
|
||
|
|
HAKMEM_INT_ENGINE=$INT \
|
||
|
|
./bench_random_mixed_hakmem 500000 400 42 2>/dev/null | tail -n 5)
|
||
|
|
local thr=$(echo "$out" | awk '/Throughput/{print $2}')
|
||
|
|
# Memory run (background)
|
||
|
|
HAKMEM_TINY_REFILL_ONE_ON_MISS=$REFILL_ONE \
|
||
|
|
HAKMEM_SLL_MULTIPLIER=$SLLM \
|
||
|
|
HAKMEM_TINY_IDLE_TRIM_MS=$TRIMMS \
|
||
|
|
HAKMEM_TINY_IDLE_FLUSH=$FLUSH \
|
||
|
|
HAKMEM_INT_ENGINE=$INT \
|
||
|
|
./bench_random_mixed_hakmem 5000000 400 42 >/dev/null 2>&1 &
|
||
|
|
local pid=$!
|
||
|
|
sleep 1
|
||
|
|
local rss_kb=0 vms_kb=0
|
||
|
|
if ps -p $pid >/dev/null 2>&1; then
|
||
|
|
rss_kb=$(awk '/VmRSS/{print $2}' /proc/$pid/status)
|
||
|
|
vms_kb=$(awk '/VmSize/{print $2}' /proc/$pid/status)
|
||
|
|
kill $pid 2>/dev/null || true
|
||
|
|
wait $pid 2>/dev/null || true
|
||
|
|
fi
|
||
|
|
echo "mixed,$REFILL_ONE,$SLLM,$TRIMMS,$FLUSH,$INT,$thr,$rss_kb,$vms_kb"
|
||
|
|
}
|
||
|
|
|
||
|
|
echo "bench,refill_one,sll_mult,trim_ms,flush,int_engine,throughput_Mops,rss_kb,vms_kb"
|
||
|
|
|
||
|
|
# Sweep a small set of meaningful combos
|
||
|
|
COMBOS=(
|
||
|
|
"0 2 0 0 0" # baseline perf-ish
|
||
|
|
"1 1 0 0 0" # SLL shrink only
|
||
|
|
"1 1 200 1 1" # memory-mode core
|
||
|
|
"1 2 0 0 0" # refill-one only
|
||
|
|
"0 1 200 1 1" # sll shrink + idle trim
|
||
|
|
"1 1 100 1 1" # aggressive trim
|
||
|
|
)
|
||
|
|
|
||
|
|
for c in "${COMBOS[@]}"; do
|
||
|
|
set -- $c
|
||
|
|
if [[ "$MODE" == "tiny" || "$MODE" == "both" ]]; then
|
||
|
|
bench_tiny "$@"
|
||
|
|
fi
|
||
|
|
if [[ "$MODE" == "mixed" || "$MODE" == "both" ]]; then
|
||
|
|
bench_mixed "$@"
|
||
|
|
fi
|
||
|
|
done
|
||
|
|
|