From mboxrd@z Thu Jan 1 00:00:00 1970 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 C133EC4332F for ; Fri, 29 Apr 2022 20:11:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380589AbiD2UPH (ORCPT ); Fri, 29 Apr 2022 16:15:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380572AbiD2UPF (ORCPT ); Fri, 29 Apr 2022 16:15:05 -0400 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C27E63BBF8 for ; Fri, 29 Apr 2022 13:11:45 -0700 (PDT) Received: by mail-pj1-x104a.google.com with SMTP id c9-20020a17090a108900b001d5793b605aso4411934pja.4 for ; Fri, 29 Apr 2022 13:11:45 -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=an+yRArve5ZrSQoHDO73aNF7aPP+aWpAaWAPrlB9pIk=; b=rVCOmuzI6Jkg0VCtxq3Vv4tNhvcYa/7dy0aktfX+JU+3ABY/r1NuUYg6gNufzdzZyl TDx1/jOeHCUYV9kesQSDCM7gJuIkuCPZ3CI4xBiGyBYzao4KJxWyjV/wpOnUty7d2gkO xxgzezsPH49IA+C2wqMwqPUxHg+sr/u2pJ62e25BKh1gnBlY4tBxVuP6uCBRMMN8Bn0A o1aa0m514YE3U+J37NsZZ2A48FIIXDI4WlykXmRNEDZ9x5sTM9dO2kFgrvtI4EV9z//v PwFQ3hahtu5wgS2IyOj4qxw1dMwLZ0jJ58K/MjgmBn8W0hkXkDKsnnvkTtmina/ADpu8 G4Uw== 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=an+yRArve5ZrSQoHDO73aNF7aPP+aWpAaWAPrlB9pIk=; b=IPlbovWDNZn3DwtqEHafUYjSQwaOVtdGvlaf/BsKT1BUt/Hxiyfd+juewbs3WMx4HH TdOHAl6Uvp08wNCvXq6vesSIfzW/88LH6OriSXBBZVFfJao4HJYq1dC81C1LW96O5ldZ +E7WEab+TvUurTwFDpJ1tGpFSkEK7XEX4WZOwwYh2kRCZoee/x1pmlhSTXzGc8jHl8iH jJOpCutfn3J5+BFcEue3Fo+AmXCm8ESfLLFVWyvckbXYQAYx9MOVlPWnft9Uw4gfQdcm Gqm4WQUh027WHkVLLlo34/Hd/7Zeltd2DG7H2EjMWHB9MScrJxggfDWr5TTrHhTiVFYz hDtw== X-Gm-Message-State: AOAM530AqjUW9LhuK67RLPL+kJmcOssx9Gr57CXWsdy8fJWuISlE49Pg Xz0cZXirM7GMk3yz5v+Oc6Iq0YINjYev/Q+5 X-Google-Smtp-Source: ABdhPJxGZ1WYv4PcG6KKKG7/eOxb6RjoyzIw3GgB/7NGUVZUE3/7d2UGeWsMnv6NDpe3G1grI1WrkTwZdxjSyZ2c X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a17:90a:e510:b0:1d9:ee23:9fa1 with SMTP id t16-20020a17090ae51000b001d9ee239fa1mr438392pjy.0.1651263104394; Fri, 29 Apr 2022 13:11:44 -0700 (PDT) Date: Fri, 29 Apr 2022 20:11:27 +0000 Message-Id: <20220429201131.3397875-1-yosryahmed@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.36.0.464.gb9c8b46e94-goog Subject: [PATCH v4 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: 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 mmu 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. --- 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 | 35 ++++++++++++++++++++++--- 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 + 12 files changed, 89 insertions(+), 9 deletions(-) -- 2.36.0.464.gb9c8b46e94-goog