From patchwork Fri Oct 6 01:07:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shakeel Butt X-Patchwork-Id: 9988167 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7C14560291 for ; Fri, 6 Oct 2017 01:07:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6F63E28CDB for ; Fri, 6 Oct 2017 01:07:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6431828D44; Fri, 6 Oct 2017 01:07:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EC33A28CDB for ; Fri, 6 Oct 2017 01:07:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751470AbdJFBHb (ORCPT ); Thu, 5 Oct 2017 21:07:31 -0400 Received: from mail-pg0-f41.google.com ([74.125.83.41]:47116 "EHLO mail-pg0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751083AbdJFBHa (ORCPT ); Thu, 5 Oct 2017 21:07:30 -0400 Received: by mail-pg0-f41.google.com with SMTP id r25so6751859pgn.4 for ; Thu, 05 Oct 2017 18:07:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=pPLCuLgdthzCxtnKCvKNn7rkc/F3kbWIeYCSde8xkqc=; b=tbY6LpuYjYbJEcnfMqwaVu43emnPRW0XZv9WkTZPaBh6HFwOUP9l4IHB1KB/TwjAuR xJplflRr7Zzmd+6fS6LJFZpaxc/wEgpnT3wtLKILxtGiNr2mRX9j6NoBoqB8bXtvcIgF Sof3XOkrrotzDGtGosjYA0I66rmTPzFh7e4gsDkeExU5p/RWwS3imweiyIemDKaBXYjk FYXfy+D57Cqmh7swicTWCEPPlhl91tVZ0OWSHxIsZ5aUnpd1Y3L1TgsSjzn+T2b3f1PI BLFM7S3b+/H8IoiJbexPGGtOk3f610JbwJSwi8/XUHaGHMSunNR+SVzA2c292BwGCV32 wFnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=pPLCuLgdthzCxtnKCvKNn7rkc/F3kbWIeYCSde8xkqc=; b=YOv8RcE2yeCE1Ns15FEMOojVDCYOIZW7zsZmu+++8aaU6el1MI3MhtvN/zhK1Bu/Za 0y9Ef1e4J94QMAzyBgfjbDGTC8QfqiMd6GGyglkTQI5QjzXHxhANnEy8MO4Id9ts6uIn SQP3QQMT2pl1XgJZyp5OSghiHeoY8N8u9RTqjOJD6mF6BLyXWT2hXDqO2VLIi7M3JsNz 4g17PzIi78BxKF1ZrNkpwjqw8AH9LegyKn6fT2K0mSymJVhlSIxWB6GemeUQFv9moh4c aV8RjcP8UZxQ55aj9m7S4MK6gCKhAYLtOq3k5IoiMDNAAPfcH0TBoruvNnmOedyplzFZ Lk8Q== X-Gm-Message-State: AMCzsaUpB7KL8zGPeK7o1H5P5GdSwhZ8gZCCmw5N6kfii1vqmMg1lSdA 3w1dMcWW0J13C2fLC2IiegDlQQ== X-Google-Smtp-Source: AOwi7QCE6qtwZFb8D4ytjg5ZglKajRz+Hy9QrcboOD/N5iRwF9JcZlM7rqR60hodg5ePAgHAvO1C6Q== X-Received: by 10.98.242.3 with SMTP id m3mr478214pfh.306.1507252049420; Thu, 05 Oct 2017 18:07:29 -0700 (PDT) Received: from shakeelb.mtv.corp.google.com ([100.123.228.219]) by smtp.gmail.com with ESMTPSA id r79sm301182pfa.179.2017.10.05.18.07.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 05 Oct 2017 18:07:28 -0700 (PDT) From: Shakeel Butt To: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , Vladimir Davydov , Michal Hocko , Greg Thelen Cc: Andrew Morton , linux-mm@kvack.org, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Shakeel Butt Subject: [PATCH] kvm, mm: account kvm related kmem slabs to kmemcg Date: Thu, 5 Oct 2017 18:07:24 -0700 Message-Id: <20171006010724.186563-1-shakeelb@google.com> X-Mailer: git-send-email 2.14.2.920.gcf0c67979c-goog Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The kvm slabs can consume a significant amount of system memory and indeed in our production environment we have observed that a lot of machines are spending significant amount of memory that can not be left as system memory overhead. Also the allocations from these slabs can be triggered directly by user space applications which has access to kvm and thus a buggy application can leak such memory. So, these caches should be accounted to kmemcg. Signed-off-by: Shakeel Butt Reviewed-by: Paolo Bonzini --- arch/x86/kvm/mmu.c | 4 ++-- virt/kvm/kvm_main.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index eca30c1eb1d9..87c5db9e644d 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -5475,13 +5475,13 @@ int kvm_mmu_module_init(void) pte_list_desc_cache = kmem_cache_create("pte_list_desc", sizeof(struct pte_list_desc), - 0, 0, NULL); + 0, SLAB_ACCOUNT, NULL); if (!pte_list_desc_cache) goto nomem; mmu_page_header_cache = kmem_cache_create("kvm_mmu_page_header", sizeof(struct kvm_mmu_page), - 0, 0, NULL); + 0, SLAB_ACCOUNT, NULL); if (!mmu_page_header_cache) goto nomem; diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 9deb5a245b83..3d73299e05f2 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -4010,7 +4010,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align, if (!vcpu_align) vcpu_align = __alignof__(struct kvm_vcpu); kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align, - 0, NULL); + SLAB_ACCOUNT, NULL); if (!kvm_vcpu_cache) { r = -ENOMEM; goto out_free_3;