Created
January 23, 2026 20:35
-
-
Save maurorappa/4a724b1d39a9d16c23363680f0672972 to your computer and use it in GitHub Desktop.
NUMA isolation script
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
| it shows you the NUMA CPU split and make you choose where to run the OS and where the trading sw |
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
| #!/bin/sh | |
| ### ---------- Dependency check & install ---------- | |
| need_root() { | |
| if [ "$(id -u)" -ne 0 ]; then | |
| echo "This script must be run as root to install dependencies." | |
| exit 1 | |
| fi | |
| } | |
| install_packages() { | |
| if command -v apt-get >/dev/null 2>&1; then | |
| apt-get update | |
| apt-get install -y dialog numactl | |
| elif command -v yum >/dev/null 2>&1; then | |
| yum install -y dialog numactl | |
| else | |
| echo "No supported package manager found (apt or yum)." | |
| exit 1 | |
| fi | |
| } | |
| missing="" | |
| command -v dialog >/dev/null 2>&1 || missing="$missing dialog" | |
| command -v numactl >/dev/null 2>&1 || missing="$missing numactl" | |
| if [ -n "$missing" ]; then | |
| need_root | |
| echo "Installing missing packages:$missing" | |
| install_packages | |
| fi | |
| ### ---------- Verify NUMA support ---------- | |
| ONLINE_FILE=/sys/devices/system/node/online | |
| if [ ! -r "$ONLINE_FILE" ]; then | |
| echo "NUMA is not supported or $ONLINE_FILE is missing." | |
| exit 0 | |
| fi | |
| ### ---------- Helpers ---------- | |
| expand_range() { | |
| echo "$1" | tr ',' '\n' | while read part; do | |
| case "$part" in | |
| *-*) | |
| start=${part%-*} | |
| end=${part#*-} | |
| i=$start | |
| while [ "$i" -le "$end" ]; do | |
| echo "$i" | |
| i=$((i + 1)) | |
| done | |
| ;; | |
| *) | |
| echo "$part" | |
| ;; | |
| esac | |
| done | |
| } | |
| all_nodes=$(expand_range "$(cat "$ONLINE_FILE")") | |
| ### ---------- Dialog 1: OS NUMA node ---------- | |
| set -- dialog --separate-output \ | |
| --checklist "Select ONE OS NUMA node (reserved for the OS):" 15 55 6 | |
| first=true | |
| for n in $all_nodes; do | |
| if [ "$first" = true ]; then | |
| set -- "$@" "$n" "OS NUMA node $n" on | |
| first=false | |
| else | |
| set -- "$@" "$n" "OS NUMA node $n" off | |
| fi | |
| done | |
| os_node=$("$@" 2>&1 >/dev/tty) || exit 1 | |
| ### ---------- Remaining nodes ---------- | |
| app_candidates="" | |
| for n in $all_nodes; do | |
| [ "$n" = "$os_node" ] && continue | |
| app_candidates="$app_candidates $n" | |
| done | |
| ### ---------- Dialog 2: Application NUMA nodes ---------- | |
| if [ -n "$app_candidates" ]; then | |
| set -- dialog --separate-output \ | |
| --checklist "Select Application NUMA nodes:" 15 55 6 | |
| for n in $app_candidates; do | |
| set -- "$@" "$n" "Application NUMA node $n" off | |
| done | |
| app_nodes=$("$@" 2>&1 >/dev/tty) || exit 1 | |
| else | |
| app_nodes="" | |
| fi | |
| ### ---------- Read OS node CPU list ---------- | |
| OS_CPU_LIST_FILE="/sys/devices/system/node/node${os_node}/cpulist" | |
| APP_CPU_LIST_FILE="/sys/devices/system/node/node${app_nodes}/cpulist" | |
| os_cpu_list=$(cat "$OS_CPU_LIST_FILE") | |
| app_cpu_list=$(cat "$APP_CPU_LIST_FILE") | |
| clear | |
| echo "OS NUMA node:" | |
| echo " Node: $os_node" | |
| echo " CPU list: $os_cpu_list" | |
| echo | |
| echo "Application NUMA nodes:" | |
| echo " None: $app_nodes" | |
| echo " CPU list: $app_cpu_list" | |
| proposed_config="isolcpus=$app_cpu_list nohz_full=$app_cpu_list rcu_nocbs=$app_cpu_list irqaffinity=$os_cpu_list" | |
| if dialog --stdout --title "Apply the following config to the kernel boot parameters?" --yesno "$proposed_config" 15 55; then | |
| dialog --title "Information" --msgbox "Applying.." 6 44 | |
| #grubby --update-kernel=ALL --args=$proposed_config | |
| sed -i "s/GRUB_CMDLINE_LINUX_DEFAULT=\"\"/GRUB_CMDLINE_LINUX_DEFAULT=\"$proposed_config\"/g" /etc/default/grub | |
| update-grub | |
| else | |
| dialog --title "Information" --msgbox "nothing change, bye, chicken!" 6 44 | |
| fi | |
| clear |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment