Created
January 14, 2026 18:32
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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