From patchwork Tue Apr 26 05:38:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 12826486 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6894DC43219 for ; Tue, 26 Apr 2022 05:39:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244410AbiDZFm0 (ORCPT ); Tue, 26 Apr 2022 01:42:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241042AbiDZFmZ (ORCPT ); Tue, 26 Apr 2022 01:42:25 -0400 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C8DA326EB for ; Mon, 25 Apr 2022 22:39:18 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id w24-20020a170902a71800b0015d00267d74so4089526plq.6 for ; Mon, 25 Apr 2022 22:39:18 -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=wiy4ZFErG6M19mqQHUKpS1yTWJiAAlT4dR/xLvJk6Hw=; b=FnVqBEYT/x+/otkeQ3+MGU8nRgioALOZEJyWRms+DoU60vLvG4knvZ85+k1mr3tVc0 vqArKWu7LcXihZYZOL7dZijR1qW/fUI1ogYdryU7KR30je7tEjpL7SWeqEnnd/Z0l+6p oQzkcbfWngpMAliZPhAsfXTSWCnwz8fWFa74DRSIzlIoZx+NC9CPJeMNUZ3R63A72PJf QZcKxPUm3H1SOIAqby7P9meP48e3oR4Bh8C/ma3u+fJEHhbZdFo9brPFPEbwbLiTho1C Qvh2BmXNRXBqnJccxzxqqdYZqemamQonwCzTKOX5d0cQHIkgbJ7rHfmHl0679wZSmYIx AFng== 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=wiy4ZFErG6M19mqQHUKpS1yTWJiAAlT4dR/xLvJk6Hw=; b=DEUTwuJf6WFdbjPT7va8o7MwEx/2TVIcAReSjL7PoyDoRLCQo4EdhjIQwL84gH6+p8 nZqU0V0ixj34/uAUvkctgzOn/j6Pfh6GWEiw/W4hrLsgujNaOEIUwkw0+Z2G9cr94nFl YrVoozUcGQ5LLfTrn5CF1fPBiXm52Jf33GoGZodv3zzsCMxLA/EkofqkitOCib/rpgQB Aeg5jDuSQbs8STIoTirkUfFDeNbBWgusecEPk8oNfKoUdadbuZiLyUGkZovv251VLrKK hoywWmw0mFkRJjsIU95NgpT/BI+U9A+Qp+mqTLdHC+7q1gvVNFXfmeclsOMzpv2pDrfc 5/OA== X-Gm-Message-State: AOAM533qtWoHH+mJZtvqrMdWmT+XkK+waRu+bTPBJFfhdIt/cH6+dF6g HjSfI66bNmPcPsHqEThkgwOwnGF35Jc8L3EV X-Google-Smtp-Source: ABdhPJxvg8pZpaAGbW2v0JTDOhNhWaI7b9G2UFmwsQAHLCDtYBjVtAQ+AyjheoLnE1s4SzV5HxUjB6H2aYquwIV1 X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a05:6a00:8c8:b0:4fe:ecb:9b8f with SMTP id s8-20020a056a0008c800b004fe0ecb9b8fmr22623121pfu.55.1650951557634; Mon, 25 Apr 2022 22:39:17 -0700 (PDT) Date: Tue, 26 Apr 2022 05:38:58 +0000 Message-Id: <20220426053904.3684293-1-yosryahmed@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.36.0.rc2.479.g8af0fa9b8e-goog Subject: [PATCH v3 0/6] KVM: mm: count KVM page table pages in memory stats From: Yosry Ahmed To: Sean Christopherson , Huacai Chen , Aleksandar Markovic , Anup Patel , Atish Patra , Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Andrew Morton , Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , James Morse , Catalin Marinas , Shameer Kolothum , Marc Zyngier , Alexandru Elisei , Suzuki K Poulose Cc: linux-mips@vger.kernel.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, cgroups@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, Yosry Ahmed Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org We keep track of several kernel memory stats (total kernel memory, page tables, stack, vmalloc, etc) on multiple levels (global, per-node, per-memcg, etc). These stats give insights to users to how much memory is used by the kernel and for what purposes. Currently, memory used by kvm for its page tables is not accounted in any of those kernel memory stats. This patch series accounts the memory pages used by KVM for page tables in those stats in a new NR_SECONDARY_PAGETABLE stat. The riscv and mips patches are not tested due to lack of resources. Feel free to test or drop them. 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 (6): mm: add NR_SECONDARY_PAGETABLE stat KVM: mmu: add a helper to account page table pages used by KVM. KVM: x86/mmu: count KVM page table pages in pagetable stats KVM: arm64/mmu: count KVM page table pages in pagetable stats KVM: riscv/mmu: count KVM page table pages in pagetable stats KVM: mips/mmu: count KVM page table pages in pagetable stats arch/arm64/kernel/image-vars.h | 3 ++ arch/arm64/kvm/hyp/pgtable.c | 50 +++++++++++++++++++++------------- arch/mips/kvm/mips.c | 1 + arch/mips/kvm/mmu.c | 9 +++++- arch/riscv/kvm/mmu.c | 26 +++++++++++++----- arch/x86/kvm/mmu/mmu.c | 16 +++++++++-- arch/x86/kvm/mmu/tdp_mmu.c | 16 +++++++++-- drivers/base/node.c | 2 ++ fs/proc/meminfo.c | 2 ++ include/linux/kvm_host.h | 9 ++++++ include/linux/mmzone.h | 1 + mm/memcontrol.c | 1 + mm/page_alloc.c | 6 +++- mm/vmstat.c | 1 + 14 files changed, 111 insertions(+), 32 deletions(-)