mirror of
https://github.com/opencontainers/runc.git
synced 2026-02-05 18:45:28 +01:00
libct: switch to unix.SetMemPolicy wrapper
This is mostly a mechanical change, but we also need to change some types to match the "mode int" argument that golang.org/x/sys/unix decided to use. Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
This commit is contained in:
@@ -2,7 +2,6 @@ package linux
|
||||
|
||||
import (
|
||||
"os"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
@@ -75,13 +74,9 @@ func Sendmsg(fd int, p, oob []byte, to unix.Sockaddr, flags int) error {
|
||||
}
|
||||
|
||||
// SetMempolicy wraps set_mempolicy.
|
||||
func SetMempolicy(mode uint, mask *unix.CPUSet) error {
|
||||
func SetMempolicy(mode int, mask *unix.CPUSet) error {
|
||||
err := retryOnEINTR(func() error {
|
||||
_, _, errno := unix.Syscall(unix.SYS_SET_MEMPOLICY, uintptr(mode), uintptr(unsafe.Pointer(mask)), unsafe.Sizeof(*mask)*8)
|
||||
if errno != 0 {
|
||||
return errno
|
||||
}
|
||||
return nil
|
||||
return unix.SetMemPolicy(mode, mask)
|
||||
})
|
||||
return os.NewSyscallError("set_mempolicy", err)
|
||||
}
|
||||
|
||||
@@ -23,9 +23,9 @@ const (
|
||||
type LinuxMemoryPolicy struct {
|
||||
// Mode specifies memory policy mode without mode flags. See
|
||||
// set_mempolicy() documentation for details.
|
||||
Mode uint `json:"mode,omitempty"`
|
||||
Mode int `json:"mode,omitempty"`
|
||||
// Flags contains mode flags.
|
||||
Flags uint `json:"flags,omitempty"`
|
||||
Flags int `json:"flags,omitempty"`
|
||||
// Nodes contains NUMA nodes to which the mode applies.
|
||||
Nodes *unix.CPUSet `json:"nodes,omitempty"`
|
||||
}
|
||||
|
||||
@@ -42,8 +42,8 @@ var (
|
||||
flag int
|
||||
}
|
||||
complexFlags map[string]func(*configs.Mount)
|
||||
mpolModeMap map[string]uint
|
||||
mpolModeFMap map[string]uint
|
||||
mpolModeMap map[string]int
|
||||
mpolModeFMap map[string]int
|
||||
)
|
||||
|
||||
func initMaps() {
|
||||
@@ -152,20 +152,20 @@ func initMaps() {
|
||||
},
|
||||
}
|
||||
|
||||
mpolModeMap = map[string]uint{
|
||||
string(specs.MpolDefault): configs.MPOL_DEFAULT,
|
||||
string(specs.MpolPreferred): configs.MPOL_PREFERRED,
|
||||
string(specs.MpolBind): configs.MPOL_BIND,
|
||||
string(specs.MpolInterleave): configs.MPOL_INTERLEAVE,
|
||||
string(specs.MpolLocal): configs.MPOL_LOCAL,
|
||||
string(specs.MpolPreferredMany): configs.MPOL_PREFERRED_MANY,
|
||||
string(specs.MpolWeightedInterleave): configs.MPOL_WEIGHTED_INTERLEAVE,
|
||||
mpolModeMap = map[string]int{
|
||||
string(specs.MpolDefault): unix.MPOL_DEFAULT,
|
||||
string(specs.MpolPreferred): unix.MPOL_PREFERRED,
|
||||
string(specs.MpolBind): unix.MPOL_BIND,
|
||||
string(specs.MpolInterleave): unix.MPOL_INTERLEAVE,
|
||||
string(specs.MpolLocal): unix.MPOL_LOCAL,
|
||||
string(specs.MpolPreferredMany): unix.MPOL_PREFERRED_MANY,
|
||||
string(specs.MpolWeightedInterleave): unix.MPOL_WEIGHTED_INTERLEAVE,
|
||||
}
|
||||
|
||||
mpolModeFMap = map[string]uint{
|
||||
string(specs.MpolFStaticNodes): configs.MPOL_F_STATIC_NODES,
|
||||
string(specs.MpolFRelativeNodes): configs.MPOL_F_RELATIVE_NODES,
|
||||
string(specs.MpolFNumaBalancing): configs.MPOL_F_NUMA_BALANCING,
|
||||
mpolModeFMap = map[string]int{
|
||||
string(specs.MpolFStaticNodes): unix.MPOL_F_STATIC_NODES,
|
||||
string(specs.MpolFRelativeNodes): unix.MPOL_F_RELATIVE_NODES,
|
||||
string(specs.MpolFNumaBalancing): unix.MPOL_F_NUMA_BALANCING,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user