Documentation ¶
Overview ¶
Package cpuset is a library for manipulation of Linux cpusets.
Index ¶
- type CPUSet
- func (c *CPUSet) AddTask(task int) error
- func (c *CPUSet) AddTasks(tasks []int) error
- func (c *CPUSet) CPUExclusive() (bool, error)
- func (c *CPUSet) CPUs() (Set, error)
- func (c *CPUSet) DisableCPUExclusive() error
- func (c *CPUSet) DisableMemExclusive() error
- func (c *CPUSet) DisableMemHardwall() error
- func (c *CPUSet) DisableMemoryMigrate() error
- func (c *CPUSet) DisableMemoryPressureEnabled() error
- func (c *CPUSet) DisableMemorySpreadPage() error
- func (c *CPUSet) DisableMemorySpreadSlab() error
- func (c *CPUSet) DisableNotifyOnRelease() error
- func (c *CPUSet) DisableSchedLoadBalance() error
- func (c *CPUSet) EnableCPUExclusive() error
- func (c *CPUSet) EnableMemExclusive() error
- func (c *CPUSet) EnableMemHardwall() error
- func (c *CPUSet) EnableMemoryMigrate() error
- func (c *CPUSet) EnableMemoryPressureEnabled() error
- func (c *CPUSet) EnableMemorySpreadPage() error
- func (c *CPUSet) EnableMemorySpreadSlab() error
- func (c *CPUSet) EnableNotifyOnRelease() error
- func (c *CPUSet) EnableSchedLoadBalance() error
- func (c *CPUSet) MemExclusive() (bool, error)
- func (c *CPUSet) MemHardwall() (bool, error)
- func (c *CPUSet) MemoryMigrate() (bool, error)
- func (c *CPUSet) MemoryPressure() (int, error)
- func (c *CPUSet) MemoryPressureEnabled() (bool, error)
- func (c *CPUSet) MemorySpreadPage() (bool, error)
- func (c *CPUSet) MemorySpreadSlab() (bool, error)
- func (c *CPUSet) Mems() (Set, error)
- func (c *CPUSet) NotifyOnRelease() (bool, error)
- func (c *CPUSet) Path() string
- func (c *CPUSet) Remove() error
- func (c *CPUSet) SchedLoadBalance() (bool, error)
- func (c *CPUSet) SchedRelaxDomainLevel() (int, error)
- func (c *CPUSet) SetCPUExclusive(enabled bool) error
- func (c *CPUSet) SetCPUs(s Set) error
- func (c *CPUSet) SetMemExclusive(enabled bool) error
- func (c *CPUSet) SetMemHardwall(enabled bool) error
- func (c *CPUSet) SetMemoryMigrate(enabled bool) error
- func (c *CPUSet) SetMemoryPressureEnabled(enabled bool) error
- func (c *CPUSet) SetMemorySpreadPage(enabled bool) error
- func (c *CPUSet) SetMemorySpreadSlab(enabled bool) error
- func (c *CPUSet) SetMems(s Set) error
- func (c *CPUSet) SetNotifyOnRelease(enabled bool) error
- func (c *CPUSet) SetSchedLoadBalance(enabled bool) error
- func (c *CPUSet) SetSchedRelaxDomainLevel(level int) error
- func (c *CPUSet) Tasks() ([]int, error)
- type MoveResult
- type Set
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CPUSet ¶
type CPUSet struct {
// contains filtered or unexported fields
}
CPUSet represents a cpuset in the sysfs filesystem.
func CreatePath ¶
CreatePath creates a cpuset at a custom path.
func NewCPUSet ¶
NewCPUSet returns a reference to the named cpuset under the standard sysfs hierarchy.
func NewCPUSetPath ¶
NewCPUSetPath returns a reference to a cpuset directory at a custom path.
func (*CPUSet) AddTasks ¶
AddTasks writes to the "tasks" file of the cpuset.
See Tasks() for the meaning of this field.
func (*CPUSet) CPUExclusive ¶
CPUExclusive reports whether the cpuset has exclusive use of its CPUs (no sibling or cousin cpuset may overlap CPUs). By default, this is off. Newly created cpusets also initially default this to off.
Two cpusets are sibling cpusets if they share the same parent cpuset in the hierarchy. Two cpusets are cousin cpusets if neither is the ancestor of the other. Regardless of the cpu_exclusive setting, if one cpuset is the ancestor of another, and if both of these cpusets have nonempty cpus, then their cpus must overlap, because the cpus of any cpuset are always a subset of the cpus of its parent cpuset.
Corresponds to the "cpuset.cpu_exclusive" file in the cpuset directory.
func (*CPUSet) CPUs ¶
CPUs returns the set of physical numbers of the CPUs on which processes in the cpuset are allowed to execute.
Corresponds to the "cpuset.cpus" file in the cpuset directory.
func (*CPUSet) DisableCPUExclusive ¶
DisableCPUExclusive sets the "cpuset.cpu_exclusive" file to false.
See CPUExclusive() for the meaning of this field.
func (*CPUSet) DisableMemExclusive ¶
DisableMemExclusive sets the "cpuset.mem_exclusive" file to false.
See MemExclusive() for the meaning of this field.
func (*CPUSet) DisableMemHardwall ¶
DisableMemHardwall sets the "cpuset.mem_hardwall" file to false.
See MemHardwall() for the meaning of this field.
func (*CPUSet) DisableMemoryMigrate ¶
DisableMemoryMigrate sets the "cpuset.memory_migrate" file to false.
See MemoryMigrate() for the meaning of this field.
func (*CPUSet) DisableMemoryPressureEnabled ¶
DisableMemoryPressureEnabled sets the "cpuset.memory_pressure_enabled" file to false.
See MemoryPressureEnabled() for the meaning of this field.
func (*CPUSet) DisableMemorySpreadPage ¶
DisableMemorySpreadPage sets the "cpuset.memory_spread_page" file to false.
See MemorySpreadPage() for the meaning of this field.
func (*CPUSet) DisableMemorySpreadSlab ¶
DisableMemorySpreadSlab sets the "cpuset.memory_spread_slab" file to false.
See MemorySpreadSlab() for the meaning of this field.
func (*CPUSet) DisableNotifyOnRelease ¶
DisableNotifyOnRelease sets the "notify_on_release" file to false.
See NotifyOnRelease() for the meaning of this field.
func (*CPUSet) DisableSchedLoadBalance ¶
DisableSchedLoadBalance sets the "cpuset.sched_load_balance" file to false.
See SchedLoadBalance() for the meaning of this field.
func (*CPUSet) EnableCPUExclusive ¶
EnableCPUExclusive sets the "cpuset.cpu_exclusive" file to true.
See CPUExclusive() for the meaning of this field.
func (*CPUSet) EnableMemExclusive ¶
EnableMemExclusive sets the "cpuset.mem_exclusive" file to true.
See MemExclusive() for the meaning of this field.
func (*CPUSet) EnableMemHardwall ¶
EnableMemHardwall sets the "cpuset.mem_hardwall" file to true.
See MemHardwall() for the meaning of this field.
func (*CPUSet) EnableMemoryMigrate ¶
EnableMemoryMigrate sets the "cpuset.memory_migrate" file to true.
See MemoryMigrate() for the meaning of this field.
func (*CPUSet) EnableMemoryPressureEnabled ¶
EnableMemoryPressureEnabled sets the "cpuset.memory_pressure_enabled" file to true.
See MemoryPressureEnabled() for the meaning of this field.
func (*CPUSet) EnableMemorySpreadPage ¶
EnableMemorySpreadPage sets the "cpuset.memory_spread_page" file to true.
See MemorySpreadPage() for the meaning of this field.
func (*CPUSet) EnableMemorySpreadSlab ¶
EnableMemorySpreadSlab sets the "cpuset.memory_spread_slab" file to true.
See MemorySpreadSlab() for the meaning of this field.
func (*CPUSet) EnableNotifyOnRelease ¶
EnableNotifyOnRelease sets the "notify_on_release" file to true.
See NotifyOnRelease() for the meaning of this field.
func (*CPUSet) EnableSchedLoadBalance ¶
EnableSchedLoadBalance sets the "cpuset.sched_load_balance" file to true.
See SchedLoadBalance() for the meaning of this field.
func (*CPUSet) MemExclusive ¶
MemExclusive reports whether the cpuset has exclusive use of its memory nodes (no sibling or cousin may overlap). Also if set, the cpuset is a Hardwall cpuset. By default, this is off. Newly created cpusets also initially default this to off.
Regardless of the mem_exclusive setting, if one cpuset is the ancestor of another, then their memory nodes must overlap, because the memory nodes of any cpuset are always a subset of the memory nodes of that cpuset's parent cpuset.
Corresponds to the "cpuset.mem_exclusive" file in the cpuset directory.
func (*CPUSet) MemHardwall ¶
MemHardwall reports whether the cpuset is a Hardwall cpuset (see below). Unlike mem_exclusive, there is no constraint on whether cpusets marked mem_hardwall may have overlapping memory nodes with sibling or cousin cpusets. By default, this is off. Newly created cpusets also initially default this to off.
Corresponds to the "cpuset.mem_hardwall" file in the cpuset directory.
func (*CPUSet) MemoryMigrate ¶
MemoryMigrate reports whether memory migration is enabled.
Corresponds to the "cpuset.memory_migrate" file in the cpuset directory.
func (*CPUSet) MemoryPressure ¶
MemoryPressure reports a measure of how much memory pressure the processes in this cpuset are causing. If MemoryPressureEnabled() is false this will always be 0.
Corresponds to the "cpuset.memory_pressure" file in the cpuset directory.
func (*CPUSet) MemoryPressureEnabled ¶
MemoryPressureEnabled reports whether memory pressure calculations are enabled for all cpusets in the system. This method only works for the root cpuset. By default, this is off.
Corresponds to the "cpuset.memory_pressure_enabled" file in the cpuset directory.
func (*CPUSet) MemorySpreadPage ¶
MemorySpreadPage reports whether pages in the kernel page cache (filesystem buffers) are uniformly spread across the cpuset. By default, this is off (0) in the top cpuset, and inherited from the parent cpuset in newly created cpusets.
Corresponds to the "cpuset.memory_spread_page" file in the cpuset directory.
func (*CPUSet) MemorySpreadSlab ¶
MemorySpreadSlab reports whether the kernel slab caches for file I/O (directory and inode structures) are uniformly spread across the cpuset. By default, this is off (0) in the top cpuset, and inherited from the parent cpuset in newly created cpusets.
Corresponds to the "cpuset.memory_spread_slab" file in the cpuset directory.
func (*CPUSet) Mems ¶
Mems returns the list of memory nodes on which processes in this cpuset are allowed to allocate memory.
Corresponds to the "cpuset.mems" file in the cpuset directory.
func (*CPUSet) NotifyOnRelease ¶
NotifyOnRelease reports whether the notify_on_release flag is set for this cpuset. If true, that cpuset will receive special handling after it is released, that is, after all processes cease using it (i.e., terminate or are moved to a different cpuset) and all child cpuset directories have been removed.
Corresponds to the "notify_on_release" file in the cpuset directory.
func (*CPUSet) Remove ¶
Remove the cpuset. Note the cpuset must have no children or attached processes.
func (*CPUSet) SchedLoadBalance ¶
SchedLoadBalance reports wether the kernel will automatically load balance processes in that cpuset over the allowed CPUs in that cpuset. If false the kernel will avoid load balancing processes in this cpuset, unless some other cpuset with overlapping CPUs has its sched_load_balance flag set.
Corresponds to the "cpuset.sched_load_balance" file in the cpuset directory.
func (*CPUSet) SchedRelaxDomainLevel ¶
SchedRelaxDomainLevel controls the width of the range of CPUs over which the kernel scheduler performs immediate rebalancing of runnable tasks across CPUs. If sched_load_balance is disabled, then the setting of sched_relax_domain_level does not matter, as no such load balancing is done. If sched_load_balance is enabled, then the higher the value of the sched_relax_domain_level, the wider the range of CPUs over which immediate load balancing is attempted.
Corresponds to the "cpuset.sched_relax_domain_level" file in the cpuset directory.
func (*CPUSet) SetCPUExclusive ¶
SetCPUExclusive writes to the "cpuset.cpu_exclusive" file of the cpuset.
See CPUExclusive() for the meaning of this field.
func (*CPUSet) SetCPUs ¶
SetCPUs writes to the "cpuset.cpus" file of the cpuset.
See CPUs() for the meaning of this field.
func (*CPUSet) SetMemExclusive ¶
SetMemExclusive writes to the "cpuset.mem_exclusive" file of the cpuset.
See MemExclusive() for the meaning of this field.
func (*CPUSet) SetMemHardwall ¶
SetMemHardwall writes to the "cpuset.mem_hardwall" file of the cpuset.
See MemHardwall() for the meaning of this field.
func (*CPUSet) SetMemoryMigrate ¶
SetMemoryMigrate writes to the "cpuset.memory_migrate" file of the cpuset.
See MemoryMigrate() for the meaning of this field.
func (*CPUSet) SetMemoryPressureEnabled ¶
SetMemoryPressureEnabled writes to the "cpuset.memory_pressure_enabled" file of the cpuset.
See MemoryPressureEnabled() for the meaning of this field.
func (*CPUSet) SetMemorySpreadPage ¶
SetMemorySpreadPage writes to the "cpuset.memory_spread_page" file of the cpuset.
See MemorySpreadPage() for the meaning of this field.
func (*CPUSet) SetMemorySpreadSlab ¶
SetMemorySpreadSlab writes to the "cpuset.memory_spread_slab" file of the cpuset.
See MemorySpreadSlab() for the meaning of this field.
func (*CPUSet) SetMems ¶
SetMems writes to the "cpuset.mems" file of the cpuset.
See Mems() for the meaning of this field.
func (*CPUSet) SetNotifyOnRelease ¶
SetNotifyOnRelease writes to the "notify_on_release" file of the cpuset.
See NotifyOnRelease() for the meaning of this field.
func (*CPUSet) SetSchedLoadBalance ¶
SetSchedLoadBalance writes to the "cpuset.sched_load_balance" file of the cpuset.
See SchedLoadBalance() for the meaning of this field.
func (*CPUSet) SetSchedRelaxDomainLevel ¶
SetSchedRelaxDomainLevel writes to the "cpuset.sched_relax_domain_level" file of the cpuset.
See SchedRelaxDomainLevel() for the meaning of this field.
type MoveResult ¶
type MoveResult struct { // Tasks successfully moved. Moved []int // Tasks which could not be found. Nonexistent []int // Invalid tasks were unmovable for some reason. For example, "bound" tasks // that are already pinned to CPUs cannot be moved, nor can the "kthreadd" // task. Invalid []int }
MoveResult records the outcome of a batch task migration from one cpuset to another.
func MoveTasks ¶
func MoveTasks(src, dst *CPUSet) (*MoveResult, error)
MoveTasks attempts to move all tasks from src to dst cpusets, returning the result in a MoveResult struct. Certain error cases are common, for example tasks bound to CPUs cannot be moved, and it's also possible for tasks to terminate while the move is taking place. These cases will not cause the entire operation to error, rather they will be recorded in the MoveResult return value for inspection by the caller. Other error cases will be bubbled up as errors from MoveTasks.
type Set ¶
Set of unsigned integers.
func ParseList ¶
ParseList parses a set represented in "List Format", specifically a comma-separated list of ranges.
Example ¶
package main import ( "fmt" "github.com/mmcloughlin/goperf/pkg/cpuset" ) func main() { s, _ := cpuset.ParseList("0-2,7,12-14") for n := range s { fmt.Println(n) } }
Output: 0 1 2 7 12 13 14
func ParseMask ¶
ParseMask parses a set represented in linux "Mask Format", specifically a comma-separated list of 32-bit hex words in big-endian order.
Example ¶
package main import ( "fmt" "github.com/mmcloughlin/goperf/pkg/cpuset" ) func main() { s, _ := cpuset.ParseMask("40000000,00000001,00000000") for n := range s { fmt.Println(n) } }
Output: 32 94
func (Set) Difference ¶
Difference returns a new set with elements in s but not in t.
func (Set) FormatList ¶
FormatList represents s in "List Format".
Example ¶
package main import ( "fmt" "github.com/mmcloughlin/goperf/pkg/cpuset" ) func main() { s := cpuset.NewSet(13, 2, 0, 7, 1, 14, 12) fmt.Println(s.FormatList()) }
Output: 0-2,7,12-14
func (Set) FormatMask ¶
FormatMask represents s in linux "Mask Format".
Example ¶
package main import ( "fmt" "github.com/mmcloughlin/goperf/pkg/cpuset" ) func main() { s := cpuset.NewSet(32, 64, 0, 1, 4, 2, 8, 16) fmt.Println(s.FormatMask()) }
Output: 00000001,00000001,00010117
func (Set) Members ¶
Members returns the members of s as a slice. No guarantees are made about order.
func (Set) SortedMembers ¶
SortedMembers returns the members of s as a slice in sorted order.