From patchwork Fri Nov 6 20:29:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shakeel Butt X-Patchwork-Id: 11888049 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D9D6214B4 for ; Fri, 6 Nov 2020 20:29:36 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5678821D81 for ; Fri, 6 Nov 2020 20:29:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="qxK63C85" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5678821D81 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 09B5E6B0036; Fri, 6 Nov 2020 15:29:35 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 04BE06B005C; Fri, 6 Nov 2020 15:29:34 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E55916B005D; Fri, 6 Nov 2020 15:29:34 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0249.hostedemail.com [216.40.44.249]) by kanga.kvack.org (Postfix) with ESMTP id B63A46B0036 for ; Fri, 6 Nov 2020 15:29:34 -0500 (EST) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 450A3180AD81D for ; Fri, 6 Nov 2020 20:29:34 +0000 (UTC) X-FDA: 77455133868.05.glove93_3701640272d5 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin05.hostedemail.com (Postfix) with ESMTP id 263821801AB46 for ; Fri, 6 Nov 2020 20:29:34 +0000 (UTC) X-Spam-Summary: 1,0,0,de758ca8e2b058d5,d41d8cd98f00b204,3llklxwgkccszohrllsinvvnsl.jvtspube-ttrchjr.vyn@flex--shakeelb.bounces.google.com,,RULES_HIT:41:152:355:379:541:800:960:966:973:988:989:1260:1277:1313:1314:1345:1437:1516:1518:1535:1542:1593:1594:1711:1730:1747:1777:1792:2196:2199:2393:2559:2562:3138:3139:3140:3141:3142:3152:3353:3865:3866:3867:3871:3874:4250:4321:4385:4605:5007:6119:6261:6653:7903:7974:9969:10004:10400:11026:11232:11473:11657:11658:11914:12043:12296:12297:12438:12555:12895:12986:13161:13227:13229:14093:14096:14097:14181:14394:14659:14721:21080:21433:21444:21450:21451:21627:21660:21795:21990:30001:30034:30051:30054:30080,0,RBL:209.85.222.202:@flex--shakeelb.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04yr4kschdhk5z8nrq3cwfb4giww3op9rkdfkub6dtko8zf37ubbtu46z1xwuon.z7pkmgjn9x3dkfy4pphmwhfhxsjpsni45k6krswi9oxxrrid33h4sep4epxexx5.e-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not b ulk,SPF: X-HE-Tag: glove93_3701640272d5 X-Filterd-Recvd-Size: 5398 Received: from mail-qk1-f202.google.com (mail-qk1-f202.google.com [209.85.222.202]) by imf47.hostedemail.com (Postfix) with ESMTP for ; Fri, 6 Nov 2020 20:29:33 +0000 (UTC) Received: by mail-qk1-f202.google.com with SMTP id w4so1270315qki.20 for ; Fri, 06 Nov 2020 12:29:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:message-id:mime-version:subject:from:to:cc; bh=ULc2QwdCH5im+pfEGHCAJt9dFDUjORAmMg0iMDdD/ZE=; b=qxK63C85+mLWqUM6fF6ufmuq09cUwYZSbRvdqXOVlKWkYTVHLWgKHZPW23Sgbbpsut J/dtITSGF8n2ylyWL2J9oazEIkmB5z36lETuij7i6T4x90ka4hoRiMp+aJSiHe5hR7Qm cYwBLWMnyNt7WRI+pi7pWUPKuW5krdqFEjpBcH9aLwC3eZv4Mlwd+483rDk01xUiWOPA YOboDY+r4fchGJs6SogwqO9pRRdrR/wihlrcAt3wzN7FILrUxhYUpL5uDNEEDCicu449 vkBz2bGesJpH1iphht0MRywvktZwKa/xSxTJh38piWQ4q5tWgTV+bb+bGUip3QSEVU9v vFgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:message-id:mime-version:subject:from :to:cc; bh=ULc2QwdCH5im+pfEGHCAJt9dFDUjORAmMg0iMDdD/ZE=; b=Myqh0jm4myXwGB9kSI5qBqBweTi6sywFgNsYqhj0IJB3Iw+9UrXAd02FEXeOLkbo1F yezUr3gFeyYCv3eXtjQIQBB9CLOCOFGeV9WTeLeOdz8qxuucz9KMntvzps+a+FHO5klg 3ul+tYHBFqrhbVHrsk6NtuZJg7VOQMqiMN1Qr53meKolEjFZwceJyP4FmSkjFCVGWaTV 5kJU6nZAXmiwJFNsj6eso0nro6ulE2Lh2NTFRQdcLU5UqcNxaqyMOI7yRCQCQye2iYSn FZvzgN3Du7feuSzRr+vHOY+gSHvc0u9a39nVcKG16zTD0m6TVsfxJAPnHN5q8AwMOkoF 895A== X-Gm-Message-State: AOAM533xVEhVUftze0Gy3W31ED0IlRIx5bnW6EedPFhcTPzzUc4hYx5w k/BjWGW6mJ7KRgDqSNAWL8UmWoPtlnPKDg== X-Google-Smtp-Source: ABdhPJzRtuBmM7hT4n/AykR+FlOUggYbVMe/LDkuyotS0xBuSPRCU2hzDublBhwIcsnZ8iR6EFpEw7C4KtLO4Q== X-Received: from shakeelb.svl.corp.google.com ([2620:15c:2cd:202:a28c:fdff:fee8:36f0]) (user=shakeelb job=sendgmr) by 2002:ac8:6e8b:: with SMTP id c11mr3303614qtv.2.1604694572860; Fri, 06 Nov 2020 12:29:32 -0800 (PST) Date: Fri, 6 Nov 2020 12:29:23 -0800 Message-Id: <20201106202923.2087414-1-shakeelb@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH] mm, kvm: account kvm_vcpu_mmap to kmemcg From: Shakeel Butt To: Roman Gushchin , Johannes Weiner , Michal Hocko Cc: Andrew Morton , Paolo Bonzini , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Shakeel Butt X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 Acked-by: Roman Gushchin Acked-by: Paolo Bonzini --- 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;