From patchwork Tue Aug 23 00:46:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 12951571 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 01B85C28D13 for ; Tue, 23 Aug 2022 00:46:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 580AE8D0002; Mon, 22 Aug 2022 20:46:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 530208D0001; Mon, 22 Aug 2022 20:46:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3D0B78D0002; Mon, 22 Aug 2022 20:46:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 2A3E98D0001 for ; Mon, 22 Aug 2022 20:46:45 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id EC6C581341 for ; Tue, 23 Aug 2022 00:46:44 +0000 (UTC) X-FDA: 79829017128.09.7E84258 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) by imf01.hostedemail.com (Postfix) with ESMTP id A19344001B for ; Tue, 23 Aug 2022 00:46:44 +0000 (UTC) Received: by mail-pg1-f202.google.com with SMTP id m22-20020a6562d6000000b0042a7471b984so2657862pgv.4 for ; Mon, 22 Aug 2022 17:46:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:mime-version:message-id:date:from:to:cc; bh=+5ILiONNT2Raf8lvKVWoFP9Lx9r+QT/j1xkxXvfLAg4=; b=o+XzIuiX0mVrmTljlwxKQE5BPa7fWhxeXonBF2ujsHDIIkmrP/BArjGG8vKGXZzxHZ aGCyHZQGHV5fEhDCrdkCSs+rAYyXOsbuGhwIvEGUIpM+alq9pj57H5dboCmNEc09TK0z c6heO/8eSor/4/h1izel8Myn9DtJfj72/a/q7U1fFyl1Dno74zfJPMJQRSCl7AkmFpA2 YVxX7c0VRywxlO0x4/jEhIDRhafho11s7qXBSJr3SCWVNdlEtnYGvZenzxKVAARYwX+f oi9flWWlqVqqz3XGywpOOfYXa3KiMvQtqdVJT3SmOpYgrc6NAr9neqgsbzx2bpt4Hix/ 1rNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:mime-version:message-id:date:x-gm-message-state :from:to:cc; bh=+5ILiONNT2Raf8lvKVWoFP9Lx9r+QT/j1xkxXvfLAg4=; b=pIq+MXxjmx6vPLjC1KUoXvLTtknrdWfOwhhU6YG2Daer9EIFhYcatUzzYQPY1RWzJk a93wqzXmRXtWOjCT7c+dtcugf4+7hOAv6Drp2xbxRCbYSoDuD5zbWgnZqlOckaa6D8/w j4F89uog9x2w8kczhug6ElRTsfU5W74DZiYoP/T8sKffRDV2QSm6Dvr7exgD/TZV+Gwv N4LQiD2BVQygn8ZmwvytR17jEFmSsaD/l3qcI/eSHODL4B0dUhpNZpCtUOtFsReOEWXQ cveUaW/FqHwg7HP/B+fYiRfHLiitl+v/+D++pfwwT0+tZ6FeEBLUE4EALBwcGCrTfksm kK6w== X-Gm-Message-State: ACgBeo1oYu6+c++wwjS6EV1aq9gyIA0baPGwyXuWBDRZqTh9bBd016mH cL9Rx3wkWb5Ue/Lm+bUfQEs6aN6dc7hMkb8g X-Google-Smtp-Source: AA6agR7n4HaZkWJXrjZPxJF0LYP1shjmb62PXEmeLlBFj/2/BudXQckF9s5n2JZ4jSwiCza7N/CifAgyNs456d/H X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a17:90b:4c8c:b0:1fa:c44f:473a with SMTP id my12-20020a17090b4c8c00b001fac44f473amr840678pjb.195.1661215603362; Mon, 22 Aug 2022 17:46:43 -0700 (PDT) Date: Tue, 23 Aug 2022 00:46:35 +0000 Message-Id: <20220823004639.2387269-1-yosryahmed@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.37.1.595.g718a3a8f04-goog Subject: [PATCH v7 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-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661215604; 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=+5ILiONNT2Raf8lvKVWoFP9Lx9r+QT/j1xkxXvfLAg4=; b=EPU8/TioGiSrnRBMXgzMGBXkeyxxwbc1ti6xTtwOyjKuaKVtw2BGYVa1W8BKXjbqx54wYL a/MiwZB9oVlAw8HOEWTs5Uzt8sknPguTSjswqpHN0AA2d8DwzXbdNbzmPk9QabGGMZOUqs ZJF5mdkvEEOUEsg/8aHrDr4/iaScEZ0= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=o+XzIuiX; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf01.hostedemail.com: domain of 3cyMEYwoKCOgiYcbiKRWONQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--yosryahmed.bounces.google.com designates 209.85.215.202 as permitted sender) smtp.mailfrom=3cyMEYwoKCOgiYcbiKRWONQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--yosryahmed.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661215604; a=rsa-sha256; cv=none; b=cEdcEHwq6qWoLUv207BM0oXoubovQocm8sLZd1FkragVIVa93t2t3sVf2NYfehp/VGqbv/ OC5/OXaxbCOAyUuY9+47vFYMPtfRg+n0WDlXfWM9KnLIKiaPAau1aEG5a6uN6mCMcofXDD 7+S/FZEKePUVKe3X+AzJl5bK6p8L97I= X-Rspamd-Queue-Id: A19344001B X-Rspam-User: Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=o+XzIuiX; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf01.hostedemail.com: domain of 3cyMEYwoKCOgiYcbiKRWONQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--yosryahmed.bounces.google.com designates 209.85.215.202 as permitted sender) smtp.mailfrom=3cyMEYwoKCOgiYcbiKRWONQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--yosryahmed.bounces.google.com X-Rspamd-Server: rspam03 X-Stat-Signature: xzeetuiyye17hobkuosa3qsgcqwy96ot X-HE-Tag: 1661215604-937640 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 V7: - Rebased on top of kvm/queue. - Fixed doc spaces in proc.rst (Sean). - Commit message s/kvm/KVM (Sean). - Example of NR_SECONDARY_PAGETABLE s/KVM shadow pagetables/KVM pagetables (Sean). - Added comment that kvm_account_pgtable_pages() is thread-safe (Sean). - Collected Acks and Reviewed-by's from Sean and Marc (Thanks!). 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 | 13 +++++++++ include/linux/mmzone.h | 1 + mm/memcontrol.c | 1 + mm/page_alloc.c | 6 ++++- mm/vmstat.c | 1 + 12 files changed, 92 insertions(+), 7 deletions(-)