platform

package
v1.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 6, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package platform provides OS-level helpers for CPU pinning and NUMA distribution.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindNumaNode added in v1.1.0

func BindNumaNode(node int) error

BindNumaNode sets the calling thread's memory allocation policy to MPOL_BIND for the given NUMA node. All subsequent mmap allocations will be satisfied from that node's memory. Returns an error if the syscall fails; the caller should treat failure as non-fatal (allocations will use default policy).

func CPUForNode added in v1.1.0

func CPUForNode(cpu int) int

CPUForNode returns the NUMA node that the given CPU belongs to. Returns 0 if the node cannot be determined (safe default).

func DistributeWorkers

func DistributeWorkers(numWorkers, numCPU, numaNodes int) []int

DistributeWorkers returns CPU IDs for numWorkers distributed across NUMA nodes. On multi-socket systems, workers are interleaved across sockets so that each socket handles roughly equal traffic. Falls back to sequential round-robin when NUMA topology is unavailable.

func PinToCPU

func PinToCPU(cpu int) error

PinToCPU pins the calling OS thread to the given CPU core via sched_setaffinity.

func ResetNumaPolicy added in v1.1.0

func ResetNumaPolicy() error

ResetNumaPolicy restores the default (local) memory allocation policy.

Types

type NUMATopology added in v1.1.0

type NUMATopology struct {
	NumNodes int
	NodeCPUs [][]int
}

NUMATopology holds detected NUMA topology information.

func DetectNUMA added in v1.1.0

func DetectNUMA() NUMATopology

DetectNUMA probes the system's NUMA topology via sysfs. Returns NumNodes=1 if NUMA info is unavailable.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL