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: 11888051 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A956C5517A for ; Fri, 6 Nov 2020 20:29:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1AEE921D7F for ; Fri, 6 Nov 2020 20:29:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="qxK63C85" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728410AbgKFU3e (ORCPT ); Fri, 6 Nov 2020 15:29:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728237AbgKFU3e (ORCPT ); Fri, 6 Nov 2020 15:29:34 -0500 Received: from mail-qt1-x849.google.com (mail-qt1-x849.google.com [IPv6:2607:f8b0:4864:20::849]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C46F3C0613D2 for ; Fri, 6 Nov 2020 12:29:33 -0800 (PST) Received: by mail-qt1-x849.google.com with SMTP id e19so1725637qtq.17 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=rhEoR/6D8vX4TOQ+2LkzcUbZQu9R+ryjMgPUtvgJ9qFB2KWtm6yakUUmR5vtmPMzHZ cysb9XetbzHSlLK3aePDzubUCV4MVrriRPZMFAsXYvyDnqkN8Sggkyry6I10j65324gJ B9hACiPC9nlwgqww/Fp0ASz7yYxdH8b4qBHXpLba2+WuDE1sveHmM3y31BDEerEmi70e 9koyYEdcGYYthgLymStCQL+6ZvHDwGFIccwM932G2W4qA4EbetfyM0pCNkWudRSXrGEG EOx52GUkKFAQlPXz4L4pC8Iu2PtEms2bGUgBycEPOXRDuBLfjcWzKgTc7ZWVY4gRNDrv d5Iw== X-Gm-Message-State: AOAM530zqDtkpddlp0vSF9TwOUHDgJzKO8dtiMd4YSpVD8SiUY3l1qyz 3ebLdoqNMbYYCPjq+jOb+yk9SAEDU3vouQ== X-Google-Smtp-Source: ABdhPJzRtuBmM7hT4n/AykR+FlOUggYbVMe/LDkuyotS0xBuSPRCU2hzDublBhwIcsnZ8iR6EFpEw7C4KtLO4Q== Sender: "shakeelb via sendgmr" 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 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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;