kvm, mm: account shadow page tables to kmemcg
Subsystems (5)
PATCH v2 1/1 kvm, mm: account shadow page tables to kmemcg
The size of kvm's shadow page tables corresponds to the size of the guest virtual machines on the system. Large VMs can spend a significant amount of memory as shadow page tables which can not be left as system memory overhead. So, account shadow page tables to the kmemcg.
---
Changelog since v1:
- replaced (GFP_KERNEL|__GFP_ACCOUNT) with GFP_KERNEL_ACCOUNT
arch/x86/kvm/mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/mmu.c +1 -1
@@ -890,7 +890,7 @@ static int mmu_topup_memory_cache_page(struct kvm_mmu_memory_cache *cache,if (cache->nobjs >= min)return 0 ;while (cache->nobjs <ARRAY_SIZE (cache->objects)) { - page = (void *)__get_free_page (GFP_KERNEL ); + page = (void *)__get_free_page (GFP_KERNEL_ACCOUNT );if (!page)return -ENOMEM ; cache->objects[cache->nobjs++] = page;
Signature · 1 line
2.18.0.rc2.346.g013aa6912e-goog
Quoted 5 lines · Shakeel Butt
The size of kvm's shadow page tables corresponds to the size of the guest virtual machines on the system. Large VMs can spend a significant amount of memory as shadow page tables which can not be left as system memory overhead. So, account shadow page tables to the kmemcg.
Quoted 10 lines
Signed-off-by Shakeel Butt <[email protected]>Cc Michal Hocko <[email protected]>Cc Johannes Weiner <[email protected]>Cc Vladimir Davydov <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Greg Thelen <[email protected]>Cc Radim Krčmář <[email protected]>Cc Peter Feiner <[email protected]>Cc Andrew Morton <[email protected]>
I am not familiar wtih kvm to judge but if we are going to account this memory we will probably want to let oom_badness know how much memory to account to a specific process. Is this something that we can do? We will probably need a new MM_KERNEL rss_stat stat for that purpose.
Just to make it clear. I am not opposing to this patch but considering that shadow page tables might consume a lot of memory it would be good to know who is responsible for it from the OOM perspective. Something to solve on top of this.
I would also love to see a note how this memory is bound to the owner life time in the changelog. That would make the review much more easier.
Quoted 22 lines
---
Changelog since v1:
- replaced (GFP_KERNEL|__GFP_ACCOUNT) withGFP_KERNEL_ACCOUNTarch/x86/kvm/mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/kvm/mmu.c +1
-1@@ -890,7 +890,7 @@ static int mmu_topup_memory_cache_page(struct kvm_mmu_memory_cache *cache,if (cache->nobjs >= min)return 0 ;while (cache->nobjs <ARRAY_SIZE (cache->objects)) { - page = (void *)__get_free_page (GFP_KERNEL ); + page = (void *)__get_free_page (GFP_KERNEL_ACCOUNT );if (!page)return -ENOMEM ; cache->objects[cache->nobjs++] = page;Signature · 1 line
2.18.0.rc2.346.g013aa6912e-goog
Signature · 2 lines
Michal Hocko SUSE Labs
Paolo Bonzini
maintainerQuoted 9 lines · Michal Hocko
I am not familiar wtih kvm to judge but if we are going to account this memory we will probably want to let
oom_badnessknow how much memory to account to a specific process. Is this something that we can do? We will probably need a newMM_KERNELrss_statstat for that purpose.Just to make it clear. I am not opposing to this patch but considering that shadow page tables might consume a lot of memory it would be good to know who is responsible for it from the OOM perspective. Something to solve on top of this.
The amount of memory is generally proportional to the size of the virtual machine memory, which is reflected directly into RSS. Because KVM processes are usually huge, and will probably dwarf everything else in the system (except firefox and chromium of course :)), the general order of magnitude of the oom_badness should be okay.
Quoted 2 lines
I would also love to see a note how this memory is bound to the owner life time in the changelog. That would make the review much more easier.
--verbose for people that aren't well versed in linux mm, please...
Paolo
Quoted 11 lines · Paolo Bonzini
Quoted 9 lines · Michal Hocko
I am not familiar wtih kvm to judge but if we are going to account this memory we will probably want to let
oom_badnessknow how much memory to account to a specific process. Is this something that we can do? We will probably need a newMM_KERNELrss_statstat for that purpose.Just to make it clear. I am not opposing to this patch but considering that shadow page tables might consume a lot of memory it would be good to know who is responsible for it from the OOM perspective. Something to solve on top of this.
Quoted 5 lines
The amount of memory is generally proportional to the size of the virtual machine memory, which is reflected directly into RSS. Because KVM processes are usually huge, and will probably dwarf everything else in the system (except firefox and chromium of course :)), the general order of magnitude of the
oom_badnessshould be okay.
I think we will need MM_KERNEL longterm anyway. As I've said this is not a must for this patch to go. But it is better to have a fair comparision and kill larger processes if at all possible. It seems this should be the case here.
Quoted 4 lines
Quoted 2 lines
I would also love to see a note how this memory is bound to the owner life time in the changelog. That would make the review much more easier.
--verbose for people that aren't well versed in linux mm, please...
Well, if the memory accounted to the memcg hits the hard limit and there is no way to reclaim anything to reduce the charged memory then we have to kill something. Hopefully the memory hog. If that one dies it would be great it releases its charges along the way. My remark was just to explain how that would happen for this specific type of memory. Bound to a file, has its own tear down etc. Basically make life of reviewers easier to understand the lifetime of charged objects without digging deep into the specific subsystem.
Signature · 2 lines
Michal Hocko SUSE Labs
Paolo Bonzini
maintainerQuoted 11 lines · Michal Hocko
Quoted 3 lines
Quoted 2 lines
I would also love to see a note how this memory is bound to the owner life time in the changelog. That would make the review much more easier.
--verbose for people that aren't well versed in linux mm, please...
Well, if the memory accounted to the memcg hits the hard limit and there is no way to reclaim anything to reduce the charged memory then we have to kill something. Hopefully the memory hog. If that one dies it would be great it releases its charges along the way. My remark was just to explain how that would happen for this specific type of memory. Bound to a file, has its own tear down etc. Basically make life of reviewers easier to understand the lifetime of charged objects without digging deep into the specific subsystem.
Oh I see. Yes, it's all freed when the VM file descriptor (which you get with a ioctl on /dev/kvm) is closed.
Thanks,
Paolo
Quoted 19 lines · Michal Hocko
Quoted 11 lines · Paolo Bonzini
Quoted 9 lines · Michal Hocko
I am not familiar wtih kvm to judge but if we are going to account this memory we will probably want to let
oom_badnessknow how much memory to account to a specific process. Is this something that we can do? We will probably need a newMM_KERNELrss_statstat for that purpose.Just to make it clear. I am not opposing to this patch but considering that shadow page tables might consume a lot of memory it would be good to know who is responsible for it from the OOM perspective. Something to solve on top of this.
Quoted 5 lines
The amount of memory is generally proportional to the size of the virtual machine memory, which is reflected directly into RSS. Because KVM processes are usually huge, and will probably dwarf everything else in the system (except firefox and chromium of course :)), the general order of magnitude of the
oom_badnessshould be okay.
Quoted 5 lines
I think we will need
MM_KERNELlongterm anyway. As I've said this is not a must for this patch to go. But it is better to have a fair comparision and kill larger processes if at all possible. It seems this should be the case here.
I will look more into MM_KERNEL counter. I still have couple more kmem allocations in kvm (like dirty bitmap) which I want to be accounted. I will bundle them together.
thanks,
Shakeel