Skip to content

Commit 28c5bda

Browse files
kolyshkingopherbot
authored andcommitted
unix: add SetMemPolicy and its mode/flag values
This reuses CPUSet type as it fits perfectly. No GetMemPolicy support yet. Change-Id: I549361bc1ed95ee73fd38d00277ec0f9f348a9ba Reviewed-on: https://go-review.googlesource.com/c/sys/+/706917 Auto-Submit: Michael Pratt <[email protected]> Reviewed-by: Antti Kervinen <[email protected]> Reviewed-by: Tobias Klauser <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Michael Pratt <[email protected]> Reviewed-by: Carlos Amedee <[email protected]>
1 parent b731f78 commit 28c5bda

File tree

4 files changed

+75
-0
lines changed

4 files changed

+75
-0
lines changed

unix/linux/types.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ struct termios2 {
135135
#include <linux/landlock.h>
136136
#include <linux/loop.h>
137137
#include <linux/lwtunnel.h>
138+
#include <linux/mempolicy.h>
138139
#include <linux/mpls_iptunnel.h>
139140
#include <linux/ncsi.h>
140141
#include <linux/net_namespace.h>
@@ -6250,3 +6251,34 @@ type SockDiagReq C.struct_sock_diag_req
62506251

62516252
// Removed in Linux 6.13, kept for backwards compatibility.
62526253
const RTM_NEWNVLAN = 0x70
6254+
6255+
// Memory policy modes and flags for [SetMemPolicy], as defined in /usr/include/linux/mempolicy.h.
6256+
// Not all can be used, see set_mempolicy(2).
6257+
// Generated by:
6258+
// $ { perl -nlE '/^#define (MPOL_\w+)/ && say "\t$1 = C.$1"' /usr/include/linux/mempolicy.h; perl -nlE '/^\s*(MPOL_\w+)/ && say "\t$1 = C.$1"' /usr/include/linux/mempolicy.h; } | sort | uniq
6259+
const (
6260+
MPOL_BIND = C.MPOL_BIND
6261+
MPOL_DEFAULT = C.MPOL_DEFAULT
6262+
MPOL_F_ADDR = C.MPOL_F_ADDR
6263+
MPOL_F_MEMS_ALLOWED = C.MPOL_F_MEMS_ALLOWED
6264+
MPOL_F_MOF = C.MPOL_F_MOF
6265+
MPOL_F_MORON = C.MPOL_F_MORON
6266+
MPOL_F_NODE = C.MPOL_F_NODE
6267+
MPOL_F_NUMA_BALANCING = C.MPOL_F_NUMA_BALANCING
6268+
MPOL_F_RELATIVE_NODES = C.MPOL_F_RELATIVE_NODES
6269+
MPOL_F_SHARED = C.MPOL_F_SHARED
6270+
MPOL_F_STATIC_NODES = C.MPOL_F_STATIC_NODES
6271+
MPOL_INTERLEAVE = C.MPOL_INTERLEAVE
6272+
MPOL_LOCAL = C.MPOL_LOCAL
6273+
MPOL_MAX = C.MPOL_MAX
6274+
MPOL_MF_INTERNAL = C.MPOL_MF_INTERNAL
6275+
MPOL_MF_LAZY = C.MPOL_MF_LAZY
6276+
MPOL_MF_MOVE_ALL = C.MPOL_MF_MOVE_ALL
6277+
MPOL_MF_MOVE = C.MPOL_MF_MOVE
6278+
MPOL_MF_STRICT = C.MPOL_MF_STRICT
6279+
MPOL_MF_VALID = C.MPOL_MF_VALID
6280+
MPOL_MODE_FLAGS = C.MPOL_MODE_FLAGS
6281+
MPOL_PREFERRED = C.MPOL_PREFERRED
6282+
MPOL_PREFERRED_MANY = C.MPOL_PREFERRED_MANY
6283+
MPOL_WEIGHTED_INTERLEAVE = C.MPOL_WEIGHTED_INTERLEAVE
6284+
)

unix/syscall_linux.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2643,3 +2643,9 @@ func SchedGetAttr(pid int, flags uint) (*SchedAttr, error) {
26432643

26442644
//sys Cachestat(fd uint, crange *CachestatRange, cstat *Cachestat_t, flags uint) (err error)
26452645
//sys Mseal(b []byte, flags uint) (err error)
2646+
2647+
//sys setMemPolicy(mode int, mask *CPUSet, size int) (err error) = SYS_SET_MEMPOLICY
2648+
2649+
func SetMemPolicy(mode int, mask *CPUSet) error {
2650+
return setMemPolicy(mode, mask, _CPU_SETSIZE)
2651+
}

unix/zsyscall_linux.go

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unix/ztypes_linux.go

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)