€•IŒsphinx.addnodes”Œdocument”“”)”}”(Œ rawsource”Œ”Œchildren”]”(Œ translations”Œ LanguagesNode”“”)”}”(hhh]”(hŒ pending_xref”“”)”}”(hhh]”Œdocutils.nodes”ŒText”“”ŒChinese (Simplified)”…””}”Œparent”hsbaŒ attributes”}”(Œids”]”Œclasses”]”Œnames”]”Œdupnames”]”Œbackrefs”]”Œ refdomain”Œstd”Œreftype”Œdoc”Œ reftarget”Œ5/translations/zh_CN/admin-guide/mm/numa_memory_policy”Œmodname”NŒ classname”NŒ refexplicit”ˆuŒtagname”hhh ubh)”}”(hhh]”hŒChinese (Traditional)”…””}”hh2sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ5/translations/zh_TW/admin-guide/mm/numa_memory_policy”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒItalian”…””}”hhFsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ5/translations/it_IT/admin-guide/mm/numa_memory_policy”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒJapanese”…””}”hhZsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ5/translations/ja_JP/admin-guide/mm/numa_memory_policy”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒKorean”…””}”hhnsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ5/translations/ko_KR/admin-guide/mm/numa_memory_policy”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒPortuguese (Brazilian)”…””}”hh‚sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ5/translations/pt_BR/admin-guide/mm/numa_memory_policy”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒSpanish”…””}”hh–sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ5/translations/sp_SP/admin-guide/mm/numa_memory_policy”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubeh}”(h]”h ]”h"]”h$]”h&]”Œcurrent_language”ŒEnglish”uh1h hhŒ _document”hŒsource”NŒline”NubhŒsection”“”)”}”(hhh]”(hŒtitle”“”)”}”(hŒNUMA Memory Policy”h]”hŒNUMA Memory Policy”…””}”(hh¼h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhh·h²hh³ŒO/var/lib/git/docbuild/linux/Documentation/admin-guide/mm/numa_memory_policy.rst”h´Kubh¶)”}”(hhh]”(h»)”}”(hŒWhat is NUMA Memory Policy?”h]”hŒWhat is NUMA Memory Policy?”…””}”(hhÎh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhhËh²hh³hÊh´KubhŒ paragraph”“”)”}”(hXŽIn the Linux kernel, "memory policy" determines from which node the kernel will allocate memory in a NUMA system or in an emulated NUMA system. Linux has supported platforms with Non-Uniform Memory Access architectures since 2.4.?. The current memory policy support was added to Linux 2.6 around May 2004. This document attempts to describe the concepts and APIs of the 2.6 memory policy support.”h]”hX’In the Linux kernel, “memory policy†determines from which node the kernel will allocate memory in a NUMA system or in an emulated NUMA system. Linux has supported platforms with Non-Uniform Memory Access architectures since 2.4.?. The current memory policy support was added to Linux 2.6 around May 2004. This document attempts to describe the concepts and APIs of the 2.6 memory policy support.”…””}”(hhÞh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´KhhËh²hubhÝ)”}”(hXÿMemory policies should not be confused with cpusets (``Documentation/admin-guide/cgroup-v1/cpusets.rst``) which is an administrative mechanism for restricting the nodes from which memory may be allocated by a set of processes. Memory policies are a programming interface that a NUMA-aware application can take advantage of. When both cpusets and policies are applied to a task, the restrictions of the cpuset takes priority. See :ref:`Memory Policies and cpusets ` below for more details.”h]”(hŒ5Memory policies should not be confused with cpusets (”…””}”(hhìh²hh³Nh´NubhŒliteral”“”)”}”(hŒ3``Documentation/admin-guide/cgroup-v1/cpusets.rst``”h]”hŒ/Documentation/admin-guide/cgroup-v1/cpusets.rst”…””}”(hhöh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hôhhìubhXG) which is an administrative mechanism for restricting the nodes from which memory may be allocated by a set of processes. Memory policies are a programming interface that a NUMA-aware application can take advantage of. When both cpusets and policies are applied to a task, the restrictions of the cpuset takes priority. See ”…””}”(hhìh²hh³Nh´Nubh)”}”(hŒ8:ref:`Memory Policies and cpusets `”h]”hŒinline”“”)”}”(hj h]”hŒMemory Policies and cpusets”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”(Œxref”Œstd”Œstd-ref”eh"]”h$]”h&]”uh1j hjubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”Œ!admin-guide/mm/numa_memory_policy”Œ refdomain”jŒreftype”Œref”Œ refexplicit”ˆŒrefwarn”ˆŒ reftarget”Œmem_pol_and_cpusets”uh1hh³hÊh´KhhìubhŒ below for more details.”…””}”(hhìh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´KhhËh²hubeh}”(h]”Œwhat-is-numa-memory-policy”ah ]”h"]”Œwhat is numa memory policy?”ah$]”h&]”uh1hµhh·h²hh³hÊh´Kubh¶)”}”(hhh]”(h»)”}”(hŒMemory Policy Concepts”h]”hŒMemory Policy Concepts”…””}”(hjBh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhj?h²hh³hÊh´Kubh¶)”}”(hhh]”(h»)”}”(hŒScope of Memory Policies”h]”hŒScope of Memory Policies”…””}”(hjSh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjPh²hh³hÊh´KubhÝ)”}”(hŒgThe Linux kernel supports _scopes_ of memory policy, described here from most general to most specific:”h]”hŒgThe Linux kernel supports _scopes_ of memory policy, described here from most general to most specific:”…””}”(hjah²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´KhjPh²hubhŒdefinition_list”“”)”}”(hhh]”(hŒdefinition_list_item”“”)”}”(hXSystem Default Policy this policy is "hard coded" into the kernel. It is the policy that governs all page allocations that aren't controlled by one of the more specific policy scopes discussed below. When the system is "up and running", the system default policy will use "local allocation" described below. However, during boot up, the system default policy will be set to interleave allocations across all nodes with "sufficient" memory, so as not to overload the initial boot node with boot-time allocations. ”h]”(hŒterm”“”)”}”(hŒSystem Default Policy”h]”hŒSystem Default Policy”…””}”(hj|h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jzh³hÊh´K*hjvubhŒ definition”“”)”}”(hhh]”hÝ)”}”(hXìthis policy is "hard coded" into the kernel. It is the policy that governs all page allocations that aren't controlled by one of the more specific policy scopes discussed below. When the system is "up and running", the system default policy will use "local allocation" described below. However, during boot up, the system default policy will be set to interleave allocations across all nodes with "sufficient" memory, so as not to overload the initial boot node with boot-time allocations.”h]”hXþthis policy is “hard coded†into the kernel. It is the policy that governs all page allocations that aren’t controlled by one of the more specific policy scopes discussed below. When the system is “up and runningâ€, the system default policy will use “local allocation†described below. However, during boot up, the system default policy will be set to interleave allocations across all nodes with “sufficient†memory, so as not to overload the initial boot node with boot-time allocations.”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´K"hjŒubah}”(h]”h ]”h"]”h$]”h&]”uh1jŠhjvubeh}”(h]”h ]”h"]”h$]”h&]”uh1jth³hÊh´K*hjqubju)”}”(hXbTask/Process Policy this is an optional, per-task policy. When defined for a specific task, this policy controls all page allocations made by or on behalf of the task that aren't controlled by a more specific scope. If a task does not define a task policy, then all page allocations that would have been controlled by the task policy "fall back" to the System Default Policy. The task policy applies to the entire address space of a task. Thus, it is inheritable, and indeed is inherited, across both fork() [clone() w/o the CLONE_VM flag] and exec*(). This allows a parent task to establish the task policy for a child task exec()'d from an executable image that has no awareness of memory policy. See the :ref:`Memory Policy APIs ` section, below, for an overview of the system call that a task may use to set/change its task/process policy. In a multi-threaded task, task policies apply only to the thread [Linux kernel task] that installs the policy and any threads subsequently created by that thread. Any sibling threads existing at the time a new task policy is installed retain their current policy. A task policy applies only to pages allocated after the policy is installed. Any pages already faulted in by the task when the task changes its task policy remain where they were allocated based on the policy at the time they were allocated. ”h]”(j{)”}”(hŒTask/Process Policy”h]”hŒTask/Process Policy”…””}”(hj­h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jzh³hÊh´KFhj©ubj‹)”}”(hhh]”(hÝ)”}”(hXdthis is an optional, per-task policy. When defined for a specific task, this policy controls all page allocations made by or on behalf of the task that aren't controlled by a more specific scope. If a task does not define a task policy, then all page allocations that would have been controlled by the task policy "fall back" to the System Default Policy.”h]”hXjthis is an optional, per-task policy. When defined for a specific task, this policy controls all page allocations made by or on behalf of the task that aren’t controlled by a more specific scope. If a task does not define a task policy, then all page allocations that would have been controlled by the task policy “fall back†to the System Default Policy.”…””}”(hj¾h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´K-hj»ubhÝ)”}”(hXéThe task policy applies to the entire address space of a task. Thus, it is inheritable, and indeed is inherited, across both fork() [clone() w/o the CLONE_VM flag] and exec*(). This allows a parent task to establish the task policy for a child task exec()'d from an executable image that has no awareness of memory policy. See the :ref:`Memory Policy APIs ` section, below, for an overview of the system call that a task may use to set/change its task/process policy.”h]”(hXOThe task policy applies to the entire address space of a task. Thus, it is inheritable, and indeed is inherited, across both fork() [clone() w/o the CLONE_VM flag] and exec*(). This allows a parent task to establish the task policy for a child task exec()’d from an executable image that has no awareness of memory policy. See the ”…””}”(hjÌh²hh³Nh´Nubh)”}”(hŒ.:ref:`Memory Policy APIs `”h]”j )”}”(hjÖh]”hŒMemory Policy APIs”…””}”(hjØh²hh³Nh´Nubah}”(h]”h ]”(jŒstd”Œstd-ref”eh"]”h$]”h&]”uh1j hjÔubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j%Œ refdomain”jâŒreftype”Œref”Œ refexplicit”ˆŒrefwarn”ˆj+Œmemory_policy_apis”uh1hh³hÊh´K4hjÌubhŒn section, below, for an overview of the system call that a task may use to set/change its task/process policy.”…””}”(hjÌh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´K4hj»ubhÝ)”}”(hXIn a multi-threaded task, task policies apply only to the thread [Linux kernel task] that installs the policy and any threads subsequently created by that thread. Any sibling threads existing at the time a new task policy is installed retain their current policy.”h]”hXIn a multi-threaded task, task policies apply only to the thread [Linux kernel task] that installs the policy and any threads subsequently created by that thread. Any sibling threads existing at the time a new task policy is installed retain their current policy.”…””}”(hjþh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´K=hj»ubhÝ)”}”(hŒòA task policy applies only to pages allocated after the policy is installed. Any pages already faulted in by the task when the task changes its task policy remain where they were allocated based on the policy at the time they were allocated.”h]”hŒòA task policy applies only to pages allocated after the policy is installed. Any pages already faulted in by the task when the task changes its task policy remain where they were allocated based on the policy at the time they were allocated.”…””}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´KChj»ubeh}”(h]”h ]”h"]”h$]”h&]”uh1jŠhj©ubeh}”(h]”h ]”h"]”h$]”h&]”uh1jth³hÊh´KFhjqh²hubeh}”(h]”h ]”h"]”h$]”h&]”uh1johjPh²hh³hÊh´NubhŒtarget”“”)”}”(hŒ.. _vma_policy:”h]”h}”(h]”h ]”h"]”h$]”h&]”Œrefid”Œ vma-policy”uh1j,h´KHhjPh²hh³hÊubjp)”}”(hhh]”(ju)”}”(hXVMA Policy A "VMA" or "Virtual Memory Area" refers to a range of a task's virtual address space. A task may define a specific policy for a range of its virtual address space. See the :ref:`Memory Policy APIs ` section, below, for an overview of the mbind() system call used to set a VMA policy. A VMA policy will govern the allocation of pages that back this region of the address space. Any regions of the task's address space that don't have an explicit VMA policy will fall back to the task policy, which may itself fall back to the System Default Policy. VMA policies have a few complicating details: * VMA policy applies ONLY to anonymous pages. These include pages allocated for anonymous segments, such as the task stack and heap, and any regions of the address space mmap()ed with the MAP_ANONYMOUS flag. If a VMA policy is applied to a file mapping, it will be ignored if the mapping used the MAP_SHARED flag. If the file mapping used the MAP_PRIVATE flag, the VMA policy will only be applied when an anonymous page is allocated on an attempt to write to the mapping-- i.e., at Copy-On-Write. * VMA policies are shared between all tasks that share a virtual address space--a.k.a. threads--independent of when the policy is installed; and they are inherited across fork(). However, because VMA policies refer to a specific region of a task's address space, and because the address space is discarded and recreated on exec*(), VMA policies are NOT inheritable across exec(). Thus, only NUMA-aware applications may use VMA policies. * A task may install a new VMA policy on a sub-range of a previously mmap()ed region. When this happens, Linux splits the existing virtual memory area into 2 or 3 VMAs, each with its own policy. * By default, VMA policy applies only to pages allocated after the policy is installed. Any pages already faulted into the VMA range remain where they were allocated based on the policy at the time they were allocated. However, since 2.6.16, Linux supports page migration via the mbind() system call, so that page contents can be moved to match a newly installed policy. ”h]”(j{)”}”(hŒ VMA Policy”h]”hŒ VMA Policy”…””}”(hjAh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jzh³hÊh´Kxhj=ubj‹)”}”(hhh]”(hÝ)”}”(hX2A "VMA" or "Virtual Memory Area" refers to a range of a task's virtual address space. A task may define a specific policy for a range of its virtual address space. See the :ref:`Memory Policy APIs ` section, below, for an overview of the mbind() system call used to set a VMA policy.”h]”(hŒ¹A “VMA†or “Virtual Memory Area†refers to a range of a task’s virtual address space. A task may define a specific policy for a range of its virtual address space. See the ”…””}”(hjRh²hh³Nh´Nubh)”}”(hŒ.:ref:`Memory Policy APIs `”h]”j )”}”(hj\h]”hŒMemory Policy APIs”…””}”(hj^h²hh³Nh´Nubah}”(h]”h ]”(jŒstd”Œstd-ref”eh"]”h$]”h&]”uh1j hjZubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j%Œ refdomain”jhŒreftype”Œref”Œ refexplicit”ˆŒrefwarn”ˆj+Œmemory_policy_apis”uh1hh³hÊh´KKhjRubhŒU section, below, for an overview of the mbind() system call used to set a VMA policy.”…””}”(hjRh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´KKhjOubhÝ)”}”(hXA VMA policy will govern the allocation of pages that back this region of the address space. Any regions of the task's address space that don't have an explicit VMA policy will fall back to the task policy, which may itself fall back to the System Default Policy.”h]”hX A VMA policy will govern the allocation of pages that back this region of the address space. Any regions of the task’s address space that don’t have an explicit VMA policy will fall back to the task policy, which may itself fall back to the System Default Policy.”…””}”(hj„h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´KRhjOubhÝ)”}”(hŒ-VMA policies have a few complicating details:”h]”hŒ-VMA policies have a few complicating details:”…””}”(hj’h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´KXhjOubhŒ bullet_list”“”)”}”(hhh]”(hŒ list_item”“”)”}”(hXòVMA policy applies ONLY to anonymous pages. These include pages allocated for anonymous segments, such as the task stack and heap, and any regions of the address space mmap()ed with the MAP_ANONYMOUS flag. If a VMA policy is applied to a file mapping, it will be ignored if the mapping used the MAP_SHARED flag. If the file mapping used the MAP_PRIVATE flag, the VMA policy will only be applied when an anonymous page is allocated on an attempt to write to the mapping-- i.e., at Copy-On-Write. ”h]”hÝ)”}”(hXñVMA policy applies ONLY to anonymous pages. These include pages allocated for anonymous segments, such as the task stack and heap, and any regions of the address space mmap()ed with the MAP_ANONYMOUS flag. If a VMA policy is applied to a file mapping, it will be ignored if the mapping used the MAP_SHARED flag. If the file mapping used the MAP_PRIVATE flag, the VMA policy will only be applied when an anonymous page is allocated on an attempt to write to the mapping-- i.e., at Copy-On-Write.”h]”hXñVMA policy applies ONLY to anonymous pages. These include pages allocated for anonymous segments, such as the task stack and heap, and any regions of the address space mmap()ed with the MAP_ANONYMOUS flag. If a VMA policy is applied to a file mapping, it will be ignored if the mapping used the MAP_SHARED flag. If the file mapping used the MAP_PRIVATE flag, the VMA policy will only be applied when an anonymous page is allocated on an attempt to write to the mapping-- i.e., at Copy-On-Write.”…””}”(hj«h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´KZhj§ubah}”(h]”h ]”h"]”h$]”h&]”uh1j¥hj¢ubj¦)”}”(hXµVMA policies are shared between all tasks that share a virtual address space--a.k.a. threads--independent of when the policy is installed; and they are inherited across fork(). However, because VMA policies refer to a specific region of a task's address space, and because the address space is discarded and recreated on exec*(), VMA policies are NOT inheritable across exec(). Thus, only NUMA-aware applications may use VMA policies. ”h]”hÝ)”}”(hX´VMA policies are shared between all tasks that share a virtual address space--a.k.a. threads--independent of when the policy is installed; and they are inherited across fork(). However, because VMA policies refer to a specific region of a task's address space, and because the address space is discarded and recreated on exec*(), VMA policies are NOT inheritable across exec(). Thus, only NUMA-aware applications may use VMA policies.”h]”hX¶VMA policies are shared between all tasks that share a virtual address space--a.k.a. threads--independent of when the policy is installed; and they are inherited across fork(). However, because VMA policies refer to a specific region of a task’s address space, and because the address space is discarded and recreated on exec*(), VMA policies are NOT inheritable across exec(). Thus, only NUMA-aware applications may use VMA policies.”…””}”(hjÃh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´Kdhj¿ubah}”(h]”h ]”h"]”h$]”h&]”uh1j¥hj¢ubj¦)”}”(hŒÂA task may install a new VMA policy on a sub-range of a previously mmap()ed region. When this happens, Linux splits the existing virtual memory area into 2 or 3 VMAs, each with its own policy. ”h]”hÝ)”}”(hŒÁA task may install a new VMA policy on a sub-range of a previously mmap()ed region. When this happens, Linux splits the existing virtual memory area into 2 or 3 VMAs, each with its own policy.”h]”hŒÁA task may install a new VMA policy on a sub-range of a previously mmap()ed region. When this happens, Linux splits the existing virtual memory area into 2 or 3 VMAs, each with its own policy.”…””}”(hjÛh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´Kmhj×ubah}”(h]”h ]”h"]”h$]”h&]”uh1j¥hj¢ubj¦)”}”(hXsBy default, VMA policy applies only to pages allocated after the policy is installed. Any pages already faulted into the VMA range remain where they were allocated based on the policy at the time they were allocated. However, since 2.6.16, Linux supports page migration via the mbind() system call, so that page contents can be moved to match a newly installed policy. ”h]”hÝ)”}”(hXrBy default, VMA policy applies only to pages allocated after the policy is installed. Any pages already faulted into the VMA range remain where they were allocated based on the policy at the time they were allocated. However, since 2.6.16, Linux supports page migration via the mbind() system call, so that page contents can be moved to match a newly installed policy.”h]”hXrBy default, VMA policy applies only to pages allocated after the policy is installed. Any pages already faulted into the VMA range remain where they were allocated based on the policy at the time they were allocated. However, since 2.6.16, Linux supports page migration via the mbind() system call, so that page contents can be moved to match a newly installed policy.”…””}”(hjóh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´Krhjïubah}”(h]”h ]”h"]”h$]”h&]”uh1j¥hj¢ubeh}”(h]”h ]”h"]”h$]”h&]”Œbullet”Œ*”uh1j h³hÊh´KZhjOubeh}”(h]”h ]”h"]”h$]”h&]”uh1jŠhj=ubeh}”(h]”h ]”h"]”h$]”h&]”uh1jth³hÊh´Kxhj:ubju)”}”(hXShared Policy Conceptually, shared policies apply to "memory objects" mapped shared into one or more tasks' distinct address spaces. An application installs shared policies the same way as VMA policies--using the mbind() system call specifying a range of virtual addresses that map the shared object. However, unlike VMA policies, which can be considered to be an attribute of a range of a task's address space, shared policies apply directly to the shared object. Thus, all tasks that attach to the object share the policy, and all pages allocated for the shared object, by any task, will obey the shared policy. As of 2.6.22, only shared memory segments, created by shmget() or mmap(MAP_ANONYMOUS|MAP_SHARED), support shared policy. When shared policy support was added to Linux, the associated data structures were added to hugetlbfs shmem segments. At the time, hugetlbfs did not support allocation at fault time--a.k.a lazy allocation--so hugetlbfs shmem segments were never "hooked up" to the shared policy support. Although hugetlbfs segments now support lazy allocation, their support for shared policy has not been completed. As mentioned above in :ref:`VMA policies ` section, allocations of page cache pages for regular files mmap()ed with MAP_SHARED ignore any VMA policy installed on the virtual address range backed by the shared file mapping. Rather, shared page cache pages, including pages backing private mappings that have not yet been written by the task, follow task policy, if any, else System Default Policy. The shared policy infrastructure supports different policies on subset ranges of the shared object. However, Linux still splits the VMA of the task that installs the policy for each range of distinct policy. Thus, different tasks that attach to a shared memory segment can have different VMA configurations mapping that one shared object. This can be seen by examining the /proc//numa_maps of tasks sharing a shared memory region, when one task has installed shared policy on one or more ranges of the region. ”h]”(j{)”}”(hŒ Shared Policy”h]”hŒ Shared Policy”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jzh³hÊh´Kžhjubj‹)”}”(hhh]”(hÝ)”}”(hXZConceptually, shared policies apply to "memory objects" mapped shared into one or more tasks' distinct address spaces. An application installs shared policies the same way as VMA policies--using the mbind() system call specifying a range of virtual addresses that map the shared object. However, unlike VMA policies, which can be considered to be an attribute of a range of a task's address space, shared policies apply directly to the shared object. Thus, all tasks that attach to the object share the policy, and all pages allocated for the shared object, by any task, will obey the shared policy.”h]”hXbConceptually, shared policies apply to “memory objects†mapped shared into one or more tasks’ distinct address spaces. An application installs shared policies the same way as VMA policies--using the mbind() system call specifying a range of virtual addresses that map the shared object. However, unlike VMA policies, which can be considered to be an attribute of a range of a task’s address space, shared policies apply directly to the shared object. Thus, all tasks that attach to the object share the policy, and all pages allocated for the shared object, by any task, will obey the shared policy.”…””}”(hj0h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´K{hj-ubhÝ)”}”(hX As of 2.6.22, only shared memory segments, created by shmget() or mmap(MAP_ANONYMOUS|MAP_SHARED), support shared policy. When shared policy support was added to Linux, the associated data structures were added to hugetlbfs shmem segments. At the time, hugetlbfs did not support allocation at fault time--a.k.a lazy allocation--so hugetlbfs shmem segments were never "hooked up" to the shared policy support. Although hugetlbfs segments now support lazy allocation, their support for shared policy has not been completed.”h]”hXAs of 2.6.22, only shared memory segments, created by shmget() or mmap(MAP_ANONYMOUS|MAP_SHARED), support shared policy. When shared policy support was added to Linux, the associated data structures were added to hugetlbfs shmem segments. At the time, hugetlbfs did not support allocation at fault time--a.k.a lazy allocation--so hugetlbfs shmem segments were never “hooked up†to the shared policy support. Although hugetlbfs segments now support lazy allocation, their support for shared policy has not been completed.”…””}”(hj>h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´K†hj-ubhÝ)”}”(hX™As mentioned above in :ref:`VMA policies ` section, allocations of page cache pages for regular files mmap()ed with MAP_SHARED ignore any VMA policy installed on the virtual address range backed by the shared file mapping. Rather, shared page cache pages, including pages backing private mappings that have not yet been written by the task, follow task policy, if any, else System Default Policy.”h]”(hŒAs mentioned above in ”…””}”(hjLh²hh³Nh´Nubh)”}”(hŒ :ref:`VMA policies `”h]”j )”}”(hjVh]”hŒ VMA policies”…””}”(hjXh²hh³Nh´Nubah}”(h]”h ]”(jŒstd”Œstd-ref”eh"]”h$]”h&]”uh1j hjTubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j%Œ refdomain”jbŒreftype”Œref”Œ refexplicit”ˆŒrefwarn”ˆj+Œ vma_policy”uh1hh³hÊh´KhjLubhXc section, allocations of page cache pages for regular files mmap()ed with MAP_SHARED ignore any VMA policy installed on the virtual address range backed by the shared file mapping. Rather, shared page cache pages, including pages backing private mappings that have not yet been written by the task, follow task policy, if any, else System Default Policy.”…””}”(hjLh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´Khj-ubhÝ)”}”(hXThe shared policy infrastructure supports different policies on subset ranges of the shared object. However, Linux still splits the VMA of the task that installs the policy for each range of distinct policy. Thus, different tasks that attach to a shared memory segment can have different VMA configurations mapping that one shared object. This can be seen by examining the /proc//numa_maps of tasks sharing a shared memory region, when one task has installed shared policy on one or more ranges of the region.”h]”hXThe shared policy infrastructure supports different policies on subset ranges of the shared object. However, Linux still splits the VMA of the task that installs the policy for each range of distinct policy. Thus, different tasks that attach to a shared memory segment can have different VMA configurations mapping that one shared object. This can be seen by examining the /proc//numa_maps of tasks sharing a shared memory region, when one task has installed shared policy on one or more ranges of the region.”…””}”(hj~h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´K—hj-ubeh}”(h]”h ]”h"]”h$]”h&]”uh1jŠhjubeh}”(h]”h ]”h"]”h$]”h&]”uh1jth³hÊh´Kžhj:h²hubeh}”(h]”j9ah ]”h"]”Œ vma_policy”ah$]”h&]”uh1johjPh²hh³Nh´NŒexpect_referenced_by_name”}”jœj.sŒexpect_referenced_by_id”}”j9j.subeh}”(h]”Œscope-of-memory-policies”ah ]”h"]”Œscope of memory policies”ah$]”h&]”uh1hµhj?h²hh³hÊh´Kubh¶)”}”(hhh]”(h»)”}”(hŒComponents of Memory Policies”h]”hŒComponents of Memory Policies”…””}”(hj®h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhj«h²hh³hÊh´K¡ubhÝ)”}”(hXA NUMA memory policy consists of a "mode", optional mode flags, and an optional set of nodes. The mode determines the behavior of the policy, the optional mode flags determine the behavior of the mode, and the optional set of nodes can be viewed as the arguments to the policy behavior.”h]”hX#A NUMA memory policy consists of a “modeâ€, optional mode flags, and an optional set of nodes. The mode determines the behavior of the policy, the optional mode flags determine the behavior of the mode, and the optional set of nodes can be viewed as the arguments to the policy behavior.”…””}”(hj¼h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´K£hj«h²hubhÝ)”}”(hŒÄInternally, memory policies are implemented by a reference counted structure, struct mempolicy. Details of this structure will be discussed in context, below, as required to explain the behavior.”h]”hŒÄInternally, memory policies are implemented by a reference counted structure, struct mempolicy. Details of this structure will be discussed in context, below, as required to explain the behavior.”…””}”(hjÊh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´K©hj«h²hubhÝ)”}”(hŒ=NUMA memory policy supports the following 4 behavioral modes:”h]”hŒ=NUMA memory policy supports the following 4 behavioral modes:”…””}”(hjØh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´K­hj«h²hubjp)”}”(hhh]”(ju)”}”(hX¦Default Mode--MPOL_DEFAULT This mode is only used in the memory policy APIs. Internally, MPOL_DEFAULT is converted to the NULL memory policy in all policy scopes. Any existing non-default policy will simply be removed when MPOL_DEFAULT is specified. As a result, MPOL_DEFAULT means "fall back to the next most specific policy scope." For example, a NULL or default task policy will fall back to the system default policy. A NULL or default vma policy will fall back to the task policy. When specified in one of the memory policy APIs, the Default mode does not use the optional set of nodes. It is an error for the set of nodes specified for this policy to be non-empty. ”h]”(j{)”}”(hŒDefault Mode--MPOL_DEFAULT”h]”hŒDefault Mode--MPOL_DEFAULT”…””}”(hjíh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jzh³hÊh´K¿hjéubj‹)”}”(hhh]”(hÝ)”}”(hX5This mode is only used in the memory policy APIs. Internally, MPOL_DEFAULT is converted to the NULL memory policy in all policy scopes. Any existing non-default policy will simply be removed when MPOL_DEFAULT is specified. As a result, MPOL_DEFAULT means "fall back to the next most specific policy scope."”h]”hX9This mode is only used in the memory policy APIs. Internally, MPOL_DEFAULT is converted to the NULL memory policy in all policy scopes. Any existing non-default policy will simply be removed when MPOL_DEFAULT is specified. As a result, MPOL_DEFAULT means “fall back to the next most specific policy scope.—…””}”(hjþh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´K°hjûubhÝ)”}”(hŒ˜For example, a NULL or default task policy will fall back to the system default policy. A NULL or default vma policy will fall back to the task policy.”h]”hŒ˜For example, a NULL or default task policy will fall back to the system default policy. A NULL or default vma policy will fall back to the task policy.”…””}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´K·hjûubhÝ)”}”(hŒiWhen specified in one of the memory policy APIs, the Default mode does not use the optional set of nodes.”h]”hŒiWhen specified in one of the memory policy APIs, the Default mode does not use the optional set of nodes.”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´K»hjûubhÝ)”}”(hŒNIt is an error for the set of nodes specified for this policy to be non-empty.”h]”hŒNIt is an error for the set of nodes specified for this policy to be non-empty.”…””}”(hj(h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´K¾hjûubeh}”(h]”h ]”h"]”h$]”h&]”uh1jŠhjéubeh}”(h]”h ]”h"]”h$]”h&]”uh1jth³hÊh´K¿hjæubju)”}”(hŒðMPOL_BIND This mode specifies that memory must come from the set of nodes specified by the policy. Memory will be allocated from the node in the set with sufficient free memory that is closest to the node where the allocation takes place. ”h]”(j{)”}”(hŒ MPOL_BIND”h]”hŒ MPOL_BIND”…””}”(hjFh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jzh³hÊh´KÅhjBubj‹)”}”(hhh]”hÝ)”}”(hŒåThis mode specifies that memory must come from the set of nodes specified by the policy. Memory will be allocated from the node in the set with sufficient free memory that is closest to the node where the allocation takes place.”h]”hŒåThis mode specifies that memory must come from the set of nodes specified by the policy. Memory will be allocated from the node in the set with sufficient free memory that is closest to the node where the allocation takes place.”…””}”(hjWh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´KÂhjTubah}”(h]”h ]”h"]”h$]”h&]”uh1jŠhjBubeh}”(h]”h ]”h"]”h$]”h&]”uh1jth³hÊh´KÅhjæh²hubju)”}”(hXšMPOL_PREFERRED This mode specifies that the allocation should be attempted from the single node specified in the policy. If that allocation fails, the kernel will search other nodes, in order of increasing distance from the preferred node based on information provided by the platform firmware. Internally, the Preferred policy uses a single node--the preferred_node member of struct mempolicy. When the internal mode flag MPOL_F_LOCAL is set, the preferred_node is ignored and the policy is interpreted as local allocation. "Local" allocation policy can be viewed as a Preferred policy that starts at the node containing the cpu where the allocation takes place. It is possible for the user to specify that local allocation is always preferred by passing an empty nodemask with this mode. If an empty nodemask is passed, the policy cannot use the MPOL_F_STATIC_NODES or MPOL_F_RELATIVE_NODES flags described below. ”h]”(j{)”}”(hŒMPOL_PREFERRED”h]”hŒMPOL_PREFERRED”…””}”(hjuh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jzh³hÊh´KÚhjqubj‹)”}”(hhh]”(hÝ)”}”(hXThis mode specifies that the allocation should be attempted from the single node specified in the policy. If that allocation fails, the kernel will search other nodes, in order of increasing distance from the preferred node based on information provided by the platform firmware.”h]”hXThis mode specifies that the allocation should be attempted from the single node specified in the policy. If that allocation fails, the kernel will search other nodes, in order of increasing distance from the preferred node based on information provided by the platform firmware.”…””}”(hj†h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´KÈhjƒubhÝ)”}”(hXrInternally, the Preferred policy uses a single node--the preferred_node member of struct mempolicy. When the internal mode flag MPOL_F_LOCAL is set, the preferred_node is ignored and the policy is interpreted as local allocation. "Local" allocation policy can be viewed as a Preferred policy that starts at the node containing the cpu where the allocation takes place.”h]”hXvInternally, the Preferred policy uses a single node--the preferred_node member of struct mempolicy. When the internal mode flag MPOL_F_LOCAL is set, the preferred_node is ignored and the policy is interpreted as local allocation. “Local†allocation policy can be viewed as a Preferred policy that starts at the node containing the cpu where the allocation takes place.”…””}”(hj”h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´KÎhjƒubhÝ)”}”(hŒüIt is possible for the user to specify that local allocation is always preferred by passing an empty nodemask with this mode. If an empty nodemask is passed, the policy cannot use the MPOL_F_STATIC_NODES or MPOL_F_RELATIVE_NODES flags described below.”h]”hŒüIt is possible for the user to specify that local allocation is always preferred by passing an empty nodemask with this mode. If an empty nodemask is passed, the policy cannot use the MPOL_F_STATIC_NODES or MPOL_F_RELATIVE_NODES flags described below.”…””}”(hj¢h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´KÖhjƒubeh}”(h]”h ]”h"]”h$]”h&]”uh1jŠhjqubeh}”(h]”h ]”h"]”h$]”h&]”uh1jth³hÊh´KÚhjæh²hubju)”}”(hXàMPOL_INTERLEAVE This mode specifies that page allocations be interleaved, on a page granularity, across the nodes specified in the policy. This mode also behaves slightly differently, based on the context where it is used: For allocation of anonymous pages and shared memory pages, Interleave mode indexes the set of nodes specified by the policy using the page offset of the faulting address into the segment [VMA] containing the address modulo the number of nodes specified by the policy. It then attempts to allocate a page, starting at the selected node, as if the node had been specified by a Preferred policy or had been selected by a local allocation. That is, allocation will follow the per node zonelist. For allocation of page cache pages, Interleave mode indexes the set of nodes specified by the policy using a node counter maintained per task. This counter wraps around to the lowest specified node after it reaches the highest specified node. This will tend to spread the pages out over the nodes specified by the policy based on the order in which they are allocated, rather than based on any page offset into an address range or file. During system boot up, the temporary interleaved system default policy works in this mode. ”h]”(j{)”}”(hŒMPOL_INTERLEAVE”h]”hŒMPOL_INTERLEAVE”…””}”(hjÀh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jzh³hÊh´Kôhj¼ubj‹)”}”(hhh]”(hÝ)”}”(hŒÎThis mode specifies that page allocations be interleaved, on a page granularity, across the nodes specified in the policy. This mode also behaves slightly differently, based on the context where it is used:”h]”hŒÎThis mode specifies that page allocations be interleaved, on a page granularity, across the nodes specified in the policy. This mode also behaves slightly differently, based on the context where it is used:”…””}”(hjÑh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´KÝhjÎubhÝ)”}”(hXìFor allocation of anonymous pages and shared memory pages, Interleave mode indexes the set of nodes specified by the policy using the page offset of the faulting address into the segment [VMA] containing the address modulo the number of nodes specified by the policy. It then attempts to allocate a page, starting at the selected node, as if the node had been specified by a Preferred policy or had been selected by a local allocation. That is, allocation will follow the per node zonelist.”h]”hXìFor allocation of anonymous pages and shared memory pages, Interleave mode indexes the set of nodes specified by the policy using the page offset of the faulting address into the segment [VMA] containing the address modulo the number of nodes specified by the policy. It then attempts to allocate a page, starting at the selected node, as if the node had been specified by a Preferred policy or had been selected by a local allocation. That is, allocation will follow the per node zonelist.”…””}”(hjßh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´KâhjÎubhÝ)”}”(hXFor allocation of page cache pages, Interleave mode indexes the set of nodes specified by the policy using a node counter maintained per task. This counter wraps around to the lowest specified node after it reaches the highest specified node. This will tend to spread the pages out over the nodes specified by the policy based on the order in which they are allocated, rather than based on any page offset into an address range or file. During system boot up, the temporary interleaved system default policy works in this mode.”h]”hXFor allocation of page cache pages, Interleave mode indexes the set of nodes specified by the policy using a node counter maintained per task. This counter wraps around to the lowest specified node after it reaches the highest specified node. This will tend to spread the pages out over the nodes specified by the policy based on the order in which they are allocated, rather than based on any page offset into an address range or file. During system boot up, the temporary interleaved system default policy works in this mode.”…””}”(hjíh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´KìhjÎubeh}”(h]”h ]”h"]”h$]”h&]”uh1jŠhj¼ubeh}”(h]”h ]”h"]”h$]”h&]”uh1jth³hÊh´Kôhjæh²hubju)”}”(hXLMPOL_PREFERRED_MANY This mode specifies that the allocation should be preferably satisfied from the nodemask specified in the policy. If there is a memory pressure on all nodes in the nodemask, the allocation can fall back to all existing numa nodes. This is effectively MPOL_PREFERRED allowed for a mask rather than a single node. ”h]”(j{)”}”(hŒMPOL_PREFERRED_MANY”h]”hŒMPOL_PREFERRED_MANY”…””}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jzh³hÊh´Kûhjubj‹)”}”(hhh]”hÝ)”}”(hX7This mode specifies that the allocation should be preferably satisfied from the nodemask specified in the policy. If there is a memory pressure on all nodes in the nodemask, the allocation can fall back to all existing numa nodes. This is effectively MPOL_PREFERRED allowed for a mask rather than a single node.”h]”hX7This mode specifies that the allocation should be preferably satisfied from the nodemask specified in the policy. If there is a memory pressure on all nodes in the nodemask, the allocation can fall back to all existing numa nodes. This is effectively MPOL_PREFERRED allowed for a mask rather than a single node.”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´K÷hjubah}”(h]”h ]”h"]”h$]”h&]”uh1jŠhjubeh}”(h]”h ]”h"]”h$]”h&]”uh1jth³hÊh´Kûhjæh²hubju)”}”(hX{MPOL_WEIGHTED_INTERLEAVE This mode operates the same as MPOL_INTERLEAVE, except that interleaving behavior is executed based on weights set in /sys/kernel/mm/mempolicy/weighted_interleave/ Weighted interleave allocates pages on nodes according to a weight. For example if nodes [0,1] are weighted [5,2], 5 pages will be allocated on node0 for every 2 pages allocated on node1. ”h]”(j{)”}”(hŒMPOL_WEIGHTED_INTERLEAVE”h]”hŒMPOL_WEIGHTED_INTERLEAVE”…””}”(hj:h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jzh³hÊh´Mhj6ubj‹)”}”(hhh]”(hÝ)”}”(hŒ£This mode operates the same as MPOL_INTERLEAVE, except that interleaving behavior is executed based on weights set in /sys/kernel/mm/mempolicy/weighted_interleave/”h]”hŒ£This mode operates the same as MPOL_INTERLEAVE, except that interleaving behavior is executed based on weights set in /sys/kernel/mm/mempolicy/weighted_interleave/”…””}”(hjKh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´KþhjHubhÝ)”}”(hŒ¼Weighted interleave allocates pages on nodes according to a weight. For example if nodes [0,1] are weighted [5,2], 5 pages will be allocated on node0 for every 2 pages allocated on node1.”h]”hŒ¼Weighted interleave allocates pages on nodes according to a weight. For example if nodes [0,1] are weighted [5,2], 5 pages will be allocated on node0 for every 2 pages allocated on node1.”…””}”(hjYh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´MhjHubeh}”(h]”h ]”h"]”h$]”h&]”uh1jŠhj6ubeh}”(h]”h ]”h"]”h$]”h&]”uh1jth³hÊh´Mhjæh²hubeh}”(h]”h ]”h"]”h$]”h&]”uh1johj«h²hh³hÊh´NubhÝ)”}”(hŒ>NUMA memory policy supports the following optional mode flags:”h]”hŒ>NUMA memory policy supports the following optional mode flags:”…””}”(hjyh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´Mhj«h²hubjp)”}”(hhh]”(ju)”}”(hXBMPOL_F_STATIC_NODES This flag specifies that the nodemask passed by the user should not be remapped if the task or VMA's set of allowed nodes changes after the memory policy has been defined. Without this flag, any time a mempolicy is rebound because of a change in the set of allowed nodes, the preferred nodemask (Preferred Many), preferred node (Preferred) or nodemask (Bind, Interleave) is remapped to the new set of allowed nodes. This may result in nodes being used that were previously undesired. With this flag, if the user-specified nodes overlap with the nodes allowed by the task's cpuset, then the memory policy is applied to their intersection. If the two sets of nodes do not overlap, the Default policy is used. For example, consider a task that is attached to a cpuset with mems 1-3 that sets an Interleave policy over the same set. If the cpuset's mems change to 3-5, the Interleave will now occur over nodes 3, 4, and 5. With this flag, however, since only node 3 is allowed from the user's nodemask, the "interleave" only occurs over that node. If no nodes from the user's nodemask are now allowed, the Default behavior is used. MPOL_F_STATIC_NODES cannot be combined with the MPOL_F_RELATIVE_NODES flag. It also cannot be used for MPOL_PREFERRED policies that were created with an empty nodemask (local allocation). ”h]”(j{)”}”(hŒMPOL_F_STATIC_NODES”h]”hŒMPOL_F_STATIC_NODES”…””}”(hjŽh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jzh³hÊh´M#hjŠubj‹)”}”(hhh]”(hÝ)”}”(hŒ«This flag specifies that the nodemask passed by the user should not be remapped if the task or VMA's set of allowed nodes changes after the memory policy has been defined.”h]”hŒ­This flag specifies that the nodemask passed by the user should not be remapped if the task or VMA’s set of allowed nodes changes after the memory policy has been defined.”…””}”(hjŸh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´M hjœubhÝ)”}”(hX8Without this flag, any time a mempolicy is rebound because of a change in the set of allowed nodes, the preferred nodemask (Preferred Many), preferred node (Preferred) or nodemask (Bind, Interleave) is remapped to the new set of allowed nodes. This may result in nodes being used that were previously undesired.”h]”hX8Without this flag, any time a mempolicy is rebound because of a change in the set of allowed nodes, the preferred nodemask (Preferred Many), preferred node (Preferred) or nodemask (Bind, Interleave) is remapped to the new set of allowed nodes. This may result in nodes being used that were previously undesired.”…””}”(hj­h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´M hjœubhÝ)”}”(hŒßWith this flag, if the user-specified nodes overlap with the nodes allowed by the task's cpuset, then the memory policy is applied to their intersection. If the two sets of nodes do not overlap, the Default policy is used.”h]”hŒáWith this flag, if the user-specified nodes overlap with the nodes allowed by the task’s cpuset, then the memory policy is applied to their intersection. If the two sets of nodes do not overlap, the Default policy is used.”…””}”(hj»h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´MhjœubhÝ)”}”(hX§For example, consider a task that is attached to a cpuset with mems 1-3 that sets an Interleave policy over the same set. If the cpuset's mems change to 3-5, the Interleave will now occur over nodes 3, 4, and 5. With this flag, however, since only node 3 is allowed from the user's nodemask, the "interleave" only occurs over that node. If no nodes from the user's nodemask are now allowed, the Default behavior is used.”h]”hX±For example, consider a task that is attached to a cpuset with mems 1-3 that sets an Interleave policy over the same set. If the cpuset’s mems change to 3-5, the Interleave will now occur over nodes 3, 4, and 5. With this flag, however, since only node 3 is allowed from the user’s nodemask, the “interleave†only occurs over that node. If no nodes from the user’s nodemask are now allowed, the Default behavior is used.”…””}”(hjÉh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´MhjœubhÝ)”}”(hŒ¼MPOL_F_STATIC_NODES cannot be combined with the MPOL_F_RELATIVE_NODES flag. It also cannot be used for MPOL_PREFERRED policies that were created with an empty nodemask (local allocation).”h]”hŒ¼MPOL_F_STATIC_NODES cannot be combined with the MPOL_F_RELATIVE_NODES flag. It also cannot be used for MPOL_PREFERRED policies that were created with an empty nodemask (local allocation).”…””}”(hj×h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´M hjœubeh}”(h]”h ]”h"]”h$]”h&]”uh1jŠhjŠubeh}”(h]”h ]”h"]”h$]”h&]”uh1jth³hÊh´M#hj‡ubju)”}”(hXä MPOL_F_RELATIVE_NODES This flag specifies that the nodemask passed by the user will be mapped relative to the set of the task or VMA's set of allowed nodes. The kernel stores the user-passed nodemask, and if the allowed nodes changes, then that original nodemask will be remapped relative to the new set of allowed nodes. Without this flag (and without MPOL_F_STATIC_NODES), anytime a mempolicy is rebound because of a change in the set of allowed nodes, the node (Preferred) or nodemask (Bind, Interleave) is remapped to the new set of allowed nodes. That remap may not preserve the relative nature of the user's passed nodemask to its set of allowed nodes upon successive rebinds: a nodemask of 1,3,5 may be remapped to 7-9 and then to 1-3 if the set of allowed nodes is restored to its original state. With this flag, the remap is done so that the node numbers from the user's passed nodemask are relative to the set of allowed nodes. In other words, if nodes 0, 2, and 4 are set in the user's nodemask, the policy will be effected over the first (and in the Bind or Interleave case, the third and fifth) nodes in the set of allowed nodes. The nodemask passed by the user represents nodes relative to task or VMA's set of allowed nodes. If the user's nodemask includes nodes that are outside the range of the new set of allowed nodes (for example, node 5 is set in the user's nodemask when the set of allowed nodes is only 0-3), then the remap wraps around to the beginning of the nodemask and, if not already set, sets the node in the mempolicy nodemask. For example, consider a task that is attached to a cpuset with mems 2-5 that sets an Interleave policy over the same set with MPOL_F_RELATIVE_NODES. If the cpuset's mems change to 3-7, the interleave now occurs over nodes 3,5-7. If the cpuset's mems then change to 0,2-3,5, then the interleave occurs over nodes 0,2-3,5. Thanks to the consistent remapping, applications preparing nodemasks to specify memory policies using this flag should disregard their current, actual cpuset imposed memory placement and prepare the nodemask as if they were always located on memory nodes 0 to N-1, where N is the number of memory nodes the policy is intended to manage. Let the kernel then remap to the set of memory nodes allowed by the task's cpuset, as that may change over time. MPOL_F_RELATIVE_NODES cannot be combined with the MPOL_F_STATIC_NODES flag. It also cannot be used for MPOL_PREFERRED policies that were created with an empty nodemask (local allocation). ”h]”(j{)”}”(hŒMPOL_F_RELATIVE_NODES”h]”hŒMPOL_F_RELATIVE_NODES”…””}”(hjõh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jzh³hÊh´MVhjñubj‹)”}”(hhh]”(hÝ)”}”(hX,This flag specifies that the nodemask passed by the user will be mapped relative to the set of the task or VMA's set of allowed nodes. The kernel stores the user-passed nodemask, and if the allowed nodes changes, then that original nodemask will be remapped relative to the new set of allowed nodes.”h]”hX.This flag specifies that the nodemask passed by the user will be mapped relative to the set of the task or VMA’s set of allowed nodes. The kernel stores the user-passed nodemask, and if the allowed nodes changes, then that original nodemask will be remapped relative to the new set of allowed nodes.”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´M&hjubhÝ)”}”(hXãWithout this flag (and without MPOL_F_STATIC_NODES), anytime a mempolicy is rebound because of a change in the set of allowed nodes, the node (Preferred) or nodemask (Bind, Interleave) is remapped to the new set of allowed nodes. That remap may not preserve the relative nature of the user's passed nodemask to its set of allowed nodes upon successive rebinds: a nodemask of 1,3,5 may be remapped to 7-9 and then to 1-3 if the set of allowed nodes is restored to its original state.”h]”hXåWithout this flag (and without MPOL_F_STATIC_NODES), anytime a mempolicy is rebound because of a change in the set of allowed nodes, the node (Preferred) or nodemask (Bind, Interleave) is remapped to the new set of allowed nodes. That remap may not preserve the relative nature of the user’s passed nodemask to its set of allowed nodes upon successive rebinds: a nodemask of 1,3,5 may be remapped to 7-9 and then to 1-3 if the set of allowed nodes is restored to its original state.”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´M,hjubhÝ)”}”(hX´With this flag, the remap is done so that the node numbers from the user's passed nodemask are relative to the set of allowed nodes. In other words, if nodes 0, 2, and 4 are set in the user's nodemask, the policy will be effected over the first (and in the Bind or Interleave case, the third and fifth) nodes in the set of allowed nodes. The nodemask passed by the user represents nodes relative to task or VMA's set of allowed nodes.”h]”hXºWith this flag, the remap is done so that the node numbers from the user’s passed nodemask are relative to the set of allowed nodes. In other words, if nodes 0, 2, and 4 are set in the user’s nodemask, the policy will be effected over the first (and in the Bind or Interleave case, the third and fifth) nodes in the set of allowed nodes. The nodemask passed by the user represents nodes relative to task or VMA’s set of allowed nodes.”…””}”(hj"h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´M5hjubhÝ)”}”(hX>If the user's nodemask includes nodes that are outside the range of the new set of allowed nodes (for example, node 5 is set in the user's nodemask when the set of allowed nodes is only 0-3), then the remap wraps around to the beginning of the nodemask and, if not already set, sets the node in the mempolicy nodemask.”h]”hXBIf the user’s nodemask includes nodes that are outside the range of the new set of allowed nodes (for example, node 5 is set in the user’s nodemask when the set of allowed nodes is only 0-3), then the remap wraps around to the beginning of the nodemask and, if not already set, sets the node in the mempolicy nodemask.”…””}”(hj0h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´M=hjubhÝ)”}”(hXBFor example, consider a task that is attached to a cpuset with mems 2-5 that sets an Interleave policy over the same set with MPOL_F_RELATIVE_NODES. If the cpuset's mems change to 3-7, the interleave now occurs over nodes 3,5-7. If the cpuset's mems then change to 0,2-3,5, then the interleave occurs over nodes 0,2-3,5.”h]”hXFFor example, consider a task that is attached to a cpuset with mems 2-5 that sets an Interleave policy over the same set with MPOL_F_RELATIVE_NODES. If the cpuset’s mems change to 3-7, the interleave now occurs over nodes 3,5-7. If the cpuset’s mems then change to 0,2-3,5, then the interleave occurs over nodes 0,2-3,5.”…””}”(hj>h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´MChjubhÝ)”}”(hXÂThanks to the consistent remapping, applications preparing nodemasks to specify memory policies using this flag should disregard their current, actual cpuset imposed memory placement and prepare the nodemask as if they were always located on memory nodes 0 to N-1, where N is the number of memory nodes the policy is intended to manage. Let the kernel then remap to the set of memory nodes allowed by the task's cpuset, as that may change over time.”h]”hXÄThanks to the consistent remapping, applications preparing nodemasks to specify memory policies using this flag should disregard their current, actual cpuset imposed memory placement and prepare the nodemask as if they were always located on memory nodes 0 to N-1, where N is the number of memory nodes the policy is intended to manage. Let the kernel then remap to the set of memory nodes allowed by the task’s cpuset, as that may change over time.”…””}”(hjLh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´MJhjubhÝ)”}”(hŒ¼MPOL_F_RELATIVE_NODES cannot be combined with the MPOL_F_STATIC_NODES flag. It also cannot be used for MPOL_PREFERRED policies that were created with an empty nodemask (local allocation).”h]”hŒ¼MPOL_F_RELATIVE_NODES cannot be combined with the MPOL_F_STATIC_NODES flag. It also cannot be used for MPOL_PREFERRED policies that were created with an empty nodemask (local allocation).”…””}”(hjZh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´MShjubeh}”(h]”h ]”h"]”h$]”h&]”uh1jŠhjñubeh}”(h]”h ]”h"]”h$]”h&]”uh1jth³hÊh´MVhj‡h²hubeh}”(h]”h ]”h"]”h$]”h&]”uh1johj«h²hh³hÊh´Nubeh}”(h]”Œcomponents-of-memory-policies”ah ]”h"]”Œcomponents of memory policies”ah$]”h&]”uh1hµhj?h²hh³hÊh´K¡ubeh}”(h]”Œmemory-policy-concepts”ah ]”h"]”Œmemory policy concepts”ah$]”h&]”uh1hµhh·h²hh³hÊh´Kubh¶)”}”(hhh]”(h»)”}”(hŒ Memory Policy Reference Counting”h]”hŒ Memory Policy Reference Counting”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjŠh²hh³hÊh´MYubhÝ)”}”(hX.To resolve use/free races, struct mempolicy contains an atomic reference count field. Internal interfaces, mpol_get()/mpol_put() increment and decrement this reference count, respectively. mpol_put() will only free the structure back to the mempolicy kmem cache when the reference count goes to zero.”h]”hX.To resolve use/free races, struct mempolicy contains an atomic reference count field. Internal interfaces, mpol_get()/mpol_put() increment and decrement this reference count, respectively. mpol_put() will only free the structure back to the mempolicy kmem cache when the reference count goes to zero.”…””}”(hj›h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´M[hjŠh²hubhÝ)”}”(hX[When a new memory policy is allocated, its reference count is initialized to '1', representing the reference held by the task that is installing the new policy. When a pointer to a memory policy structure is stored in another structure, another reference is added, as the task's reference will be dropped on completion of the policy installation.”h]”hXaWhen a new memory policy is allocated, its reference count is initialized to ‘1’, representing the reference held by the task that is installing the new policy. When a pointer to a memory policy structure is stored in another structure, another reference is added, as the task’s reference will be dropped on completion of the policy installation.”…””}”(hj©h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´MahjŠh²hubhÝ)”}”(hŒ×During run-time "usage" of the policy, we attempt to minimize atomic operations on the reference count, as this can lead to cache lines bouncing between cpus and NUMA nodes. "Usage" here means one of the following:”h]”hŒßDuring run-time “usage†of the policy, we attempt to minimize atomic operations on the reference count, as this can lead to cache lines bouncing between cpus and NUMA nodes. “Usage†here means one of the following:”…””}”(hj·h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´MghjŠh²hubhŒenumerated_list”“”)”}”(hhh]”(j¦)”}”(hŒ querying of the policy, either by the task itself [using the get_mempolicy() API discussed below] or by another task using the /proc//numa_maps interface. ”h]”hÝ)”}”(hŒŸquerying of the policy, either by the task itself [using the get_mempolicy() API discussed below] or by another task using the /proc//numa_maps interface.”h]”hŒŸquerying of the policy, either by the task itself [using the get_mempolicy() API discussed below] or by another task using the /proc//numa_maps interface.”…””}”(hjÎh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´MkhjÊubah}”(h]”h ]”h"]”h$]”h&]”uh1j¥hjÇh²hh³hÊh´Nubj¦)”}”(hXjexamination of the policy to determine the policy mode and associated node or node lists, if any, for page allocation. This is considered a "hot path". Note that for MPOL_BIND, the "usage" extends across the entire allocation process, which may sleep during page reclamation, because the BIND policy nodemask is used, by reference, to filter ineligible nodes. ”h]”hÝ)”}”(hXiexamination of the policy to determine the policy mode and associated node or node lists, if any, for page allocation. This is considered a "hot path". Note that for MPOL_BIND, the "usage" extends across the entire allocation process, which may sleep during page reclamation, because the BIND policy nodemask is used, by reference, to filter ineligible nodes.”h]”hXqexamination of the policy to determine the policy mode and associated node or node lists, if any, for page allocation. This is considered a “hot pathâ€. Note that for MPOL_BIND, the “usage†extends across the entire allocation process, which may sleep during page reclamation, because the BIND policy nodemask is used, by reference, to filter ineligible nodes.”…””}”(hjæh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´Mohjâubah}”(h]”h ]”h"]”h$]”h&]”uh1j¥hjÇh²hh³hÊh´Nubeh}”(h]”h ]”h"]”h$]”h&]”Œenumtype”Œarabic”Œprefix”hŒsuffix”Œ)”uh1jÅhjŠh²hh³hÊh´MkubhÝ)”}”(hŒQWe can avoid taking an extra reference during the usages listed above as follows:”h]”hŒQWe can avoid taking an extra reference during the usages listed above as follows:”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´MuhjŠh²hubjÆ)”}”(hhh]”(j¦)”}”(hŒ{we never need to get/free the system default policy as this is never changed nor freed, once the system is up and running. ”h]”hÝ)”}”(hŒzwe never need to get/free the system default policy as this is never changed nor freed, once the system is up and running.”h]”hŒzwe never need to get/free the system default policy as this is never changed nor freed, once the system is up and running.”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´Mxhjubah}”(h]”h ]”h"]”h$]”h&]”uh1j¥hjh²hh³hÊh´Nubj¦)”}”(hXÁfor querying the policy, we do not need to take an extra reference on the target task's task policy nor vma policies because we always acquire the task's mm's mmap_lock for read during the query. The set_mempolicy() and mbind() APIs [see below] always acquire the mmap_lock for write when installing or replacing task or vma policies. Thus, there is no possibility of a task or thread freeing a policy while another task or thread is querying it. ”h]”hÝ)”}”(hXÀfor querying the policy, we do not need to take an extra reference on the target task's task policy nor vma policies because we always acquire the task's mm's mmap_lock for read during the query. The set_mempolicy() and mbind() APIs [see below] always acquire the mmap_lock for write when installing or replacing task or vma policies. Thus, there is no possibility of a task or thread freeing a policy while another task or thread is querying it.”•Xh]”hXÆfor querying the policy, we do not need to take an extra reference on the target task’s task policy nor vma policies because we always acquire the task’s mm’s mmap_lock for read during the query. The set_mempolicy() and mbind() APIs [see below] always acquire the mmap_lock for write when installing or replacing task or vma policies. Thus, there is no possibility of a task or thread freeing a policy while another task or thread is querying it.”…””}”(hj2h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´M{hj.ubah}”(h]”h ]”h"]”h$]”h&]”uh1j¥hjh²hh³hÊh´Nubj¦)”}”(hX"Page allocation usage of task or vma policy occurs in the fault path where we hold them mmap_lock for read. Again, because replacing the task or vma policy requires that the mmap_lock be held for write, the policy can't be freed out from under us while we're using it for page allocation. ”h]”hÝ)”}”(hX!Page allocation usage of task or vma policy occurs in the fault path where we hold them mmap_lock for read. Again, because replacing the task or vma policy requires that the mmap_lock be held for write, the policy can't be freed out from under us while we're using it for page allocation.”h]”hX%Page allocation usage of task or vma policy occurs in the fault path where we hold them mmap_lock for read. Again, because replacing the task or vma policy requires that the mmap_lock be held for write, the policy can’t be freed out from under us while we’re using it for page allocation.”…””}”(hjJh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´MƒhjFubah}”(h]”h ]”h"]”h$]”h&]”uh1j¥hjh²hh³hÊh´Nubj¦)”}”(hXShared policies require special consideration. One task can replace a shared memory policy while another task, with a distinct mmap_lock, is querying or allocating a page based on the policy. To resolve this potential race, the shared policy infrastructure adds an extra reference to the shared policy during lookup while holding a spin lock on the shared policy management structure. This requires that we drop this extra reference when we're finished "using" the policy. We must drop the extra reference on shared policies in the same query/allocation paths used for non-shared policies. For this reason, shared policies are marked as such, and the extra reference is dropped "conditionally"--i.e., only for shared policies. Because of this extra reference counting, and because we must lookup shared policies in a tree structure under spinlock, shared policies are more expensive to use in the page allocation path. This is especially true for shared policies on shared memory regions shared by tasks running on different NUMA nodes. This extra overhead can be avoided by always falling back to task or system default policy for shared memory regions, or by prefaulting the entire shared memory region into memory and locking it down. However, this might not be appropriate for all applications. ”h]”(hÝ)”}”(hXÛShared policies require special consideration. One task can replace a shared memory policy while another task, with a distinct mmap_lock, is querying or allocating a page based on the policy. To resolve this potential race, the shared policy infrastructure adds an extra reference to the shared policy during lookup while holding a spin lock on the shared policy management structure. This requires that we drop this extra reference when we're finished "using" the policy. We must drop the extra reference on shared policies in the same query/allocation paths used for non-shared policies. For this reason, shared policies are marked as such, and the extra reference is dropped "conditionally"--i.e., only for shared policies.”h]”hXåShared policies require special consideration. One task can replace a shared memory policy while another task, with a distinct mmap_lock, is querying or allocating a page based on the policy. To resolve this potential race, the shared policy infrastructure adds an extra reference to the shared policy during lookup while holding a spin lock on the shared policy management structure. This requires that we drop this extra reference when we’re finished “using†the policy. We must drop the extra reference on shared policies in the same query/allocation paths used for non-shared policies. For this reason, shared policies are marked as such, and the extra reference is dropped “conditionallyâ€--i.e., only for shared policies.”…””}”(hjbh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´Mˆhj^ubhÝ)”}”(hX>Because of this extra reference counting, and because we must lookup shared policies in a tree structure under spinlock, shared policies are more expensive to use in the page allocation path. This is especially true for shared policies on shared memory regions shared by tasks running on different NUMA nodes. This extra overhead can be avoided by always falling back to task or system default policy for shared memory regions, or by prefaulting the entire shared memory region into memory and locking it down. However, this might not be appropriate for all applications.”h]”hX>Because of this extra reference counting, and because we must lookup shared policies in a tree structure under spinlock, shared policies are more expensive to use in the page allocation path. This is especially true for shared policies on shared memory regions shared by tasks running on different NUMA nodes. This extra overhead can be avoided by always falling back to task or system default policy for shared memory regions, or by prefaulting the entire shared memory region into memory and locking it down. However, this might not be appropriate for all applications.”…””}”(hjph²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´M”hj^ubeh}”(h]”h ]”h"]”h$]”h&]”uh1j¥hjh²hh³hÊh´Nubeh}”(h]”h ]”h"]”h$]”h&]”jjjhjjuh1jÅhjŠh²hh³hÊh´Mxubj-)”}”(hŒ.. _memory_policy_apis:”h]”h}”(h]”h ]”h"]”h$]”h&]”j8Œmemory-policy-apis”uh1j,h´MhjŠh²hh³hÊubeh}”(h]”Œ memory-policy-reference-counting”ah ]”h"]”Œ memory policy reference counting”ah$]”h&]”uh1hµhh·h²hh³hÊh´MYubh¶)”}”(hhh]”(h»)”}”(hŒMemory Policy APIs”h]”hŒMemory Policy APIs”…””}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjh²hh³hÊh´M ubhÝ)”}”(hŒÓLinux supports 4 system calls for controlling memory policy. These APIS always affect only the calling task, the calling task's address space, or some shared object mapped into the calling task's address space.”h]”hŒ×Linux supports 4 system calls for controlling memory policy. These APIS always affect only the calling task, the calling task’s address space, or some shared object mapped into the calling task’s address space.”…””}”(hj®h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´M¢hjh²hubhŒnote”“”)”}”(hX7the headers that define these APIs and the parameter data types for user space applications reside in a package that is not part of the Linux kernel. The kernel system call interfaces, with the 'sys\_' prefix, are defined in ; the mode and flag definitions are defined in .”h]”hÝ)”}”(hX7the headers that define these APIs and the parameter data types for user space applications reside in a package that is not part of the Linux kernel. The kernel system call interfaces, with the 'sys\_' prefix, are defined in ; the mode and flag definitions are defined in .”h]”hX;the headers that define these APIs and the parameter data types for user space applications reside in a package that is not part of the Linux kernel. The kernel system call interfaces, with the ‘sys_’ prefix, are defined in ; the mode and flag definitions are defined in .”…””}”(hjÂh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´M§hj¾ubah}”(h]”h ]”h"]”h$]”h&]”uh1j¼hjh²hh³hÊh´NubhÝ)”}”(hŒSet [Task] Memory Policy::”h]”hŒSet [Task] Memory Policy:”…””}”(hjÖh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´M­hjh²hubhŒ literal_block”“”)”}”(hŒplong set_mempolicy(int mode, const unsigned long *nmask, unsigned long maxnode);”h]”hŒplong set_mempolicy(int mode, const unsigned long *nmask, unsigned long maxnode);”…””}”hjæsbah}”(h]”h ]”h"]”h$]”h&]”Œ xml:space”Œpreserve”uh1jäh³hÊh´M¯hjh²hubhÝ)”}”(hX\Set's the calling task's "task/process memory policy" to mode specified by the 'mode' argument and the set of nodes defined by 'nmask'. 'nmask' points to a bit mask of node ids containing at least 'maxnode' ids. Optional mode flags may be passed by combining the 'mode' argument with the flag (for example: MPOL_INTERLEAVE | MPOL_F_STATIC_NODES).”h]”hXxSet’s the calling task’s “task/process memory policy†to mode specified by the ‘mode’ argument and the set of nodes defined by ‘nmask’. ‘nmask’ points to a bit mask of node ids containing at least ‘maxnode’ ids. Optional mode flags may be passed by combining the ‘mode’ argument with the flag (for example: MPOL_INTERLEAVE | MPOL_F_STATIC_NODES).”…””}”(hjöh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´M²hjh²hubhÝ)”}”(hŒ2See the set_mempolicy(2) man page for more details”h]”hŒ2See the set_mempolicy(2) man page for more details”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´M¹hjh²hubhÝ)”}”(hŒ1Get [Task] Memory Policy or Related Information::”h]”hŒ0Get [Task] Memory Policy or Related Information:”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´M¼hjh²hubjå)”}”(hŒŽlong get_mempolicy(int *mode, const unsigned long *nmask, unsigned long maxnode, void *addr, int flags);”h]”hŒŽlong get_mempolicy(int *mode, const unsigned long *nmask, unsigned long maxnode, void *addr, int flags);”…””}”hj sbah}”(h]”h ]”h"]”h$]”h&]”jôjõuh1jäh³hÊh´M¾hjh²hubhÝ)”}”(hŒšQueries the "task/process memory policy" of the calling task, or the policy or location of a specified virtual address, depending on the 'flags' argument.”h]”hŒ¢Queries the “task/process memory policy†of the calling task, or the policy or location of a specified virtual address, depending on the ‘flags’ argument.”…””}”(hj.h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´MÂhjh²hubhÝ)”}”(hŒ2See the get_mempolicy(2) man page for more details”h]”hŒ2See the get_mempolicy(2) man page for more details”…””}”(hj<h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´MÆhjh²hubhÝ)”}”(hŒ?Install VMA/Shared Policy for a Range of Task's Address Space::”h]”hŒ@Install VMA/Shared Policy for a Range of Task’s Address Space:”…””}”(hjJh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´MÉhjh²hubjå)”}”(hŒŽlong mbind(void *start, unsigned long len, int mode, const unsigned long *nmask, unsigned long maxnode, unsigned flags);”h]”hŒŽlong mbind(void *start, unsigned long len, int mode, const unsigned long *nmask, unsigned long maxnode, unsigned flags);”…””}”hjXsbah}”(h]”h ]”h"]”h$]”h&]”jôjõuh1jäh³hÊh´MËhjh²hubhÝ)”}”(hŒïmbind() installs the policy specified by (mode, nmask, maxnodes) as a VMA policy for the range of the calling task's address space specified by the 'start' and 'len' arguments. Additional actions may be requested via the 'flags' argument.”h]”hŒýmbind() installs the policy specified by (mode, nmask, maxnodes) as a VMA policy for the range of the calling task’s address space specified by the ‘start’ and ‘len’ arguments. Additional actions may be requested via the ‘flags’ argument.”…””}”(hjfh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´MÏhjh²hubhÝ)”}”(hŒ+See the mbind(2) man page for more details.”h]”hŒ+See the mbind(2) man page for more details.”…””}”(hjth²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´MÔhjh²hubhÝ)”}”(hŒ4Set home node for a Range of Task's Address Spacec::”h]”hŒ5Set home node for a Range of Task’s Address Spacec:”…””}”(hj‚h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´MÖhjh²hubjå)”}”(hŒ¹long sys_set_mempolicy_home_node(unsigned long start, unsigned long len, unsigned long home_node, unsigned long flags);”h]”hŒ¹long sys_set_mempolicy_home_node(unsigned long start, unsigned long len, unsigned long home_node, unsigned long flags);”…””}”hjsbah}”(h]”h ]”h"]”h$]”h&]”jôjõuh1jäh³hÊh´MØhjh²hubhÝ)”}”(hX¡sys_set_mempolicy_home_node set the home node for a VMA policy present in the task's address range. The system call updates the home node only for the existing mempolicy range. Other address ranges are ignored. A home node is the NUMA node closest to which page allocation will come from. Specifying the home node override the default allocation policy to allocate memory close to the local node for an executing CPU.”h]”hX£sys_set_mempolicy_home_node set the home node for a VMA policy present in the task’s address range. The system call updates the home node only for the existing mempolicy range. Other address ranges are ignored. A home node is the NUMA node closest to which page allocation will come from. Specifying the home node override the default allocation policy to allocate memory close to the local node for an executing CPU.”…””}”(hjžh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´MÜhjh²hubeh}”(h]”(j”Œid1”eh ]”h"]”(Œmemory policy apis”Œmemory_policy_apis”eh$]”h&]”uh1hµhh·h²hh³hÊh´M jŸ}”j²jŠsj¡}”j”jŠsubh¶)”}”(hhh]”(h»)”}”(hŒ$Memory Policy Command Line Interface”h]”hŒ$Memory Policy Command Line Interface”…””}”(hjºh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhj·h²hh³hÊh´MåubhÝ)”}”(hŒ„Although not strictly part of the Linux implementation of memory policy, a command line tool, numactl(8), exists that allows one to:”h]”hŒ„Although not strictly part of the Linux implementation of memory policy, a command line tool, numactl(8), exists that allows one to:”…””}”(hjÈh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´Mçhj·h²hubj¡)”}”(hhh]”(j¦)”}”(hŒVset the task policy for a specified program via set_mempolicy(2), fork(2) and exec(2) ”h]”hÝ)”}”(hŒUset the task policy for a specified program via set_mempolicy(2), fork(2) and exec(2)”h]”hŒUset the task policy for a specified program via set_mempolicy(2), fork(2) and exec(2)”…””}”(hjÝh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´MêhjÙubah}”(h]”h ]”h"]”h$]”h&]”uh1j¥hjÖh²hh³hÊh´Nubj¦)”}”(hŒ?set the shared policy for a shared memory segment via mbind(2) ”h]”hÝ)”}”(hŒ>set the shared policy for a shared memory segment via mbind(2)”h]”hŒ>set the shared policy for a shared memory segment via mbind(2)”…””}”(hjõh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´Míhjñubah}”(h]”h ]”h"]”h$]”h&]”uh1j¥hjÖh²hh³hÊh´Nubeh}”(h]”h ]”h"]”h$]”h&]”j Œ+”uh1j h³hÊh´Mêhj·h²hubhÝ)”}”(hŒáThe numactl(8) tool is packaged with the run-time version of the library containing the memory policy system call wrappers. Some distributions package the headers and compile-time libraries in a separate development package.”h]”hŒáThe numactl(8) tool is packaged with the run-time version of the library containing the memory policy system call wrappers. Some distributions package the headers and compile-time libraries in a separate development package.”…””}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´Mïhj·h²hubj-)”}”(hŒ.. _mem_pol_and_cpusets:”h]”h}”(h]”h ]”h"]”h$]”h&]”j8Œmem-pol-and-cpusets”uh1j,h´Môhj·h²hh³hÊubeh}”(h]”Œ$memory-policy-command-line-interface”ah ]”h"]”Œ$memory policy command line interface”ah$]”h&]”uh1hµhh·h²hh³hÊh´Måubh¶)”}”(hhh]”(h»)”}”(hŒMemory Policies and cpusets”h]”hŒMemory Policies and cpusets”…””}”(hj4 h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhj1 h²hh³hÊh´M÷ubhÝ)”}”(hX©Memory policies work within cpusets as described above. For memory policies that require a node or set of nodes, the nodes are restricted to the set of nodes whose memories are allowed by the cpuset constraints. If the nodemask specified for the policy contains nodes that are not allowed by the cpuset and MPOL_F_RELATIVE_NODES is not used, the intersection of the set of nodes specified for the policy and the set of nodes with memory is used. If the result is the empty set, the policy is considered invalid and cannot be installed. If MPOL_F_RELATIVE_NODES is used, the policy's nodes are mapped onto and folded into the task's set of allowed nodes as previously described.”h]”hX­Memory policies work within cpusets as described above. For memory policies that require a node or set of nodes, the nodes are restricted to the set of nodes whose memories are allowed by the cpuset constraints. If the nodemask specified for the policy contains nodes that are not allowed by the cpuset and MPOL_F_RELATIVE_NODES is not used, the intersection of the set of nodes specified for the policy and the set of nodes with memory is used. If the result is the empty set, the policy is considered invalid and cannot be installed. If MPOL_F_RELATIVE_NODES is used, the policy’s nodes are mapped onto and folded into the task’s set of allowed nodes as previously described.”…””}”(hjB h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´Mùhj1 h²hubhÝ)”}”(hX¬The interaction of memory policies and cpusets can be problematic when tasks in two cpusets share access to a memory region, such as shared memory segments created by shmget() of mmap() with the MAP_ANONYMOUS and MAP_SHARED flags, and any of the tasks install shared policy on the region, only nodes whose memories are allowed in both cpusets may be used in the policies. Obtaining this information requires "stepping outside" the memory policy APIs to use the cpuset information and requires that one know in what cpusets other task might be attaching to the shared region. Furthermore, if the cpusets' allowed memory sets are disjoint, "local" allocation is the only valid policy.”h]”hX¶The interaction of memory policies and cpusets can be problematic when tasks in two cpusets share access to a memory region, such as shared memory segments created by shmget() of mmap() with the MAP_ANONYMOUS and MAP_SHARED flags, and any of the tasks install shared policy on the region, only nodes whose memories are allowed in both cpusets may be used in the policies. Obtaining this information requires “stepping outside†the memory policy APIs to use the cpuset information and requires that one know in what cpusets other task might be attaching to the shared region. Furthermore, if the cpusets’ allowed memory sets are disjoint, “local†allocation is the only valid policy.”…””}”(hjP h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´Mhj1 h²hubeh}”(h]”(Œmemory-policies-and-cpusets”j( eh ]”h"]”(Œmemory policies and cpusets”Œmem_pol_and_cpusets”eh$]”h&]”uh1hµhh·h²hh³hÊh´M÷jŸ}”jd j sj¡}”j( j subeh}”(h]”Œnuma-memory-policy”ah ]”h"]”Œnuma memory policy”ah$]”h&]”uh1hµhhh²hh³hÊh´Kubeh}”(h]”h ]”h"]”h$]”h&]”Œsource”hÊuh1hŒcurrent_source”NŒ current_line”NŒsettings”Œdocutils.frontend”ŒValues”“”)”}”(hºNŒ generator”NŒ datestamp”NŒ source_link”NŒ source_url”NŒ toc_backlinks”Œentry”Œfootnote_backlinks”KŒ sectnum_xform”KŒstrip_comments”NŒstrip_elements_with_classes”NŒ strip_classes”NŒ report_level”KŒ halt_level”KŒexit_status_level”KŒdebug”NŒwarning_stream”NŒ traceback”ˆŒinput_encoding”Œ utf-8-sig”Œinput_encoding_error_handler”Œstrict”Œoutput_encoding”Œutf-8”Œoutput_encoding_error_handler”j” Œerror_encoding”Œutf-8”Œerror_encoding_error_handler”Œbackslashreplace”Œ language_code”Œen”Œrecord_dependencies”NŒconfig”NŒ id_prefix”hŒauto_id_prefix”Œid”Œ dump_settings”NŒdump_internals”NŒdump_transforms”NŒdump_pseudo_xml”NŒexpose_internals”NŒstrict_visitor”NŒ_disable_config”NŒ_source”hÊŒ _destination”NŒ _config_files”]”Œ7/var/lib/git/docbuild/linux/Documentation/docutils.conf”aŒfile_insertion_enabled”ˆŒ raw_enabled”KŒline_length_limit”M'Œpep_references”NŒ pep_base_url”Œhttps://peps.python.org/”Œpep_file_url_template”Œpep-%04d”Œrfc_references”NŒ rfc_base_url”Œ&https://datatracker.ietf.org/doc/html/”Œ tab_width”KŒtrim_footnote_reference_space”‰Œsyntax_highlight”Œlong”Œ smart_quotes”ˆŒsmartquotes_locales”]”Œcharacter_level_inline_markup”‰Œdoctitle_xform”‰Œ docinfo_xform”KŒsectsubtitle_xform”‰Œ image_loading”Œlink”Œembed_stylesheet”‰Œcloak_email_addresses”ˆŒsection_self_link”‰Œenv”NubŒreporter”NŒindirect_targets”]”Œsubstitution_defs”}”Œsubstitution_names”}”Œrefnames”}”Œrefids”}”(j9]”j.aj”]”jŠaj( ]”j auŒnameids”}”(jn jk j<j9j‡j„j¨j¥jœj9jj|jšj—j²j”j±j®j. j+ jd j( jc j` uŒ nametypes”}”(jn ‰j<‰j‡‰j¨‰jœˆj‰jš‰j²ˆj±‰j. ‰jd ˆjc ‰uh}”(jk h·j9hËj„j?j¥jPj9j:j|j«j—jŠj”jj®jj+ j·j( j1 j` j1 uŒ footnote_refs”}”Œ citation_refs”}”Œ autofootnotes”]”Œautofootnote_refs”]”Œsymbol_footnotes”]”Œsymbol_footnote_refs”]”Œ footnotes”]”Œ citations”]”Œautofootnote_start”KŒsymbol_footnote_start”KŒ id_counter”Œ collections”ŒCounter”“”}”j¢ Ks…”R”Œparse_messages”]”Œtransform_messages”]”(hŒsystem_message”“”)”}”(hhh]”hÝ)”}”(hhh]”hŒ0Hyperlink target "vma-policy" is not referenced.”…””}”hj sbah}”(h]”h ]”h"]”h$]”h&]”uh1hÜhjý ubah}”(h]”h ]”h"]”h$]”h&]”Œlevel”KŒtype”ŒINFO”Œsource”hÊŒline”KHuh1jû ubjü )”}”(hhh]”hÝ)”}”(hhh]”hŒ8Hyperlink target "memory-policy-apis" is not referenced.”…””}”hj sbah}”(h]”h ]”h"]”h$]”h&]”uh1hÜhj ubah}”(h]”h ]”h"]”h$]”h&]”Œlevel”KŒtype”j Œsource”hÊŒline”Muh1jû ubjü )”}”(hhh]”hÝ)”}”(hhh]”hŒ9Hyperlink target "mem-pol-and-cpusets" is not referenced.”…””}”hj5 sbah}”(h]”h ]”h"]”h$]”h&]”uh1hÜhj2 ubah}”(h]”h ]”h"]”h$]”h&]”Œlevel”KŒtype”j Œsource”hÊŒline”Môuh1jû ubeŒ transformer”NŒ include_log”]”Œ decoration”Nh²hub.