]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/set_mempolicy.2
Reordered sections to be more consistent, in some cases renaming
[thirdparty/man-pages.git] / man2 / set_mempolicy.2
1 .\" Copyright 2003,2004 Andi Kleen, SuSE Labs.
2 .\"
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
6 .\"
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
11 .\"
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein.
16 .\"
17 .\" Formatted or processed versions of this manual, if unaccompanied by
18 .\" the source, must acknowledge the copyright and authors of this work.
19 .\"
20 .\" 2006-02-03, mtk, substantial wording changes and other improvements
21 .\"
22 .TH SET_MEMPOLICY 2 2006-02-07 "Linux" "Linux Programmer's Manual"
23 .SH NAME
24 set_mempolicy \- set default NUMA memory policy for a process and its children.
25 .SH SYNOPSIS
26 .nf
27 .B "#include <numaif.h>"
28 .sp
29 .BI "int set_mempolicy(int " policy ", unsigned long *" nodemask ,
30 .BI " unsigned long " maxnode );
31 .fi
32 .SH DESCRIPTION
33 .BR set_mempolicy ()
34 sets the NUMA memory policy of the calling process to
35 .IR policy .
36
37 A NUMA machine has different
38 memory controllers with different distances to specific CPUs.
39 The memory policy defines in which node memory is allocated for
40 the process.
41
42 This system call defines the default policy for the process;
43 in addition a policy can be set for specific memory ranges using
44 .BR mbind (2).
45 The policy is only applied when a new page is allocated
46 for the process.
47 For anonymous memory this is when the page is first
48 touched by the application.
49
50 Available policies are
51 .BR MPOL_DEFAULT ,
52 .BR MPOL_BIND ,
53 .BR MPOL_INTERLEAVE ,
54 .BR MPOL_PREFERRED .
55 All policies except
56 .B MPOL_DEFAULT
57 require the caller to specify the nodes to which the policy applies in the
58 .I nodemask
59 parameter.
60 .I nodemask
61 is pointer to a bit field of nodes that contains up to
62 .I maxnode
63 bits.
64 The bit field size is rounded to the next multiple of
65 .IR "sizeof(unsigned long)" ,
66 but the kernel will only use bits up to
67 .IR maxnode .
68
69 The
70 .B MPOL_DEFAULT
71 policy is the default and means to allocate memory locally,
72 i.e., on the node of the CPU that triggered the allocation.
73 .I nodemask
74 should be specified as NULL.
75
76 The
77 .B MPOL_BIND
78 policy is a strict policy that restricts memory allocation to the
79 nodes specified in
80 .IR nodemask .
81 There won't be allocations on other nodes.
82
83 .B MPOL_INTERLEAVE
84 interleaves allocations to the nodes specified in
85 .IR nodemask .
86 This optimizes for bandwidth instead of latency.
87 To be effective the memory area should be fairly large,
88 at least 1MB or bigger.
89
90 .B MPOL_PREFERRED
91 sets the preferred node for allocation.
92 The kernel will try to allocate in this
93 node first and fall back to other nodes if the preferred node is low on free
94 memory.
95 Only the first node in the
96 .I nodemask
97 is used.
98 If no node is set in the mask, then the memory is allocated on
99 the node of the CPU that triggered the allocation allocation (like
100 .BR MPOL_DEFAULT ).
101
102 The memory policy is preserved across an
103 .BR execve (2),
104 and is inherited by child processes created using
105 .BR fork (2)
106 or
107 .BR clone (2).
108 .SH RETURN VALUE
109 On success,
110 .BR set_mempolicy ()
111 returns 0;
112 on error, \-1 is returned and
113 .I errno
114 is set to indicate the error.
115 .\" .SH ERRORS
116 .\" FIXME writeme -- no errors are listed on this page
117 .\" .
118 .\" .TP
119 .\" .B EINVAL
120 .\" .I mode is invalid.
121 .SS "Versions and Library Support"
122 See
123 .BR mbind (2).
124 .SH CONFORMING TO
125 This system call is Linux specific.
126 .SH NOTES
127 Process policy is not remembered if the page is swapped out.
128 .SH SEE ALSO
129 .BR mbind (2),
130 .BR get_mempolicy (2),
131 .BR numactl (8),
132 .BR numa (3)