Skip to content

Instantly share code, notes, and snippets.

@DocShotgun
Created January 14, 2026 18:32
Show Gist options
  • Select an option

  • Save DocShotgun/1e4e76b7a67cd44002471022a7561f82 to your computer and use it in GitHub Desktop.

Select an option

Save DocShotgun/1e4e76b7a67cd44002471022a7561f82 to your computer and use it in GitHub Desktop.
Temporarily disable system-wide NUMA balancing for the duration of execution of a command
#!/usr/bin/env bash
set -euo pipefail
NUMA_KEY="kernel.numa_balancing"
if [[ $# -eq 0 ]]; then
echo "Usage: $0 <command> [args...]" >&2
exit 1
fi
# Read current value (read is unprivileged)
ORIG_NUMA=$(sysctl -n "$NUMA_KEY")
cleanup() {
sudo sysctl -w "$NUMA_KEY=$ORIG_NUMA" >/dev/null
}
trap cleanup EXIT INT TERM
# Disable NUMA balancing
sudo sysctl -w "$NUMA_KEY=0" >/dev/null
echo "NUMA balancing disabled (was $ORIG_NUMA)"
# Run with all args
"$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment