Idempotent in-guest tuning: sysctl profile, fq/bbr, THP->madvise with boot persistence (yields to tuned), fstrim.timer. First applied to pfv-k8s-wnode-tsys3. Ticket: https://projects.knownelement.com/issues/737
85 lines
3.2 KiB
Bash
85 lines
3.2 KiB
Bash
#!/bin/bash
|
|
# deploy-guest-perfpack.sh — guest-side perf pack (ticket #737)
|
|
# Run INSIDE a guest VM: bash tests/remote.sh vm-file proxmox/perf/scripts/deploy-guest-perfpack.sh
|
|
# Idempotent. Applies: sysctl tuning (swappiness/dirty/net buffers/slow-start),
|
|
# fq + bbr (when the kernel module exists), THP->madvise (skipped when tuned
|
|
# manages THP, e.g. k8s cnodes on network-latency), fstrim.timer.
|
|
# Pairs with the host-side qm flags (iothread/ssd=1/discard=on).
|
|
set -u
|
|
|
|
log() { echo "[perfpack] $*"; }
|
|
|
|
# --- 1. sysctl profile ---
|
|
bbr=0
|
|
if modprobe tcp_bbr 2>/dev/null && grep -qw bbr /proc/sys/net/ipv4/tcp_available_congestion_control 2>/dev/null; then
|
|
bbr=1
|
|
fi
|
|
conf=/etc/sysctl.d/99-perfopt.conf
|
|
{
|
|
echo "# perf pack #737 (idempotent redeploy overwrites)"
|
|
echo "vm.swappiness = 10"
|
|
echo "vm.dirty_ratio = 10"
|
|
echo "vm.dirty_background_ratio = 3"
|
|
echo "net.core.rmem_max = 4194304"
|
|
echo "net.core.wmem_max = 4194304"
|
|
echo "net.core.rmem_default = 262144"
|
|
echo "net.core.wmem_default = 262144"
|
|
echo "net.ipv4.tcp_slow_start_after_idle = 0"
|
|
echo "net.core.default_qdisc = fq"
|
|
if [ "$bbr" = 1 ]; then
|
|
echo "net.ipv4.tcp_congestion_control = bbr"
|
|
fi
|
|
} > "$conf"
|
|
sysctl --system >/dev/null 2>&1
|
|
log "sysctl applied ($conf): swappiness=$(sysctl -n vm.swappiness 2>/dev/null) cc=$(sysctl -n net.ipv4.tcp_congestion_control 2>/dev/null) qdisc=$(sysctl -n net.core.default_qdisc 2>/dev/null) bbr=$bbr"
|
|
|
|
# --- 2. THP -> madvise (live now + persisted via oneshot unit) ---
|
|
tuned_active=0
|
|
if command -v tuned-adm >/dev/null 2>&1; then
|
|
tuned-adm active 2>/dev/null | grep -qvi 'no current\|inactive\|none' && tuned_active=1
|
|
fi
|
|
if [ "$tuned_active" = 1 ]; then
|
|
log "THP: tuned profile active ($(tuned-adm active 2>/dev/null | awk '{print $NF}')) — leaving THP to tuned"
|
|
else
|
|
thp=/sys/kernel/mm/transparent_hugepage/enabled
|
|
cur=$(tr '[]' ' ' < "$thp" 2>/dev/null | awk '{print $NF}')
|
|
if [ "$cur" != "madvise" ]; then
|
|
if echo madvise > "$thp" 2>/dev/null; then
|
|
log "THP: ${cur:-unknown} -> madvise (live)"
|
|
else
|
|
log "THP: WARNING live set failed (check $thp permissions)"
|
|
fi
|
|
else
|
|
log "THP: already madvise"
|
|
fi
|
|
unit=/etc/systemd/system/thp-madvise.service
|
|
if [ ! -f "$unit" ]; then
|
|
{
|
|
echo "[Unit]"
|
|
echo "Description=Set transparent hugepages to madvise (perf pack #737)"
|
|
echo "DefaultDependencies=no"
|
|
echo "After=local-fs.target"
|
|
echo "Before=sysinit.target"
|
|
echo
|
|
echo "[Service]"
|
|
echo "Type=oneshot"
|
|
echo "ExecStart=/bin/sh -c 'echo madvise > /sys/kernel/mm/transparent_hugepage/enabled'"
|
|
echo
|
|
echo "[Install]"
|
|
echo "WantedBy=sysinit.target"
|
|
} > "$unit"
|
|
systemctl daemon-reload
|
|
systemctl enable thp-madvise.service >/dev/null 2>&1
|
|
log "THP: persistence unit installed + enabled"
|
|
fi
|
|
fi
|
|
|
|
# --- 3. fstrim (pairs with host-side discard=on) ---
|
|
if systemctl enable --now fstrim.timer >/dev/null 2>&1; then
|
|
log "fstrim.timer enabled"
|
|
else
|
|
log "fstrim.timer: not available on this guest"
|
|
fi
|
|
|
|
log "done"
|