pkg/sysinfo: remove NUMANodeCount

Found a few issues in this code and went ahead to fix them one by one,
only to find out this function is not used anywhere in our codebase
or otherwise (see [1], [2]).

Remove it.

[1]: https://github.com/search?q=org%3Acontainers+NUMANodeCount&type=code
[2]: https://sourcegraph.com/search?q=context%3Aglobal+sysinfo.NUMANodeCount

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin 2025-04-11 12:45:45 -07:00
parent 1f01f181b9
commit fa9de4d919
3 changed files with 0 additions and 51 deletions

View File

@ -1,32 +0,0 @@
//go:build linux
package sysinfo
import (
"unsafe"
"golang.org/x/sys/unix"
)
// NUMANodeCount queries the system for the count of Memory Nodes available
// for use to this process.
func NUMANodeCount() int {
// this is the correct flag name (not defined in the unix package)
//nolint:revive
MPOL_F_MEMS_ALLOWED := (1 << 2)
var mask [1024 / 64]uintptr
_, _, err := unix.RawSyscall6(unix.SYS_GET_MEMPOLICY, 0, uintptr(unsafe.Pointer(&mask[0])), uintptr(len(mask)*8), 0, uintptr(MPOL_F_MEMS_ALLOWED), 0)
if err != 0 {
return 0
}
// For every available thread a bit is set in the mask.
nmem := 0
for _, e := range mask {
if e == 0 {
continue
}
nmem += int(popcnt(uint64(e)))
}
return nmem
}

View File

@ -1,9 +0,0 @@
//go:build (windows && ignore) || osx
package sysinfo
// NUMANodeCount queries the system for the count of Memory Nodes available
// for use to this process. Returns 0 on non NUMAs systems.
func NUMANodeCount() int {
return 0
}

View File

@ -97,13 +97,3 @@ func TestNumCPU(t *testing.T) {
t.Fatal("CPU returned must be greater than zero") t.Fatal("CPU returned must be greater than zero")
} }
} }
func TestNumMems(t *testing.T) {
if _, err := os.Stat("/proc/self/numa_maps"); !errors.Is(err, os.ErrNotExist) {
t.Skip("NUMA must be supported")
}
cpuMems := NUMANodeCount()
if cpuMems < 0 {
t.Fatal("Invalid number of memory nodes, must be 0 or greater.")
}
}