Skip to content

Instantly share code, notes, and snippets.

@jflopezfernandez
Created October 17, 2023 12:43
Show Gist options
  • Save jflopezfernandez/a290eef59a5765fc74a3bbd8f6e68f10 to your computer and use it in GitHub Desktop.
Save jflopezfernandez/a290eef59a5765fc74a3bbd8f6e68f10 to your computer and use it in GitHub Desktop.
Calculate number of NUMA nodes on the current host.
#!/bin/bash
#
# Calculate the number of NUMA nodes on the current host.
#
# iabwi8:~# number-of-numa-nodes
# 4
#
function number-of-numa-nodes() {
ls --directory /sys/devices/system/node/node* | wc --lines
}
# Output an iterable sequence of all of the NUMA nodes on the current host.
#
# This function is useful for iterating over all of the NUMA nodes on the host
# if you say need to calculate the total number of hugepages available.
#
# iabwi8:~# echo $(numa-nodes)
# 0 1 2 3
#
function numa-nodes() {
seq 0 $(($(number-of-numa-nodes) - 1))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment