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: 12951576 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 7E8B3C28D13 for ; Tue, 23 Aug 2022 00:48:10 +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=/kv57XErTaKnFDeUDVavVlKr5M5Kmgx9POEBsix6OFU=; b=oiz NlFuPuBqPJI84uLpyHmZMg17hkowzMsHWk1bq3MaXVYA8hn+5A7KC9ysVEGi6+gzRv5ZyniLqsFBs 8woIjJEOf0NGOlqjcGfxSaC40shUJLKya8MiqxJtJjq0DcycJUQ9/ogStfDclyDTOu21NoSHiHtKt F5gJyrZSqb8Mx4BzWtioWKPp6rp3J0TJj8ULuSpzYZ9XuYV78e0CAEOuxmL9j5kjHEVkdkgCnitfv BEK0MvRApaC0PBXLtxl42/FityIP2gifWAH7GbqHSlL6pK6RmLDz515d7uSnNDPMwX4lKfuhDk4yb WBaqYOL65eoZkPuKnB671ZYbjQ2M1BQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oQI4G-00GmW0-Pz; Tue, 23 Aug 2022 00:46:56 +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 1oQI45-00GmL8-BO for linux-arm-kernel@lists.infradead.org; Tue, 23 Aug 2022 00:46:49 +0000 Received: by mail-pg1-x549.google.com with SMTP id p36-20020a634f64000000b0041bd62cd236so5380546pgl.14 for ; Mon, 22 Aug 2022 17:46:43 -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=f41vl7PvOHCewRMeuJHnJuY2NaP0VHeVJc3g14UAvk0IeDlgInMxxM9YuPV/TftNzJ 3jjxwPU1EjLL1O6Z+AhZeY16UXt5wMQ9vGcEH0JHGI6JAyzriH35qQbt08iZrbDaWaio j9Zu8Z+65t8wIexgWCInyDQT0bb2tRjVhThzbVmceELrf9ufgo3jA7dOnBvJyRho9T2G npVHT9nulwvogrwooQPOFtPQoNZHyyks040nVie5PrZTkuCMf1DtZfHGN+cgVOzS+MMh eIys7gTERY0tGllyP5sl3TPyMZZ3mVJ2h6E65WmzIYaKzdYoqpPk75e5kbDf3P2lfSHO 29Hg== X-Gm-Message-State: ACgBeo11qtDm531GuF3RyzUW+YEX+kbO6c33x0sYdaxgKOuQZVeT5R1m 47z4Qdq2wd+57ZR8TkbB1BQMMPm7VoZ02PTS 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220822_174646_179190_01E368A4 X-CRM114-Status: GOOD ( 15.32 ) 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 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(-)