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: 12826472 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 4E675C433F5 for ; Tue, 26 Apr 2022 05:39:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B0F056B0074; Tue, 26 Apr 2022 01:39:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A964B6B0075; Tue, 26 Apr 2022 01:39:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9116B6B0078; Tue, 26 Apr 2022 01:39:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.27]) by kanga.kvack.org (Postfix) with ESMTP id 7B4486B0074 for ; Tue, 26 Apr 2022 01:39:19 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 6695E120779 for ; Tue, 26 Apr 2022 05:39:19 +0000 (UTC) X-FDA: 79397927238.30.09DB15C Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) by imf14.hostedemail.com (Postfix) with ESMTP id 00BCF100041 for ; Tue, 26 Apr 2022 05:39:17 +0000 (UTC) Received: by mail-pl1-f202.google.com with SMTP id x23-20020a170902b41700b0015906c1ea31so10719588plr.20 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=KHIAeov4sVPptawLq0tNsjrwEWTVm6lDzGu7zZ94selrAyoJ7izjRYcVrukDr9eoYq Wzr1R/xvxedaMfuuEIgWExx1fn0Fdwk9raC49X581g6hFEW/8jQSuzifHZKgR1Orn2Qx RhG+If1q/e04sNWgz6rnZY29uqiACxffdhAAC0jL2ZObMRFJJh+8UVzybBXe+fwgjve7 mXErPL1Ge81v7GEgbThryyyBpLiFFotR8RhWuJbi6vv7//B+oQQ/ERZMKU/W8ZoqEqcp I9MiLI5aCRfujdQ0PovliJIobi8/TjjC7axa6ESEMEl/hSFdFCGG6tATvKvV0Dy11Il4 BIcA== X-Gm-Message-State: AOAM531rDelkd64r4vavcxpXeAuq7nuVj9EB8HI5XhF9UJwUTePnKc+A kUNU6tcG8ivajZSSObNGLeHV6GxM5Bkke4VS 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 X-Rspamd-Queue-Id: 00BCF100041 X-Stat-Signature: 48txmiwap9appmac8r4g6bnnatq888o1 X-Rspam-User: Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=FnVqBEYT; spf=pass (imf14.hostedemail.com: domain of 3hYVnYgoKCEg8y218krwonqyyqvo.mywvsx47-wwu5kmu.y1q@flex--yosryahmed.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=3hYVnYgoKCEg8y218krwonqyyqvo.mywvsx47-wwu5kmu.y1q@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam09 X-HE-Tag: 1650951557-390896 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: 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(-)