sphinx.addnodesdocument)}( rawsourcechildren]( translations LanguagesNode)}(hhh](h pending_xref)}(hhh]docutils.nodesTextChinese (Simplified)}parenthsba attributes}(ids]classes]names]dupnames]backrefs] refdomainstdreftypedoc reftarget1/translations/zh_CN/admin-guide/cgroup-v1/cpusetsmodnameN classnameN refexplicitutagnamehhh ubh)}(hhh]hChinese (Traditional)}hh2sbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget1/translations/zh_TW/admin-guide/cgroup-v1/cpusetsmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hItalian}hhFsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget1/translations/it_IT/admin-guide/cgroup-v1/cpusetsmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hJapanese}hhZsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget1/translations/ja_JP/admin-guide/cgroup-v1/cpusetsmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hKorean}hhnsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget1/translations/ko_KR/admin-guide/cgroup-v1/cpusetsmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hSpanish}hhsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget1/translations/sp_SP/admin-guide/cgroup-v1/cpusetsmodnameN classnameN refexplicituh1hhh ubeh}(h]h ]h"]h$]h&]current_languageEnglishuh1h hh _documenthsourceNlineNubhtarget)}(h .. _cpusets:h]h}(h]h ]h"]h$]h&]refidcpusetsuh1hhKhhhhhK/var/lib/git/docbuild/linux/Documentation/admin-guide/cgroup-v1/cpusets.rstubhsection)}(hhh](htitle)}(hCPUSETSh]hCPUSETS}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhhhKubh paragraph)}(hCopyright (C) 2004 BULL SA.h]hCopyright (C) 2004 BULL SA.}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hWritten by Simon.Derr@bull.neth](h Written by }(hhhhhNhNubh reference)}(hSimon.Derr@bull.neth]hSimon.Derr@bull.net}(hhhhhNhNubah}(h]h ]h"]h$]h&]refurimailto:Simon.Derr@bull.netuh1hhhubeh}(h]h ]h"]h$]h&]uh1hhhhK hhhhubh bullet_list)}(hhh](h list_item)}(h7Portions Copyright (c) 2004-2006 Silicon Graphics, Inc.h]h)}(hhh]h7Portions Copyright (c) 2004-2006 Silicon Graphics, Inc.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK hhubah}(h]h ]h"]h$]h&]uh1hhhhhhhhNubh)}(h%Modified by Paul Jackson h]h)}(hjh](hModified by Paul Jackson <}(hjhhhNhNubh)}(h pj@sgi.comh]h pj@sgi.com}(hjhhhNhNubah}(h]h ]h"]h$]h&]refurimailto:pj@sgi.comuh1hhjubh>}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK hjubah}(h]h ]h"]h$]h&]uh1hhhhhhhhNubh)}(h,Modified by Christoph Lameter h]h)}(hj@h](hModified by Christoph Lameter <}(hjBhhhNhNubh)}(h cl@linux.comh]h cl@linux.com}(hjIhhhNhNubah}(h]h ]h"]h$]h&]refurimailto:cl@linux.comuh1hhjBubh>}(hjBhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK hj>ubah}(h]h ]h"]h$]h&]uh1hhhhhhhhNubh)}(h+Modified by Paul Menage h]h)}(hjkh](hModified by Paul Menage <}(hjmhhhNhNubh)}(hmenage@google.comh]hmenage@google.com}(hjthhhNhNubah}(h]h ]h"]h$]h&]refurimailto:menage@google.comuh1hhjmubh>}(hjmhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjiubah}(h]h ]h"]h$]h&]uh1hhhhhhhhNubh)}(h;Modified by Hidetoshi Seto h]h)}(h:Modified by Hidetoshi Seto h](hModified by Hidetoshi Seto <}(hjhhhNhNubh)}(hseto.hidetoshi@jp.fujitsu.comh]hseto.hidetoshi@jp.fujitsu.com}(hjhhhNhNubah}(h]h ]h"]h$]h&]refuri$mailto:seto.hidetoshi@jp.fujitsu.comuh1hhjubh>}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1hhhhhhhhNubeh}(h]h ]h"]h$]h&]bullet-uh1hhhhK hhhhubhcomment)}(hXCONTENTS: 1. Cpusets 1.1 What are cpusets ? 1.2 Why are cpusets needed ? 1.3 How are cpusets implemented ? 1.4 What are exclusive cpusets ? 1.5 What is memory_pressure ? 1.6 What is memory spread ? 1.7 What is sched_load_balance ? 1.8 What is sched_relax_domain_level ? 1.9 How do I use cpusets ? 2. Usage Examples and Syntax 2.1 Basic Usage 2.2 Adding/removing cpus 2.3 Setting flags 2.4 Attaching processes 3. Questions 4. Contacth]hXCONTENTS: 1. Cpusets 1.1 What are cpusets ? 1.2 Why are cpusets needed ? 1.3 How are cpusets implemented ? 1.4 What are exclusive cpusets ? 1.5 What is memory_pressure ? 1.6 What is memory spread ? 1.7 What is sched_load_balance ? 1.8 What is sched_relax_domain_level ? 1.9 How do I use cpusets ? 2. Usage Examples and Syntax 2.1 Basic Usage 2.2 Adding/removing cpus 2.3 Setting flags 2.4 Attaching processes 3. Questions 4. Contact}hjsbah}(h]h ]h"]h$]h&] xml:spacepreserveuh1jhhhhhhhK$ubh)}(hhh](h)}(h 1. Cpusetsh]h 1. Cpusets}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhK&ubh)}(hhh](h)}(h1.1 What are cpusets ?h]h1.1 What are cpusets ?}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhK)ubh)}(hCpusets provide a mechanism for assigning a set of CPUs and Memory Nodes to a set of tasks. In this document "Memory Node" refers to an on-line node that contains memory.h]hCpusets provide a mechanism for assigning a set of CPUs and Memory Nodes to a set of tasks. In this document “Memory Node” refers to an on-line node that contains memory.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK+hjhhubh)}(hX(Cpusets constrain the CPU and Memory placement of tasks to only the resources within a task's current cpuset. They form a nested hierarchy visible in a virtual file system. These are the essential hooks, beyond what is already present, required to manage dynamic job placement on large systems.h]hX*Cpusets constrain the CPU and Memory placement of tasks to only the resources within a task’s current cpuset. They form a nested hierarchy visible in a virtual file system. These are the essential hooks, beyond what is already present, required to manage dynamic job placement on large systems.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK/hjhhubh)}(hfCpusets use the generic cgroup subsystem described in Documentation/admin-guide/cgroup-v1/cgroups.rst.h]hfCpusets use the generic cgroup subsystem described in Documentation/admin-guide/cgroup-v1/cgroups.rst.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK5hjhhubh)}(hXRequests by a task, using the sched_setaffinity(2) system call to include CPUs in its CPU affinity mask, and using the mbind(2) and set_mempolicy(2) system calls to include Memory Nodes in its memory policy, are both filtered through that task's cpuset, filtering out any CPUs or Memory Nodes not in that cpuset. The scheduler will not schedule a task on a CPU that is not allowed in its cpus_allowed vector, and the kernel page allocator will not allocate a page on a node that is not allowed in the requesting task's mems_allowed vector.h]hX Requests by a task, using the sched_setaffinity(2) system call to include CPUs in its CPU affinity mask, and using the mbind(2) and set_mempolicy(2) system calls to include Memory Nodes in its memory policy, are both filtered through that task’s cpuset, filtering out any CPUs or Memory Nodes not in that cpuset. The scheduler will not schedule a task on a CPU that is not allowed in its cpus_allowed vector, and the kernel page allocator will not allocate a page on a node that is not allowed in the requesting task’s mems_allowed vector.}(hj&hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK8hjhhubh)}(hX0User level code may create and destroy cpusets by name in the cgroup virtual file system, manage the attributes and permissions of these cpusets and which CPUs and Memory Nodes are assigned to each cpuset, specify and query to which cpuset a task is assigned, and list the task pids assigned to a cpuset.h]hX0User level code may create and destroy cpusets by name in the cgroup virtual file system, manage the attributes and permissions of these cpusets and which CPUs and Memory Nodes are assigned to each cpuset, specify and query to which cpuset a task is assigned, and list the task pids assigned to a cpuset.}(hj4hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKAhjhhubeh}(h]what-are-cpusetsah ]h"]1.1 what are cpusets ?ah$]h&]uh1hhjhhhhhK)ubh)}(hhh](h)}(h1.2 Why are cpusets needed ?h]h1.2 Why are cpusets needed ?}(hjMhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjJhhhhhKIubh)}(hXThe management of large computer systems, with many processors (CPUs), complex memory cache hierarchies and multiple Memory Nodes having non-uniform access times (NUMA) presents additional challenges for the efficient scheduling and memory placement of processes.h]hXThe management of large computer systems, with many processors (CPUs), complex memory cache hierarchies and multiple Memory Nodes having non-uniform access times (NUMA) presents additional challenges for the efficient scheduling and memory placement of processes.}(hj[hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKKhjJhhubh)}(hFrequently more modest sized systems can be operated with adequate efficiency just by letting the operating system automatically share the available CPU and Memory resources amongst the requesting tasks.h]hFrequently more modest sized systems can be operated with adequate efficiency just by letting the operating system automatically share the available CPU and Memory resources amongst the requesting tasks.}(hjihhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKPhjJhhubh)}(hXBut larger systems, which benefit more from careful processor and memory placement to reduce memory access times and contention, and which typically represent a larger investment for the customer, can benefit from explicitly placing jobs on properly sized subsets of the system.h]hXBut larger systems, which benefit more from careful processor and memory placement to reduce memory access times and contention, and which typically represent a larger investment for the customer, can benefit from explicitly placing jobs on properly sized subsets of the system.}(hjwhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKThjJhhubh)}(h#This can be especially valuable on:h]h#This can be especially valuable on:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKZhjJhhubh block_quote)}(h* Web Servers running multiple instances of the same web application, * Servers running different applications (for instance, a web server and a database), or * NUMA systems running large HPC applications with demanding performance characteristics. h]h)}(hhh](h)}(hCWeb Servers running multiple instances of the same web application,h]h)}(hjh]hCWeb Servers running multiple instances of the same web application,}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK\hjubah}(h]h ]h"]h$]h&]uh1hhjubh)}(hVServers running different applications (for instance, a web server and a database), orh]h)}(hVServers running different applications (for instance, a web server and a database), orh]hVServers running different applications (for instance, a web server and a database), or}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK]hjubah}(h]h ]h"]h$]h&]uh1hhjubh)}(hXNUMA systems running large HPC applications with demanding performance characteristics. h]h)}(hWNUMA systems running large HPC applications with demanding performance characteristics.h]hWNUMA systems running large HPC applications with demanding performance characteristics.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK_hjubah}(h]h ]h"]h$]h&]uh1hhjubeh}(h]h ]h"]h$]h&]j*uh1hhhhK\hjubah}(h]h ]h"]h$]h&]uh1jhhhK\hjJhhubh)}(hThese subsets, or "soft partitions" must be able to be dynamically adjusted, as the job mix changes, without impacting other concurrently executing jobs. The location of the running jobs pages may also be moved when the memory locations are changed.h]hThese subsets, or “soft partitions” must be able to be dynamically adjusted, as the job mix changes, without impacting other concurrently executing jobs. The location of the running jobs pages may also be moved when the memory locations are changed.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKbhjJhhubh)}(hXThe kernel cpuset patch provides the minimum essential kernel mechanisms required to efficiently implement such subsets. It leverages existing CPU and Memory Placement facilities in the Linux kernel to avoid any additional impact on the critical scheduler or memory allocator code.h]hXThe kernel cpuset patch provides the minimum essential kernel mechanisms required to efficiently implement such subsets. It leverages existing CPU and Memory Placement facilities in the Linux kernel to avoid any additional impact on the critical scheduler or memory allocator code.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKghjJhhubeh}(h]why-are-cpusets-neededah ]h"]1.2 why are cpusets needed ?ah$]h&]uh1hhjhhhhhKIubh)}(hhh](h)}(h!1.3 How are cpusets implemented ?h]h!1.3 How are cpusets implemented ?}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKoubh)}(h|Cpusets provide a Linux kernel mechanism to constrain which CPUs and Memory Nodes are used by a process or set of processes.h]h|Cpusets provide a Linux kernel mechanism to constrain which CPUs and Memory Nodes are used by a process or set of processes.}(hj%hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKqhjhhubh)}(hThe Linux kernel already has a pair of mechanisms to specify on which CPUs a task may be scheduled (sched_setaffinity) and on which Memory Nodes it may obtain memory (mbind, set_mempolicy).h]hThe Linux kernel already has a pair of mechanisms to specify on which CPUs a task may be scheduled (sched_setaffinity) and on which Memory Nodes it may obtain memory (mbind, set_mempolicy).}(hj3hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKthjhhubh)}(h0Cpusets extends these two mechanisms as follows:h]h0Cpusets extends these two mechanisms as follows:}(hjAhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKxhjhhubj)}(hX- Cpusets are sets of allowed CPUs and Memory Nodes, known to the kernel. - Each task in the system is attached to a cpuset, via a pointer in the task structure to a reference counted cgroup structure. - Calls to sched_setaffinity are filtered to just those CPUs allowed in that task's cpuset. - Calls to mbind and set_mempolicy are filtered to just those Memory Nodes allowed in that task's cpuset. - The root cpuset contains all the systems CPUs and Memory Nodes. - For any cpuset, one can define child cpusets containing a subset of the parents CPU and Memory Node resources. - The hierarchy of cpusets can be mounted at /dev/cpuset, for browsing and manipulation from user space. - A cpuset may be marked exclusive, which ensures that no other cpuset (except direct ancestors and descendants) may contain any overlapping CPUs or Memory Nodes. - You can list all the tasks (by pid) attached to any cpuset. h]h)}(hhh](h)}(hGCpusets are sets of allowed CPUs and Memory Nodes, known to the kernel.h]h)}(hGCpusets are sets of allowed CPUs and Memory Nodes, known to the kernel.h]hGCpusets are sets of allowed CPUs and Memory Nodes, known to the kernel.}(hjZhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKzhjVubah}(h]h ]h"]h$]h&]uh1hhjSubh)}(h}Each task in the system is attached to a cpuset, via a pointer in the task structure to a reference counted cgroup structure.h]h)}(h}Each task in the system is attached to a cpuset, via a pointer in the task structure to a reference counted cgroup structure.h]h}Each task in the system is attached to a cpuset, via a pointer in the task structure to a reference counted cgroup structure.}(hjrhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK|hjnubah}(h]h ]h"]h$]h&]uh1hhjSubh)}(hYCalls to sched_setaffinity are filtered to just those CPUs allowed in that task's cpuset.h]h)}(hYCalls to sched_setaffinity are filtered to just those CPUs allowed in that task's cpuset.h]h[Calls to sched_setaffinity are filtered to just those CPUs allowed in that task’s cpuset.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK~hjubah}(h]h ]h"]h$]h&]uh1hhjSubh)}(hgCalls to mbind and set_mempolicy are filtered to just those Memory Nodes allowed in that task's cpuset.h]h)}(hgCalls to mbind and set_mempolicy are filtered to just those Memory Nodes allowed in that task's cpuset.h]hiCalls to mbind and set_mempolicy are filtered to just those Memory Nodes allowed in that task’s cpuset.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1hhjSubh)}(h?The root cpuset contains all the systems CPUs and Memory Nodes.h]h)}(h?The root cpuset contains all the systems CPUs and Memory Nodes.h]h?The root cpuset contains all the systems CPUs and Memory Nodes.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1hhjSubh)}(hnFor any cpuset, one can define child cpusets containing a subset of the parents CPU and Memory Node resources.h]h)}(hnFor any cpuset, one can define child cpusets containing a subset of the parents CPU and Memory Node resources.h]hnFor any cpuset, one can define child cpusets containing a subset of the parents CPU and Memory Node resources.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1hhjSubh)}(hfThe hierarchy of cpusets can be mounted at /dev/cpuset, for browsing and manipulation from user space.h]h)}(hfThe hierarchy of cpusets can be mounted at /dev/cpuset, for browsing and manipulation from user space.h]hfThe hierarchy of cpusets can be mounted at /dev/cpuset, for browsing and manipulation from user space.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1hhjSubh)}(hA cpuset may be marked exclusive, which ensures that no other cpuset (except direct ancestors and descendants) may contain any overlapping CPUs or Memory Nodes.h]h)}(hA cpuset may be marked exclusive, which ensures that no other cpuset (except direct ancestors and descendants) may contain any overlapping CPUs or Memory Nodes.h]hA cpuset may be marked exclusive, which ensures that no other cpuset (except direct ancestors and descendants) may contain any overlapping CPUs or Memory Nodes.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1hhjSubh)}(hin fork and exit, to attach and detach a task from its cpuset.h]h)}(hjhh]h>in fork and exit, to attach and detach a task from its cpuset.}(hjjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjfubah}(h]h ]h"]h$]h&]uh1hhjLubh)}(hYin sched_setaffinity, to mask the requested CPUs by what's allowed in that task's cpuset.h]h)}(hYin sched_setaffinity, to mask the requested CPUs by what's allowed in that task's cpuset.h]h]in sched_setaffinity, to mask the requested CPUs by what’s allowed in that task’s cpuset.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj}ubah}(h]h ]h"]h$]h&]uh1hhjLubh)}(hnin sched.c migrate_live_tasks(), to keep migrating tasks within the CPUs allowed by their cpuset, if possible.h]h)}(hnin sched.c migrate_live_tasks(), to keep migrating tasks within the CPUs allowed by their cpuset, if possible.h]hnin sched.c migrate_live_tasks(), to keep migrating tasks within the CPUs allowed by their cpuset, if possible.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1hhjLubh)}(hxin the mbind and set_mempolicy system calls, to mask the requested Memory Nodes by what's allowed in that task's cpuset.h]h)}(hxin the mbind and set_mempolicy system calls, to mask the requested Memory Nodes by what's allowed in that task's cpuset.h]h|in the mbind and set_mempolicy system calls, to mask the requested Memory Nodes by what’s allowed in that task’s cpuset.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1hhjLubh)}(h5in page_alloc.c, to restrict memory to allowed nodes.h]h)}(hjh]h5in page_alloc.c, to restrict memory to allowed nodes.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1hhjLubh)}(h>in vmscan.c, to restrict page recovery to the current cpuset. h]h)}(h=in vmscan.c, to restrict page recovery to the current cpuset.h]h=in vmscan.c, to restrict page recovery to the current cpuset.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1hhjLubeh}(h]h ]h"]h$]h&]jjuh1hhhhKhjHubah}(h]h ]h"]h$]h&]uh1jhhhKhjhhubh)}(hYou should mount the "cgroup" filesystem type in order to enable browsing and modifying the cpusets presently known to the kernel. No new system calls are added for cpusets - all support for querying and modifying cpusets is via this cpuset file system.h]hXYou should mount the “cgroup” filesystem type in order to enable browsing and modifying the cpusets presently known to the kernel. No new system calls are added for cpusets - all support for querying and modifying cpusets is via this cpuset file system.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hThe /proc//status file for each task has four added lines, displaying the task's cpus_allowed (on which CPUs it may be scheduled) and mems_allowed (on which Memory Nodes it may obtain memory), in the two formats seen in the following example::h]hThe /proc//status file for each task has four added lines, displaying the task’s cpus_allowed (on which CPUs it may be scheduled) and mems_allowed (on which Memory Nodes it may obtain memory), in the two formats seen in the following example:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh literal_block)}(hCpus_allowed: ffffffff,ffffffff,ffffffff,ffffffff Cpus_allowed_list: 0-127 Mems_allowed: ffffffff,ffffffff Mems_allowed_list: 0-63h]hCpus_allowed: ffffffff,ffffffff,ffffffff,ffffffff Cpus_allowed_list: 0-127 Mems_allowed: ffffffff,ffffffff Mems_allowed_list: 0-63}hjsbah}(h]h ]h"]h$]h&]jjuh1jhhhKhjhhubh)}(hEach cpuset is represented by a directory in the cgroup file system containing (on top of the standard cgroup files) the following files describing that cpuset:h]hEach cpuset is represented by a directory in the cgroup file system containing (on top of the standard cgroup files) the following files describing that cpuset:}(hj,hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubj)}(hX- cpuset.cpus: list of CPUs in that cpuset - cpuset.mems: list of Memory Nodes in that cpuset - cpuset.memory_migrate flag: if set, move pages to cpusets nodes - cpuset.cpu_exclusive flag: is cpu placement exclusive? - cpuset.mem_exclusive flag: is memory placement exclusive? - cpuset.mem_hardwall flag: is memory allocation hardwalled - cpuset.memory_pressure: measure of how much paging pressure in cpuset - cpuset.memory_spread_page flag: if set, spread page cache evenly on allowed nodes - cpuset.memory_spread_slab flag: OBSOLETE. Doesn't have any function. - cpuset.sched_load_balance flag: if set, load balance within CPUs on that cpuset - cpuset.sched_relax_domain_level: the searching range when migrating tasks h]h)}(hhh](h)}(h(cpuset.cpus: list of CPUs in that cpuseth]h)}(hjCh]h(cpuset.cpus: list of CPUs in that cpuset}(hjEhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjAubah}(h]h ]h"]h$]h&]uh1hhj>ubh)}(h0cpuset.mems: list of Memory Nodes in that cpuseth]h)}(hjZh]h0cpuset.mems: list of Memory Nodes in that cpuset}(hj\hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjXubah}(h]h ]h"]h$]h&]uh1hhj>ubh)}(h?cpuset.memory_migrate flag: if set, move pages to cpusets nodesh]h)}(hjqh]h?cpuset.memory_migrate flag: if set, move pages to cpusets nodes}(hjshhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjoubah}(h]h ]h"]h$]h&]uh1hhj>ubh)}(h6cpuset.cpu_exclusive flag: is cpu placement exclusive?h]h)}(hjh]h6cpuset.cpu_exclusive flag: is cpu placement exclusive?}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1hhj>ubh)}(h9cpuset.mem_exclusive flag: is memory placement exclusive?h]h)}(hjh]h9cpuset.mem_exclusive flag: is memory placement exclusive?}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1hhj>ubh)}(h:cpuset.mem_hardwall flag: is memory allocation hardwalledh]h)}(hjh]h:cpuset.mem_hardwall flag: is memory allocation hardwalled}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1hhj>ubh)}(hEcpuset.memory_pressure: measure of how much paging pressure in cpuseth]h)}(hjh]hEcpuset.memory_pressure: measure of how much paging pressure in cpuset}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1hhj>ubh)}(hQcpuset.memory_spread_page flag: if set, spread page cache evenly on allowed nodesh]h)}(hjh]hQcpuset.memory_spread_page flag: if set, spread page cache evenly on allowed nodes}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1hhj>ubh)}(hDcpuset.memory_spread_slab flag: OBSOLETE. Doesn't have any function.h]h)}(hjh]hFcpuset.memory_spread_slab flag: OBSOLETE. Doesn’t have any function.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1hhj>ubh)}(hOcpuset.sched_load_balance flag: if set, load balance within CPUs on that cpuseth]h)}(hjh]hOcpuset.sched_load_balance flag: if set, load balance within CPUs on that cpuset}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1hhj>ubh)}(hJcpuset.sched_relax_domain_level: the searching range when migrating tasks h]h)}(hIcpuset.sched_relax_domain_level: the searching range when migrating tasksh]hIcpuset.sched_relax_domain_level: the searching range when migrating tasks}(hj+hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj'ubah}(h]h ]h"]h$]h&]uh1hhj>ubeh}(h]h ]h"]h$]h&]jjuh1hhhhKhj:ubah}(h]h ]h"]h$]h&]uh1jhhhKhjhhubh)}(h9In addition, only the root cpuset has the following file:h]h9In addition, only the root cpuset has the following file:}(hjKhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubj)}(h@- cpuset.memory_pressure_enabled flag: compute memory_pressure? h]h)}(hhh]h)}(h>cpuset.memory_pressure_enabled flag: compute memory_pressure? h]h)}(h=cpuset.memory_pressure_enabled flag: compute memory_pressure?h]h=cpuset.memory_pressure_enabled flag: compute memory_pressure?}(hjdhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj`ubah}(h]h ]h"]h$]h&]uh1hhj]ubah}(h]h ]h"]h$]h&]jjuh1hhhhKhjYubah}(h]h ]h"]h$]h&]uh1jhhhKhjhhubh)}(hXNew cpusets are created using the mkdir system call or shell command. The properties of a cpuset, such as its flags, allowed CPUs and Memory Nodes, and attached tasks, are modified by writing to the appropriate file in that cpusets directory, as listed above.h]hXNew cpusets are created using the mkdir system call or shell command. The properties of a cpuset, such as its flags, allowed CPUs and Memory Nodes, and attached tasks, are modified by writing to the appropriate file in that cpusets directory, as listed above.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hThe named hierarchical structure of nested cpusets allows partitioning a large system into nested, dynamically changeable, "soft-partitions".h]hThe named hierarchical structure of nested cpusets allows partitioning a large system into nested, dynamically changeable, “soft-partitions”.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hXThe attachment of each task, automatically inherited at fork by any children of that task, to a cpuset allows organizing the work load on a system into related sets of tasks such that each set is constrained to using the CPUs and Memory Nodes of a particular cpuset. A task may be re-attached to any other cpuset, if allowed by the permissions on the necessary cpuset file system directories.h]hXThe attachment of each task, automatically inherited at fork by any children of that task, to a cpuset allows organizing the work load on a system into related sets of tasks such that each set is constrained to using the CPUs and Memory Nodes of a particular cpuset. A task may be re-attached to any other cpuset, if allowed by the permissions on the necessary cpuset file system directories.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hSuch management of a system "in the large" integrates smoothly with the detailed placement done on individual tasks and memory regions using the sched_setaffinity, mbind and set_mempolicy system calls.h]hSuch management of a system “in the large” integrates smoothly with the detailed placement done on individual tasks and memory regions using the sched_setaffinity, mbind and set_mempolicy system calls.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(h)The following rules apply to each cpuset:h]h)The following rules apply to each cpuset:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubj)}(h- Its CPUs and Memory Nodes must be a subset of its parents. - It can't be marked exclusive unless its parent is. - If its cpu or memory is exclusive, they may not overlap any sibling. h]h)}(hhh](h)}(h:Its CPUs and Memory Nodes must be a subset of its parents.h]h)}(hjh]h:Its CPUs and Memory Nodes must be a subset of its parents.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1hhjubh)}(h2It can't be marked exclusive unless its parent is.h]h)}(hjh]h4It can’t be marked exclusive unless its parent is.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1hhjubh)}(hEIf its cpu or memory is exclusive, they may not overlap any sibling. h]h)}(hDIf its cpu or memory is exclusive, they may not overlap any sibling.h]hDIf its cpu or memory is exclusive, they may not overlap any sibling.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1hhjubeh}(h]h ]h"]h$]h&]jjuh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhhhKhjhhubh)}(hXThese rules, and the natural hierarchy of cpusets, enable efficient enforcement of the exclusive guarantee, without having to scan all cpusets every time any of them change to ensure nothing overlaps a exclusive cpuset. Also, the use of a Linux virtual file system (vfs) to represent the cpuset hierarchy provides for a familiar permission and name space for cpusets, with a minimum of additional kernel code.h]hXThese rules, and the natural hierarchy of cpusets, enable efficient enforcement of the exclusive guarantee, without having to scan all cpusets every time any of them change to ensure nothing overlaps a exclusive cpuset. Also, the use of a Linux virtual file system (vfs) to represent the cpuset hierarchy provides for a familiar permission and name space for cpusets, with a minimum of additional kernel code.}(hj#hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hX5The cpus and mems files in the root (top_cpuset) cpuset are read-only. The cpus file automatically tracks the value of cpu_online_mask using a CPU hotplug notifier, and the mems file automatically tracks the value of node_states[N_MEMORY]--i.e., nodes with memory--using the cpuset_track_online_nodes() hook.h]hX5The cpus and mems files in the root (top_cpuset) cpuset are read-only. The cpus file automatically tracks the value of cpu_online_mask using a CPU hotplug notifier, and the mems file automatically tracks the value of node_states[N_MEMORY]--i.e., nodes with memory--using the cpuset_track_online_nodes() hook.}(hj1hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hXThe cpuset.effective_cpus and cpuset.effective_mems files are normally read-only copies of cpuset.cpus and cpuset.mems files respectively. If the cpuset cgroup filesystem is mounted with the special "cpuset_v2_mode" option, the behavior of these files will become similar to the corresponding files in cpuset v2. In other words, hotplug events will not change cpuset.cpus and cpuset.mems. Those events will only affect cpuset.effective_cpus and cpuset.effective_mems which show the actual cpus and memory nodes that are currently used by this cpuset. See Documentation/admin-guide/cgroup-v2.rst for more information about cpuset v2 behavior.h]hXThe cpuset.effective_cpus and cpuset.effective_mems files are normally read-only copies of cpuset.cpus and cpuset.mems files respectively. If the cpuset cgroup filesystem is mounted with the special “cpuset_v2_mode” option, the behavior of these files will become similar to the corresponding files in cpuset v2. In other words, hotplug events will not change cpuset.cpus and cpuset.mems. Those events will only affect cpuset.effective_cpus and cpuset.effective_mems which show the actual cpus and memory nodes that are currently used by this cpuset. See Documentation/admin-guide/cgroup-v2.rst for more information about cpuset v2 behavior.}(hj?hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubeh}(h]how-are-cpusets-implementedah ]h"]!1.3 how are cpusets implemented ?ah$]h&]uh1hhjhhhhhKoubh)}(hhh](h)}(h 1.4 What are exclusive cpusets ?h]h 1.4 What are exclusive cpusets ?}(hjXhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjUhhhhhKubh)}(hIf a cpuset is cpu or mem exclusive, no other cpuset, other than a direct ancestor or descendant, may share any of the same CPUs or Memory Nodes.h]hIf a cpuset is cpu or mem exclusive, no other cpuset, other than a direct ancestor or descendant, may share any of the same CPUs or Memory Nodes.}(hjfhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjUhhubh)}(hXA cpuset that is cpuset.mem_exclusive *or* cpuset.mem_hardwall is "hardwalled", i.e. it restricts kernel allocations for page, buffer and other data commonly shared by the kernel across multiple users. All cpusets, whether hardwalled or not, restrict allocations of memory for user space. This enables configuring a system so that several independent jobs can share common kernel data, such as file system pages, while isolating each job's user allocation in its own cpuset. To do this, construct a large mem_exclusive cpuset to hold all the jobs, and construct child, non-mem_exclusive cpusets for each individual job. Only a small amount of typical kernel memory, such as requests from interrupt handlers, is allowed to be taken outside even a mem_exclusive cpuset.h](h&A cpuset that is cpuset.mem_exclusive }(hjthhhNhNubhemphasis)}(h*or*h]hor}(hj~hhhNhNubah}(h]h ]h"]h$]h&]uh1j|hjtubhX cpuset.mem_hardwall is “hardwalled”, i.e. it restricts kernel allocations for page, buffer and other data commonly shared by the kernel across multiple users. All cpusets, whether hardwalled or not, restrict allocations of memory for user space. This enables configuring a system so that several independent jobs can share common kernel data, such as file system pages, while isolating each job’s user allocation in its own cpuset. To do this, construct a large mem_exclusive cpuset to hold all the jobs, and construct child, non-mem_exclusive cpusets for each individual job. Only a small amount of typical kernel memory, such as requests from interrupt handlers, is allowed to be taken outside even a mem_exclusive cpuset.}(hjthhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjUhhubeh}(h]what-are-exclusive-cpusetsah ]h"] 1.4 what are exclusive cpusets ?ah$]h&]uh1hhjhhhhhKubh)}(hhh](h)}(h1.5 What is memory_pressure ?h]h1.5 What is memory_pressure ?}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMubh)}(hThe memory_pressure of a cpuset provides a simple per-cpuset metric of the rate that the tasks in a cpuset are attempting to free up in use memory on the nodes of the cpuset to satisfy additional memory requests.h]hThe memory_pressure of a cpuset provides a simple per-cpuset metric of the rate that the tasks in a cpuset are attempting to free up in use memory on the nodes of the cpuset to satisfy additional memory requests.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hThis enables batch managers monitoring jobs running in dedicated cpusets to efficiently detect what level of memory pressure that job is causing.h]hThis enables batch managers monitoring jobs running in dedicated cpusets to efficiently detect what level of memory pressure that job is causing.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM hjhhubh)}(hXThis is useful both on tightly managed systems running a wide mix of submitted jobs, which may choose to terminate or re-prioritize jobs that are trying to use more memory than allowed on the nodes assigned to them, and with tightly coupled, long running, massively parallel scientific computing jobs that will dramatically fail to meet required performance goals if they start to use more memory than allowed to them.h]hXThis is useful both on tightly managed systems running a wide mix of submitted jobs, which may choose to terminate or re-prioritize jobs that are trying to use more memory than allowed on the nodes assigned to them, and with tightly coupled, long running, massively parallel scientific computing jobs that will dramatically fail to meet required performance goals if they start to use more memory than allowed to them.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hThis mechanism provides a very economical way for the batch manager to monitor a cpuset for signs of memory pressure. It's up to the batch manager or other user code to decide what to do about it and take action.h]hThis mechanism provides a very economical way for the batch manager to monitor a cpuset for signs of memory pressure. It’s up to the batch manager or other user code to decide what to do about it and take action.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubhdefinition_list)}(hhh]hdefinition_list_item)}(hXA==> Unless this feature is enabled by writing "1" to the special file /dev/cpuset/memory_pressure_enabled, the hook in the rebalance code of __alloc_pages() for this metric reduces to simply noticing that the cpuset_memory_pressure_enabled flag is zero. So only systems that enable this feature will compute the metric. h](hterm)}(h==>h]h==>}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhhhM!hjubh definition)}(hhh]h)}(hX<Unless this feature is enabled by writing "1" to the special file /dev/cpuset/memory_pressure_enabled, the hook in the rebalance code of __alloc_pages() for this metric reduces to simply noticing that the cpuset_memory_pressure_enabled flag is zero. So only systems that enable this feature will compute the metric.h]hX@Unless this feature is enabled by writing “1” to the special file /dev/cpuset/memory_pressure_enabled, the hook in the rebalance code of __alloc_pages() for this metric reduces to simply noticing that the cpuset_memory_pressure_enabled flag is zero. So only systems that enable this feature will compute the metric.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhhhM!hjubah}(h]h ]h"]h$]h&]uh1jhjhhhhhNubh)}(h"Why a per-cpuset, running average:h]h"Why a per-cpuset, running average:}(hj'hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM#hjhhubj)}(hXBecause this meter is per-cpuset, rather than per-task or mm, the system load imposed by a batch scheduler monitoring this metric is sharply reduced on large systems, because a scan of the tasklist can be avoided on each set of queries. Because this meter is a running average, instead of an accumulating counter, a batch scheduler can detect memory pressure with a single read, instead of having to read and accumulate results for a period of time. Because this meter is per-cpuset rather than per-task or mm, the batch scheduler can obtain the key information, memory pressure in a cpuset, with a single read, rather than having to query and accumulate results over all the (dynamically changing) set of tasks in the cpuset. h](h)}(hBecause this meter is per-cpuset, rather than per-task or mm, the system load imposed by a batch scheduler monitoring this metric is sharply reduced on large systems, because a scan of the tasklist can be avoided on each set of queries.h]hBecause this meter is per-cpuset, rather than per-task or mm, the system load imposed by a batch scheduler monitoring this metric is sharply reduced on large systems, because a scan of the tasklist can be avoided on each set of queries.}(hj9hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM%hj5ubh)}(hBecause this meter is a running average, instead of an accumulating counter, a batch scheduler can detect memory pressure with a single read, instead of having to read and accumulate results for a period of time.h]hBecause this meter is a running average, instead of an accumulating counter, a batch scheduler can detect memory pressure with a single read, instead of having to read and accumulate results for a period of time.}(hjGhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM*hj5ubh)}(hXBecause this meter is per-cpuset rather than per-task or mm, the batch scheduler can obtain the key information, memory pressure in a cpuset, with a single read, rather than having to query and accumulate results over all the (dynamically changing) set of tasks in the cpuset.h]hXBecause this meter is per-cpuset rather than per-task or mm, the batch scheduler can obtain the key information, memory pressure in a cpuset, with a single read, rather than having to query and accumulate results over all the (dynamically changing) set of tasks in the cpuset.}(hjUhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM/hj5ubeh}(h]h ]h"]h$]h&]uh1jhhhM%hjhhubh)}(hA per-cpuset simple digital filter (requires a spinlock and 3 words of data per-cpuset) is kept, and updated by any task attached to that cpuset, if it enters the synchronous (direct) page reclaim code.h]hA per-cpuset simple digital filter (requires a spinlock and 3 words of data per-cpuset) is kept, and updated by any task attached to that cpuset, if it enters the synchronous (direct) page reclaim code.}(hjihhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM5hjhhubh)}(hA per-cpuset file provides an integer number representing the recent (half-life of 10 seconds) rate of direct page reclaims caused by the tasks in the cpuset, in units of reclaims attempted per second, times 1000.h]hA per-cpuset file provides an integer number representing the recent (half-life of 10 seconds) rate of direct page reclaims caused by the tasks in the cpuset, in units of reclaims attempted per second, times 1000.}(hjwhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM9hjhhubeh}(h]what-is-memory-pressureah ]h"]1.5 what is memory_pressure ?ah$]h&]uh1hhjhhhhhMubh)}(hhh](h)}(h1.6 What is memory spread ?h]h1.6 What is memory spread ?}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhM@ubh)}(hThere are two boolean flag files per cpuset that control where the kernel allocates pages for the file system buffers and related in kernel data structures. They are called 'cpuset.memory_spread_page' and 'cpuset.memory_spread_slab'.h]hThere are two boolean flag files per cpuset that control where the kernel allocates pages for the file system buffers and related in kernel data structures. They are called ‘cpuset.memory_spread_page’ and ‘cpuset.memory_spread_slab’.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMAhjhhubh)}(hXIf the per-cpuset boolean flag file 'cpuset.memory_spread_page' is set, then the kernel will spread the file system buffers (page cache) evenly over all the nodes that the faulting task is allowed to use, instead of preferring to put those pages on the node where the task is running.h]hX If the per-cpuset boolean flag file ‘cpuset.memory_spread_page’ is set, then the kernel will spread the file system buffers (page cache) evenly over all the nodes that the faulting task is allowed to use, instead of preferring to put those pages on the node where the task is running.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMFhjhhubh)}(hX=If the per-cpuset boolean flag file 'cpuset.memory_spread_slab' is set, then the kernel will spread some file system related slab caches, such as for inodes and dentries evenly over all the nodes that the faulting task is allowed to use, instead of preferring to put those pages on the node where the task is running.h]hXAIf the per-cpuset boolean flag file ‘cpuset.memory_spread_slab’ is set, then the kernel will spread some file system related slab caches, such as for inodes and dentries evenly over all the nodes that the faulting task is allowed to use, instead of preferring to put those pages on the node where the task is running.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMKhjhhubh)}(hcThe setting of these flags does not affect anonymous data segment or stack segment pages of a task.h]hcThe setting of these flags does not affect anonymous data segment or stack segment pages of a task.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMQhjhhubh)}(hX By default, both kinds of memory spreading are off, and memory pages are allocated on the node local to where the task is running, except perhaps as modified by the task's NUMA mempolicy or cpuset configuration, so long as sufficient free memory pages are available.h]hX By default, both kinds of memory spreading are off, and memory pages are allocated on the node local to where the task is running, except perhaps as modified by the task’s NUMA mempolicy or cpuset configuration, so long as sufficient free memory pages are available.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMThjhhubh)}(hVWhen new cpusets are created, they inherit the memory spread settings of their parent.h]hVWhen new cpusets are created, they inherit the memory spread settings of their parent.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMYhjhhubh)}(hXSetting memory spreading causes allocations for the affected page or slab caches to ignore the task's NUMA mempolicy and be spread instead. Tasks using mbind() or set_mempolicy() calls to set NUMA mempolicies will not notice any change in these calls as a result of their containing task's memory spread settings. If memory spreading is turned off, then the currently specified NUMA mempolicy once again applies to memory page allocations.h]hXSetting memory spreading causes allocations for the affected page or slab caches to ignore the task’s NUMA mempolicy and be spread instead. Tasks using mbind() or set_mempolicy() calls to set NUMA mempolicies will not notice any change in these calls as a result of their containing task’s memory spread settings. If memory spreading is turned off, then the currently specified NUMA mempolicy once again applies to memory page allocations.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM\hjhhubh)}(hBoth 'cpuset.memory_spread_page' and 'cpuset.memory_spread_slab' are boolean flag files. By default they contain "0", meaning that the feature is off for that cpuset. If a "1" is written to that file, then that turns the named feature on.h]hXBoth ‘cpuset.memory_spread_page’ and ‘cpuset.memory_spread_slab’ are boolean flag files. By default they contain “0”, meaning that the feature is off for that cpuset. If a “1” is written to that file, then that turns the named feature on.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMdhjhhubh)}(hThe implementation is simple.h]hThe implementation is simple.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMihjhhubh)}(hXSetting the flag 'cpuset.memory_spread_page' turns on a per-process flag PFA_SPREAD_PAGE for each task that is in that cpuset or subsequently joins that cpuset. The page allocation calls for the page cache is modified to perform an inline check for this PFA_SPREAD_PAGE task flag, and if set, a call to a new routine cpuset_mem_spread_node() returns the node to prefer for the allocation.h]hXSetting the flag ‘cpuset.memory_spread_page’ turns on a per-process flag PFA_SPREAD_PAGE for each task that is in that cpuset or subsequently joins that cpuset. The page allocation calls for the page cache is modified to perform an inline check for this PFA_SPREAD_PAGE task flag, and if set, a call to a new routine cpuset_mem_spread_node() returns the node to prefer for the allocation.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMkhjhhubh)}(hSimilarly, setting 'cpuset.memory_spread_slab' turns on the flag PFA_SPREAD_SLAB, and appropriately marked slab caches will allocate pages from the node returned by cpuset_mem_spread_node().h]hSimilarly, setting ‘cpuset.memory_spread_slab’ turns on the flag PFA_SPREAD_SLAB, and appropriately marked slab caches will allocate pages from the node returned by cpuset_mem_spread_node().}(hj* hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMrhjhhubh)}(hThe cpuset_mem_spread_node() routine is also simple. It uses the value of a per-task rotor cpuset_mem_spread_rotor to select the next node in the current task's mems_allowed to prefer for the allocation.h]hThe cpuset_mem_spread_node() routine is also simple. It uses the value of a per-task rotor cpuset_mem_spread_rotor to select the next node in the current task’s mems_allowed to prefer for the allocation.}(hj8 hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMvhjhhubh)}(h\This memory placement policy is also known (in other contexts) as round-robin or interleave.h]h\This memory placement policy is also known (in other contexts) as round-robin or interleave.}(hjF hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMzhjhhubh)}(hXThis policy can provide substantial improvements for jobs that need to place thread local data on the corresponding node, but that need to access large file system data sets that need to be spread across the several nodes in the jobs cpuset in order to fit. Without this policy, especially for jobs that might have one thread reading in the data set, the memory allocation across the nodes in the jobs cpuset can become very uneven.h]hXThis policy can provide substantial improvements for jobs that need to place thread local data on the corresponding node, but that need to access large file system data sets that need to be spread across the several nodes in the jobs cpuset in order to fit. Without this policy, especially for jobs that might have one thread reading in the data set, the memory allocation across the nodes in the jobs cpuset can become very uneven.}(hjT hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM}hjhhubeh}(h]what-is-memory-spreadah ]h"]1.6 what is memory spread ?ah$]h&]uh1hhjhhhhhM@ubh)}(hhh](h)}(h 1.7 What is sched_load_balance ?h]h 1.7 What is sched_load_balance ?}(hjm hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjj hhhhhMubh)}(hX3The kernel scheduler (kernel/sched/core.c) automatically load balances tasks. If one CPU is underutilized, kernel code running on that CPU will look for tasks on other more overloaded CPUs and move those tasks to itself, within the constraints of such placement mechanisms as cpusets and sched_setaffinity.h]hX3The kernel scheduler (kernel/sched/core.c) automatically load balances tasks. If one CPU is underutilized, kernel code running on that CPU will look for tasks on other more overloaded CPUs and move those tasks to itself, within the constraints of such placement mechanisms as cpusets and sched_setaffinity.}(hj{ hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjj hhubh)}(hXThe algorithmic cost of load balancing and its impact on key shared kernel data structures such as the task list increases more than linearly with the number of CPUs being balanced. So the scheduler has support to partition the systems CPUs into a number of sched domains such that it only load balances within each sched domain. Each sched domain covers some subset of the CPUs in the system; no two sched domains overlap; some CPUs might not be in any sched domain and hence won't be load balanced.h]hXThe algorithmic cost of load balancing and its impact on key shared kernel data structures such as the task list increases more than linearly with the number of CPUs being balanced. So the scheduler has support to partition the systems CPUs into a number of sched domains such that it only load balances within each sched domain. Each sched domain covers some subset of the CPUs in the system; no two sched domains overlap; some CPUs might not be in any sched domain and hence won’t be load balanced.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjj hhubh)}(hPut simply, it costs less to balance between two smaller sched domains than one big one, but doing so means that overloads in one of the two domains won't be load balanced to the other one.h]hPut simply, it costs less to balance between two smaller sched domains than one big one, but doing so means that overloads in one of the two domains won’t be load balanced to the other one.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjj hhubh)}(hXBy default, there is one sched domain covering all CPUs, including those marked isolated using the kernel boot time "isolcpus=" argument. However, the isolated CPUs will not participate in load balancing, and will not have tasks running on them unless explicitly assigned.h]hXBy default, there is one sched domain covering all CPUs, including those marked isolated using the kernel boot time “isolcpus=” argument. However, the isolated CPUs will not participate in load balancing, and will not have tasks running on them unless explicitly assigned.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjj hhubh)}(h`This default load balancing across all CPUs is not well suited for the following two situations:h]h`This default load balancing across all CPUs is not well suited for the following two situations:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjj hhubj)}(hXh1) On large systems, load balancing across many CPUs is expensive. If the system is managed using cpusets to place independent jobs on separate sets of CPUs, full load balancing is unnecessary. 2) Systems supporting realtime on some CPUs need to minimize system overhead on those CPUs, including avoiding task load balancing if that is not needed. h]henumerated_list)}(hhh](h)}(hOn large systems, load balancing across many CPUs is expensive. If the system is managed using cpusets to place independent jobs on separate sets of CPUs, full load balancing is unnecessary.h]h)}(hOn large systems, load balancing across many CPUs is expensive. If the system is managed using cpusets to place independent jobs on separate sets of CPUs, full load balancing is unnecessary.h]hOn large systems, load balancing across many CPUs is expensive. If the system is managed using cpusets to place independent jobs on separate sets of CPUs, full load balancing is unnecessary.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj ubah}(h]h ]h"]h$]h&]uh1hhj ubh)}(hSystems supporting realtime on some CPUs need to minimize system overhead on those CPUs, including avoiding task load balancing if that is not needed. h]h)}(hSystems supporting realtime on some CPUs need to minimize system overhead on those CPUs, including avoiding task load balancing if that is not needed.h]hSystems supporting realtime on some CPUs need to minimize system overhead on those CPUs, including avoiding task load balancing if that is not needed.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj ubah}(h]h ]h"]h$]h&]uh1hhj ubeh}(h]h ]h"]h$]h&]enumtypearabicprefixhsuffix)uh1j hj ubah}(h]h ]h"]h$]h&]uh1jhhhMhjj hhubh)}(hXIWhen the per-cpuset flag "cpuset.sched_load_balance" is enabled (the default setting), it requests that all the CPUs in that cpusets allowed 'cpuset.cpus' be contained in a single sched domain, ensuring that load balancing can move a task (not otherwised pinned, as by sched_setaffinity) from any CPU in that cpuset to any other.h]hXQWhen the per-cpuset flag “cpuset.sched_load_balance” is enabled (the default setting), it requests that all the CPUs in that cpusets allowed ‘cpuset.cpus’ be contained in a single sched domain, ensuring that load balancing can move a task (not otherwised pinned, as by sched_setaffinity) from any CPU in that cpuset to any other.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjj hhubh)}(hWhen the per-cpuset flag "cpuset.sched_load_balance" is disabled, then the scheduler will avoid load balancing across the CPUs in that cpuset, --except-- in so far as is necessary because some overlapping cpuset has "sched_load_balance" enabled.h]hWhen the per-cpuset flag “cpuset.sched_load_balance” is disabled, then the scheduler will avoid load balancing across the CPUs in that cpuset, --except-- in so far as is necessary because some overlapping cpuset has “sched_load_balance” enabled.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjj hhubh)}(hXSo, for example, if the top cpuset has the flag "cpuset.sched_load_balance" enabled, then the scheduler will have one sched domain covering all CPUs, and the setting of the "cpuset.sched_load_balance" flag in any other cpusets won't matter, as we're already fully load balancing.h]hX#So, for example, if the top cpuset has the flag “cpuset.sched_load_balance” enabled, then the scheduler will have one sched domain covering all CPUs, and the setting of the “cpuset.sched_load_balance” flag in any other cpusets won’t matter, as we’re already fully load balancing.}(hj' hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjj hhubh)}(hTherefore in the above two situations, the top cpuset flag "cpuset.sched_load_balance" should be disabled, and only some of the smaller, child cpusets have this flag enabled.h]hTherefore in the above two situations, the top cpuset flag “cpuset.sched_load_balance” should be disabled, and only some of the smaller, child cpusets have this flag enabled.}(hj5 hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjj hhubh)}(hXWhen doing this, you don't usually want to leave any unpinned tasks in the top cpuset that might use non-trivial amounts of CPU, as such tasks may be artificially constrained to some subset of CPUs, depending on the particulars of this flag setting in descendant cpusets. Even if such a task could use spare CPU cycles in some other CPUs, the kernel scheduler might not consider the possibility of load balancing that task to that underused CPU.h]hXWhen doing this, you don’t usually want to leave any unpinned tasks in the top cpuset that might use non-trivial amounts of CPU, as such tasks may be artificially constrained to some subset of CPUs, depending on the particulars of this flag setting in descendant cpusets. Even if such a task could use spare CPU cycles in some other CPUs, the kernel scheduler might not consider the possibility of load balancing that task to that underused CPU.}(hjC hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjj hhubh)}(hOf course, tasks pinned to a particular CPU can be left in a cpuset that disables "cpuset.sched_load_balance" as those tasks aren't going anywhere else anyway.h]hOf course, tasks pinned to a particular CPU can be left in a cpuset that disables “cpuset.sched_load_balance” as those tasks aren’t going anywhere else anyway.}(hjQ hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjj hhubh)}(hThere is an impedance mismatch here, between cpusets and sched domains. Cpusets are hierarchical and nest. Sched domains are flat; they don't overlap and each CPU is in at most one sched domain.h]hThere is an impedance mismatch here, between cpusets and sched domains. Cpusets are hierarchical and nest. Sched domains are flat; they don’t overlap and each CPU is in at most one sched domain.}(hj_ hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjj hhubh)}(hXIt is necessary for sched domains to be flat because load balancing across partially overlapping sets of CPUs would risk unstable dynamics that would be beyond our understanding. So if each of two partially overlapping cpusets enables the flag 'cpuset.sched_load_balance', then we form a single sched domain that is a superset of both. We won't move a task to a CPU outside its cpuset, but the scheduler load balancing code might waste some compute cycles considering that possibility.h]hXIt is necessary for sched domains to be flat because load balancing across partially overlapping sets of CPUs would risk unstable dynamics that would be beyond our understanding. So if each of two partially overlapping cpusets enables the flag ‘cpuset.sched_load_balance’, then we form a single sched domain that is a superset of both. We won’t move a task to a CPU outside its cpuset, but the scheduler load balancing code might waste some compute cycles considering that possibility.}(hjm hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjj hhubh)}(hXpThis mismatch is why there is not a simple one-to-one relation between which cpusets have the flag "cpuset.sched_load_balance" enabled, and the sched domain configuration. If a cpuset enables the flag, it will get balancing across all its CPUs, but if it disables the flag, it will only be assured of no load balancing if no other overlapping cpuset enables the flag.h]hXtThis mismatch is why there is not a simple one-to-one relation between which cpusets have the flag “cpuset.sched_load_balance” enabled, and the sched domain configuration. If a cpuset enables the flag, it will get balancing across all its CPUs, but if it disables the flag, it will only be assured of no load balancing if no other overlapping cpuset enables the flag.}(hj{ hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjj hhubh)}(hX8If two cpusets have partially overlapping 'cpuset.cpus' allowed, and only one of them has this flag enabled, then the other may find its tasks only partially load balanced, just on the overlapping CPUs. This is just the general case of the top_cpuset example given a few paragraphs above. In the general case, as in the top cpuset case, don't leave tasks that might use non-trivial amounts of CPU in such partially load balanced cpusets, as they may be artificially constrained to some subset of the CPUs allowed to them, for lack of load balancing to the other CPUs.h]hX>If two cpusets have partially overlapping ‘cpuset.cpus’ allowed, and only one of them has this flag enabled, then the other may find its tasks only partially load balanced, just on the overlapping CPUs. This is just the general case of the top_cpuset example given a few paragraphs above. In the general case, as in the top cpuset case, don’t leave tasks that might use non-trivial amounts of CPU in such partially load balanced cpusets, as they may be artificially constrained to some subset of the CPUs allowed to them, for lack of load balancing to the other CPUs.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjj hhubh)}(hCPUs in "cpuset.isolcpus" were excluded from load balancing by the isolcpus= kernel boot option, and will never be load balanced regardless of the value of "cpuset.sched_load_balance" in any cpuset.h]hCPUs in “cpuset.isolcpus” were excluded from load balancing by the isolcpus= kernel boot option, and will never be load balanced regardless of the value of “cpuset.sched_load_balance” in any cpuset.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjj hhubeh}(h]what-is-sched-load-balanceah ]h"] 1.7 what is sched_load_balance ?ah$]h&]uh1hhjhhhhhMubh)}(hhh](h)}(h01.7.1 sched_load_balance implementation details.h]h01.7.1 sched_load_balance implementation details.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj hhhhhMubh)}(hX3The per-cpuset flag 'cpuset.sched_load_balance' defaults to enabled (contrary to most cpuset flags.) When enabled for a cpuset, the kernel will ensure that it can load balance across all the CPUs in that cpuset (makes sure that all the CPUs in the cpus_allowed of that cpuset are in the same sched domain.)h]hX7The per-cpuset flag ‘cpuset.sched_load_balance’ defaults to enabled (contrary to most cpuset flags.) When enabled for a cpuset, the kernel will ensure that it can load balance across all the CPUs in that cpuset (makes sure that all the CPUs in the cpus_allowed of that cpuset are in the same sched domain.)}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj hhubh)}(hIf two overlapping cpusets both have 'cpuset.sched_load_balance' enabled, then they will be (must be) both in the same sched domain.h]hIf two overlapping cpusets both have ‘cpuset.sched_load_balance’ enabled, then they will be (must be) both in the same sched domain.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj hhubh)}(hIf, as is the default, the top cpuset has 'cpuset.sched_load_balance' enabled, then by the above that means there is a single sched domain covering the whole system, regardless of any other cpuset settings.h]hIf, as is the default, the top cpuset has ‘cpuset.sched_load_balance’ enabled, then by the above that means there is a single sched domain covering the whole system, regardless of any other cpuset settings.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj hhubh)}(hXThe kernel commits to user space that it will avoid load balancing where it can. It will pick as fine a granularity partition of sched domains as it can while still providing load balancing for any set of CPUs allowed to a cpuset having 'cpuset.sched_load_balance' enabled.h]hXThe kernel commits to user space that it will avoid load balancing where it can. It will pick as fine a granularity partition of sched domains as it can while still providing load balancing for any set of CPUs allowed to a cpuset having ‘cpuset.sched_load_balance’ enabled.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj hhubh)}(hX7The internal kernel cpuset to scheduler interface passes from the cpuset code to the scheduler code a partition of the load balanced CPUs in the system. This partition is a set of subsets (represented as an array of struct cpumask) of CPUs, pairwise disjoint, that cover all the CPUs that must be load balanced.h]hX7The internal kernel cpuset to scheduler interface passes from the cpuset code to the scheduler code a partition of the load balanced CPUs in the system. This partition is a set of subsets (represented as an array of struct cpumask) of CPUs, pairwise disjoint, that cover all the CPUs that must be load balanced.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj hhubh)}(hThe cpuset code builds a new such partition and passes it to the scheduler sched domain setup code, to have the sched domains rebuilt as necessary, whenever:h]hThe cpuset code builds a new such partition and passes it to the scheduler sched domain setup code, to have the sched domains rebuilt as necessary, whenever:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj hhubj)}(hXg- the 'cpuset.sched_load_balance' flag of a cpuset with non-empty CPUs changes, - or CPUs come or go from a cpuset with this flag enabled, - or 'cpuset.sched_relax_domain_level' value of a cpuset with non-empty CPUs and with this flag enabled changes, - or a cpuset with non-empty CPUs and with this flag enabled is removed, - or a cpu is offlined/onlined. h]h)}(hhh](h)}(hMthe 'cpuset.sched_load_balance' flag of a cpuset with non-empty CPUs changes,h]h)}(hj h]hQthe ‘cpuset.sched_load_balance’ flag of a cpuset with non-empty CPUs changes,}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM hj ubah}(h]h ]h"]h$]h&]uh1hhj ubh)}(h8or CPUs come or go from a cpuset with this flag enabled,h]h)}(hj2 h]h8or CPUs come or go from a cpuset with this flag enabled,}(hj4 hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM hj0 ubah}(h]h ]h"]h$]h&]uh1hhj ubh)}(hnor 'cpuset.sched_relax_domain_level' value of a cpuset with non-empty CPUs and with this flag enabled changes,h]h)}(hnor 'cpuset.sched_relax_domain_level' value of a cpuset with non-empty CPUs and with this flag enabled changes,h]hror ‘cpuset.sched_relax_domain_level’ value of a cpuset with non-empty CPUs and with this flag enabled changes,}(hjK hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM hjG ubah}(h]h ]h"]h$]h&]uh1hhj ubh)}(hFor a cpuset with non-empty CPUs and with this flag enabled is removed,h]h)}(hja h]hFor a cpuset with non-empty CPUs and with this flag enabled is removed,}(hjc hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj_ ubah}(h]h ]h"]h$]h&]uh1hhj ubh)}(hor a cpu is offlined/onlined. h]h)}(hor a cpu is offlined/onlined.h]hor a cpu is offlined/onlined.}(hjz hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjv ubah}(h]h ]h"]h$]h&]uh1hhj ubeh}(h]h ]h"]h$]h&]jjuh1hhhhM hj ubah}(h]h ]h"]h$]h&]uh1jhhhM hj hhubh)}(hThis partition exactly defines what sched domains the scheduler should setup - one sched domain for each element (struct cpumask) in the partition.h]hThis partition exactly defines what sched domains the scheduler should setup - one sched domain for each element (struct cpumask) in the partition.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj hhubh)}(hXHThe scheduler remembers the currently active sched domain partitions. When the scheduler routine partition_sched_domains() is invoked from the cpuset code to update these sched domains, it compares the new partition requested with the current, and updates its sched domains, removing the old and adding the new, for each change.h]hXHThe scheduler remembers the currently active sched domain partitions. When the scheduler routine partition_sched_domains() is invoked from the cpuset code to update these sched domains, it compares the new partition requested with the current, and updates its sched domains, removing the old and adding the new, for each change.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj hhubeh}(h])sched-load-balance-implementation-detailsah ]h"]01.7.1 sched_load_balance implementation details.ah$]h&]uh1hhjhhhhhMubh)}(hhh](h)}(h&1.8 What is sched_relax_domain_level ?h]h&1.8 What is sched_relax_domain_level ?}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj hhhhhMubh)}(h|In sched domain, the scheduler migrates tasks in 2 ways; periodic load balance on tick, and at time of some schedule events.h]h|In sched domain, the scheduler migrates tasks in 2 ways; periodic load balance on tick, and at time of some schedule events.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj hhubh)}(hX5When a task is woken up, scheduler try to move the task on idle CPU. For example, if a task A running on CPU X activates another task B on the same CPU X, and if CPU Y is X's sibling and performing idle, then scheduler migrate task B to CPU Y so that task B can start on CPU Y without waiting task A on CPU X.h]hX7When a task is woken up, scheduler try to move the task on idle CPU. For example, if a task A running on CPU X activates another task B on the same CPU X, and if CPU Y is X’s sibling and performing idle, then scheduler migrate task B to CPU Y so that task B can start on CPU Y without waiting task A on CPU X.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM"hj hhubh)}(hAnd if a CPU run out of tasks in its runqueue, the CPU try to pull extra tasks from other busy CPUs to help them before it is going to be idle.h]hAnd if a CPU run out of tasks in its runqueue, the CPU try to pull extra tasks from other busy CPUs to help them before it is going to be idle.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM(hj hhubh)}(hX;Of course it takes some searching cost to find movable tasks and/or idle CPUs, the scheduler might not search all CPUs in the domain every time. In fact, in some architectures, the searching ranges on events are limited in the same socket or node where the CPU locates, while the load balance on tick searches all.h]hX;Of course it takes some searching cost to find movable tasks and/or idle CPUs, the scheduler might not search all CPUs in the domain every time. In fact, in some architectures, the searching ranges on events are limited in the same socket or node where the CPU locates, while the load balance on tick searches all.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM,hj hhubh)}(hXuFor example, assume CPU Z is relatively far from CPU X. Even if CPU Z is idle while CPU X and the siblings are busy, scheduler can't migrate woken task B from X to Z since it is out of its searching range. As the result, task B on CPU X need to wait task A or wait load balance on the next tick. For some applications in special situation, waiting 1 tick may be too long.h]hXwFor example, assume CPU Z is relatively far from CPU X. Even if CPU Z is idle while CPU X and the siblings are busy, scheduler can’t migrate woken task B from X to Z since it is out of its searching range. As the result, task B on CPU X need to wait task A or wait load balance on the next tick. For some applications in special situation, waiting 1 tick may be too long.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM2hj hhubh)}(hXThe 'cpuset.sched_relax_domain_level' file allows you to request changing this searching range as you like. This file takes int value which indicates size of searching range in levels approximately as follows, otherwise initial value -1 that indicates the cpuset has no request.h]hXThe ‘cpuset.sched_relax_domain_level’ file allows you to request changing this searching range as you like. This file takes int value which indicates size of searching range in levels approximately as follows, otherwise initial value -1 that indicates the cpuset has no request.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM9hj hhubhtable)}(hhh]htgroup)}(hhh](hcolspec)}(hhh]h}(h]h ]h"]h$]h&]colwidthKuh1j- hj* ubj. )}(hhh]h}(h]h ]h"]h$]h&]colwidthK;uh1j- hj* ubhtbody)}(hhh](hrow)}(hhh](hentry)}(hhh]h)}(h-1h]h-1}(hjR hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM?hjO ubah}(h]h ]h"]h$]h&]uh1jM hjJ ubjN )}(hhh]h)}(h;no request. use system default or follow request of others.h]h;no request. use system default or follow request of others.}(hji hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM?hjf ubah}(h]h ]h"]h$]h&]uh1jM hjJ ubeh}(h]h ]h"]h$]h&]uh1jH hjE ubjI )}(hhh](jN )}(hhh]h)}(h0h]h0}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM@hj ubah}(h]h ]h"]h$]h&]uh1jM hj ubjN )}(hhh]h)}(h no search.h]h no search.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM@hj ubah}(h]h ]h"]h$]h&]uh1jM hj ubeh}(h]h ]h"]h$]h&]uh1jH hjE ubjI )}(hhh](jN )}(hhh]h)}(h1h]h1}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMAhj ubah}(h]h ]h"]h$]h&]uh1jM hj ubjN )}(hhh]h)}(h)search siblings (hyperthreads in a core).h]h)search siblings (hyperthreads in a core).}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMAhj ubah}(h]h ]h"]h$]h&]uh1jM hj ubeh}(h]h ]h"]h$]h&]uh1jH hjE ubjI )}(hhh](jN )}(hhh]h)}(h2h]h2}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMBhj ubah}(h]h ]h"]h$]h&]uh1jM hj ubjN )}(hhh]h)}(hsearch cores in a package.h]hsearch cores in a package.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMBhj ubah}(h]h ]h"]h$]h&]uh1jM hj ubeh}(h]h ]h"]h$]h&]uh1jH hjE ubjI )}(hhh](jN )}(hhh]h)}(h3h]h3}(hj. hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMChj+ ubah}(h]h ]h"]h$]h&]uh1jM hj( ubjN )}(hhh]h)}(h8search cpus in a node [= system wide on non-NUMA system]h]h8search cpus in a node [= system wide on non-NUMA system]}(hjE hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMChjB ubah}(h]h ]h"]h$]h&]uh1jM hj( ubeh}(h]h ]h"]h$]h&]uh1jH hjE ubjI )}(hhh](jN )}(hhh]h)}(h4h]h4}(hje hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMDhjb ubah}(h]h ]h"]h$]h&]uh1jM hj_ ubjN )}(hhh]h)}(h0search nodes in a chunk of node [on NUMA system]h]h0search nodes in a chunk of node [on NUMA system]}(hj| hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMDhjy ubah}(h]h ]h"]h$]h&]uh1jM hj_ ubeh}(h]h ]h"]h$]h&]uh1jH hjE ubjI )}(hhh](jN )}(hhh]h)}(h5h]h5}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMEhj ubah}(h]h ]h"]h$]h&]uh1jM hj ubjN )}(hhh]h)}(h#search system wide [on NUMA system]h]h#search system wide [on NUMA system]}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMEhj ubah}(h]h ]h"]h$]h&]uh1jM hj ubeh}(h]h ]h"]h$]h&]uh1jH hjE ubeh}(h]h ]h"]h$]h&]uh1jC hj* ubeh}(h]h ]h"]h$]h&]colsKuh1j( hj% ubah}(h]h ]h"]h$]h&]uh1j# hj hhhhhNubh)}(hNot all levels can be present and values can change depending on the system architecture and kernel configuration. Check /sys/kernel/debug/sched/domains/cpu*/domain*/ for system-specific details.h]hNot all levels can be present and values can change depending on the system architecture and kernel configuration. Check /sys/kernel/debug/sched/domains/cpu*/domain*/ for system-specific details.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMHhj hhubh)}(h~The system default is architecture dependent. The system default can be changed using the relax_domain_level= boot parameter.h]h~The system default is architecture dependent. The system default can be changed using the relax_domain_level= boot parameter.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMMhj hhubh)}(hXThis file is per-cpuset and affect the sched domain where the cpuset belongs to. Therefore if the flag 'cpuset.sched_load_balance' of a cpuset is disabled, then 'cpuset.sched_relax_domain_level' have no effect since there is no sched domain belonging the cpuset.h]hXThis file is per-cpuset and affect the sched domain where the cpuset belongs to. Therefore if the flag ‘cpuset.sched_load_balance’ of a cpuset is disabled, then ‘cpuset.sched_relax_domain_level’ have no effect since there is no sched domain belonging the cpuset.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMPhj hhubh)}(hIf multiple cpusets are overlapping and hence they form a single sched domain, the largest value among those is used. Be careful, if one requests 0 and others are -1 then 0 is used.h]hIf multiple cpusets are overlapping and hence they form a single sched domain, the largest value among those is used. Be careful, if one requests 0 and others are -1 then 0 is used.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMUhj hhubh)}(hNote that modifying this file will have both good and bad effects, and whether it is acceptable or not depends on your situation. Don't modify this file if you are not sure.h]hNote that modifying this file will have both good and bad effects, and whether it is acceptable or not depends on your situation. Don’t modify this file if you are not sure.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMYhj hhubh)}(hIf your situation is:h]hIf your situation is:}(hj&hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM]hj hhubj)}(hX- The migration costs between each cpu can be assumed considerably small(for you) due to your special application's behavior or special hardware support for CPU cache etc. - The searching cost doesn't have impact(for you) or you can make the searching cost enough small by managing cpuset to compact etc. - The latency is required even it sacrifices cache hit rate etc. then increasing 'sched_relax_domain_level' would benefit you. h]h)}(hhh](h)}(hThe migration costs between each cpu can be assumed considerably small(for you) due to your special application's behavior or special hardware support for CPU cache etc.h]h)}(hThe migration costs between each cpu can be assumed considerably small(for you) due to your special application's behavior or special hardware support for CPU cache etc.h]hThe migration costs between each cpu can be assumed considerably small(for you) due to your special application’s behavior or special hardware support for CPU cache etc.}(hj?hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM_hj;ubah}(h]h ]h"]h$]h&]uh1hhj8ubh)}(hThe searching cost doesn't have impact(for you) or you can make the searching cost enough small by managing cpuset to compact etc.h]h)}(hThe searching cost doesn't have impact(for you) or you can make the searching cost enough small by managing cpuset to compact etc.h]hThe searching cost doesn’t have impact(for you) or you can make the searching cost enough small by managing cpuset to compact etc.}(hjWhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMbhjSubah}(h]h ]h"]h$]h&]uh1hhj8ubh)}(h~The latency is required even it sacrifices cache hit rate etc. then increasing 'sched_relax_domain_level' would benefit you. h]h)}(h|The latency is required even it sacrifices cache hit rate etc. then increasing 'sched_relax_domain_level' would benefit you.h]hThe latency is required even it sacrifices cache hit rate etc. then increasing ‘sched_relax_domain_level’ would benefit you.}(hjohhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMdhjkubah}(h]h ]h"]h$]h&]uh1hhj8ubeh}(h]h ]h"]h$]h&]jjuh1hhhhM_hj4ubah}(h]h ]h"]h$]h&]uh1jhhhM_hj hhubeh}(h] what-is-sched-relax-domain-levelah ]h"]&1.8 what is sched_relax_domain_level ?ah$]h&]uh1hhjhhhhhMubh)}(hhh](h)}(h1.9 How do I use cpusets ?h]h1.9 How do I use cpusets ?}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMiubh)}(hXXIn order to minimize the impact of cpusets on critical kernel code, such as the scheduler, and due to the fact that the kernel does not support one task updating the memory placement of another task directly, the impact on a task of changing its cpuset CPU or Memory Node placement, or of changing to which cpuset a task is attached, is subtle.h]hXXIn order to minimize the impact of cpusets on critical kernel code, such as the scheduler, and due to the fact that the kernel does not support one task updating the memory placement of another task directly, the impact on a task of changing its cpuset CPU or Memory Node placement, or of changing to which cpuset a task is attached, is subtle.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMkhjhhubh)}(hXIf a cpuset has its Memory Nodes modified, then for each task attached to that cpuset, the next time that the kernel attempts to allocate a page of memory for that task, the kernel will notice the change in the task's cpuset, and update its per-task memory placement to remain within the new cpusets memory placement. If the task was using mempolicy MPOL_BIND, and the nodes to which it was bound overlap with its new cpuset, then the task will continue to use whatever subset of MPOL_BIND nodes are still allowed in the new cpuset. If the task was using MPOL_BIND and now none of its MPOL_BIND nodes are allowed in the new cpuset, then the task will be essentially treated as if it was MPOL_BIND bound to the new cpuset (even though its NUMA placement, as queried by get_mempolicy(), doesn't change). If a task is moved from one cpuset to another, then the kernel will adjust the task's memory placement, as above, the next time that the kernel attempts to allocate a page of memory for that task.h]hXIf a cpuset has its Memory Nodes modified, then for each task attached to that cpuset, the next time that the kernel attempts to allocate a page of memory for that task, the kernel will notice the change in the task’s cpuset, and update its per-task memory placement to remain within the new cpusets memory placement. If the task was using mempolicy MPOL_BIND, and the nodes to which it was bound overlap with its new cpuset, then the task will continue to use whatever subset of MPOL_BIND nodes are still allowed in the new cpuset. If the task was using MPOL_BIND and now none of its MPOL_BIND nodes are allowed in the new cpuset, then the task will be essentially treated as if it was MPOL_BIND bound to the new cpuset (even though its NUMA placement, as queried by get_mempolicy(), doesn’t change). If a task is moved from one cpuset to another, then the kernel will adjust the task’s memory placement, as above, the next time that the kernel attempts to allocate a page of memory for that task.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMrhjhhubh)}(hXIf a cpuset has its 'cpuset.cpus' modified, then each task in that cpuset will have its allowed CPU placement changed immediately. Similarly, if a task's pid is written to another cpuset's 'tasks' file, then its allowed CPU placement is changed immediately. If such a task had been bound to some subset of its cpuset using the sched_setaffinity() call, the task will be allowed to run on any CPU allowed in its new cpuset, negating the effect of the prior sched_setaffinity() call.h]hXIf a cpuset has its ‘cpuset.cpus’ modified, then each task in that cpuset will have its allowed CPU placement changed immediately. Similarly, if a task’s pid is written to another cpuset’s ‘tasks’ file, then its allowed CPU placement is changed immediately. If such a task had been bound to some subset of its cpuset using the sched_setaffinity() call, the task will be allowed to run on any CPU allowed in its new cpuset, negating the effect of the prior sched_setaffinity() call.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hIn summary, the memory placement of a task whose cpuset is changed is updated by the kernel, on the next allocation of a page for that task, and the processor placement is updated immediately.h]hIn summary, the memory placement of a task whose cpuset is changed is updated by the kernel, on the next allocation of a page for that task, and the processor placement is updated immediately.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hXNormally, once a page is allocated (given a physical page of main memory) then that page stays on whatever node it was allocated, so long as it remains allocated, even if the cpusets memory placement policy 'cpuset.mems' subsequently changes. If the cpuset flag file 'cpuset.memory_migrate' is set true, then when tasks are attached to that cpuset, any pages that task had allocated to it on nodes in its previous cpuset are migrated to the task's new cpuset. The relative placement of the page within the cpuset is preserved during these migration operations if possible. For example if the page was on the second valid node of the prior cpuset then the page will be placed on the second valid node of the new cpuset.h]hXNormally, once a page is allocated (given a physical page of main memory) then that page stays on whatever node it was allocated, so long as it remains allocated, even if the cpusets memory placement policy ‘cpuset.mems’ subsequently changes. If the cpuset flag file ‘cpuset.memory_migrate’ is set true, then when tasks are attached to that cpuset, any pages that task had allocated to it on nodes in its previous cpuset are migrated to the task’s new cpuset. The relative placement of the page within the cpuset is preserved during these migration operations if possible. For example if the page was on the second valid node of the prior cpuset then the page will be placed on the second valid node of the new cpuset.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hXpAlso if 'cpuset.memory_migrate' is set true, then if that cpuset's 'cpuset.mems' file is modified, pages allocated to tasks in that cpuset, that were on nodes in the previous setting of 'cpuset.mems', will be moved to nodes in the new setting of 'mems.' Pages that were not in the task's prior cpuset, or in the cpuset's prior 'cpuset.mems' setting, will not be moved.h]hXAlso if ‘cpuset.memory_migrate’ is set true, then if that cpuset’s ‘cpuset.mems’ file is modified, pages allocated to tasks in that cpuset, that were on nodes in the previous setting of ‘cpuset.mems’, will be moved to nodes in the new setting of ‘mems.’ Pages that were not in the task’s prior cpuset, or in the cpuset’s prior ‘cpuset.mems’ setting, will not be moved.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hX%There is an exception to the above. If hotplug functionality is used to remove all the CPUs that are currently assigned to a cpuset, then all the tasks in that cpuset will be moved to the nearest ancestor with non-empty cpus. But the moving of some (or all) tasks might fail if cpuset is bound with another cgroup subsystem which has some restrictions on task attaching. In this failing case, those tasks will stay in the original cpuset, and the kernel will automatically update their cpus_allowed to allow all online CPUs. When memory hotplug functionality for removing Memory Nodes is available, a similar exception is expected to apply there as well. In general, the kernel prefers to violate cpuset placement, over starving a task that has had all its allowed CPUs or Memory Nodes taken offline.h]hX%There is an exception to the above. If hotplug functionality is used to remove all the CPUs that are currently assigned to a cpuset, then all the tasks in that cpuset will be moved to the nearest ancestor with non-empty cpus. But the moving of some (or all) tasks might fail if cpuset is bound with another cgroup subsystem which has some restrictions on task attaching. In this failing case, those tasks will stay in the original cpuset, and the kernel will automatically update their cpus_allowed to allow all online CPUs. When memory hotplug functionality for removing Memory Nodes is available, a similar exception is expected to apply there as well. In general, the kernel prefers to violate cpuset placement, over starving a task that has had all its allowed CPUs or Memory Nodes taken offline.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hXThere is a second exception to the above. GFP_ATOMIC requests are kernel internal allocations that must be satisfied, immediately. The kernel may drop some request, in rare cases even panic, if a GFP_ATOMIC alloc fails. If the request cannot be satisfied within the current task's cpuset, then we relax the cpuset, and look for memory anywhere we can find it. It's better to violate the cpuset than stress the kernel.h]hXThere is a second exception to the above. GFP_ATOMIC requests are kernel internal allocations that must be satisfied, immediately. The kernel may drop some request, in rare cases even panic, if a GFP_ATOMIC alloc fails. If the request cannot be satisfied within the current task’s cpuset, then we relax the cpuset, and look for memory anywhere we can find it. It’s better to violate the cpuset than stress the kernel.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hJTo start a new job that is to be contained within a cpuset, the steps are:h]hJTo start a new job that is to be contained within a cpuset, the steps are:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj)}(hX1) mkdir /sys/fs/cgroup/cpuset 2) mount -t cgroup -ocpuset cpuset /sys/fs/cgroup/cpuset 3) Create the new cpuset by doing mkdir's and write's (or echo's) in the /sys/fs/cgroup/cpuset virtual file system. 4) Start a task that will be the "founding father" of the new job. 5) Attach that task to the new cpuset by writing its pid to the /sys/fs/cgroup/cpuset tasks file for that cpuset. 6) fork, exec or clone the job tasks from this founding father task. h]j )}(hhh](h)}(hmkdir /sys/fs/cgroup/cpuseth]h)}(hj/h]hmkdir /sys/fs/cgroup/cpuset}(hj1hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj-ubah}(h]h ]h"]h$]h&]uh1hhj*ubh)}(h5mount -t cgroup -ocpuset cpuset /sys/fs/cgroup/cpuseth]h)}(hjFh]h5mount -t cgroup -ocpuset cpuset /sys/fs/cgroup/cpuset}(hjHhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjDubah}(h]h ]h"]h$]h&]uh1hhj*ubh)}(hpCreate the new cpuset by doing mkdir's and write's (or echo's) in the /sys/fs/cgroup/cpuset virtual file system.h]h)}(hpCreate the new cpuset by doing mkdir's and write's (or echo's) in the /sys/fs/cgroup/cpuset virtual file system.h]hvCreate the new cpuset by doing mkdir’s and write’s (or echo’s) in the /sys/fs/cgroup/cpuset virtual file system.}(hj_hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj[ubah}(h]h ]h"]h$]h&]uh1hhj*ubh)}(h?Start a task that will be the "founding father" of the new job.h]h)}(hjuh]hCStart a task that will be the “founding father” of the new job.}(hjwhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjsubah}(h]h ]h"]h$]h&]uh1hhj*ubh)}(hnAttach that task to the new cpuset by writing its pid to the /sys/fs/cgroup/cpuset tasks file for that cpuset.h]h)}(hnAttach that task to the new cpuset by writing its pid to the /sys/fs/cgroup/cpuset tasks file for that cpuset.h]hnAttach that task to the new cpuset by writing its pid to the /sys/fs/cgroup/cpuset tasks file for that cpuset.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1hhj*ubh)}(hBfork, exec or clone the job tasks from this founding father task. h]h)}(hAfork, exec or clone the job tasks from this founding father task.h]hAfork, exec or clone the job tasks from this founding father task.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1hhj*ubeh}(h]h ]h"]h$]h&]j j j hj j uh1j hj&ubah}(h]h ]h"]h$]h&]uh1jhhhMhjhhubh)}(hFor example, the following sequence of commands will setup a cpuset named "Charlie", containing just CPUs 2 and 3, and Memory Node 1, and then start a subshell 'sh' in that cpuset::h]hFor example, the following sequence of commands will setup a cpuset named “Charlie”, containing just CPUs 2 and 3, and Memory Node 1, and then start a subshell ‘sh’ in that cpuset:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj)}(hX*mount -t cgroup -ocpuset cpuset /sys/fs/cgroup/cpuset cd /sys/fs/cgroup/cpuset mkdir Charlie cd Charlie /bin/echo 2-3 > cpuset.cpus /bin/echo 1 > cpuset.mems /bin/echo $$ > tasks sh # The subshell 'sh' is now running in cpuset Charlie # The next line should display '/Charlie' cat /proc/self/cpuseth]hX*mount -t cgroup -ocpuset cpuset /sys/fs/cgroup/cpuset cd /sys/fs/cgroup/cpuset mkdir Charlie cd Charlie /bin/echo 2-3 > cpuset.cpus /bin/echo 1 > cpuset.mems /bin/echo $$ > tasks sh # The subshell 'sh' is now running in cpuset Charlie # The next line should display '/Charlie' cat /proc/self/cpuset}hjsbah}(h]h ]h"]h$]h&]jjuh1jhhhMhjhhubh)}(h*There are ways to query or modify cpusets:h]h*There are ways to query or modify cpusets:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj)}(hX>- via the cpuset file system directly, using the various cd, mkdir, echo, cat, rmdir commands from the shell, or their equivalent from C. - via the C library libcpuset. - via the C library libcgroup. (https://github.com/libcgroup/libcgroup/) - via the python application cset. (http://code.google.com/p/cpuset/) h]h)}(hhh](h)}(hvia the cpuset file system directly, using the various cd, mkdir, echo, cat, rmdir commands from the shell, or their equivalent from C.h]h)}(hvia the cpuset file system directly, using the various cd, mkdir, echo, cat, rmdir commands from the shell, or their equivalent from C.h]hvia the cpuset file system directly, using the various cd, mkdir, echo, cat, rmdir commands from the shell, or their equivalent from C.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1hhjubh)}(hvia the C library libcpuset.h]h)}(hjh]hvia the C library libcpuset.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1hhjubh)}(hFvia the C library libcgroup. (https://github.com/libcgroup/libcgroup/)h]h)}(hFvia the C library libcgroup. (https://github.com/libcgroup/libcgroup/)h](hvia the C library libcgroup. (}(hj*hhhNhNubh)}(h'https://github.com/libcgroup/libcgroup/h]h'https://github.com/libcgroup/libcgroup/}(hj2hhhNhNubah}(h]h ]h"]h$]h&]refurij4uh1hhj*ubh)}(hj*hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj&ubah}(h]h ]h"]h$]h&]uh1hhjubh)}(hDvia the python application cset. (http://code.google.com/p/cpuset/) h]h)}(hCvia the python application cset. (http://code.google.com/p/cpuset/)h](h"via the python application cset. (}(hjUhhhNhNubh)}(h http://code.google.com/p/cpuset/h]h http://code.google.com/p/cpuset/}(hj]hhhNhNubah}(h]h ]h"]h$]h&]refurij_uh1hhjUubh)}(hjUhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjQubah}(h]h ]h"]h$]h&]uh1hhjubeh}(h]h ]h"]h$]h&]jjuh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1jhhhMhjhhubh)}(hThe sched_setaffinity calls can also be done at the shell prompt using SGI's runon or Robert Love's taskset. The mbind and set_mempolicy calls can be done at the shell prompt using the numactl command (part of Andi Kleen's numa package).h]hThe sched_setaffinity calls can also be done at the shell prompt using SGI’s runon or Robert Love’s taskset. The mbind and set_mempolicy calls can be done at the shell prompt using the numactl command (part of Andi Kleen’s numa package).}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubeh}(h]how-do-i-use-cpusetsah ]h"]1.9 how do i use cpusets ?ah$]h&]uh1hhjhhhhhMiubeh}(h]id2ah ]h"] 1. cpusetsah$]h&]uh1hhhhhhhhK&ubh)}(hhh](h)}(h2. Usage Examples and Syntaxh]h2. Usage Examples and Syntax}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMubh)}(hhh](h)}(h2.1 Basic Usageh]h2.1 Basic Usage}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMubh)}(hYCreating, modifying, using the cpusets can be done through the cpuset virtual filesystem.h]hYCreating, modifying, using the cpusets can be done through the cpuset virtual filesystem.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hKTo mount it, type: # mount -t cgroup -o cpuset cpuset /sys/fs/cgroup/cpuseth]hKTo mount it, type: # mount -t cgroup -o cpuset cpuset /sys/fs/cgroup/cpuset}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hThen under /sys/fs/cgroup/cpuset you can find a tree that corresponds to the tree of the cpusets in the system. For instance, /sys/fs/cgroup/cpuset is the cpuset that holds the whole system.h]hThen under /sys/fs/cgroup/cpuset you can find a tree that corresponds to the tree of the cpusets in the system. For instance, /sys/fs/cgroup/cpuset is the cpuset that holds the whole system.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(h@If you want to create a new cpuset under /sys/fs/cgroup/cpuset::h]h?If you want to create a new cpuset under /sys/fs/cgroup/cpuset:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj)}(h,# cd /sys/fs/cgroup/cpuset # mkdir my_cpuseth]h,# cd /sys/fs/cgroup/cpuset # mkdir my_cpuset}hjsbah}(h]h ]h"]h$]h&]jjuh1jhhhMhjhhubh)}(h/Now you want to do something with this cpuset::h]h.Now you want to do something with this cpuset:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj)}(h# cd my_cpuseth]h# cd my_cpuset}hjsbah}(h]h ]h"]h$]h&]jjuh1jhhhMhjhhubh)}(h.In this directory you can find several files::h]h-In this directory you can find several files:}(hj*hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj)}(hXe# ls cgroup.clone_children cpuset.memory_pressure cgroup.event_control cpuset.memory_spread_page cgroup.procs cpuset.memory_spread_slab cpuset.cpu_exclusive cpuset.mems cpuset.cpus cpuset.sched_load_balance cpuset.mem_exclusive cpuset.sched_relax_domain_level cpuset.mem_hardwall notify_on_release cpuset.memory_migrate tasksh]hXe# ls cgroup.clone_children cpuset.memory_pressure cgroup.event_control cpuset.memory_spread_page cgroup.procs cpuset.memory_spread_slab cpuset.cpu_exclusive cpuset.mems cpuset.cpus cpuset.sched_load_balance cpuset.mem_exclusive cpuset.sched_relax_domain_level cpuset.mem_hardwall notify_on_release cpuset.memory_migrate tasks}hj8sbah}(h]h ]h"]h$]h&]jjuh1jhhhMhjhhubh)}(hReading them will give you information about the state of this cpuset: the CPUs and Memory Nodes it can use, the processes that are using it, its properties. By writing to these files you can manipulate the cpuset.h]hReading them will give you information about the state of this cpuset: the CPUs and Memory Nodes it can use, the processes that are using it, its properties. By writing to these files you can manipulate the cpuset.}(hjFhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hSet some flags::h]hSet some flags:}(hjThhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM hjhhubj)}(h$# /bin/echo 1 > cpuset.cpu_exclusiveh]h$# /bin/echo 1 > cpuset.cpu_exclusive}hjbsbah}(h]h ]h"]h$]h&]jjuh1jhhhM hjhhubh)}(hAdd some cpus::h]hAdd some cpus:}(hjphhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj)}(h# /bin/echo 0-7 > cpuset.cpush]h# /bin/echo 0-7 > cpuset.cpus}hj~sbah}(h]h ]h"]h$]h&]jjuh1jhhhMhjhhubh)}(hAdd some mems::h]hAdd some mems:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj)}(h# /bin/echo 0-7 > cpuset.memsh]h# /bin/echo 0-7 > cpuset.mems}hjsbah}(h]h ]h"]h$]h&]jjuh1jhhhMhjhhubh)}(h&Now attach your shell to this cpuset::h]h%Now attach your shell to this cpuset:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj)}(h# /bin/echo $$ > tasksh]h# /bin/echo $$ > tasks}hjsbah}(h]h ]h"]h$]h&]jjuh1jhhhMhjhhubh)}(hQYou can also create cpusets inside your cpuset by using mkdir in this directory::h]hPYou can also create cpusets inside your cpuset by using mkdir in this directory:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj)}(h# mkdir my_sub_csh]h# mkdir my_sub_cs}hjsbah}(h]h ]h"]h$]h&]jjuh1jhhhMhjhhubh)}(h$To remove a cpuset, just use rmdir::h]h#To remove a cpuset, just use rmdir:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj)}(h# rmdir my_sub_csh]h# rmdir my_sub_cs}hjsbah}(h]h ]h"]h$]h&]jjuh1jhhhM!hjhhubh)}(hWThis will fail if the cpuset is in use (has cpusets inside, or has processes attached).h]hWThis will fail if the cpuset is in use (has cpusets inside, or has processes attached).}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM#hjhhubh)}(hgNote that for legacy reasons, the "cpuset" filesystem exists as a wrapper around the cgroup filesystem.h]hkNote that for legacy reasons, the “cpuset” filesystem exists as a wrapper around the cgroup filesystem.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM&hjhhubh)}(h The command::h]h The command:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM)hjhhubj)}(h'mount -t cpuset X /sys/fs/cgroup/cpuseth]h'mount -t cpuset X /sys/fs/cgroup/cpuset}hj&sbah}(h]h ]h"]h$]h&]jjuh1jhhhM+hjhhubh)}(his equivalent to::h]his equivalent to:}(hj4hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM-hjhhubj)}(hmount -t cgroup -ocpuset,noprefix X /sys/fs/cgroup/cpuset echo "/sbin/cpuset_release_agent" > /sys/fs/cgroup/cpuset/release_agenth]hmount -t cgroup -ocpuset,noprefix X /sys/fs/cgroup/cpuset echo "/sbin/cpuset_release_agent" > /sys/fs/cgroup/cpuset/release_agent}hjBsbah}(h]h ]h"]h$]h&]jjuh1jhhhM/hjhhubeh}(h] basic-usageah ]h"]2.1 basic usageah$]h&]uh1hhjhhhhhMubh)}(hhh](h)}(h2.2 Adding/removing cpush]h2.2 Adding/removing cpus}(hj[hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjXhhhhhM3ubh)}(hXThis is the syntax to use when writing in the cpus or mems files in cpuset directories::h]hWThis is the syntax to use when writing in the cpus or mems files in cpuset directories:}(hjihhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM5hjXhhubj)}(h# /bin/echo 1-4 > cpuset.cpus -> set cpus list to cpus 1,2,3,4 # /bin/echo 1,2,3,4 > cpuset.cpus -> set cpus list to cpus 1,2,3,4h]h# /bin/echo 1-4 > cpuset.cpus -> set cpus list to cpus 1,2,3,4 # /bin/echo 1,2,3,4 > cpuset.cpus -> set cpus list to cpus 1,2,3,4}hjwsbah}(h]h ]h"]h$]h&]jjuh1jhhhM8hjXhhubh)}(hrTo add a CPU to a cpuset, write the new list of CPUs including the CPU to be added. To add 6 to the above cpuset::h]hqTo add a CPU to a cpuset, write the new list of CPUs including the CPU to be added. To add 6 to the above cpuset:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM;hjXhhubj)}(hH# /bin/echo 1-4,6 > cpuset.cpus -> set cpus list to cpus 1,2,3,4,6h]hH# /bin/echo 1-4,6 > cpuset.cpus -> set cpus list to cpus 1,2,3,4,6}hjsbah}(h]h ]h"]h$]h&]jjuh1jhhhM>hjXhhubh)}(hbSimilarly to remove a CPU from a cpuset, write the new list of CPUs without the CPU to be removed.h]hbSimilarly to remove a CPU from a cpuset, write the new list of CPUs without the CPU to be removed.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM@hjXhhubh)}(hTo remove all the CPUs::h]hTo remove all the CPUs:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMChjXhhubj)}(h8# /bin/echo "" > cpuset.cpus -> clear cpus listh]h8# /bin/echo "" > cpuset.cpus -> clear cpus list}hjsbah}(h]h ]h"]h$]h&]jjuh1jhhhMEhjXhhubeh}(h]adding-removing-cpusah ]h"]2.2 adding/removing cpusah$]h&]uh1hhjhhhhhM3ubh)}(hhh](h)}(h2.3 Setting flagsh]h2.3 Setting flags}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMHubh)}(hThe syntax is very simple::h]hThe syntax is very simple:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMJhjhhubj)}(h# /bin/echo 1 > cpuset.cpu_exclusive -> set flag 'cpuset.cpu_exclusive' # /bin/echo 0 > cpuset.cpu_exclusive -> unset flag 'cpuset.cpu_exclusive'h]h# /bin/echo 1 > cpuset.cpu_exclusive -> set flag 'cpuset.cpu_exclusive' # /bin/echo 0 > cpuset.cpu_exclusive -> unset flag 'cpuset.cpu_exclusive'}hjsbah}(h]h ]h"]h$]h&]jjuh1jhhhMLhjhhubeh}(h] setting-flagsah ]h"]2.3 setting flagsah$]h&]uh1hhjhhhhhMHubh)}(hhh](h)}(h2.4 Attaching processesh]h2.4 Attaching processes}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMPubj)}(h# /bin/echo PID > tasksh]h# /bin/echo PID > tasks}hjsbah}(h]h ]h"]h$]h&]jjuh1jhhhMThjhhubh)}(hNote that it is PID, not PIDs. You can only attach ONE task at a time. If you have several tasks to attach, you have to do it one after another::h]hNote that it is PID, not PIDs. You can only attach ONE task at a time. If you have several tasks to attach, you have to do it one after another:}(hj'hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMVhjhhubj)}(hT# /bin/echo PID1 > tasks # /bin/echo PID2 > tasks ... # /bin/echo PIDn > tasksh]hT# /bin/echo PID1 > tasks # /bin/echo PID2 > tasks ... # /bin/echo PIDn > tasks}hj5sbah}(h]h ]h"]h$]h&]jjuh1jhhhMYhjhhubeh}(h]attaching-processesah ]h"]2.4 attaching processesah$]h&]uh1hhjhhhhhMPubeh}(h]usage-examples-and-syntaxah ]h"]2. usage examples and syntaxah$]h&]uh1hhhhhhhhMubh)}(hhh](h)}(h 3. Questionsh]h 3. Questions}(hjVhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjShhhhhM`ubj)}(hhh](j)}(h%Q: what's up with this '/bin/echo' ? h](j)}(hQ:h]hQ:}(hjkhhhNhNubah}(h]h ]h"]h$]h&]uh1jhhhMchjgubj)}(hhh]h)}(h!what's up with this '/bin/echo' ?h]h'what’s up with this ‘/bin/echo’ ?}(hj|hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMchjyubah}(h]h ]h"]h$]h&]uh1jhjgubeh}(h]h ]h"]h$]h&]uh1jhhhMchjdubj)}(hA: bash's builtin 'echo' command does not check calls to write() against errors. If you use it in the cpuset file system, you won't be able to tell whether a command succeeded or failed. h](j)}(hA:h]hA:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhhhMhhjubj)}(hhh]h)}(hbash's builtin 'echo' command does not check calls to write() against errors. If you use it in the cpuset file system, you won't be able to tell whether a command succeeded or failed.h]hbash’s builtin ‘echo’ command does not check calls to write() against errors. If you use it in the cpuset file system, you won’t be able to tell whether a command succeeded or failed.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMfhjubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhhhMhhjdhhubj)}(hNQ: When I attach processes, only the first of the line gets really attached ! h](j)}(hQ:h]hQ:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhhhMkhjubj)}(hhh]h)}(hJWhen I attach processes, only the first of the line gets really attached !h]hJWhen I attach processes, only the first of the line gets really attached !}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMkhjubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhhhMkhjdhhubj)}(h_A: We can only return one error code per call to write(). So you should also put only ONE pid. h](j)}(hA:h]hA:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhhhMohjubj)}(hhh]h)}(h[We can only return one error code per call to write(). So you should also put only ONE pid.h]h[We can only return one error code per call to write(). So you should also put only ONE pid.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMnhjubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhhhMohjdhhubeh}(h]h ]h"]h$]h&]uh1jhjShhhhhNubeh}(h] questionsah ]h"] 3. questionsah$]h&]uh1hhhhhhhhM`ubh)}(hhh](h)}(h 4. Contacth]h 4. Contact}(hj4hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj1hhhhhMrubh)}(h)Web: http://www.bullopensource.org/cpuseth](hWeb: }(hjBhhhNhNubh)}(h$http://www.bullopensource.org/cpuseth]h$http://www.bullopensource.org/cpuset}(hjJhhhNhNubah}(h]h ]h"]h$]h&]refurijLuh1hhjBubeh}(h]h ]h"]h$]h&]uh1hhhhMthj1hhubeh}(h]contactah ]h"] 4. contactah$]h&]uh1hhhhhhhhMrubeh}(h](hid1eh ]h"]cpusetsah$]cpusetsah&]uh1hhhhhhhhK referencedKexpect_referenced_by_name}jlhsexpect_referenced_by_id}hhsubeh}(h]h ]h"]h$]h&]sourcehuh1hcurrent_sourceN current_lineNsettingsdocutils.frontendValues)}(hN generatorN datestampN source_linkN source_urlN toc_backlinksjM footnote_backlinksK sectnum_xformKstrip_commentsNstrip_elements_with_classesN strip_classesN report_levelK halt_levelKexit_status_levelKdebugNwarning_streamN tracebackinput_encoding utf-8-siginput_encoding_error_handlerstrictoutput_encodingutf-8output_encoding_error_handlerjerror_encodingutf-8error_encoding_error_handlerbackslashreplace language_codeenrecord_dependenciesNconfigN id_prefixhauto_id_prefixid dump_settingsNdump_internalsNdump_transformsNdump_pseudo_xmlNexpose_internalsNstrict_visitorN_disable_configN_sourceh _destinationN _config_files]7/var/lib/git/docbuild/linux/Documentation/docutils.confafile_insertion_enabled raw_enabledKline_length_limitM'pep_referencesN pep_base_urlhttps://peps.python.org/pep_file_url_templatepep-%04drfc_referencesN rfc_base_url&https://datatracker.ietf.org/doc/html/ tab_widthKtrim_footnote_reference_spacesyntax_highlightlong smart_quotessmartquotes_locales]character_level_inline_markupdoctitle_xform docinfo_xformKsectsubtitle_xform image_loadinglinkembed_stylesheetcloak_email_addressessection_self_linkenvNubreporterNindirect_targets]substitution_defs}substitution_names}refnames}refids}h]hasnameids}(jlhjjjGjDjjjRjOjjjjjg jd j j j j jjjjjPjMjUjRjjjjjHjEj.j+jdjau nametypes}(jljjGjjRjjjg j j jjjPjUjjjHj.jduh}(hhjihjjjDjjjJjOjjjUjjjd jj jj j j jj jjjMjjRjjjXjjjEjj+jSjaj1u footnote_refs} citation_refs} autofootnotes]autofootnote_refs]symbol_footnotes]symbol_footnote_refs] footnotes] citations]autofootnote_startKsymbol_footnote_startK id_counter collectionsCounter}jKsRparse_messages]hsystem_message)}(hhh]h)}(h*Duplicate implicit target name: "cpusets".h]h.Duplicate implicit target name: “cpusets”.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]jialevelKtypeINFOsourcehlineKuh1jhhhhhhhKubatransform_messages]j)}(hhh]h)}(hhh]h-Hyperlink target "cpusets" is not referenced.}hjsbah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]levelKtypejsourcehlineKuh1juba transformerN include_log] decorationNhhub.