€•Õ¹Œ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”Œ4/translations/zh_CN/admin-guide/cgroup-v1/memcg_test”Œmodname”NŒ classname”NŒ refexplicit”ˆuŒtagname”hhh ubh)�”}”(hhh]”hŒChinese (Traditional)”…”�”}”hh2sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ4/translations/zh_TW/admin-guide/cgroup-v1/memcg_test”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)�”}”(hhh]”hŒItalian”…”�”}”hhFsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ4/translations/it_IT/admin-guide/cgroup-v1/memcg_test”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)�”}”(hhh]”hŒJapanese”…”�”}”hhZsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ4/translations/ja_JP/admin-guide/cgroup-v1/memcg_test”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)�”}”(hhh]”hŒKorean”…”�”}”hhnsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ4/translations/ko_KR/admin-guide/cgroup-v1/memcg_test”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)�”}”(hhh]”hŒPortuguese (Brazilian)”…”�”}”hh‚sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ4/translations/pt_BR/admin-guide/cgroup-v1/memcg_test”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)�”}”(hhh]”hŒSpanish”…”�”}”hh–sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ4/translations/sp_SP/admin-guide/cgroup-v1/memcg_test”Œ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Œ5Memory Resource Controller(Memcg) Implementation Memo”h]”hŒ5Memory Resource Controller(Memcg) Implementation Memo”…”�”}”(hh¼h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhh·h²hh³ŒN/var/lib/git/docbuild/linux/Documentation/admin-guide/cgroup-v1/memcg_test.rst”h´KubhŒ paragraph”“”)�”}”(hŒLast Updated: 2010/2”h]”hŒLast Updated: 2010/2”…”�”}”(hhÍh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Khh·h²hubhÌ)�”}”(hŒ>Base Kernel Version: based on 2.6.33-rc7-mm(candidate for 34).”h]”hŒ>Base Kernel Version: based on 2.6.33-rc7-mm(candidate for 34).”…”�”}”(hhÛh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Khh·h²hubhÌ)�”}”(hŒÂBecause VM is getting complex (one of reasons is memcg...), memcg's behavior is complex. This is a document for memcg's internal behavior. Please note that implementation details can be changed.”h]”hŒÆBecause VM is getting complex (one of reasons is memcg...), memcg’s behavior is complex. This is a document for memcg’s internal behavior. Please note that implementation details can be changed.”…”�”}”(hhéh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K hh·h²hubhÌ)�”}”(hŒM(*) Topics on API should be in Documentation/admin-guide/cgroup-v1/memory.rst”h]”hŒM(*) Topics on API should be in Documentation/admin-guide/cgroup-v1/memory.rst”…”�”}”(hh÷h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K hh·h²hubh¶)�”}”(hhh]”(h»)�”}”(hŒ0. How to record usage ?”h]”hŒ0. How to record usage ?”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjh²hh³hÊh´KubhŒ block_quote”“”)�”}”(hXk2 objects are used. page_cgroup ....an object per page. Allocated at boot or memory hotplug. Freed at memory hot removal. swap_cgroup ... an entry per swp_entry. Allocated at swapon(). Freed at swapoff(). The page_cgroup has USED bit and double count against a page_cgroup never occurs. swap_cgroup is used only when a charged page is swapped-out. ”h]”(hÌ)�”}”(hŒ2 objects are used.”h]”hŒ2 objects are used.”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KhjubhÌ)�”}”(hŒ#page_cgroup ....an object per page.”h]”hŒ#page_cgroup ....an object per page.”…”�”}”(hj*h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Khjubj)�”}”(hŒBAllocated at boot or memory hotplug. Freed at memory hot removal. ”h]”hÌ)�”}”(hŒAAllocated at boot or memory hotplug. Freed at memory hot removal.”h]”hŒAAllocated at boot or memory hotplug. Freed at memory hot removal.”…”�”}”(hj<h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Khj8ubah}”(h]”h ]”h"]”h$]”h&]”uh1jh³hÊh´KhjubhÌ)�”}”(hŒ'swap_cgroup ... an entry per swp_entry.”h]”hŒ'swap_cgroup ... an entry per swp_entry.”…”�”}”(hjPh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Khjubj)�”}”(hŒ+Allocated at swapon(). Freed at swapoff(). ”h]”hÌ)�”}”(hŒ*Allocated at swapon(). Freed at swapoff().”h]”hŒ*Allocated at swapon(). Freed at swapoff().”…”�”}”(hjbh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Khj^ubah}”(h]”h ]”h"]”h$]”h&]”uh1jh³hÊh´KhjubhÌ)�”}”(hŒŽThe page_cgroup has USED bit and double count against a page_cgroup never occurs. swap_cgroup is used only when a charged page is swapped-out.”h]”hŒŽThe page_cgroup has USED bit and double count against a page_cgroup never occurs. swap_cgroup is used only when a charged page is swapped-out.”…”�”}”(hjvh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Khjubeh}”(h]”h ]”h"]”h$]”h&]”uh1jh³hÊh´Khjh²hubeh}”(h]”Œhow-to-record-usage”ah ]”h"]”Œ0. how to record usage ?”ah$]”h&]”uh1hµhh·h²hh³hÊh´Kubh¶)�”}”(hhh]”(h»)�”}”(hŒ 1. Charge”h]”hŒ 1. Charge”…”�”}”(hj•h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhj’h²hh³hÊh´K ubj)�”}”(hŒVa page/swp_entry may be charged (usage += PAGE_SIZE) at mem_cgroup_try_charge() ”h]”(hÌ)�”}”(hŒ7a page/swp_entry may be charged (usage += PAGE_SIZE) at”h]”hŒ7a page/swp_entry may be charged (usage += PAGE_SIZE) at”…”�”}”(hj§h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K"hj£ubj)�”}”(hŒmem_cgroup_try_charge() ”h]”hÌ)�”}”(hŒmem_cgroup_try_charge()”h]”hŒmem_cgroup_try_charge()”…”�”}”(hj¹h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K$hjµubah}”(h]”h ]”h"]”h$]”h&]”uh1jh³hÊh´K$hj£ubeh}”(h]”h ]”h"]”h$]”h&]”uh1jh³hÊh´K"hj’h²hubeh}”(h]”Œcharge”ah ]”h"]”Œ 1. charge”ah$]”h&]”uh1hµhh·h²hh³hÊh´K ubh¶)�”}”(hhh]”(h»)�”}”(hŒ 2. Uncharge”h]”hŒ 2. Uncharge”…”�”}”(hjÞh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjÛh²hh³hÊh´K'ubj)�”}”(hXa page/swp_entry may be uncharged (usage -= PAGE_SIZE) by mem_cgroup_uncharge() Called when a page's refcount goes down to 0. mem_cgroup_uncharge_swap() Called when swp_entry's refcnt goes down to 0. A charge against swap disappears. ”h]”(hÌ)�”}”(hŒ9a page/swp_entry may be uncharged (usage -= PAGE_SIZE) by”h]”hŒ9a page/swp_entry may be uncharged (usage -= PAGE_SIZE) by”…”�”}”(hjðh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K)hjìubj)�”}”(hŒ·mem_cgroup_uncharge() Called when a page's refcount goes down to 0. mem_cgroup_uncharge_swap() Called when swp_entry's refcnt goes down to 0. A charge against swap disappears. ”h]”hŒdefinition_list”“”)�”}”(hhh]”(hŒdefinition_list_item”“”)�”}”(hŒDmem_cgroup_uncharge() Called when a page's refcount goes down to 0. ”h]”(hŒterm”“”)�”}”(hŒmem_cgroup_uncharge()”h]”hŒmem_cgroup_uncharge()”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j h³hÊh´K,hj ubhŒ definition”“”)�”}”(hhh]”hÌ)�”}”(hŒ-Called when a page's refcount goes down to 0.”h]”hŒ/Called when a page’s refcount goes down to 0.”…”�”}”(hj"h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K,hjubah}”(h]”h ]”h"]”h$]”h&]”uh1jhj ubeh}”(h]”h ]”h"]”h$]”h&]”uh1jh³hÊh´K,hjubj)�”}”(hŒlmem_cgroup_uncharge_swap() Called when swp_entry's refcnt goes down to 0. A charge against swap disappears. ”h]”(j)�”}”(hŒmem_cgroup_uncharge_swap()”h]”hŒmem_cgroup_uncharge_swap()”…”�”}”(hj@h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j h³hÊh´K0hj<ubj)�”}”(hhh]”hÌ)�”}”(hŒPCalled when swp_entry's refcnt goes down to 0. A charge against swap disappears.”h]”hŒRCalled when swp_entry’s refcnt goes down to 0. A charge against swap disappears.”…”�”}”(hjQh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K/hjNubah}”(h]”h ]”h"]”h$]”h&]”uh1jhj<ubeh}”(h]”h ]”h"]”h$]”h&]”uh1jh³hÊh´K0hjubeh}”(h]”h ]”h"]”h$]”h&]”uh1jhjþubah}”(h]”h ]”h"]”h$]”h&]”uh1jh³hÊh´K+hjìubeh}”(h]”h ]”h"]”h$]”h&]”uh1jh³hÊh´K)hjÛh²hubeh}”(h]”Œuncharge”ah ]”h"]”Œ 2. uncharge”ah$]”h&]”uh1hµhh·h²hh³hÊh´K'ubh¶)�”}”(hhh]”(h»)�”}”(hŒ3. charge-commit”h]”hŒ3. charge-commit”…”�”}”(hjˆh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhj…h²hh³hÊh´K3ubj)�”}”(hŒÿMemcg pages are charged in two steps: - mem_cgroup_try_charge() - commit_charge() At try_charge(), there are no flags to say "this page is charged". at this point, usage += PAGE_SIZE. At commit(), the page is associated with the memcg. ”h]”(hÌ)�”}”(hŒ%Memcg pages are charged in two steps:”h]”hŒ%Memcg pages are charged in two steps:”…”�”}”(hjšh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K5hj–ubj)�”}”(hŒ,- mem_cgroup_try_charge() - commit_charge() ”h]”hŒ bullet_list”“”)�”}”(hhh]”(hŒ list_item”“”)�”}”(hŒmem_cgroup_try_charge()”h]”hÌ)�”}”(hjµh]”hŒmem_cgroup_try_charge()”…”�”}”(hj·h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K7hj³ubah}”(h]”h ]”h"]”h$]”h&]”uh1j±hj®ubj²)�”}”(hŒcommit_charge() ”h]”hÌ)�”}”(hŒcommit_charge()”h]”hŒcommit_charge()”…”�”}”(hjÎh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K8hjÊubah}”(h]”h ]”h"]”h$]”h&]”uh1j±hj®ubeh}”(h]”h ]”h"]”h$]”h&]”Œbullet”Œ-”uh1j¬h³hÊh´K7hj¨ubah}”(h]”h ]”h"]”h$]”h&]”uh1jh³hÊh´K7hj–ubhÌ)�”}”(hŒeAt try_charge(), there are no flags to say "this page is charged". at this point, usage += PAGE_SIZE.”h]”hŒiAt try_charge(), there are no flags to say “this page is chargedâ€�. at this point, usage += PAGE_SIZE.”…”�”}”(hjðh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K:hj–ubhÌ)�”}”(hŒ3At commit(), the page is associated with the memcg.”h]”hŒ3At commit(), the page is associated with the memcg.”…”�”}”(hjþh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K=hj–ubeh}”(h]”h ]”h"]”h$]”h&]”uh1jh³hÊh´K5hj…h²hubhÌ)�”}”(hŒ1Under below explanation, we assume CONFIG_SWAP=y.”h]”hŒ1Under below explanation, we assume CONFIG_SWAP=y.”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K?hj…h²hubeh}”(h]”Œ charge-commit”ah ]”h"]”Œ3. charge-commit”ah$]”h&]”uh1hµhh·h²hh³hÊh´K3ubh¶)�”}”(hhh]”(h»)�”}”(hŒ 4. Anonymous”h]”hŒ 4. Anonymous”…”�”}”(hj+h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhj(h²hh³hÊh´KBubj)�”}”(hXÛAnonymous page is newly allocated at - page fault into MAP_ANONYMOUS mapping. - Copy-On-Write. 4.1 Swap-in. At swap-in, the page is taken from swap-cache. There are 2 cases. (a) If the SwapCache is newly allocated and read, it has no charges. (b) If the SwapCache has been mapped by processes, it has been charged already. 4.2 Swap-out. At swap-out, typical state transition is below. (a) add to swap cache. (marked as SwapCache) swp_entry's refcnt += 1. (b) fully unmapped. swp_entry's refcnt += # of ptes. (c) write back to swap. (d) delete from swap cache. (remove from SwapCache) swp_entry's refcnt -= 1. Finally, at task exit, (e) zap_pte() is called and swp_entry's refcnt -=1 -> 0. ”h]”(j)�”}”(hhh]”j)�”}”(hŒ_Anonymous page is newly allocated at - page fault into MAP_ANONYMOUS mapping. - Copy-On-Write. ”h]”(j)�”}”(hŒ$Anonymous page is newly allocated at”h]”hŒ$Anonymous page is newly allocated at”…”�”}”(hjDh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j h³hÊh´KFhj@ubj)�”}”(hhh]”j­)�”}”(hhh]”(j²)�”}”(hŒ&page fault into MAP_ANONYMOUS mapping.”h]”hÌ)�”}”(hjZh]”hŒ&page fault into MAP_ANONYMOUS mapping.”…”�”}”(hj\h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KEhjXubah}”(h]”h ]”h"]”h$]”h&]”uh1j±hjUubj²)�”}”(hŒCopy-On-Write. ”h]”hÌ)�”}”(hŒCopy-On-Write.”h]”hŒCopy-On-Write.”…”�”}”(hjsh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KFhjoubah}”(h]”h ]”h"]”h$]”h&]”uh1j±hjUubeh}”(h]”h ]”h"]”h$]”h&]”jèjéuh1j¬h³hÊh´KEhjRubah}”(h]”h ]”h"]”h$]”h&]”uh1jhj@ubeh}”(h]”h ]”h"]”h$]”h&]”uh1jh³hÊh´KFhj=ubah}”(h]”h ]”h"]”h$]”h&]”uh1jhj9ubhÌ)�”}”(hŒN4.1 Swap-in. At swap-in, the page is taken from swap-cache. There are 2 cases.”h]”hŒN4.1 Swap-in. At swap-in, the page is taken from swap-cache. There are 2 cases.”…”�”}”(hjŸh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KHhj9ubhŒenumerated_list”“”)�”}”(hhh]”(j²)�”}”(hŒ@If the SwapCache is newly allocated and read, it has no charges.”h]”hÌ)�”}”(hj´h]”hŒ@If the SwapCache is newly allocated and read, it has no charges.”…”�”}”(hj¶h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KKhj²ubah}”(h]”h ]”h"]”h$]”h&]”uh1j±hj¯ubj²)�”}”(hŒLIf the SwapCache has been mapped by processes, it has been charged already. ”h]”hÌ)�”}”(hŒKIf the SwapCache has been mapped by processes, it has been charged already.”h]”hŒKIf the SwapCache has been mapped by processes, it has been charged already.”…”�”}”(hjÍh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KLhjÉubah}”(h]”h ]”h"]”h$]”h&]”uh1j±hj¯ubeh}”(h]”h ]”h"]”h$]”h&]”Œenumtype”Œ loweralpha”Œprefix”Œ(”Œsuffix”Œ)”uh1j­hj9ubhÌ)�”}”(hŒ=4.2 Swap-out. At swap-out, typical state transition is below.”h]”hŒ=4.2 Swap-out. At swap-out, typical state transition is below.”…”�”}”(hjíh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KOhj9ubj®)�”}”(hhh]”(j²)�”}”(hŒAadd to swap cache. (marked as SwapCache) swp_entry's refcnt += 1.”h]”hÌ)�”}”(hŒAadd to swap cache. (marked as SwapCache) swp_entry's refcnt += 1.”h]”hŒCadd to swap cache. (marked as SwapCache) swp_entry’s refcnt += 1.”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KRhjþubah}”(h]”h ]”h"]”h$]”h&]”uh1j±hjûubj²)�”}”(hŒ0fully unmapped. swp_entry's refcnt += # of ptes.”h]”hÌ)�”}”(hŒ0fully unmapped. swp_entry's refcnt += # of ptes.”h]”hŒ2fully unmapped. swp_entry’s refcnt += # of ptes.”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KThjubah}”(h]”h ]”h"]”h$]”h&]”uh1j±hjûubj²)�”}”(hŒwrite back to swap.”h]”hÌ)�”}”(hj0h]”hŒwrite back to swap.”…”�”}”(hj2h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KVhj.ubah}”(h]”h ]”h"]”h$]”h&]”uh1j±hjûubj²)�”}”(hŒJdelete from swap cache. (remove from SwapCache) swp_entry's refcnt -= 1. ”h]”hÌ)�”}”(hŒHdelete from swap cache. (remove from SwapCache) swp_entry's refcnt -= 1.”h]”hŒJdelete from swap cache. (remove from SwapCache) swp_entry’s refcnt -= 1.”…”�”}”(hjIh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KWhjEubah}”(h]”h ]”h"]”h$]”h&]”uh1j±hjûubeh}”(h]”h ]”h"]”h$]”h&]”jçjèjéjêjëjìuh1j­hj9ubhÌ)�”}”(hŒOFinally, at task exit, (e) zap_pte() is called and swp_entry's refcnt -=1 -> 0.”h]”hŒQFinally, at task exit, (e) zap_pte() is called and swp_entry’s refcnt -=1 -> 0.”…”�”}”(hjch²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K[hj9ubeh}”(h]”h ]”h"]”h$]”h&]”uh1jh³hÊh´KDhj(h²hubeh}”(h]”Œ anonymous”ah ]”h"]”Œ 4. anonymous”ah$]”h&]”uh1hµhh·h²hh³hÊh´KBubh¶)�”}”(hhh]”(h»)�”}”(hŒ 5. Page Cache”h]”hŒ 5. Page Cache”…”�”}”(hj‚h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjh²hh³hÊh´K_ubj)�”}”(hŒÇPage Cache is charged at - filemap_add_folio(). The logic is very clear. (About migration, see below) Note: __filemap_remove_folio() is called by filemap_remove_folio() and __remove_mapping(). ”h]”(hÌ)�”}”(hŒ/Page Cache is charged at - filemap_add_folio().”h]”hŒ/Page Cache is charged at - filemap_add_folio().”…”�”}”(hj”h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Kahj�ubhÌ)�”}”(hŒ5The logic is very clear. (About migration, see below)”h]”hŒ5The logic is very clear. (About migration, see below)”…”�”}”(hj¢h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Kdhj�ubj)�”}”(hhh]”j)�”}”(hŒ[Note: __filemap_remove_folio() is called by filemap_remove_folio() and __remove_mapping(). ”h]”(j)�”}”(hŒNote:”h]”hŒNote:”…”�”}”(hj·h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j h³hÊh´Khhj³ubj)�”}”(hhh]”hÌ)�”}”(hŒT__filemap_remove_folio() is called by filemap_remove_folio() and __remove_mapping().”h]”hŒT__filemap_remove_folio() is called by filemap_remove_folio() and __remove_mapping().”…”�”}”(hjÈh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KghjÅubah}”(h]”h ]”h"]”h$]”h&]”uh1jhj³ubeh}”(h]”h ]”h"]”h$]”h&]”uh1jh³hÊh´Khhj°ubah}”(h]”h ]”h"]”h$]”h&]”uh1jhj�ubeh}”(h]”h ]”h"]”h$]”h&]”uh1jh³hÊh´Kahjh²hubeh}”(h]”Œ page-cache”ah ]”h"]”Œ 5. page cache”ah$]”h&]”uh1hµhh·h²hh³hÊh´K_ubh¶)�”}”(hhh]”(h»)�”}”(hŒ6. Shmem(tmpfs) Page Cache”h]”hŒ6. Shmem(tmpfs) Page Cache”…”�”}”(hjùh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjöh²hh³hÊh´Kkubj)�”}”(hXThe best way to understand shmem's page state transition is to read mm/shmem.c. But brief explanation of the behavior of memcg around shmem will be helpful to understand the logic. Shmem's page (just leaf page, not direct/indirect block) can be on - radix-tree of shmem's inode. - SwapCache. - Both on radix-tree and SwapCache. This happens at swap-in and swap-out, It's charged when... - A new page is added to shmem's radix-tree. - A swp page is read. (move a charge from swap_cgroup to page_cgroup) ”h]”(hÌ)�”}”(hŒOThe best way to understand shmem's page state transition is to read mm/shmem.c.”h]”hŒQThe best way to understand shmem’s page state transition is to read mm/shmem.c.”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KmhjubhÌ)�”}”(hŒdBut brief explanation of the behavior of memcg around shmem will be helpful to understand the logic.”h]”hŒdBut brief explanation of the behavior of memcg around shmem will be helpful to understand the logic.”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KphjubhÌ)�”}”(hŒBShmem's page (just leaf page, not direct/indirect block) can be on”h]”hŒDShmem’s page (just leaf page, not direct/indirect block) can be on”…”�”}”(hj'h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Kshjubj)�”}”(hŒx- radix-tree of shmem's inode. - SwapCache. - Both on radix-tree and SwapCache. This happens at swap-in and swap-out, ”h]”j­)�”}”(hhh]”(j²)�”}”(hŒradix-tree of shmem's inode.”h]”hÌ)�”}”(hj>h]”hŒradix-tree of shmem’s inode.”…”�”}”(hj@h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Kuhj<ubah}”(h]”h ]”h"]”h$]”h&]”uh1j±hj9ubj²)�”}”(hŒ SwapCache.”h]”hÌ)�”}”(hjUh]”hŒ SwapCache.”…”�”}”(hjWh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KvhjSubah}”(h]”h ]”h"]”h$]”h&]”uh1j±hj9ubj²)�”}”(hŒHBoth on radix-tree and SwapCache. This happens at swap-in and swap-out, ”h]”hÌ)�”}”(hŒGBoth on radix-tree and SwapCache. This happens at swap-in and swap-out,”h]”hŒGBoth on radix-tree and SwapCache. This happens at swap-in and swap-out,”…”�”}”(hjnh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Kwhjjubah}”(h]”h ]”h"]”h$]”h&]”uh1j±hj9ubeh}”(h]”h ]”h"]”h$]”h&]”jèjéuh1j¬h³hÊh´Kuhj5ubah}”(h]”h ]”h"]”h$]”h&]”uh1jh³hÊh´KuhjubhÌ)�”}”(hŒIt's charged when...”h]”hŒIt’s charged when...”…”�”}”(hjŽh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Kzhjubj­)�”}”(hhh]”(j²)�”}”(hŒ*A new page is added to shmem's radix-tree.”h]”hÌ)�”}”(hj¡h]”hŒ,A new page is added to shmem’s radix-tree.”…”�”}”(hj£h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K|hjŸubah}”(h]”h ]”h"]”h$]”h&]”uh1j±hjœubj²)�”}”(hŒDA swp page is read. (move a charge from swap_cgroup to page_cgroup) ”h]”hÌ)�”}”(hŒCA swp page is read. (move a charge from swap_cgroup to page_cgroup)”h]”hŒCA swp page is read. (move a charge from swap_cgroup to page_cgroup)”…”�”}”(hjºh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K}hj¶ubah}”(h]”h ]”h"]”h$]”h&]”uh1j±hjœubeh}”(h]”h ]”h"]”h$]”h&]”jèjéuh1j¬h³hÊh´K|hjubeh}”(h]”h ]”h"]”h$]”h&]”uh1jh³hÊh´Kmhjöh²hubeh}”(h]”Œshmem-tmpfs-page-cache”ah ]”h"]”Œ6. shmem(tmpfs) page cache”ah$]”h&]”uh1hµhh·h²hh³hÊh´Kkubh¶)�”}”(hhh]”(h»)�”}”(hŒ7. Page Migration”h]”hŒ7. Page Migration”…”�”}”(hjåh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjâh²hh³hÊh´K€ubj)�”}”(hŒmem_cgroup_migrate() ”h]”hÌ)�”}”(hŒmem_cgroup_migrate()”h]”hŒmem_cgroup_migrate()”…”�”}”(hj÷h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K‚hjóubah}”(h]”h ]”h"]”h$]”h&]”uh1jh³hÊh´K‚hjâh²hubeh}”(h]”Œpage-migration”ah ]”h"]”Œ7. page migration”ah$]”h&]”uh1hµhh·h²hh³hÊh´K€ubh¶)�”}”(hhh]”(h»)�”}”(hŒ8. LRU”h]”hŒ8. LRU”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjh²hh³hÊh´K…ubj)�”}”(hŒÇEach memcg has its own vector of LRUs (inactive anon, active anon, inactive file, active file, unevictable) of pages from each node, each LRU handled under a single lru_lock for that memcg and node. ”h]”hÌ)�”}”(hŒÆEach memcg has its own vector of LRUs (inactive anon, active anon, inactive file, active file, unevictable) of pages from each node, each LRU handled under a single lru_lock for that memcg and node.”h]”hŒÆEach memcg has its own vector of LRUs (inactive anon, active anon, inactive file, active file, unevictable) of pages from each node, each LRU handled under a single lru_lock for that memcg and node.”…”�”}”(hj(h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K†hj$ubah}”(h]”h ]”h"]”h$]”h&]”uh1jh³hÊh´K†hjh²hubeh}”(h]”Œlru”ah ]”h"]”Œ8. lru”ah$]”h&]”uh1hµhh·h²hh³hÊh´K…ubh¶)�”}”(hhh]”(h»)�”}”(hŒ9. Typical Tests.”h]”hŒ9. Typical Tests.”…”�”}”(hjGh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjDh²hh³hÊh´K‹ubj)�”}”(hŒTests for racy cases. ”h]”hÌ)�”}”(hŒTests for racy cases.”h]”hŒTests for racy cases.”…”�”}”(hjYh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K�hjUubah}”(h]”h ]”h"]”h$]”h&]”uh1jh³hÊh´K�hjDh²hubh¶)�”}”(hhh]”(h»)�”}”(hŒ9.1 Small limit to memcg.”h]”hŒ9.1 Small limit to memcg.”…”�”}”(hjph²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjmh²hh³hÊh´K�ubj)�”}”(hŒ÷When you do test to do racy case, it's good test to set memcg's limit to be very small rather than GB. Many races found in the test under xKB or xxMB limits. (Memory behavior under GB and Memory behavior under MB shows very different situation.) ”h]”(hÌ)�”}”(hŒ�When you do test to do racy case, it's good test to set memcg's limit to be very small rather than GB. Many races found in the test under xKB or xxMB limits.”h]”hŒ¡When you do test to do racy case, it’s good test to set memcg’s limit to be very small rather than GB. Many races found in the test under xKB or xxMB limits.”…”�”}”(hj‚h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K’hj~ubhÌ)�”}”(hŒW(Memory behavior under GB and Memory behavior under MB shows very different situation.)”h]”hŒW(Memory behavior under GB and Memory behavior under MB shows very different situation.)”…”�”}”(hj�h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K–hj~ubeh}”(h]”h ]”h"]”h$]”h&]”uh1jh³hÊh´K’hjmh²hubeh}”(h]”Œsmall-limit-to-memcg”ah ]”h"]”Œ9.1 small limit to memcg.”ah$]”h&]”uh1hµhjDh²hh³hÊh´K�ubh¶)�”}”(hhh]”(h»)�”}”(hŒ 9.2 Shmem”h]”hŒ 9.2 Shmem”…”�”}”(hj¯h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhj¬h²hh³hÊh´Kšubj)�”}”(hŒ¼Historically, memcg's shmem handling was poor and we saw some amount of troubles here. This is because shmem is page-cache but can be SwapCache. Test with shmem/tmpfs is always good test. ”h]”hÌ)�”}”(hŒ»Historically, memcg's shmem handling was poor and we saw some amount of troubles here. This is because shmem is page-cache but can be SwapCache. Test with shmem/tmpfs is always good test.”h]”hŒ½Historically, memcg’s shmem handling was poor and we saw some amount of troubles here. This is because shmem is page-cache but can be SwapCache. Test with shmem/tmpfs is always good test.”…”�”}”(hjÁh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Kœhj½ubah}”(h]”h ]”h"]”h$]”h&]”uh1jh³hÊh´Kœhj¬h²hubeh}”(h]”Œshmem”ah ]”h"]”Œ 9.2 shmem”ah$]”h&]”uh1hµhjDh²hh³hÊh´Kšubh¶)�”}”(hhh]”(h»)�”}”(hŒ 9.3 Migration”h]”hŒ 9.3 Migration”…”�”}”(hjàh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjÝh²hh³hÊh´K¡ubj)�”}”(hXýFor NUMA, migration is an another special case. To do easy test, cpuset is useful. Following is a sample script to do migration:: mount -t cgroup -o cpuset none /opt/cpuset mkdir /opt/cpuset/01 echo 1 > /opt/cpuset/01/cpuset.cpus echo 0 > /opt/cpuset/01/cpuset.mems echo 1 > /opt/cpuset/01/cpuset.memory_migrate mkdir /opt/cpuset/02 echo 1 > /opt/cpuset/02/cpuset.cpus echo 1 > /opt/cpuset/02/cpuset.mems echo 1 > /opt/cpuset/02/cpuset.memory_migrate In above set, when you moves a task from 01 to 02, page migration to node 0 to node 1 will occur. Following is a script to migrate all under cpuset.:: -- move_task() { for pid in $1 do /bin/echo $pid >$2/tasks 2>/dev/null echo -n $pid echo -n " " done echo END } G1_TASK=`cat ${G1}/tasks` G2_TASK=`cat ${G2}/tasks` move_task "${G1_TASK}" ${G2} & -- ”h]”(hÌ)�”}”(hŒ�For NUMA, migration is an another special case. To do easy test, cpuset is useful. Following is a sample script to do migration::”h]”hŒ€For NUMA, migration is an another special case. To do easy test, cpuset is useful. Following is a sample script to do migration:”…”�”}”(hjòh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K£hjîubhŒ literal_block”“”)�”}”(hXAmount -t cgroup -o cpuset none /opt/cpuset mkdir /opt/cpuset/01 echo 1 > /opt/cpuset/01/cpuset.cpus echo 0 > /opt/cpuset/01/cpuset.mems echo 1 > /opt/cpuset/01/cpuset.memory_migrate mkdir /opt/cpuset/02 echo 1 > /opt/cpuset/02/cpuset.cpus echo 1 > /opt/cpuset/02/cpuset.mems echo 1 > /opt/cpuset/02/cpuset.memory_migrate”h]”hXAmount -t cgroup -o cpuset none /opt/cpuset mkdir /opt/cpuset/01 echo 1 > /opt/cpuset/01/cpuset.cpus echo 0 > /opt/cpuset/01/cpuset.mems echo 1 > /opt/cpuset/01/cpuset.memory_migrate mkdir /opt/cpuset/02 echo 1 > /opt/cpuset/02/cpuset.cpus echo 1 > /opt/cpuset/02/cpuset.mems echo 1 > /opt/cpuset/02/cpuset.memory_migrate”…”�”}”hjsbah}”(h]”h ]”h"]”h$]”h&]”Œ xml:space”Œpreserve”uh1jh³hÊh´K¦hjîubhÌ)�”}”(hŒ–In above set, when you moves a task from 01 to 02, page migration to node 0 to node 1 will occur. Following is a script to migrate all under cpuset.::”h]”hŒ•In above set, when you moves a task from 01 to 02, page migration to node 0 to node 1 will occur. Following is a script to migrate all under cpuset.:”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K±hjîubj)�”}”(hŒÞ-- move_task() { for pid in $1 do /bin/echo $pid >$2/tasks 2>/dev/null echo -n $pid echo -n " " done echo END } G1_TASK=`cat ${G1}/tasks` G2_TASK=`cat ${G2}/tasks` move_task "${G1_TASK}" ${G2} & --”h]”hŒÞ-- move_task() { for pid in $1 do /bin/echo $pid >$2/tasks 2>/dev/null echo -n $pid echo -n " " done echo END } G1_TASK=`cat ${G1}/tasks` G2_TASK=`cat ${G2}/tasks` move_task "${G1_TASK}" ${G2} & --”…”�”}”hj sbah}”(h]”h ]”h"]”h$]”h&]”jjuh1jh³hÊh´Kµhjîubeh}”(h]”h ]”h"]”h$]”h&]”uh1jh³hÊh´K£hjÝh²hubeh}”(h]”Œ migration”ah ]”h"]”Œ 9.3 migration”ah$]”h&]”uh1hµhjDh²hh³hÊh´K¡ubh¶)�”}”(hhh]”(h»)�”}”(hŒ9.4 Memory hotplug”h]”hŒ9.4 Memory hotplug”…”�”}”(hj?h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhj<h²hh³hÊh´KÇubj)�”}”(hŒámemory hotplug test is one of good test. to offline memory, do following:: # echo offline > /sys/devices/system/memory/memoryXXX/state (XXX is the place of memory) This is an easy way to test page migration, too. ”h]”(hÌ)�”}”(hŒ(memory hotplug test is one of good test.”h]”hŒ(memory hotplug test is one of good test.”…”�”}”(hjQh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KÉhjMubhÌ)�”}”(hŒ!to offline memory, do following::”h]”hŒ to offline memory, do following:”…”�”}”(hj_h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KËhjMubj)�”}”(hŒ;# echo offline > /sys/devices/system/memory/memoryXXX/state”h]”hŒ;# echo offline > /sys/devices/system/memory/memoryXXX/state”…”�”}”hjmsbah}”(h]”h ]”h"]”h$]”h&]”jjuh1jh³hÊh´KÍhjMubhÌ)�”}”(hŒ(XXX is the place of memory)”h]”hŒ(XXX is the place of memory)”…”�”}”(hj{h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KÏhjMubhÌ)�”}”(hŒ0This is an easy way to test page migration, too.”h]”hŒ0This is an easy way to test page migration, too.”…”�”}”(hj‰h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KÑhjMubeh}”(h]”h ]”h"]”h$]”h&]”uh1jh³hÊh´KÉhj<h²hubeh}”(h]”Œmemory-hotplug”ah ]”h"]”Œ9.4 memory hotplug”ah$]”h&]”uh1hµhjDh²hh³hÊh´KÇubh¶)�”}”(hhh]”(h»)�”}”(hŒ9.5 nested cgroups”h]”hŒ9.5 nested cgroups”…”�”}”(hj¨h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhj¥h²hh³hÊh´KÔubj)�”}”(hXÊUse tests like the following for testing nested cgroups:: mkdir /opt/cgroup/01/child_a mkdir /opt/cgroup/01/child_b set limit to 01. add limit to 01/child_b run jobs under child_a and child_b create/delete following groups at random while jobs are running:: /opt/cgroup/01/child_a/child_aa /opt/cgroup/01/child_b/child_bb /opt/cgroup/01/child_c running new jobs in new group is also good. ”h]”(hÌ)�”}”(hŒ9Use tests like the following for testing nested cgroups::”h]”hŒ8Use tests like the following for testing nested cgroups:”…”�”}”(hjºh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KÖhj¶ubj)�”}”(hŒ†mkdir /opt/cgroup/01/child_a mkdir /opt/cgroup/01/child_b set limit to 01. add limit to 01/child_b run jobs under child_a and child_b”h]”hŒ†mkdir /opt/cgroup/01/child_a mkdir /opt/cgroup/01/child_b set limit to 01. add limit to 01/child_b run jobs under child_a and child_b”…”�”}”hjÈsbah}”(h]”h ]”h"]”h$]”h&]”jjuh1jh³hÊh´KØhj¶ubhÌ)�”}”(hŒAcreate/delete following groups at random while jobs are running::”h]”hŒ@create/delete following groups at random while jobs are running:”…”�”}”(hjÖh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Kßhj¶ubj)�”}”(hŒV/opt/cgroup/01/child_a/child_aa /opt/cgroup/01/child_b/child_bb /opt/cgroup/01/child_c”h]”hŒV/opt/cgroup/01/child_a/child_aa /opt/cgroup/01/child_b/child_bb /opt/cgroup/01/child_c”…”�”}”hjäsbah}”(h]”h ]”h"]”h$]”h&]”jjuh1jh³hÊh´Káhj¶ubhÌ)�”}”(hŒ+running new jobs in new group is also good.”h]”hŒ+running new jobs in new group is also good.”…”�”}”(hjòh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Kåhj¶ubeh}”(h]”h ]”h"]”h$]”h&]”uh1jh³hÊh´KÖhj¥h²hubeh}”(h]”Œnested-cgroups”ah ]”h"]”Œ9.5 nested cgroups”ah$]”h&]”uh1hµhjDh²hh³hÊh´KÔubh¶)�”}”(hhh]”(h»)�”}”(hŒ9.6 Mount with other subsystems”h]”hŒ9.6 Mount with other subsystems”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjh²hh³hÊh´Kèubj)�”}”(hŒúMounting with other subsystems is a good test because there is a race and lock dependency with other cgroup subsystems. example:: # mount -t cgroup none /cgroup -o cpuset,memory,cpu,devices and do task move, mkdir, rmdir etc...under this. ”h]”(hÌ)�”}”(hŒwMounting with other subsystems is a good test because there is a race and lock dependency with other cgroup subsystems.”h]”hŒwMounting with other subsystems is a good test because there is a race and lock dependency with other cgroup subsystems.”…”�”}”(hj#h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KêhjubhÌ)�”}”(hŒ example::”h]”hŒexample:”…”�”}”(hj1h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Kíhjubj)�”}”(hŒ;# mount -t cgroup none /cgroup -o cpuset,memory,cpu,devices”h]”hŒ;# mount -t cgroup none /cgroup -o cpuset,memory,cpu,devices”…”�”}”hj?sbah}”(h]”h ]”h"]”h$]”h&]”jjuh1jh³hÊh´KïhjubhÌ)�”}”(hŒ0and do task move, mkdir, rmdir etc...under this.”h]”hŒ0and do task move, mkdir, rmdir etc...under this.”…”�”}”(hjMh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Kñhjubeh}”(h]”h ]”h"]”h$]”h&]”uh1jh³hÊh´Kêhjh²hubeh}”(h]”Œmount-with-other-subsystems”ah ]”h"]”Œ9.6 mount with other subsystems”ah$]”h&]”uh1hµhjDh²hh³hÊh´Kèubh¶)�”}”(hhh]”(h»)�”}”(hŒ 9.7 swapoff”h]”hŒ 9.7 swapoff”…”�”}”(hjlh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjih²hh³hÊh´Kôubj)�”}”(hXžBesides management of swap is one of complicated parts of memcg, call path of swap-in at swapoff is not same as usual swap-in path.. It's worth to be tested explicitly. For example, test like following is good: (Shell-A):: # mount -t cgroup none /cgroup -o memory # mkdir /cgroup/test # echo 40M > /cgroup/test/memory.limit_in_bytes # echo 0 > /cgroup/test/tasks Run malloc(100M) program under this. You'll see 60M of swaps. (Shell-B):: # move all tasks in /cgroup/test to /cgroup # /sbin/swapoff -a # rmdir /cgroup/test # kill malloc task. Of course, tmpfs v.s. swapoff test should be tested, too. ”h]”(hÌ)�”}”(hŒ¨Besides management of swap is one of complicated parts of memcg, call path of swap-in at swapoff is not same as usual swap-in path.. It's worth to be tested explicitly.”h]”hŒªBesides management of swap is one of complicated parts of memcg, call path of swap-in at swapoff is not same as usual swap-in path.. It’s worth to be tested explicitly.”…”�”}”(hj~h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KöhjzubhÌ)�”}”(hŒ)For example, test like following is good:”h]”hŒ)For example, test like following is good:”…”�”}”(hjŒh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KúhjzubhÌ)�”}”(hŒ (Shell-A)::”h]”hŒ (Shell-A):”…”�”}”(hjšh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Kühjzubj)�”}”(hŒ‹# mount -t cgroup none /cgroup -o memory # mkdir /cgroup/test # echo 40M > /cgroup/test/memory.limit_in_bytes # echo 0 > /cgroup/test/tasks”h]”hŒ‹# mount -t cgroup none /cgroup -o memory # mkdir /cgroup/test # echo 40M > /cgroup/test/memory.limit_in_bytes # echo 0 > /cgroup/test/tasks”…”�”}”hj¨sbah}”(h]”h ]”h"]”h$]”h&]”jjuh1jh³hÊh´KþhjzubhÌ)�”}”(hŒ=Run malloc(100M) program under this. You'll see 60M of swaps.”h]”hŒ?Run malloc(100M) program under this. You’ll see 60M of swaps.”…”�”}”(hj¶h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´MhjzubhÌ)�”}”(hŒ (Shell-B)::”h]”hŒ (Shell-B):”…”�”}”(hjÄh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Mhjzubj)�”}”(hŒg# move all tasks in /cgroup/test to /cgroup # /sbin/swapoff -a # rmdir /cgroup/test # kill malloc task.”h]”hŒg# move all tasks in /cgroup/test to /cgroup # /sbin/swapoff -a # rmdir /cgroup/test # kill malloc task.”…”�”}”hjÒsbah}”(h]”h ]”h"]”h$]”h&]”jjuh1jh³hÊh´MhjzubhÌ)�”}”(hŒ9Of course, tmpfs v.s. swapoff test should be tested, too.”h]”hŒ9Of course, tmpfs v.s. swapoff test should be tested, too.”…”�”}”(hjàh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´M hjzubeh}”(h]”h ]”h"]”h$]”h&]”uh1jh³hÊh´Köhjih²hubeh}”(h]”Œswapoff”ah ]”h"]”Œ 9.7 swapoff”ah$]”h&]”uh1hµhjDh²hh³hÊh´Kôubh¶)�”}”(hhh]”(h»)�”}”(hŒ9.8 OOM-Killer”h]”hŒ9.8 OOM-Killer”…”�”}”(hjÿh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjüh²hh³hÊh´Mubj)�”}”(hX<Out-of-memory caused by memcg's limit will kill tasks under the memcg. When hierarchy is used, a task under hierarchy will be killed by the kernel. In this case, panic_on_oom shouldn't be invoked and tasks in other groups shouldn't be killed. It's not difficult to cause OOM under memcg as following. Case A) when you can swapoff:: #swapoff -a #echo 50M > /memory.limit_in_bytes run 51M of malloc Case B) when you use mem+swap limitation:: #echo 50M > memory.limit_in_bytes #echo 50M > memory.memsw.limit_in_bytes run 51M of malloc ”h]”(hÌ)�”}”(hŒ“Out-of-memory caused by memcg's limit will kill tasks under the memcg. When hierarchy is used, a task under hierarchy will be killed by the kernel.”h]”hŒ•Out-of-memory caused by memcg’s limit will kill tasks under the memcg. When hierarchy is used, a task under hierarchy will be killed by the kernel.”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Mhj ubhÌ)�”}”(hŒ^In this case, panic_on_oom shouldn't be invoked and tasks in other groups shouldn't be killed.”h]”hŒbIn this case, panic_on_oom shouldn’t be invoked and tasks in other groups shouldn’t be killed.”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Mhj ubhÌ)�”}”(hŒ9It's not difficult to cause OOM under memcg as following.”h]”hŒ;It’s not difficult to cause OOM under memcg as following.”…”�”}”(hj- h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Mhj ubhÌ)�”}”(hŒCase A) when you can swapoff::”h]”hŒCase A) when you can swapoff:”…”�”}”(hj; h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Mhj ubj)�”}”(hŒ.#swapoff -a #echo 50M > /memory.limit_in_bytes”h]”hŒ.#swapoff -a #echo 50M > /memory.limit_in_bytes”…”�”}”hjI sbah}”(h]”h ]”h"]”h$]”h&]”jjuh1jh³hÊh´Mhj ubhÌ)�”}”(hŒrun 51M of malloc”h]”hŒrun 51M of malloc”…”�”}”(hjW h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Mhj ubhÌ)�”}”(hŒ*Case B) when you use mem+swap limitation::”h]”hŒ)Case B) when you use mem+swap limitation:”…”�”}”(hje h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´M!hj ubj)�”}”(hŒI#echo 50M > memory.limit_in_bytes #echo 50M > memory.memsw.limit_in_bytes”h]”hŒI#echo 50M > memory.limit_in_bytes #echo 50M > memory.memsw.limit_in_bytes”…”�”}”hjs sbah}”(h]”h ]”h"]”h$]”h&]”jjuh1jh³hÊh´M#hj ubhÌ)�”}”(hŒrun 51M of malloc”h]”hŒrun 51M of malloc”…”�”}”(hj� h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´M&hj ubeh}”(h]”h ]”h"]”h$]”h&]”uh1jh³hÊh´Mhjüh²hubeh}”(h]”Œ oom-killer”ah ]”h"]”Œ9.8 oom-killer”ah$]”h&]”uh1hµhjDh²hh³hÊh´Mubh¶)�”}”(hhh]”(h»)�”}”(hŒ"9.9 Move charges at task migration”h]”hŒ"9.9 Move charges at task migration”…”�”}”(hj  h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhj� h²hh³hÊh´M)ubj)�”}”(hX\Charges associated with a task can be moved along with task migration. (Shell-A):: #mkdir /cgroup/A #echo $$ >/cgroup/A/tasks run some programs which uses some amount of memory in /cgroup/A. (Shell-B):: #mkdir /cgroup/B #echo 1 >/cgroup/B/memory.move_charge_at_immigrate #echo "pid of the program running in group A" >/cgroup/B/tasks You can see charges have been moved by reading ``*.usage_in_bytes`` or memory.stat of both A and B. See 8.2 of Documentation/admin-guide/cgroup-v1/memory.rst to see what value should be written to move_charge_at_immigrate. ”h]”(hÌ)�”}”(hŒFCharges associated with a task can be moved along with task migration.”h]”hŒFCharges associated with a task can be moved along with task migration.”…”�”}”(hj² h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´M+hj® ubhÌ)�”}”(hŒ (Shell-A)::”h]”hŒ (Shell-A):”…”�”}”(hjÀ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´M-hj® ubj)�”}”(hŒ*#mkdir /cgroup/A #echo $$ >/cgroup/A/tasks”h]”hŒ*#mkdir /cgroup/A #echo $$ >/cgroup/A/tasks”…”�”}”hjÎ sbah}”(h]”h ]”h"]”h$]”h&]”jjuh1jh³hÊh´M/hj® ubhÌ)�”}”(hŒ@run some programs which uses some amount of memory in /cgroup/A.”h]”hŒ@run some programs which uses some amount of memory in /cgroup/A.”…”�”}”(hjÜ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´M2hj® ubhÌ)�”}”(hŒ (Shell-B)::”h]”hŒ (Shell-B):”…”�”}”(hjê h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´M4hj® ubj)�”}”(hŒ‚#mkdir /cgroup/B #echo 1 >/cgroup/B/memory.move_charge_at_immigrate #echo "pid of the program running in group A" >/cgroup/B/tasks”h]”hŒ‚#mkdir /cgroup/B #echo 1 >/cgroup/B/memory.move_charge_at_immigrate #echo "pid of the program running in group A" >/cgroup/B/tasks”…”�”}”hjø sbah}”(h]”h ]”h"]”h$]”h&]”jjuh1jh³hÊh´M6hj® ubhÌ)�”}”(hŒcYou can see charges have been moved by reading ``*.usage_in_bytes`` or memory.stat of both A and B.”h]”(hŒ/You can see charges have been moved by reading ”…”�”}”(hj h²hh³Nh´NubhŒliteral”“”)�”}”(hŒ``*.usage_in_bytes``”h]”hŒ*.usage_in_bytes”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j hj ubhŒ or memory.stat of both A and B.”…”�”}”(hj h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´M:hj® ubhÌ)�”}”(hŒzSee 8.2 of Documentation/admin-guide/cgroup-v1/memory.rst to see what value should be written to move_charge_at_immigrate.”h]”hŒzSee 8.2 of Documentation/admin-guide/cgroup-v1/memory.rst to see what value should be written to move_charge_at_immigrate.”…”�”}”(hj( h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´M=hj® ubeh}”(h]”h ]”h"]”h$]”h&]”uh1jh³hÊh´M+hj� h²hubeh}”(h]”Œmove-charges-at-task-migration”ah ]”h"]”Œ"9.9 move charges at task migration”ah$]”h&]”uh1hµhjDh²hh³hÊh´M)ubh¶)�”}”(hhh]”(h»)�”}”(hŒ9.10 Memory thresholds”h]”hŒ9.10 Memory thresholds”…”�”}”(hjG h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjD h²hh³hÊh´MAubj)�”}”(hXŒMemory controller implements memory thresholds using cgroups notification API. You can use samples/cgroup/cgroup_event_listener.c to test it. (Shell-A) Create cgroup and run event listener:: # mkdir /cgroup/A # ./cgroup_event_listener /cgroup/A/memory.usage_in_bytes 5M (Shell-B) Add task to cgroup and try to allocate and free memory:: # echo $$ >/cgroup/A/tasks # a="$(dd if=/dev/zero bs=1M count=10)" # a= You will see message from cgroup_event_listener every time you cross the thresholds. Use /cgroup/A/memory.memsw.usage_in_bytes to test memsw thresholds. It's good idea to test root cgroup as well.”h]”(hÌ)�”}”(hŒ�Memory controller implements memory thresholds using cgroups notification API. You can use samples/cgroup/cgroup_event_listener.c to test it.”h]”hŒ�Memory controller implements memory thresholds using cgroups notification API. You can use samples/cgroup/cgroup_event_listener.c to test it.”…”�”}”(hjY h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´MChjU ubhÌ)�”}”(hŒ0(Shell-A) Create cgroup and run event listener::”h]”hŒ/(Shell-A) Create cgroup and run event listener:”…”�”}”(hjg h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´MFhjU ubj)�”}”(hŒN# mkdir /cgroup/A # ./cgroup_event_listener /cgroup/A/memory.usage_in_bytes 5M”h]”hŒN# mkdir /cgroup/A # ./cgroup_event_listener /cgroup/A/memory.usage_in_bytes 5M”…”�”}”hju sbah}”(h]”h ]”h"]”h$]”h&]”jjuh1jh³hÊh´MHhjU ubhÌ)�”}”(hŒB(Shell-B) Add task to cgroup and try to allocate and free memory::”h]”hŒA(Shell-B) Add task to cgroup and try to allocate and free memory:”…”�”}”(hjƒ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´MKhjU ubj)�”}”(hŒG# echo $$ >/cgroup/A/tasks # a="$(dd if=/dev/zero bs=1M count=10)" # a=”h]”hŒG# echo $$ >/cgroup/A/tasks # a="$(dd if=/dev/zero bs=1M count=10)" # a=”…”�”}”hj‘ sbah}”(h]”h ]”h"]”h$]”h&]”jjuh1jh³hÊh´MMhjU ubhÌ)�”}”(hŒTYou will see message from cgroup_event_listener every time you cross the thresholds.”h]”hŒTYou will see message from cgroup_event_listener every time you cross the thresholds.”…”�”}”(hjŸ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´MQhjU ubhÌ)�”}”(hŒCUse /cgroup/A/memory.memsw.usage_in_bytes to test memsw thresholds.”h]”hŒCUse /cgroup/A/memory.memsw.usage_in_bytes to test memsw thresholds.”…”�”}”(hj­ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´MThjU ubhÌ)�”}”(hŒ+It's good idea to test root cgroup as well.”h]”hŒ-It’s good idea to test root cgroup as well.”…”�”}”(hj» h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´MVhjU ubeh}”(h]”h ]”h"]”h$]”h&]”uh1jh³hÊh´MChjD h²hubeh}”(h]”Œmemory-thresholds”ah ]”h"]”Œ9.10 memory thresholds”ah$]”h&]”uh1hµhjDh²hh³hÊh´MAubeh}”(h]”Œ typical-tests”ah ]”h"]”Œ9. typical tests.”ah$]”h&]”uh1hµhh·h²hh³hÊh´K‹ubeh}”(h]”Œ4memory-resource-controller-memcg-implementation-memo”ah ]”h"]”Œ5memory resource controller(memcg) implementation memo”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”}”Œnameids”}”(jä já j�jŒjØjÕj‚jj%j"j|jyjójðjßjÜjj jAj>jÜ jÙ j©j¦jÚj×j9j6j¢jŸj jjfjcjùjöjš j— jA j> jÔ jÑ uŒ nametypes”}”(jä ‰j�‰j؉j‚‰j%‰j|‰jó‰j߉j‰jA‰jÜ ‰j©‰jÚ‰j9‰j¢‰j ‰jf‰jù‰jš ‰jA ‰jÔ ‰uh}”(já h·jŒjjÕj’jjÛj"j…jyj(jðjjÜjöj jâj>jjÙ jDj¦jmj×j¬j6jÝjŸj<jj¥jcjjöjij— jüj> j� jÑ jD 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”“”}”…”R”Œparse_messages”]”Œtransform_messages”]”Œ transformer”NŒ include_log”]”Œ decoration”Nh²hub.