Message ID | 20201106202923.2087414-1-shakeelb@google.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | mm, kvm: account kvm_vcpu_mmap to kmemcg | expand |
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!
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
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;
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(-)