linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm, kvm: account kvm_vcpu_mmap to kmemcg
@ 2020-11-06 20:29 Shakeel Butt
  2020-11-06 20:52 ` Roman Gushchin
  0 siblings, 1 reply; 3+ messages in thread
From: Shakeel Butt @ 2020-11-06 20:29 UTC (permalink / raw)
  To: Roman Gushchin, Johannes Weiner, Michal Hocko
  Cc: Andrew Morton, Paolo Bonzini, linux-mm, linux-kernel, kvm, Shakeel Butt

A VCPU of a VM can allocate couple of pages which can be mmap'ed by the
user space application. At the moment this memory is not charged to the
memcg of the VMM. On a large machine running large number of VMs or
small number of VMs having large number of VCPUs, this unaccounted
memory can be very significant. So, charge this memory to the memcg of
the VMM. Please note that lifetime of these allocations corresponds to
the lifetime of the VMM.

Signed-off-by: Shakeel Butt <shakeelb@google.com>
---

This patch has dependency on Roman's patch series "mm: allow mapping
accounted kernel pages to userspace".

 arch/s390/kvm/kvm-s390.c  | 2 +-
 arch/x86/kvm/x86.c        | 2 +-
 virt/kvm/coalesced_mmio.c | 2 +-
 virt/kvm/kvm_main.c       | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index 6b74b92c1a58..8364c5ee91a5 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -3243,7 +3243,7 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
 	int rc;
 
 	BUILD_BUG_ON(sizeof(struct sie_page) != 4096);
-	sie_page = (struct sie_page *) get_zeroed_page(GFP_KERNEL);
+	sie_page = (struct sie_page *) get_zeroed_page(GFP_KERNEL_ACCOUNT);
 	if (!sie_page)
 		return -ENOMEM;
 
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 397f599b20e5..d37acf3ce17f 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -9829,7 +9829,7 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
 
 	r = -ENOMEM;
 
-	page = alloc_page(GFP_KERNEL | __GFP_ZERO);
+	page = alloc_page(GFP_KERNEL_ACCOUNT | __GFP_ZERO);
 	if (!page)
 		goto fail_free_lapic;
 	vcpu->arch.pio_data = page_address(page);
diff --git a/virt/kvm/coalesced_mmio.c b/virt/kvm/coalesced_mmio.c
index e2c197fd4f9d..62bd908ecd58 100644
--- a/virt/kvm/coalesced_mmio.c
+++ b/virt/kvm/coalesced_mmio.c
@@ -111,7 +111,7 @@ int kvm_coalesced_mmio_init(struct kvm *kvm)
 {
 	struct page *page;
 
-	page = alloc_page(GFP_KERNEL | __GFP_ZERO);
+	page = alloc_page(GFP_KERNEL_ACCOUNT | __GFP_ZERO);
 	if (!page)
 		return -ENOMEM;
 
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 2541a17ff1c4..f69357a29688 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -3116,7 +3116,7 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, u32 id)
 	}
 
 	BUILD_BUG_ON(sizeof(struct kvm_run) > PAGE_SIZE);
-	page = alloc_page(GFP_KERNEL | __GFP_ZERO);
+	page = alloc_page(GFP_KERNEL_ACCOUNT | __GFP_ZERO);
 	if (!page) {
 		r = -ENOMEM;
 		goto vcpu_free;
-- 
2.29.1.341.ge80a0c044ae-goog



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm, kvm: account kvm_vcpu_mmap to kmemcg
  2020-11-06 20:29 [PATCH] mm, kvm: account kvm_vcpu_mmap to kmemcg Shakeel Butt
@ 2020-11-06 20:52 ` Roman Gushchin
  2020-11-08 11:23   ` Paolo Bonzini
  0 siblings, 1 reply; 3+ messages in thread
From: Roman Gushchin @ 2020-11-06 20:52 UTC (permalink / raw)
  To: Shakeel Butt
  Cc: Johannes Weiner, Michal Hocko, Andrew Morton, Paolo Bonzini,
	linux-mm, linux-kernel, kvm

On Fri, Nov 06, 2020 at 12:29:23PM -0800, Shakeel Butt wrote:
> A VCPU of a VM can allocate couple of pages which can be mmap'ed by the
> user space application. At the moment this memory is not charged to the
> memcg of the VMM. On a large machine running large number of VMs or
> small number of VMs having large number of VCPUs, this unaccounted
> memory can be very significant. So, charge this memory to the memcg of
> the VMM. Please note that lifetime of these allocations corresponds to
> the lifetime of the VMM.
> 
> Signed-off-by: Shakeel Butt <shakeelb@google.com>
> ---

Acked-by: Roman Gushchin <guro@fb.com>

Thanks, Shakeel!


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm, kvm: account kvm_vcpu_mmap to kmemcg
  2020-11-06 20:52 ` Roman Gushchin
@ 2020-11-08 11:23   ` Paolo Bonzini
  0 siblings, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2020-11-08 11:23 UTC (permalink / raw)
  To: Roman Gushchin, Shakeel Butt
  Cc: Johannes Weiner, Michal Hocko, Andrew Morton, linux-mm,
	linux-kernel, kvm

On 06/11/20 21:52, Roman Gushchin wrote:
> On Fri, Nov 06, 2020 at 12:29:23PM -0800, Shakeel Butt wrote:
>> A VCPU of a VM can allocate couple of pages which can be mmap'ed by the
>> user space application. At the moment this memory is not charged to the
>> memcg of the VMM. On a large machine running large number of VMs or
>> small number of VMs having large number of VCPUs, this unaccounted
>> memory can be very significant. So, charge this memory to the memcg of
>> the VMM. Please note that lifetime of these allocations corresponds to
>> the lifetime of the VMM.
>>
>> Signed-off-by: Shakeel Butt <shakeelb@google.com>
>> ---
> 
> Acked-by: Roman Gushchin <guro@fb.com>
> 
> Thanks, Shakeel!
> 

Acked-by: Paolo Bonzini <pbonzini@redhat.com>

If this patch is not merged via -mm, please ping me again once its 
dependency is part of Linus's tree.

Thanks,

Paolo



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-11-08 11:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-06 20:29 [PATCH] mm, kvm: account kvm_vcpu_mmap to kmemcg Shakeel Butt
2020-11-06 20:52 ` Roman Gushchin
2020-11-08 11:23   ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).