Skip to content

sysfs: add NUMANodeCPUList to read per-node CPU lists - #892

Open
baozhuoran wants to merge 3 commits into
prometheus:masterfrom
baozhuoran:numa-node-cpulist
Open

baozhuoran wants to merge 3 commits into
prometheus:masterfrom
baozhuoran:numa-node-cpulist

Conversation

@baozhuoran

@baozhuoran baozhuoran commented Oct 26, 2026 •

Copy link
Copy Markdown

Summary

Add FS.NUMANodeCPUList(), which returns the online CPUs belonging to each NUMA node, read from /sys/devices/system/node/nodeN/cpulist (kernel ABI doc) and keyed by node number. The kernel only lists online CPUs in this file. Memory-only nodes return an empty list.

  • Parsing reuses the existing private parseCPURange helper, which already has its own tests.
  • Node discovery reuses the glob and regexp from VMStatNUMA.
  • The file is read with parsers.ReadFileNoStat rather than SysReadFile, because cpulist can exceed 128 bytes on large hosts with non-contiguous CPU numbering.

Motivation

node_exporter currently exposes per-NUMA-node memory (meminfo_numa), but nothing tells you which CPUs belong to which NUMA node. We plan to use this in node_exporter to expose the CPU-to-NUMA-node mapping. That makes it possible to get per-node CPU capacity and to aggregate existing per-CPU metrics by NUMA node. This is useful for NUMA-aware placement, for example checking how much CPU capacity each node has on a hypervisor. Adding the parsing here keeps sysfs parsing out of node_exporter.

This PR is a dependency of prometheus/node_exporter#3785, which adds that metric.

Testing

  • Added cpulist fixtures for node1 (0-3,8,10-11) and node2 (memory-only, empty).
  • go test ./..., go vet ./... and golangci-lint (v2.14.0) pass on Linux.

Zhuoran-Bao added 2 commits October 26, 2026 16:17
Add FS.NUMANodeCPUs, which returns the CPUs of each NUMA node read from
/sys/devices/system/node/nodeN/cpulist, keyed by node number. Memory-only
nodes return an empty list. The existing parseCPURange helper is reused.

Signed-off-by: Zhuoran-Bao <zhuoran.bao@ibm.com>
Name the method after the cpulist file it reads and reference the kernel
ABI documentation, per the API implementation guidelines.

Signed-off-by: Zhuoran-Bao <zhuoran.bao@ibm.com>
@baozhuoran baozhuoran changed the title sysfs: add NUMANodeCPUs to read per-node CPU lists sysfs: add NUMANodeCPUList to read per-node CPU lists Oct 26, 2026
@baozhuoran
baozhuoran marked this pull request as ready for review October 26, 2026 21:32
Signed-off-by: Zhuoran-Bao <zhuoran.bao@ibm.com>
baozhuoran pushed a commit to baozhuoran/node_exporter that referenced this pull request Nov 10, 2026
Temporary replace directive pointing at prometheus/procfs#892. Drop this
commit and bump github.com/prometheus/procfs once a release contains
sysfs.FS.NUMANodeCPUList.

Signed-off-by: Zhuoran-Bao <zhuoran.bao@ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant