1GET_MEMPOLICY(2)           Linux Programmer's Manual          GET_MEMPOLICY(2)
2
3
4

NAME

6       get_mempolicy - retrieve NUMA memory policy for a thread
7

SYNOPSIS

9       #include <numaif.h>
10
11       long get_mempolicy(int *mode, unsigned long *nodemask,
12                         unsigned long maxnode, void *addr,
13                         unsigned long flags);
14
15       Link with -lnuma.
16

DESCRIPTION

18       get_mempolicy() retrieves the NUMA policy of the calling thread or of a
19       memory address, depending on the setting of flags.
20
21       A NUMA machine has different memory  controllers  with  different  dis‐
22       tances  to  specific  CPUs.   The memory policy defines from which node
23       memory is allocated for the thread.
24
25       If flags is specified as 0, then information about the calling thread's
26       default policy (as set by set_mempolicy(2)) is returned, in the buffers
27       pointed to by mode and nodemask.  The value returned in these arguments
28       may  be used to restore the thread's policy to its state at the time of
29       the call to get_mempolicy() using set_mempolicy(2).  When flags  is  0,
30       addr must be specified as NULL.
31
32       If  flags specifies MPOL_F_MEMS_ALLOWED (available since Linux 2.6.24),
33       the mode argument is ignored and the set of nodes (memories)  that  the
34       thread  is  allowed  to  specify  in  subsequent  calls  to mbind(2) or
35       set_mempolicy(2) (in the absence of any  mode  flags)  is  returned  in
36       nodemask.   It  is  not  permitted  to combine MPOL_F_MEMS_ALLOWED with
37       either MPOL_F_ADDR or MPOL_F_NODE.
38
39       If flags specifies MPOL_F_ADDR, then information is returned about  the
40       policy  governing the memory address given in addr.  This policy may be
41       different from the thread's default policy if mbind(2) or  one  of  the
42       helper functions described in numa(3) has been used to establish a pol‐
43       icy for the memory range containing addr.
44
45       If the mode argument is not NULL, then get_mempolicy() will  store  the
46       policy mode and any optional mode flags of the requested NUMA policy in
47       the location pointed to by this argument.  If  nodemask  is  not  NULL,
48       then  the  nodemask  associated  with  the policy will be stored in the
49       location pointed to by this argument.  maxnode specifies the number  of
50       node  IDs that can be stored into nodemask—that is, the maximum node ID
51       plus one.  The value specified by maxnode is always rounded to a multi‐
52       ple of sizeof(unsigned long)*8.
53
54       If  flags  specifies  both MPOL_F_NODE and MPOL_F_ADDR, get_mempolicy()
55       will return the node ID of the node on which the address addr is  allo‐
56       cated  into  the  location pointed to by mode.  If no page has yet been
57       allocated for the specified address, get_mempolicy()  will  allocate  a
58       page  as  if  the  thread  had  performed  a read (load) access to that
59       address, and return the ID of the node where that page was allocated.
60
61       If flags specifies MPOL_F_NODE, but not MPOL_F_ADDR, and  the  thread's
62       current  policy is MPOL_INTERLEAVE, then get_mempolicy() will return in
63       the location pointed to by a non-NULL mode argument, the node ID of the
64       next  node  that will be used for interleaving of internal kernel pages
65       allocated on behalf of the thread.  These allocations include pages for
66       memory-mapped  files  in process memory ranges mapped using the mmap(2)
67       call with the MAP_PRIVATE flag for read accesses, and in memory  ranges
68       mapped with the MAP_SHARED flag for all accesses.
69
70       Other flag values are reserved.
71
72       For an overview of the possible policies see set_mempolicy(2).
73

RETURN VALUE

75       On  success,  get_mempolicy()  returns  0; on error, -1 is returned and
76       errno is set to indicate the error.
77

ERRORS

79       EFAULT Part of all of the memory range specified by nodemask and  maxn‐
80              ode points outside your accessible address space.
81
82       EINVAL The  value  specified by maxnode is less than the number of node
83              IDs supported by the system.  Or flags  specified  values  other
84              than  MPOL_F_NODE or MPOL_F_ADDR; or flags specified MPOL_F_ADDR
85              and addr is NULL, or flags did not specify MPOL_F_ADDR and  addr
86              is   not   NULL.    Or,  flags  specified  MPOL_F_NODE  but  not
87              MPOL_F_ADDR and the current thread  policy  is  not  MPOL_INTER‐
88              LEAVE.   Or,  flags  specified  MPOL_F_MEMS_ALLOWED  with either
89              MPOL_F_ADDR or MPOL_F_NODE.  (And there are other EINVAL cases.)
90

VERSIONS

92       The get_mempolicy() system call was added to the Linux kernel  in  ver‐
93       sion 2.6.7.
94

CONFORMING TO

96       This system call is Linux-specific.
97

NOTES

99       For information on library support, see numa(7).
100

SEE ALSO

102       getcpu(2),   mbind(2),  mmap(2),  set_mempolicy(2),  numa(3),  numa(7),
103       numactl(8)
104

COLOPHON

106       This page is part of release 4.15 of the Linux  man-pages  project.   A
107       description  of  the project, information about reporting bugs, and the
108       latest    version    of    this    page,    can     be     found     at
109       https://www.kernel.org/doc/man-pages/.
110
111
112
113Linux                             2017-09-15                  GET_MEMPOLICY(2)
Impressum