From patchwork Tue Jun 28 22:09:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 12899021 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7592ECCA479 for ; Tue, 28 Jun 2022 22:11:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Mime-Version: Message-Id:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=YbKmcPG/5q1FWH+pJURpmK87+A2xUITpfMsJem5aZZ8=; b=RbJ 9al93WPjs6dH9ohOI2lgVDsSDsEowSIT1e6xpxW49FXwCEnkAm1V36m+/nhrRQlD7msM7mks52gKU wN93nM/NsIwU+WgyO+nbAEjSG8p3lEKXKHeKWw4DcZwqmgb35D6yrz63uxxvv/b/FVkZCH3/joFpn LvFBUdA9FytjkDxJSNjuIeLCHjz0RN0zKkofEaymGWESP+acyeNHfAXIq+MYoHadJGz/wvCQY3gcA esfGv+xDqyKtnyz3fOEF6iPOaBS6/oSiYVI+d4r5+zPLnr5j4Tz7tbG8ykvxaOz7t/iquf40z8sG2 z6c5pivvXfCKz6I7b3iJ47wkEmWw5yw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o6JP2-008L9i-Ig; Tue, 28 Jun 2022 22:09:48 +0000 Received: from mail-pg1-x549.google.com ([2607:f8b0:4864:20::549]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o6JOz-008L8W-5q for linux-arm-kernel@lists.infradead.org; Tue, 28 Jun 2022 22:09:46 +0000 Received: by mail-pg1-x549.google.com with SMTP id f9-20020a636a09000000b00401b6bc63beso7287110pgc.23 for ; Tue, 28 Jun 2022 15:09:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=j7vQtUkT6qRG3QKeX4UpMqnVZiZTqDS8DcvKPJ9fshM=; b=GzxwozEneycpYxfYkAxZnBbfe2kKbiWaUb3au/3inz+96+E7+zLStOmquVbMClhDJN mymnRTDsodttIg6bONJTV+Qf5sR0A/4Eufj9q5UkrnT+X4ZTX9KUSPZals5kueYPLHS3 5ZKToqFOZmswpxTUHknfNDUsMGF7F/uaQqn/NEHMx2U6nUHbDS6x4NydE1vgoQf5Vtt0 6DmHVpPjAhtY1SKXtzIeH1gmnX+GXgSguGwom5FHISPhcwC8dDainyvR7TPw7gTaHg5e aUNIUtPDYqw7Y7eMijqWWljoO7q9a0HYG+8ZpKEazP1QJOUU4M542v67wi7XPxaE8BoY dfHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=j7vQtUkT6qRG3QKeX4UpMqnVZiZTqDS8DcvKPJ9fshM=; b=geftHpCD9IIFjSyEn1zOuZtAJu4hyTCkx8EjCjWnii8kDZiLPr0bot094xIgqeRDzS I9iNRVe6pzfwPuRuQ6Xb2ycUr80bZcHKiVbfto/JPjkKuXydgNxr6/lzXFGma4uhX+As QKQL580ccT+aiEpYrzebfb3LbxXCGPz9jCRLQxOjdnTPc4TzNnaJYJRe/syuGNOWIJgB QuU08EgVv2aX1yRIVv+Lf+paYcQFKmI8/TC3jzErwSbeprWAgwcFw1OT4ssPkCsXH1Pb gb1QWWQY4oXJ1MoK5TtOMcXVtZlnECLovkKDNw95pTgOHzAd2B6FcQCGIOgij/RVaukr nOAA== X-Gm-Message-State: AJIora91q0iOTVnLxDIrMuobZjYNlMQiW/kOYlvDCGLyjiH+uu5VvnJh jf9KJ20aUpd+ZHVZVOQMi3R6rJ2aQ6zXyfV2 X-Google-Smtp-Source: AGRyM1tAsY26pwu8BYVe36xK0WPC+OOzu0ciBh5fVZFr2DkYJV+K61VKlr8YtnVAaRLZuPtKG1T6lcJUgBOER+dp X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a17:902:d212:b0:16b:9cf9:6523 with SMTP id t18-20020a170902d21200b0016b9cf96523mr932471ply.33.1656454183407; Tue, 28 Jun 2022 15:09:43 -0700 (PDT) Date: Tue, 28 Jun 2022 22:09:34 +0000 Message-Id: <20220628220938.3657876-1-yosryahmed@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.37.0.rc0.161.g10f37bed90-goog Subject: [PATCH v6 0/4] KVM: mm: count KVM mmu usage in memory stats From: Yosry Ahmed To: Tejun Heo , Johannes Weiner , Zefan Li , Marc Zyngier , James Morse , Alexandru Elisei , Suzuki K Poulose , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Andrew Morton , Michal Hocko , Roman Gushchin , Shakeel Butt , Oliver Upton Cc: Huang@google.com, Shaoqin , cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-mm@kvack.org, Yosry Ahmed X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220628_150945_277200_F3BA6B75 X-CRM114-Status: GOOD ( 15.95 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add NR_SECONDARY_PAGETABLE memory stat and use it to account KVM mmu usage as the first type of accounted secondary page tables. This stat can be later extended to account for other types of secondary pages tables (e.g. iommu page tables). Rationale behind why this is useful and link to extended discussion in the first patch. --- Changes in V6: - Rebased on top of kvm/queue and fixed conflicts. - Fixed docs spaces and tabs (Sean). - More narrative commit logs (Sean and Oliver). - Updated kvm_account_pgtable_pages() documentation to describe the rules of using it more clearly (Sean). - Collected Acks and Reviewed-by's by Shakeel and Oliver (Thanks!) Changes in V5: - Updated cover letter to explain more the rationale behind the change (Thanks to contributions by Sean Christopherson). - Removed extraneous + in arm64 patch (Oliver Upton, Marc Zyngier). - Shortened secondary_pagetables to sec_pagetables (Shakeel Butt). - Removed dependency on other patchsets (applies to queue branch). Changes in V4: - Changed accounting hooks in arm64 to only account s2 page tables and refactored them to a much cleaner form, based on recommendations from Oliver Upton and Marc Zyngier. - Dropped patches for mips and riscv. I am not interested in those archs anyway and don't have the resources to test them. I posted them for completeness but it doesn't seem like anyone was interested. Changes in V3: - Added NR_SECONDARY_PAGETABLE instead of piggybacking on NR_PAGETABLE stats. Changes in V2: - Added accounting stats for other archs than x86. - Changed locations in the code where x86 KVM page table stats were accounted based on suggestions from Sean Christopherson. --- Yosry Ahmed (4): mm: add NR_SECONDARY_PAGETABLE to count secondary page table uses. KVM: mmu: add a helper to account memory used by KVM MMU. KVM: x86/mmu: count KVM mmu usage in secondary pagetable stats. KVM: arm64/mmu: count KVM s2 mmu usage in secondary pagetable stats Documentation/admin-guide/cgroup-v2.rst | 5 ++++ Documentation/filesystems/proc.rst | 4 +++ arch/arm64/kvm/mmu.c | 36 ++++++++++++++++++++++--- arch/x86/kvm/mmu/mmu.c | 16 +++++++++-- arch/x86/kvm/mmu/tdp_mmu.c | 12 +++++++++ drivers/base/node.c | 2 ++ fs/proc/meminfo.c | 2 ++ include/linux/kvm_host.h | 10 +++++++ include/linux/mmzone.h | 1 + mm/memcontrol.c | 1 + mm/page_alloc.c | 6 ++++- mm/vmstat.c | 1 + 12 files changed, 89 insertions(+), 7 deletions(-)