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:
Aleksa Sarai
2025-11-10 16:03:02 +11:00
parent 071beab281
commit a0e809a8ba
3 changed files with 18 additions and 23 deletions
+2 -7
View File
@@ -2,7 +2,6 @@ package linux
import ( import (
"os" "os"
"unsafe"
"golang.org/x/sys/unix" "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. // SetMempolicy wraps set_mempolicy.
func SetMempolicy(mode uint, mask *unix.CPUSet) error { func SetMempolicy(mode int, mask *unix.CPUSet) error {
err := retryOnEINTR(func() error { err := retryOnEINTR(func() error {
_, _, errno := unix.Syscall(unix.SYS_SET_MEMPOLICY, uintptr(mode), uintptr(unsafe.Pointer(mask)), unsafe.Sizeof(*mask)*8) return unix.SetMemPolicy(mode, mask)
if errno != 0 {
return errno
}
return nil
}) })
return os.NewSyscallError("set_mempolicy", err) return os.NewSyscallError("set_mempolicy", err)
} }
+2 -2
View File
@@ -23,9 +23,9 @@ const (
type LinuxMemoryPolicy struct { type LinuxMemoryPolicy struct {
// Mode specifies memory policy mode without mode flags. See // Mode specifies memory policy mode without mode flags. See
// set_mempolicy() documentation for details. // set_mempolicy() documentation for details.
Mode uint `json:"mode,omitempty"` Mode int `json:"mode,omitempty"`
// Flags contains mode flags. // Flags contains mode flags.
Flags uint `json:"flags,omitempty"` Flags int `json:"flags,omitempty"`
// Nodes contains NUMA nodes to which the mode applies. // Nodes contains NUMA nodes to which the mode applies.
Nodes *unix.CPUSet `json:"nodes,omitempty"` Nodes *unix.CPUSet `json:"nodes,omitempty"`
} }
+14 -14
View File
@@ -42,8 +42,8 @@ var (
flag int flag int
} }
complexFlags map[string]func(*configs.Mount) complexFlags map[string]func(*configs.Mount)
mpolModeMap map[string]uint mpolModeMap map[string]int
mpolModeFMap map[string]uint mpolModeFMap map[string]int
) )
func initMaps() { func initMaps() {
@@ -152,20 +152,20 @@ func initMaps() {
}, },
} }
mpolModeMap = map[string]uint{ mpolModeMap = map[string]int{
string(specs.MpolDefault): configs.MPOL_DEFAULT, string(specs.MpolDefault): unix.MPOL_DEFAULT,
string(specs.MpolPreferred): configs.MPOL_PREFERRED, string(specs.MpolPreferred): unix.MPOL_PREFERRED,
string(specs.MpolBind): configs.MPOL_BIND, string(specs.MpolBind): unix.MPOL_BIND,
string(specs.MpolInterleave): configs.MPOL_INTERLEAVE, string(specs.MpolInterleave): unix.MPOL_INTERLEAVE,
string(specs.MpolLocal): configs.MPOL_LOCAL, string(specs.MpolLocal): unix.MPOL_LOCAL,
string(specs.MpolPreferredMany): configs.MPOL_PREFERRED_MANY, string(specs.MpolPreferredMany): unix.MPOL_PREFERRED_MANY,
string(specs.MpolWeightedInterleave): configs.MPOL_WEIGHTED_INTERLEAVE, string(specs.MpolWeightedInterleave): unix.MPOL_WEIGHTED_INTERLEAVE,
} }
mpolModeFMap = map[string]uint{ mpolModeFMap = map[string]int{
string(specs.MpolFStaticNodes): configs.MPOL_F_STATIC_NODES, string(specs.MpolFStaticNodes): unix.MPOL_F_STATIC_NODES,
string(specs.MpolFRelativeNodes): configs.MPOL_F_RELATIVE_NODES, string(specs.MpolFRelativeNodes): unix.MPOL_F_RELATIVE_NODES,
string(specs.MpolFNumaBalancing): configs.MPOL_F_NUMA_BALANCING, string(specs.MpolFNumaBalancing): unix.MPOL_F_NUMA_BALANCING,
} }
}) })
} }