OSDN Git Service

LDP: Update original to LDP v3.79
[linuxjm/LDP_man-pages.git] / original / man7 / cpuset.7
1 .\" Copyright (c) 2008 Silicon Graphics, Inc.
2 .\"
3 .\" Author: Paul Jackson (http://oss.sgi.com/projects/cpusets)
4 .\"
5 .\" %%%LICENSE_START(GPLv2_MISC)
6 .\" This is free documentation; you can redistribute it and/or
7 .\" modify it under the terms of the GNU General Public License
8 .\" version 2 as published by the Free Software Foundation.
9 .\"
10 .\" The GNU General Public License's references to "object code"
11 .\" and "executables" are to be interpreted as the output of any
12 .\" document formatting or typesetting system, including
13 .\" intermediate and printed output.
14 .\"
15 .\" This manual is distributed in the hope that it will be useful,
16 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
17 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 .\" GNU General Public License for more details.
19 .\"
20 .\" You should have received a copy of the GNU General Public
21 .\" License along with this manual; if not, see
22 .\" <http://www.gnu.org/licenses/>.
23 .\" %%%LICENSE_END
24 .\"
25 .TH CPUSET 7 2014-05-21 "Linux" "Linux Programmer's Manual"
26 .SH NAME
27 cpuset \- confine processes to processor and memory node subsets
28 .SH DESCRIPTION
29 The cpuset filesystem is a pseudo-filesystem interface
30 to the kernel cpuset mechanism,
31 which is used to control the processor placement
32 and memory placement of processes.
33 It is commonly mounted at
34 .IR /dev/cpuset .
35 .PP
36 On systems with kernels compiled with built in support for cpusets,
37 all processes are attached to a cpuset, and cpusets are always present.
38 If a system supports cpusets, then it will have the entry
39 .B nodev cpuset
40 in the file
41 .IR /proc/filesystems .
42 By mounting the cpuset filesystem (see the
43 .B EXAMPLE
44 section below),
45 the administrator can configure the cpusets on a system
46 to control the processor and memory placement of processes
47 on that system.
48 By default, if the cpuset configuration
49 on a system is not modified or if the cpuset filesystem
50 is not even mounted, then the cpuset mechanism,
51 though present, has no affect on the system's behavior.
52 .PP
53 A cpuset defines a list of CPUs and memory nodes.
54 .PP
55 The CPUs of a system include all the logical processing
56 units on which a process can execute, including, if present,
57 multiple processor cores within a package and Hyper-Threads
58 within a processor core.
59 Memory nodes include all distinct
60 banks of main memory; small and SMP systems typically have
61 just one memory node that contains all the system's main memory,
62 while NUMA (non-uniform memory access) systems have multiple memory nodes.
63 .PP
64 Cpusets are represented as directories in a hierarchical
65 pseudo-filesystem, where the top directory in the hierarchy
66 .RI ( /dev/cpuset )
67 represents the entire system (all online CPUs and memory nodes)
68 and any cpuset that is the child (descendant) of
69 another parent cpuset contains a subset of that parent's
70 CPUs and memory nodes.
71 The directories and files representing cpusets have normal
72 filesystem permissions.
73 .PP
74 Every process in the system belongs to exactly one cpuset.
75 A process is confined to run only on the CPUs in
76 the cpuset it belongs to, and to allocate memory only
77 on the memory nodes in that cpuset.
78 When a process
79 .BR fork (2)s,
80 the child process is placed in the same cpuset as its parent.
81 With sufficient privilege, a process may be moved from one
82 cpuset to another and the allowed CPUs and memory nodes
83 of an existing cpuset may be changed.
84 .PP
85 When the system begins booting, a single cpuset is
86 defined that includes all CPUs and memory nodes on the
87 system, and all processes are in that cpuset.
88 During the boot process, or later during normal system operation,
89 other cpusets may be created, as subdirectories of this top cpuset,
90 under the control of the system administrator,
91 and processes may be placed in these other cpusets.
92 .PP
93 Cpusets are integrated with the
94 .BR sched_setaffinity (2)
95 scheduling affinity mechanism and the
96 .BR mbind (2)
97 and
98 .BR set_mempolicy (2)
99 memory-placement mechanisms in the kernel.
100 Neither of these mechanisms let a process make use
101 of a CPU or memory node that is not allowed by that process's cpuset.
102 If changes to a process's cpuset placement conflict with these
103 other mechanisms, then cpuset placement is enforced
104 even if it means overriding these other mechanisms.
105 The kernel accomplishes this overriding by silently
106 restricting the CPUs and memory nodes requested by
107 these other mechanisms to those allowed by the
108 invoking process's cpuset.
109 This can result in these
110 other calls returning an error, if for example, such
111 a call ends up requesting an empty set of CPUs or
112 memory nodes, after that request is restricted to
113 the invoking process's cpuset.
114 .PP
115 Typically, a cpuset is used to manage
116 the CPU and memory-node confinement for a set of
117 cooperating processes such as a batch scheduler job, and these
118 other mechanisms are used to manage the placement of
119 individual processes or memory regions within that set or job.
120 .SH FILES
121 Each directory below
122 .I /dev/cpuset
123 represents a cpuset and contains a fixed set of pseudo-files
124 describing the state of that cpuset.
125 .PP
126 New cpusets are created using the
127 .BR mkdir (2)
128 system call or the
129 .BR mkdir (1)
130 command.
131 The properties of a cpuset, such as its flags, allowed
132 CPUs and memory nodes, and attached processes, are queried and modified
133 by reading or writing to the appropriate file in that cpuset's directory,
134 as listed below.
135 .PP
136 The pseudo-files in each cpuset directory are automatically created when
137 the cpuset is created, as a result of the
138 .BR mkdir (2)
139 invocation.
140 It is not possible to directly add or remove these pseudo-files.
141 .PP
142 A cpuset directory that contains no child cpuset directories,
143 and has no attached processes, can be removed using
144 .BR rmdir (2)
145 or
146 .BR rmdir (1).
147 It is not necessary, or possible,
148 to remove the pseudo-files inside the directory before removing it.
149 .PP
150 The pseudo-files in each cpuset directory are
151 small text files that may be read and
152 written using traditional shell utilities such as
153 .BR cat (1),
154 and
155 .BR echo (1),
156 or from a program by using file I/O library functions or system calls,
157 such as
158 .BR open (2),
159 .BR read (2),
160 .BR write (2),
161 and
162 .BR close (2).
163 .PP
164 The pseudo-files in a cpuset directory represent internal kernel
165 state and do not have any persistent image on disk.
166 Each of these per-cpuset files is listed and described below.
167 .\" ====================== tasks ======================
168 .TP
169 .I tasks
170 List of the process IDs (PIDs) of the processes in that cpuset.
171 The list is formatted as a series of ASCII
172 decimal numbers, each followed by a newline.
173 A process may be added to a cpuset (automatically removing
174 it from the cpuset that previously contained it) by writing its
175 PID to that cpuset's
176 .I tasks
177 file (with or without a trailing newline).
178
179 .B Warning:
180 only one PID may be written to the
181 .I tasks
182 file at a time.
183 If a string is written that contains more
184 than one PID, only the first one will be used.
185 .\" =================== notify_on_release ===================
186 .TP
187 .I notify_on_release
188 Flag (0 or 1).
189 If set (1), that cpuset will receive special handling
190 after it is released, that is, after all processes cease using
191 it (i.e., terminate or are moved to a different cpuset)
192 and all child cpuset directories have been removed.
193 See the \fBNotify On Release\fR section, below.
194 .\" ====================== cpus ======================
195 .TP
196 .I cpuset.cpus
197 List of the physical numbers of the CPUs on which processes
198 in that cpuset are allowed to execute.
199 See \fBList Format\fR below for a description of the
200 format of
201 .IR cpus .
202
203 The CPUs allowed to a cpuset may be changed by
204 writing a new list to its
205 .I cpus
206 file.
207 .\" ==================== cpu_exclusive ====================
208 .TP
209 .I cpuset.cpu_exclusive
210 Flag (0 or 1).
211 If set (1), the cpuset has exclusive use of
212 its CPUs (no sibling or cousin cpuset may overlap CPUs).
213 By default this is off (0).
214 Newly created cpusets also initially default this to off (0).
215
216 Two cpusets are
217 .I sibling
218 cpusets if they share the same parent cpuset in the
219 .I /dev/cpuset
220 hierarchy.
221 Two cpusets are
222 .I cousin
223 cpusets if neither is the ancestor of the other.
224 Regardless of the
225 .I cpu_exclusive
226 setting, if one cpuset is the ancestor of another,
227 and if both of these cpusets have nonempty
228 .IR cpus ,
229 then their
230 .I cpus
231 must overlap, because the
232 .I cpus
233 of any cpuset are always a subset of the
234 .I cpus
235 of its parent cpuset.
236 .\" ====================== mems ======================
237 .TP
238 .I cpuset.mems
239 List of memory nodes on which processes in this cpuset are
240 allowed to allocate memory.
241 See \fBList Format\fR below for a description of the
242 format of
243 .IR mems .
244 .\" ==================== mem_exclusive ====================
245 .TP
246 .I cpuset.mem_exclusive
247 Flag (0 or 1).
248 If set (1), the cpuset has exclusive use of
249 its memory nodes (no sibling or cousin may overlap).
250 Also if set (1), the cpuset is a \fBHardwall\fR cpuset (see below).
251 By default this is off (0).
252 Newly created cpusets also initially default this to off (0).
253
254 Regardless of the
255 .I mem_exclusive
256 setting, if one cpuset is the ancestor of another,
257 then their memory nodes must overlap, because the memory
258 nodes of any cpuset are always a subset of the memory nodes
259 of that cpuset's parent cpuset.
260 .\" ==================== mem_hardwall ====================
261 .TP
262 .IR cpuset.mem_hardwall " (since Linux 2.6.26)"
263 Flag (0 or 1).
264 If set (1), the cpuset is a \fBHardwall\fR cpuset (see below).
265 Unlike \fBmem_exclusive\fR,
266 there is no constraint on whether cpusets
267 marked \fBmem_hardwall\fR may have overlapping
268 memory nodes with sibling or cousin cpusets.
269 By default this is off (0).
270 Newly created cpusets also initially default this to off (0).
271 .\" ==================== memory_migrate ====================
272 .TP
273 .IR cpuset.memory_migrate " (since Linux 2.6.16)"
274 Flag (0 or 1).
275 If set (1), then memory migration is enabled.
276 By default this is off (0).
277 See the \fBMemory Migration\fR section, below.
278 .\" ==================== memory_pressure ====================
279 .TP
280 .IR cpuset.memory_pressure " (since Linux 2.6.16)"
281 A measure of how much memory pressure the processes in this
282 cpuset are causing.
283 See the \fBMemory Pressure\fR section, below.
284 Unless
285 .I memory_pressure_enabled
286 is enabled, always has value zero (0).
287 This file is read-only.
288 See the
289 .B WARNINGS
290 section, below.
291 .\" ================= memory_pressure_enabled =================
292 .TP
293 .IR cpuset.memory_pressure_enabled " (since Linux 2.6.16)"
294 Flag (0 or 1).
295 This file is present only in the root cpuset, normally
296 .IR /dev/cpuset .
297 If set (1), the
298 .I memory_pressure
299 calculations are enabled for all cpusets in the system.
300 By default this is off (0).
301 See the
302 \fBMemory Pressure\fR section, below.
303 .\" ================== memory_spread_page ==================
304 .TP
305 .IR cpuset.memory_spread_page " (since Linux 2.6.17)"
306 Flag (0 or 1).
307 If set (1), pages in the kernel page cache
308 (filesystem buffers) are uniformly spread across the cpuset.
309 By default this is off (0) in the top cpuset,
310 and inherited from the parent cpuset in
311 newly created cpusets.
312 See the \fBMemory Spread\fR section, below.
313 .\" ================== memory_spread_slab ==================
314 .TP
315 .IR cpuset.memory_spread_slab " (since Linux 2.6.17)"
316 Flag (0 or 1).
317 If set (1), the kernel slab caches
318 for file I/O (directory and inode structures) are
319 uniformly spread across the cpuset.
320 By default this is off (0) in the top cpuset,
321 and inherited from the parent cpuset in
322 newly created cpusets.
323 See the \fBMemory Spread\fR section, below.
324 .\" ================== sched_load_balance ==================
325 .TP
326 .IR cpuset.sched_load_balance " (since Linux 2.6.24)"
327 Flag (0 or 1).
328 If set (1, the default) the kernel will
329 automatically load balance processes in that cpuset over
330 the allowed CPUs in that cpuset.
331 If cleared (0) the
332 kernel will avoid load balancing processes in this cpuset,
333 .I unless
334 some other cpuset with overlapping CPUs has its
335 .I sched_load_balance
336 flag set.
337 See \fBScheduler Load Balancing\fR, below, for further details.
338 .\" ================== sched_relax_domain_level ==================
339 .TP
340 .IR cpuset.sched_relax_domain_level " (since Linux 2.6.26)"
341 Integer, between \-1 and a small positive value.
342 The
343 .I sched_relax_domain_level
344 controls the width of the range of CPUs over which the kernel scheduler
345 performs immediate rebalancing of runnable tasks across CPUs.
346 If
347 .I sched_load_balance
348 is disabled, then the setting of
349 .I sched_relax_domain_level
350 does not matter, as no such load balancing is done.
351 If
352 .I sched_load_balance
353 is enabled, then the higher the value of the
354 .IR sched_relax_domain_level ,
355 the wider
356 the range of CPUs over which immediate load balancing is attempted.
357 See \fBScheduler Relax Domain Level\fR, below, for further details.
358 .\" ================== proc cpuset ==================
359 .PP
360 In addition to the above pseudo-files in each directory below
361 .IR /dev/cpuset ,
362 each process has a pseudo-file,
363 .IR /proc/<pid>/cpuset ,
364 that displays the path of the process's cpuset directory
365 relative to the root of the cpuset filesystem.
366 .\" ================== proc status ==================
367 .PP
368 Also the
369 .I /proc/<pid>/status
370 file for each process has four added lines,
371 displaying the process's
372 .I Cpus_allowed
373 (on which CPUs it may be scheduled) and
374 .I Mems_allowed
375 (on which memory nodes it may obtain memory),
376 in the two formats \fBMask Format\fR and \fBList Format\fR (see below)
377 as shown in the following example:
378 .PP
379 .RS
380 .nf
381 Cpus_allowed:   ffffffff,ffffffff,ffffffff,ffffffff
382 Cpus_allowed_list:     0-127
383 Mems_allowed:   ffffffff,ffffffff
384 Mems_allowed_list:     0-63
385 .fi
386 .RE
387 .PP
388 The "allowed" fields were added in Linux 2.6.24;
389 the "allowed_list" fields were added in Linux 2.6.26.
390 .\" ================== EXTENDED CAPABILITIES ==================
391 .SH EXTENDED CAPABILITIES
392 In addition to controlling which
393 .I cpus
394 and
395 .I mems
396 a process is allowed to use, cpusets provide the following
397 extended capabilities.
398 .\" ================== Exclusive Cpusets ==================
399 .SS Exclusive cpusets
400 If a cpuset is marked
401 .I cpu_exclusive
402 or
403 .IR mem_exclusive ,
404 no other cpuset, other than a direct ancestor or descendant,
405 may share any of the same CPUs or memory nodes.
406 .PP
407 A cpuset that is
408 .I mem_exclusive
409 restricts kernel allocations for
410 buffer cache pages and other internal kernel data pages
411 commonly shared by the kernel across
412 multiple users.
413 All cpusets, whether
414 .I mem_exclusive
415 or not, restrict allocations of memory for user space.
416 This enables configuring a
417 system so that several independent jobs can share common kernel data,
418 while isolating each job's user allocation in
419 its own cpuset.
420 To do this, construct a large
421 .I mem_exclusive
422 cpuset to hold all the jobs, and construct child,
423 .RI non- mem_exclusive
424 cpusets for each individual job.
425 Only a small amount of kernel memory,
426 such as requests from interrupt handlers, is allowed to be
427 placed on memory nodes
428 outside even a
429 .I mem_exclusive
430 cpuset.
431 .\" ================== Hardwall ==================
432 .SS Hardwall
433 A cpuset that has
434 .I mem_exclusive
435 or
436 .I mem_hardwall
437 set is a
438 .I hardwall
439 cpuset.
440 A
441 .I hardwall
442 cpuset restricts kernel allocations for page, buffer,
443 and other data commonly shared by the kernel across multiple users.
444 All cpusets, whether
445 .I hardwall
446 or not, restrict allocations of memory for user space.
447 .PP
448 This enables configuring a system so that several independent
449 jobs can share common kernel data, such as filesystem pages,
450 while isolating each job's user allocation in its own cpuset.
451 To do this, construct a large
452 .I hardwall
453 cpuset to hold
454 all the jobs, and construct child cpusets for each individual
455 job which are not
456 .I hardwall
457 cpusets.
458 .PP
459 Only a small amount of kernel memory, such as requests from
460 interrupt handlers, is allowed to be taken outside even a
461 .I hardwall
462 cpuset.
463 .\" ================== Notify On Release ==================
464 .SS Notify on release
465 If the
466 .I notify_on_release
467 flag is enabled (1) in a cpuset,
468 then whenever the last process in the cpuset leaves
469 (exits or attaches to some other cpuset)
470 and the last child cpuset of that cpuset is removed,
471 the kernel will run the command
472 .IR /sbin/cpuset_release_agent ,
473 supplying the pathname (relative to the mount point of the
474 cpuset filesystem) of the abandoned cpuset.
475 This enables automatic removal of abandoned cpusets.
476 .PP
477 The default value of
478 .I notify_on_release
479 in the root cpuset at system boot is disabled (0).
480 The default value of other cpusets at creation
481 is the current value of their parent's
482 .I notify_on_release
483 setting.
484 .PP
485 The command
486 .I /sbin/cpuset_release_agent
487 is invoked, with the name
488 .RI ( /dev/cpuset
489 relative path)
490 of the to-be-released cpuset in
491 .IR argv[1] .
492 .PP
493 The usual contents of the command
494 .I /sbin/cpuset_release_agent
495 is simply the shell script:
496 .in +4n
497 .nf
498
499 #!/bin/sh
500 rmdir /dev/cpuset/$1
501 .fi
502 .in
503 .PP
504 As with other flag values below, this flag can
505 be changed by writing an ASCII
506 number 0 or 1 (with optional trailing newline)
507 into the file, to clear or set the flag, respectively.
508 .\" ================== Memory Pressure ==================
509 .SS Memory pressure
510 The
511 .I memory_pressure
512 of a cpuset provides a simple per-cpuset running average of
513 the rate that the processes in a cpuset are attempting to free up in-use
514 memory on the nodes of the cpuset to satisfy additional memory requests.
515 .PP
516 This enables batch managers that are monitoring jobs running in dedicated
517 cpusets to efficiently detect what level of memory pressure that job
518 is causing.
519 .PP
520 This is useful both on tightly managed systems running a wide mix of
521 submitted jobs, which may choose to terminate or reprioritize jobs that
522 are trying to use more memory than allowed on the nodes assigned them,
523 and with tightly coupled, long-running, massively parallel scientific
524 computing jobs that will dramatically fail to meet required performance
525 goals if they start to use more memory than allowed to them.
526 .PP
527 This mechanism provides a very economical way for the batch manager
528 to monitor a cpuset for signs of memory pressure.
529 It's up to the batch manager or other user code to decide
530 what action to take if it detects signs of memory pressure.
531 .PP
532 Unless memory pressure calculation is enabled by setting the pseudo-file
533 .IR /dev/cpuset/cpuset.memory_pressure_enabled ,
534 it is not computed for any cpuset, and reads from any
535 .I memory_pressure
536 always return zero, as represented by the ASCII string "0\en".
537 See the \fBWARNINGS\fR section, below.
538 .PP
539 A per-cpuset, running average is employed for the following reasons:
540 .IP * 3
541 Because this meter is per-cpuset rather than per-process or per virtual
542 memory region, the system load imposed by a batch scheduler monitoring
543 this metric is sharply reduced on large systems, because a scan of
544 the tasklist can be avoided on each set of queries.
545 .IP *
546 Because this meter is a running average rather than an accumulating
547 counter, a batch scheduler can detect memory pressure with a
548 single read, instead of having to read and accumulate results
549 for a period of time.
550 .IP *
551 Because this meter is per-cpuset rather than per-process,
552 the batch scheduler can obtain the key information\(emmemory
553 pressure in a cpuset\(emwith a single read, rather than having to
554 query and accumulate results over all the (dynamically changing)
555 set of processes in the cpuset.
556 .PP
557 The
558 .I memory_pressure
559 of a cpuset is calculated using a per-cpuset simple digital filter
560 that is kept within the kernel.
561 For each cpuset, this filter tracks
562 the recent rate at which processes attached to that cpuset enter the
563 kernel direct reclaim code.
564 .PP
565 The kernel direct reclaim code is entered whenever a process has to
566 satisfy a memory page request by first finding some other page to
567 repurpose, due to lack of any readily available already free pages.
568 Dirty filesystem pages are repurposed by first writing them
569 to disk.
570 Unmodified filesystem buffer pages are repurposed
571 by simply dropping them, though if that page is needed again, it
572 will have to be reread from disk.
573 .PP
574 The
575 .I cpuset.memory_pressure
576 file provides an integer number representing the recent (half-life of
577 10 seconds) rate of entries to the direct reclaim code caused by any
578 process in the cpuset, in units of reclaims attempted per second,
579 times 1000.
580 .\" ================== Memory Spread ==================
581 .SS Memory spread
582 There are two Boolean flag files per cpuset that control where the
583 kernel allocates pages for the filesystem buffers and related
584 in-kernel data structures.
585 They are called
586 .I cpuset.memory_spread_page
587 and
588 .IR cpuset.memory_spread_slab .
589 .PP
590 If the per-cpuset Boolean flag file
591 .I cpuset.memory_spread_page
592 is set, then
593 the kernel will spread the filesystem buffers (page cache) evenly
594 over all the nodes that the faulting process is allowed to use, instead
595 of preferring to put those pages on the node where the process is running.
596 .PP
597 If the per-cpuset Boolean flag file
598 .I cpuset.memory_spread_slab
599 is set,
600 then the kernel will spread some filesystem-related slab caches,
601 such as those for inodes and directory entries, evenly over all the nodes
602 that the faulting process is allowed to use, instead of preferring to
603 put those pages on the node where the process is running.
604 .PP
605 The setting of these flags does not affect the data segment
606 (see
607 .BR brk (2))
608 or stack segment pages of a process.
609 .PP
610 By default, both kinds of memory spreading are off and the kernel
611 prefers to allocate memory pages on the node local to where the
612 requesting process is running.
613 If that node is not allowed by the
614 process's NUMA memory policy or cpuset configuration or if there are
615 insufficient free memory pages on that node, then the kernel looks
616 for the nearest node that is allowed and has sufficient free memory.
617 .PP
618 When new cpusets are created, they inherit the memory spread settings
619 of their parent.
620 .PP
621 Setting memory spreading causes allocations for the affected page or
622 slab caches to ignore the process's NUMA memory policy and be spread
623 instead.
624 However, the effect of these changes in memory placement
625 caused by cpuset-specified memory spreading is hidden from the
626 .BR mbind (2)
627 or
628 .BR set_mempolicy (2)
629 calls.
630 These two NUMA memory policy calls always appear to behave as if
631 no cpuset-specified memory spreading is in effect, even if it is.
632 If cpuset memory spreading is subsequently turned off, the NUMA
633 memory policy most recently specified by these calls is automatically
634 reapplied.
635 .PP
636 Both
637 .I cpuset.memory_spread_page
638 and
639 .I cpuset.memory_spread_slab
640 are Boolean flag files.
641 By default they contain "0", meaning that the feature is off
642 for that cpuset.
643 If a "1" is written to that file, that turns the named feature on.
644 .PP
645 Cpuset-specified memory spreading behaves similarly to what is known
646 (in other contexts) as round-robin or interleave memory placement.
647 .PP
648 Cpuset-specified memory spreading can provide substantial performance
649 improvements for jobs that:
650 .IP a) 3
651 need to place thread-local data on
652 memory nodes close to the CPUs which are running the threads that most
653 frequently access that data; but also
654 .IP b)
655 need to access large filesystem data sets that must to be spread
656 across the several nodes in the job's cpuset in order to fit.
657 .PP
658 Without this policy,
659 the memory allocation across the nodes in the job's cpuset
660 can become very uneven,
661 especially for jobs that might have just a single
662 thread initializing or reading in the data set.
663 .\" ================== Memory Migration ==================
664 .SS Memory migration
665 Normally, under the default setting (disabled) of
666 .IR cpuset.memory_migrate ,
667 once a page is allocated (given a physical page
668 of main memory), then that page stays on whatever node it
669 was allocated, so long as it remains allocated, even if the
670 cpuset's memory-placement policy
671 .I mems
672 subsequently changes.
673 .PP
674 When memory migration is enabled in a cpuset, if the
675 .I mems
676 setting of the cpuset is changed, then any memory page in use by any
677 process in the cpuset that is on a memory node that is no longer
678 allowed will be migrated to a memory node that is allowed.
679 .PP
680 Furthermore, if a process is moved into a cpuset with
681 .I memory_migrate
682 enabled, any memory pages it uses that were on memory nodes allowed
683 in its previous cpuset, but which are not allowed in its new cpuset,
684 will be migrated to a memory node allowed in the new cpuset.
685 .PP
686 The relative placement of a migrated page within
687 the cpuset is preserved during these migration operations if possible.
688 For example,
689 if the page was on the second valid node of the prior cpuset,
690 then the page will be placed on the second valid node of the new cpuset,
691 if possible.
692 .\" ================== Scheduler Load Balancing ==================
693 .SS Scheduler load balancing
694 The kernel scheduler automatically load balances processes.
695 If one CPU is underutilized,
696 the kernel will look for processes on other more
697 overloaded CPUs and move those processes to the underutilized CPU,
698 within the constraints of such placement mechanisms as cpusets and
699 .BR sched_setaffinity (2).
700 .PP
701 The algorithmic cost of load balancing and its impact on key shared
702 kernel data structures such as the process list increases more than
703 linearly with the number of CPUs being balanced.
704 For example, it
705 costs more to load balance across one large set of CPUs than it does
706 to balance across two smaller sets of CPUs, each of half the size
707 of the larger set.
708 (The precise relationship between the number of CPUs being balanced
709 and the cost of load balancing depends
710 on implementation details of the kernel process scheduler, which is
711 subject to change over time, as improved kernel scheduler algorithms
712 are implemented.)
713 .PP
714 The per-cpuset flag
715 .I sched_load_balance
716 provides a mechanism to suppress this automatic scheduler load
717 balancing in cases where it is not needed and suppressing it would have
718 worthwhile performance benefits.
719 .PP
720 By default, load balancing is done across all CPUs, except those
721 marked isolated using the kernel boot time "isolcpus=" argument.
722 (See \fBScheduler Relax Domain Level\fR, below, to change this default.)
723 .PP
724 This default load balancing across all CPUs is not well suited to
725 the following two situations:
726 .IP * 3
727 On large systems, load balancing across many CPUs is expensive.
728 If the system is managed using cpusets to place independent jobs
729 on separate sets of CPUs, full load balancing is unnecessary.
730 .IP *
731 Systems supporting real-time on some CPUs need to minimize
732 system overhead on those CPUs, including avoiding process load
733 balancing if that is not needed.
734 .PP
735 When the per-cpuset flag
736 .I sched_load_balance
737 is enabled (the default setting),
738 it requests load balancing across
739 all the CPUs in that cpuset's allowed CPUs,
740 ensuring that load balancing can move a process (not otherwise pinned,
741 as by
742 .BR sched_setaffinity (2))
743 from any CPU in that cpuset to any other.
744 .PP
745 When the per-cpuset flag
746 .I sched_load_balance
747 is disabled, then the
748 scheduler will avoid load balancing across the CPUs in that cpuset,
749 \fIexcept\fR in so far as is necessary because some overlapping cpuset
750 has
751 .I sched_load_balance
752 enabled.
753 .PP
754 So, for example, if the top cpuset has the flag
755 .I sched_load_balance
756 enabled, then the scheduler will load balance across all
757 CPUs, and the setting of the
758 .I sched_load_balance
759 flag in other cpusets has no effect,
760 as we're already fully load balancing.
761 .PP
762 Therefore in the above two situations, the flag
763 .I sched_load_balance
764 should be disabled in the top cpuset, and only some of the smaller,
765 child cpusets would have this flag enabled.
766 .PP
767 When doing this, you don't usually want to leave any unpinned processes in
768 the top cpuset that might use nontrivial amounts of CPU, as such processes
769 may be artificially constrained to some subset of CPUs, depending on
770 the particulars of this flag setting in descendant cpusets.
771 Even if such a process could use spare CPU cycles in some other CPUs,
772 the kernel scheduler might not consider the possibility of
773 load balancing that process to the underused CPU.
774 .PP
775 Of course, processes pinned to a particular CPU can be left in a cpuset
776 that disables
777 .I sched_load_balance
778 as those processes aren't going anywhere else anyway.
779 .\" ================== Scheduler Relax Domain Level ==================
780 .SS Scheduler relax domain level
781 The kernel scheduler performs immediate load balancing whenever
782 a CPU becomes free or another task becomes runnable.
783 This load
784 balancing works to ensure that as many CPUs as possible are usefully
785 employed running tasks.
786 The kernel also performs periodic load
787 balancing off the software clock described in
788 .BR time (7).
789 The setting of
790 .I sched_relax_domain_level
791 applies only to immediate load balancing.
792 Regardless of the
793 .I sched_relax_domain_level
794 setting, periodic load balancing is attempted over all CPUs
795 (unless disabled by turning off
796 .IR sched_load_balance .)
797 In any case, of course, tasks will be scheduled to run only on
798 CPUs allowed by their cpuset, as modified by
799 .BR sched_setaffinity (2)
800 system calls.
801 .PP
802 On small systems, such as those with just a few CPUs, immediate load
803 balancing is useful to improve system interactivity and to minimize
804 wasteful idle CPU cycles.
805 But on large systems, attempting immediate
806 load balancing across a large number of CPUs can be more costly than
807 it is worth, depending on the particular performance characteristics
808 of the job mix and the hardware.
809 .PP
810 The exact meaning of the small integer values of
811 .I sched_relax_domain_level
812 will depend on internal
813 implementation details of the kernel scheduler code and on the
814 non-uniform architecture of the hardware.
815 Both of these will evolve
816 over time and vary by system architecture and kernel version.
817 .PP
818 As of this writing, when this capability was introduced in Linux
819 2.6.26, on certain popular architectures, the positive values of
820 .I sched_relax_domain_level
821 have the following meanings.
822 .sp
823 .PD 0
824 .IP \fB(1)\fR 4
825 Perform immediate load balancing across Hyper-Thread
826 siblings on the same core.
827 .IP \fB(2)\fR
828 Perform immediate load balancing across other cores in the same package.
829 .IP \fB(3)\fR
830 Perform immediate load balancing across other CPUs
831 on the same node or blade.
832 .IP \fB(4)\fR
833 Perform immediate load balancing across over several
834 (implementation detail) nodes [On NUMA systems].
835 .IP \fB(5)\fR
836 Perform immediate load balancing across over all CPUs
837 in system [On NUMA systems].
838 .PD
839 .PP
840 The
841 .I sched_relax_domain_level
842 value of zero (0) always means
843 don't perform immediate load balancing,
844 hence that load balancing is done only periodically,
845 not immediately when a CPU becomes available or another task becomes
846 runnable.
847 .PP
848 The
849 .I sched_relax_domain_level
850 value of minus one (\-1)
851 always means use the system default value.
852 The system default value can vary by architecture and kernel version.
853 This system default value can be changed by kernel
854 boot-time "relax_domain_level=" argument.
855 .PP
856 In the case of multiple overlapping cpusets which have conflicting
857 .I sched_relax_domain_level
858 values, then the highest such value
859 applies to all CPUs in any of the overlapping cpusets.
860 In such cases,
861 the value \fBminus one (\-1)\fR is the lowest value, overridden by any
862 other value, and the value \fBzero (0)\fR is the next lowest value.
863 .SH FORMATS
864 The following formats are used to represent sets of
865 CPUs and memory nodes.
866 .\" ================== Mask Format ==================
867 .SS Mask format
868 The \fBMask Format\fR is used to represent CPU and memory-node bit masks
869 in the
870 .I /proc/<pid>/status
871 file.
872 .PP
873 This format displays each 32-bit
874 word in hexadecimal (using ASCII characters "0" - "9" and "a" - "f");
875 words are filled with leading zeros, if required.
876 For masks longer than one word, a comma separator is used between words.
877 Words are displayed in big-endian
878 order, which has the most significant bit first.
879 The hex digits within a word are also in big-endian order.
880 .PP
881 The number of 32-bit words displayed is the minimum number needed to
882 display all bits of the bit mask, based on the size of the bit mask.
883 .PP
884 Examples of the \fBMask Format\fR:
885 .PP
886 .RS
887 .nf
888 00000001                        # just bit 0 set
889 40000000,00000000,00000000      # just bit 94 set
890 00000001,00000000,00000000      # just bit 64 set
891 000000ff,00000000               # bits 32-39 set
892 00000000,000e3862               # 1,5,6,11-13,17-19 set
893 .fi
894 .RE
895 .PP
896 A mask with bits 0, 1, 2, 4, 8, 16, 32, and 64 set displays as:
897 .PP
898 .RS
899 .nf
900 00000001,00000001,00010117
901 .fi
902 .RE
903 .PP
904 The first "1" is for bit 64, the
905 second for bit 32, the third for bit 16, the fourth for bit 8, the
906 fifth for bit 4, and the "7" is for bits 2, 1, and 0.
907 .\" ================== List Format ==================
908 .SS List format
909 The \fBList Format\fR for
910 .I cpus
911 and
912 .I mems
913 is a comma-separated list of CPU or memory-node
914 numbers and ranges of numbers, in ASCII decimal.
915 .PP
916 Examples of the \fBList Format\fR:
917 .PP
918 .RS
919 .nf
920 0-4,9           # bits 0, 1, 2, 3, 4, and 9 set
921 0-2,7,12-14     # bits 0, 1, 2, 7, 12, 13, and 14 set
922 .fi
923 .RE
924 .\" ================== RULES ==================
925 .SH RULES
926 The following rules apply to each cpuset:
927 .IP * 3
928 Its CPUs and memory nodes must be a (possibly equal)
929 subset of its parent's.
930 .IP *
931 It can be marked
932 .IR cpu_exclusive
933 only if its parent is.
934 .IP *
935 It can be marked
936 .IR mem_exclusive
937 only if its parent is.
938 .IP *
939 If it is
940 .IR cpu_exclusive ,
941 its CPUs may not overlap any sibling.
942 .IP *
943 If it is
944 .IR memory_exclusive ,
945 its memory nodes may not overlap any sibling.
946 .\" ================== PERMISSIONS ==================
947 .SH PERMISSIONS
948 The permissions of a cpuset are determined by the permissions
949 of the directories and pseudo-files in the cpuset filesystem,
950 normally mounted at
951 .IR /dev/cpuset .
952 .PP
953 For instance, a process can put itself in some other cpuset (than
954 its current one) if it can write the
955 .I tasks
956 file for that cpuset.
957 This requires execute permission on the encompassing directories
958 and write permission on the
959 .I tasks
960 file.
961 .PP
962 An additional constraint is applied to requests to place some
963 other process in a cpuset.
964 One process may not attach another to
965 a cpuset unless it would have permission to send that process
966 a signal (see
967 .BR kill (2)).
968 .PP
969 A process may create a child cpuset if it can access and write the
970 parent cpuset directory.
971 It can modify the CPUs or memory nodes
972 in a cpuset if it can access that cpuset's directory (execute
973 permissions on the each of the parent directories) and write the
974 corresponding
975 .I cpus
976 or
977 .I mems
978 file.
979 .PP
980 There is one minor difference between the manner in which these
981 permissions are evaluated and the manner in which normal filesystem
982 operation permissions are evaluated.
983 The kernel interprets
984 relative pathnames starting at a process's current working directory.
985 Even if one is operating on a cpuset file, relative pathnames
986 are interpreted relative to the process's current working directory,
987 not relative to the process's current cpuset.
988 The only ways that
989 cpuset paths relative to a process's current cpuset can be used are
990 if either the process's current working directory is its cpuset
991 (it first did a
992 .B cd
993 or
994 .BR chdir (2)
995 to its cpuset directory beneath
996 .IR /dev/cpuset ,
997 which is a bit unusual)
998 or if some user code converts the relative cpuset path to a
999 full filesystem path.
1000 .PP
1001 In theory, this means that user code should specify cpusets
1002 using absolute pathnames, which requires knowing the mount point of
1003 the cpuset filesystem (usually, but not necessarily,
1004 .IR /dev/cpuset ).
1005 In practice, all user level code that this author is aware of
1006 simply assumes that if the cpuset filesystem is mounted, then
1007 it is mounted at
1008 .IR /dev/cpuset .
1009 Furthermore, it is common practice for carefully written
1010 user code to verify the presence of the pseudo-file
1011 .I /dev/cpuset/tasks
1012 in order to verify that the cpuset pseudo-filesystem
1013 is currently mounted.
1014 .\" ================== WARNINGS ==================
1015 .SH WARNINGS
1016 .SS Enabling memory_pressure
1017 By default, the per-cpuset file
1018 .I cpuset.memory_pressure
1019 always contains zero (0).
1020 Unless this feature is enabled by writing "1" to the pseudo-file
1021 .IR /dev/cpuset/cpuset.memory_pressure_enabled ,
1022 the kernel does
1023 not compute per-cpuset
1024 .IR memory_pressure .
1025 .SS Using the echo command
1026 When using the
1027 .B echo
1028 command at the shell prompt to change the values of cpuset files,
1029 beware that the built-in
1030 .B echo
1031 command in some shells does not display an error message if the
1032 .BR write (2)
1033 system call fails.
1034 .\" Gack!  csh(1)'s echo does this
1035 For example, if the command:
1036 .in +4n
1037 .nf
1038
1039 echo 19 > cpuset.mems
1040
1041 .fi
1042 .in
1043 failed because memory node 19 was not allowed (perhaps
1044 the current system does not have a memory node 19), then the
1045 .B echo
1046 command might not display any error.
1047 It is better to use the
1048 .B /bin/echo
1049 external command to change cpuset file settings, as this
1050 command will display
1051 .BR write (2)
1052 errors, as in the example:
1053 .in +4n
1054 .nf
1055
1056 /bin/echo 19 > cpuset.mems
1057 /bin/echo: write error: Invalid argument
1058 .fi
1059 .in
1060 .\" ================== EXCEPTIONS ==================
1061 .SH EXCEPTIONS
1062 .SS Memory placement
1063 Not all allocations of system memory are constrained by cpusets,
1064 for the following reasons.
1065 .PP
1066 If hot-plug functionality is used to remove all the CPUs that are
1067 currently assigned to a cpuset, then the kernel will automatically
1068 update the
1069 .I cpus_allowed
1070 of all processes attached to CPUs in that cpuset
1071 to allow all CPUs.
1072 When memory hot-plug functionality for removing
1073 memory nodes is available, a similar exception is expected to apply
1074 there as well.
1075 In general, the kernel prefers to violate cpuset placement,
1076 rather than starving a process that has had all its allowed CPUs or
1077 memory nodes taken offline.
1078 User code should reconfigure cpusets to refer only to online CPUs
1079 and memory nodes when using hot-plug to add or remove such resources.
1080 .PP
1081 A few kernel-critical, internal memory-allocation requests, marked
1082 GFP_ATOMIC, must be satisfied immediately.
1083 The kernel may drop some
1084 request or malfunction if one of these allocations fail.
1085 If such a request cannot be satisfied within the current process's cpuset,
1086 then we relax the cpuset, and look for memory anywhere we can find it.
1087 It's better to violate the cpuset than stress the kernel.
1088 .PP
1089 Allocations of memory requested by kernel drivers while processing
1090 an interrupt lack any relevant process context, and are not confined
1091 by cpusets.
1092 .SS Renaming cpusets
1093 You can use the
1094 .BR rename (2)
1095 system call to rename cpusets.
1096 Only simple renaming is supported; that is, changing the name of a cpuset
1097 directory is permitted, but moving a directory into
1098 a different directory is not permitted.
1099 .\" ================== ERRORS ==================
1100 .SH ERRORS
1101 The Linux kernel implementation of cpusets sets
1102 .I errno
1103 to specify the reason for a failed system call affecting cpusets.
1104 .PP
1105 The possible
1106 .I errno
1107 settings and their meaning when set on
1108 a failed cpuset call are as listed below.
1109 .TP
1110 .B E2BIG
1111 Attempted a
1112 .BR write (2)
1113 on a special cpuset file
1114 with a length larger than some kernel-determined upper
1115 limit on the length of such writes.
1116 .TP
1117 .B EACCES
1118 Attempted to
1119 .BR write (2)
1120 the process ID (PID) of a process to a cpuset
1121 .I tasks
1122 file when one lacks permission to move that process.
1123 .TP
1124 .B EACCES
1125 Attempted to add, using
1126 .BR write (2),
1127 a CPU or memory node to a cpuset, when that CPU or memory node was
1128 not already in its parent.
1129 .TP
1130 .B EACCES
1131 Attempted to set, using
1132 .BR write (2),
1133 .I cpuset.cpu_exclusive
1134 or
1135 .I cpuset.mem_exclusive
1136 on a cpuset whose parent lacks the same setting.
1137 .TP
1138 .B EACCES
1139 Attempted to
1140 .BR write (2)
1141 a
1142 .I cpuset.memory_pressure
1143 file.
1144 .TP
1145 .B EACCES
1146 Attempted to create a file in a cpuset directory.
1147 .TP
1148 .B EBUSY
1149 Attempted to remove, using
1150 .BR rmdir (2),
1151 a cpuset with attached processes.
1152 .TP
1153 .B EBUSY
1154 Attempted to remove, using
1155 .BR rmdir (2),
1156 a cpuset with child cpusets.
1157 .TP
1158 .B EBUSY
1159 Attempted to remove
1160 a CPU or memory node from a cpuset
1161 that is also in a child of that cpuset.
1162 .TP
1163 .B EEXIST
1164 Attempted to create, using
1165 .BR mkdir (2),
1166 a cpuset that already exists.
1167 .TP
1168 .B EEXIST
1169 Attempted to
1170 .BR rename (2)
1171 a cpuset to a name that already exists.
1172 .TP
1173 .B EFAULT
1174 Attempted to
1175 .BR read (2)
1176 or
1177 .BR write (2)
1178 a cpuset file using
1179 a buffer that is outside the writing processes accessible address space.
1180 .TP
1181 .B EINVAL
1182 Attempted to change a cpuset, using
1183 .BR write (2),
1184 in a way that would violate a
1185 .I cpu_exclusive
1186 or
1187 .I mem_exclusive
1188 attribute of that cpuset or any of its siblings.
1189 .TP
1190 .B EINVAL
1191 Attempted to
1192 .BR write (2)
1193 an empty
1194 .I cpuset.cpus
1195 or
1196 .I cpuset.mems
1197 list to a cpuset which has attached processes or child cpusets.
1198 .TP
1199 .B EINVAL
1200 Attempted to
1201 .BR write (2)
1202 a
1203 .I cpuset.cpus
1204 or
1205 .I cpuset.mems
1206 list which included a range with the second number smaller than
1207 the first number.
1208 .TP
1209 .B EINVAL
1210 Attempted to
1211 .BR write (2)
1212 a
1213 .I cpuset.cpus
1214 or
1215 .I cpuset.mems
1216 list which included an invalid character in the string.
1217 .TP
1218 .B EINVAL
1219 Attempted to
1220 .BR write (2)
1221 a list to a
1222 .I cpuset.cpus
1223 file that did not include any online CPUs.
1224 .TP
1225 .B EINVAL
1226 Attempted to
1227 .BR write (2)
1228 a list to a
1229 .I cpuset.mems
1230 file that did not include any online memory nodes.
1231 .TP
1232 .B EINVAL
1233 Attempted to
1234 .BR write (2)
1235 a list to a
1236 .I cpuset.mems
1237 file that included a node that held no memory.
1238 .TP
1239 .B EIO
1240 Attempted to
1241 .BR write (2)
1242 a string to a cpuset
1243 .I tasks
1244 file that
1245 does not begin with an ASCII decimal integer.
1246 .TP
1247 .B EIO
1248 Attempted to
1249 .BR rename (2)
1250 a cpuset into a different directory.
1251 .TP
1252 .B ENAMETOOLONG
1253 Attempted to
1254 .BR read (2)
1255 a
1256 .I /proc/<pid>/cpuset
1257 file for a cpuset path that is longer than the kernel page size.
1258 .TP
1259 .B ENAMETOOLONG
1260 Attempted to create, using
1261 .BR mkdir (2),
1262 a cpuset whose base directory name is longer than 255 characters.
1263 .TP
1264 .B ENAMETOOLONG
1265 Attempted to create, using
1266 .BR mkdir (2),
1267 a cpuset whose full pathname,
1268 including the mount point (typically "/dev/cpuset/") prefix,
1269 is longer than 4095 characters.
1270 .TP
1271 .B ENODEV
1272 The cpuset was removed by another process at the same time as a
1273 .BR write (2)
1274 was attempted on one of the pseudo-files in the cpuset directory.
1275 .TP
1276 .B ENOENT
1277 Attempted to create, using
1278 .BR mkdir (2),
1279 a cpuset in a parent cpuset that doesn't exist.
1280 .TP
1281 .B ENOENT
1282 Attempted to
1283 .BR access (2)
1284 or
1285 .BR open (2)
1286 a nonexistent file in a cpuset directory.
1287 .TP
1288 .B ENOMEM
1289 Insufficient memory is available within the kernel; can occur
1290 on a variety of system calls affecting cpusets, but only if the
1291 system is extremely short of memory.
1292 .TP
1293 .B ENOSPC
1294 Attempted to
1295 .BR write (2)
1296 the process ID (PID)
1297 of a process to a cpuset
1298 .I tasks
1299 file when the cpuset had an empty
1300 .I cpuset.cpus
1301 or empty
1302 .I cpuset.mems
1303 setting.
1304 .TP
1305 .B ENOSPC
1306 Attempted to
1307 .BR write (2)
1308 an empty
1309 .I cpuset.cpus
1310 or
1311 .I cpuset.mems
1312 setting to a cpuset that
1313 has tasks attached.
1314 .TP
1315 .B ENOTDIR
1316 Attempted to
1317 .BR rename (2)
1318 a nonexistent cpuset.
1319 .TP
1320 .B EPERM
1321 Attempted to remove a file from a cpuset directory.
1322 .TP
1323 .B ERANGE
1324 Specified a
1325 .I cpuset.cpus
1326 or
1327 .I cpuset.mems
1328 list to the kernel which included a number too large for the kernel
1329 to set in its bit masks.
1330 .TP
1331 .B ESRCH
1332 Attempted to
1333 .BR write (2)
1334 the process ID (PID) of a nonexistent process to a cpuset
1335 .I tasks
1336 file.
1337 .\" ================== VERSIONS ==================
1338 .SH VERSIONS
1339 Cpusets appeared in version 2.6.12 of the Linux kernel.
1340 .\" ================== NOTES ==================
1341 .SH NOTES
1342 Despite its name, the
1343 .I pid
1344 parameter is actually a thread ID,
1345 and each thread in a threaded group can be attached to a different
1346 cpuset.
1347 The value returned from a call to
1348 .BR gettid (2)
1349 can be passed in the argument
1350 .IR pid .
1351 .\" ================== BUGS ==================
1352 .SH BUGS
1353 .I cpuset.memory_pressure
1354 cpuset files can be opened
1355 for writing, creation, or truncation, but then the
1356 .BR write (2)
1357 fails with
1358 .I errno
1359 set to
1360 .BR EACCES ,
1361 and the creation and truncation options on
1362 .BR open (2)
1363 have no effect.
1364 .\" ================== EXAMPLE ==================
1365 .SH EXAMPLE
1366 The following examples demonstrate querying and setting cpuset
1367 options using shell commands.
1368 .SS Creating and attaching to a cpuset.
1369 To create a new cpuset and attach the current command shell to it,
1370 the steps are:
1371 .sp
1372 .PD 0
1373 .IP 1) 4
1374 mkdir /dev/cpuset (if not already done)
1375 .IP 2)
1376 mount \-t cpuset none /dev/cpuset (if not already done)
1377 .IP 3)
1378 Create the new cpuset using
1379 .BR mkdir (1).
1380 .IP 4)
1381 Assign CPUs and memory nodes to the new cpuset.
1382 .IP 5)
1383 Attach the shell to the new cpuset.
1384 .PD
1385 .PP
1386 For example, the following sequence of commands will set up a cpuset
1387 named "Charlie", containing just CPUs 2 and 3, and memory node 1,
1388 and then attach the current shell to that cpuset.
1389 .in +4n
1390 .nf
1391
1392 .RB "$" " mkdir /dev/cpuset"
1393 .RB "$" " mount \-t cpuset cpuset /dev/cpuset"
1394 .RB "$" " cd /dev/cpuset"
1395 .RB "$" " mkdir Charlie"
1396 .RB "$" " cd Charlie"
1397 .RB "$" " /bin/echo 2-3 > cpuset.cpus"
1398 .RB "$" " /bin/echo 1 > cpuset.mems"
1399 .RB "$" " /bin/echo $$ > tasks"
1400 # The current shell is now running in cpuset Charlie
1401 # The next line should display '/Charlie'
1402 .RB "$" " cat /proc/self/cpuset"
1403 .fi
1404 .in
1405 .SS Migrating a job to different memory nodes.
1406 To migrate a job (the set of processes attached to a cpuset)
1407 to different CPUs and memory nodes in the system, including moving
1408 the memory pages currently allocated to that job,
1409 perform the following steps.
1410 .sp
1411 .PD 0
1412 .IP 1) 4
1413 Let's say we want to move the job in cpuset
1414 .I alpha
1415 (CPUs 4-7 and memory nodes 2-3) to a new cpuset
1416 .I beta
1417 (CPUs 16-19 and memory nodes 8-9).
1418 .IP 2)
1419 First create the new cpuset
1420 .IR beta .
1421 .IP 3)
1422 Then allow CPUs 16-19 and memory nodes 8-9 in
1423 .IR beta .
1424 .IP 4)
1425 Then enable
1426 .I memory_migration
1427 in
1428 .IR beta .
1429 .IP 5)
1430 Then move each process from
1431 .I alpha
1432 to
1433 .IR beta .
1434 .PD
1435 .PP
1436 The following sequence of commands accomplishes this.
1437 .in +4n
1438 .nf
1439
1440 .RB "$" " cd /dev/cpuset"
1441 .RB "$" " mkdir beta"
1442 .RB "$" " cd beta"
1443 .RB "$" " /bin/echo 16-19 > cpuset.cpus"
1444 .RB "$" " /bin/echo 8-9 > cpuset.mems"
1445 .RB "$" " /bin/echo 1 > cpuset.memory_migrate"
1446 .RB "$" " while read i; do /bin/echo $i; done < ../alpha/tasks > tasks"
1447 .fi
1448 .in
1449 .PP
1450 The above should move any processes in
1451 .I alpha
1452 to
1453 .IR beta ,
1454 and any memory held by these processes on memory nodes 2-3 to memory
1455 nodes 8-9, respectively.
1456 .PP
1457 Notice that the last step of the above sequence did not do:
1458 .in +4n
1459 .nf
1460
1461 .RB "$" " cp ../alpha/tasks tasks"
1462 .fi
1463 .in
1464 .PP
1465 The
1466 .I while
1467 loop, rather than the seemingly easier use of the
1468 .BR cp (1)
1469 command, was necessary because
1470 only one process PID at a time may be written to the
1471 .I tasks
1472 file.
1473 .PP
1474 The same effect (writing one PID at a time) as the
1475 .I while
1476 loop can be accomplished more efficiently, in fewer keystrokes and in
1477 syntax that works on any shell, but alas more obscurely, by using the
1478 .B \-u
1479 (unbuffered) option of
1480 .BR sed (1):
1481 .in +4n
1482
1483 .nf
1484 .RB "$" " sed \-un p < ../alpha/tasks > tasks"
1485 .fi
1486 .in
1487 .\" ================== SEE ALSO ==================
1488 .SH SEE ALSO
1489 .BR taskset (1),
1490 .BR get_mempolicy (2),
1491 .BR getcpu (2),
1492 .BR mbind (2),
1493 .BR sched_getaffinity (2),
1494 .BR sched_setaffinity (2),
1495 .BR sched_setscheduler (2),
1496 .BR set_mempolicy (2),
1497 .BR CPU_SET (3),
1498 .BR proc (5),
1499 .BR numa (7),
1500 .BR sched (7),
1501 .BR migratepages (8),
1502 .BR numactl (8)
1503 .PP
1504 .IR Documentation/cpusets.txt
1505 in the Linux kernel source tree
1506 .SH COLOPHON
1507 This page is part of release 3.79 of the Linux
1508 .I man-pages
1509 project.
1510 A description of the project,
1511 information about reporting bugs,
1512 and the latest version of this page,
1513 can be found at
1514 \%http://www.kernel.org/doc/man\-pages/.