]> git.baikalelectronics.ru Git - kernel.git/commitdiff
mm, kvm: account kvm_vcpu_mmap to kmemcg
authorShakeel Butt <shakeelb@google.com>
Fri, 18 Dec 2020 22:01:38 +0000 (14:01 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 19 Dec 2020 19:18:37 +0000 (11:18 -0800)
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.

Link: https://lkml.kernel.org/r/20201106202923.2087414-1-shakeelb@google.com
Signed-off-by: Shakeel Butt <shakeelb@google.com>
Acked-by: Roman Gushchin <guro@fb.com>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@suse.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
arch/x86/kvm/x86.c
virt/kvm/coalesced_mmio.c
virt/kvm/kvm_main.c

index e545a8a613b19719eb81469cdeaf1e1f7fb74684..b05aec109242e81a21274c8d988d251dc1522389 100644 (file)
@@ -9869,7 +9869,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);
index e2c197fd4f9d460778fbb71d065a3409cf6de5b5..62bd908ecd580a871bc34bf6868f1563f4e7be43 100644 (file)
@@ -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;
 
index 2541a17ff1c45394e5de176ac52669b4785f5420..f69357a296885de5eca16ff57b3943619478073d 100644 (file)
@@ -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;