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: 12899015 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5D2DC43334 for ; Tue, 28 Jun 2022 22:09:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 478308E0002; Tue, 28 Jun 2022 18:09:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4264A8E0001; Tue, 28 Jun 2022 18:09:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2EF328E0002; Tue, 28 Jun 2022 18:09:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 217208E0001 for ; Tue, 28 Jun 2022 18:09:45 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id EB8922F7D for ; Tue, 28 Jun 2022 22:09:44 +0000 (UTC) X-FDA: 79629037488.23.EF8D295 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) by imf17.hostedemail.com (Postfix) with ESMTP id 9113340022 for ; Tue, 28 Jun 2022 22:09:44 +0000 (UTC) Received: by mail-pl1-f202.google.com with SMTP id k11-20020a170902ce0b00b0016a15fe2627so7623583plg.22 for ; Tue, 28 Jun 2022 15:09:44 -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=csjAyDN6W/5D0qj3j7TaDtS5acV0Uwa/No6K0qQXZ/I87qAw4xCxCmtTBpYrMypNhB RwDOzXM4RWY38bev4xVVhBDHhoGxmHIIlb3SPpyRdJHpB7cbSS9feir5JNC7Cx2NNHF5 rVmdIi8KknO8bgGmfJC3C5xVzMONYOCMlr9/32k5MGmZt1Ore90radw4Lyw0ZBBPjgWv nraJIzYSk7/1n2s37rXGvRu9ce7k4wF9uUh7lSJKEOH4BLEQ65lkggXzxI9BK7leucxx TPtpUHzMlhKlrsm04o1JQbQQgOBFcoU1PHbjU1fQA3JdCLBQKRT2GLhbh1RR/obX9txT 8C+Q== X-Gm-Message-State: AJIora+MUajSsbexYDbl8GeCecXMHwqLY5wwWMnEldDNUVNaunWwanyF bQokNew99r2cFSBBFksDe0fkMC9R4W8O0+mM 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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656454184; a=rsa-sha256; cv=none; b=RsI6F+oCw4e3WUbsGmNilAqLmt6LlHiiqlM+yXjbYv46bF1/K+BSDXkSc7SP1eByilh2AN oW1CB6eqBHjnGs3/1sJvWtBkGO/NLMYG4A07xmiE4Ocf8SzOqO36CNDCAQJPzYvwPbmu6j gkf22t1Fn7t2Sp1JdKkktB0Yt/oi3Po= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=GzxwozEn; spf=pass (imf17.hostedemail.com: domain of 3J3y7YgoKCCoeUYXeGNSKJMUUMRK.IUSROTad-SSQbGIQ.UXM@flex--yosryahmed.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=3J3y7YgoKCCoeUYXeGNSKJMUUMRK.IUSROTad-SSQbGIQ.UXM@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656454184; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=j7vQtUkT6qRG3QKeX4UpMqnVZiZTqDS8DcvKPJ9fshM=; b=rS4X8rnx1nUW3lDYHWyjhsihTdp769tXnk1yWqJ/Y7yXriMkdjjlybu8fRnu3fD40/ETGK oAOKuCXyaXbfIRa0gbCIwNr1DNRdIcoA5ho1yhF4KhkFiPLOSCo07TGDRVAiLfUEv6MSvC x5WKRiaYghJlQx1tTEdF84XBaJfaygg= X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 9113340022 X-Rspam-User: X-Stat-Signature: caxky9f3udzn7fiy6tc4g6td9bzf5hdk Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=GzxwozEn; spf=pass (imf17.hostedemail.com: domain of 3J3y7YgoKCCoeUYXeGNSKJMUUMRK.IUSROTad-SSQbGIQ.UXM@flex--yosryahmed.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=3J3y7YgoKCCoeUYXeGNSKJMUUMRK.IUSROTad-SSQbGIQ.UXM@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-HE-Tag: 1656454184-416715 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: 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(-)