Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp220589iob; Mon, 2 May 2022 17:36:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzgBTuadi+N2jDZS/I8Qcz8UvRYf4NLNvY3Cv9r9OrSzJgvrLpjyETinK5pviEukbEflSum X-Received: by 2002:a17:902:d2c5:b0:15d:4128:21d5 with SMTP id n5-20020a170902d2c500b0015d412821d5mr14041741plc.165.1651538216350; Mon, 02 May 2022 17:36:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651538216; cv=none; d=google.com; s=arc-20160816; b=G8W0b33EcEFD9PoXiiS3/EPGtvXmiHRgl4uUJ7aqvcPsWN09fcC3/1mhri9OOOtJbN zugy3zIOZcvodfAFrVK6XSkRXLzvU7GBnxbwjCpsGR3Ucw1/ewphYLedsswyZ7emhvBc xU8B1D7ivKMKCdM5VMXshiYkO+Bt/twzAKLMPe33KsDF8rBHaKkg9znkfsrfvK+RfCbu c57odGXKtcGk2UYbg7ogfYJ7lMpjqePSiTJnbCW3a6GIJYPZHoE+0CyelW+VA81EJNsk MkoMYATCiGYnFNJqIU0IHm2mcqoommIvgSlWJqPqj6IwUpl3JnZhAKAvfSf4OM3ObeP9 O0mQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=u9wSiuSwEdY5mnTnkaPbFc68dMNs+2B7Kv3x/mlBROY=; b=qDpqugopHYbOPsMr/R6ffkJhpfBVIpeFCqjtwlMMSgmDktEJ7W6TSC5rPNvmz2QsO/ fD1v8Hjm2F45KJezA3qFGxcxscEBodst5nRsZVkrfiri1mCFcfT4TUrmcwjwUCLNHZLm w/+71SQKIdkAntX5QBo3Z7KJyTliHP96HiAPzauy8kCeIpdEfXduOH5ElbHOmEwt4Llp uRGLb/qMgDViP5ZbOOygoiGKpRo2kg6qFMIx96iSpmPSRHova8F+ZC/1EhAbKJyYu36u EAJyMLcN4E5xT0sul4kZCS6N4BS1V7ry1J0mKFKwg+PUtuMJCeXRK+7mSI4zIXkhlhhC ATfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="B5EJ0yX/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id j25-20020aa78d19000000b004fa3a8e0053si13819980pfe.266.2022.05.02.17.36.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 May 2022 17:36:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="B5EJ0yX/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DB4C738DA0; Mon, 2 May 2022 17:28:45 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357791AbiEBSue (ORCPT + 99 others); Mon, 2 May 2022 14:50:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349799AbiEBSuc (ORCPT ); Mon, 2 May 2022 14:50:32 -0400 Received: from mail-yw1-x1129.google.com (mail-yw1-x1129.google.com [IPv6:2607:f8b0:4864:20::1129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E1B8BE05 for ; Mon, 2 May 2022 11:47:03 -0700 (PDT) Received: by mail-yw1-x1129.google.com with SMTP id 00721157ae682-2f7d7e3b5bfso157816377b3.5 for ; Mon, 02 May 2022 11:47:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=u9wSiuSwEdY5mnTnkaPbFc68dMNs+2B7Kv3x/mlBROY=; b=B5EJ0yX/6p4KphD4mHUJ1Rf/ah2ZGGbyCj3/Fg8jz6NZgaKjFGHXri9nWa56usJkQV i315aF1sZwZQCXuqR1GAJi/UydKqqqyJKrMK8NO2ltYq2E6LzRLcZv32EwENsp7gEeoz iSHMNZvgfxxeDjj5++SiliEGaOkXpt+a8RHyXVhO5DpOnU48kj++PVL3oUiAbWHvgwWt /8Cr6IfX5ViwgwukGvi0D67RRVTS2aaUOaOIh181LsfJrySzqwochKRZSrWUxxtwgj0X utkbg7G1h+72m4iLsTXSquLZ7P0i2NJO3VNDlb1N0tn+bpBJNirD0jDtdQa9nWw8JgOP HsHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=u9wSiuSwEdY5mnTnkaPbFc68dMNs+2B7Kv3x/mlBROY=; b=yTTSSJYF3b3Rz/nPuxbAHLS0uUkkTCgs9ipE/Is/iMp6oKYyqkH6hGbmzeXPBT+wpC SrN28lyHJvrx0urErczaYeOHcrt+8/4bw/9KZZ0GwwxlFiuGw8xExoPWtjJ/FHhzjEjk ySP6Q228XrlCiAba9x4am38VclFRDkfS6tChfwZSAQ2ng/Jj01+gVKoaN+TjgTVvMFcP 1d3rdy/XtJzmNgdLhgEs5G6gKkj5XKsbSjFSRDgxu54lnWbPKiJYZNewirw1PYnzV9qw r7EmJJVq2dcbA9ooaC/vX5k7XI2rkm67iJTYtMIklyhLuEyO78oMvRHplD+Or1Lgy4ed 9gfA== X-Gm-Message-State: AOAM5316OKswayuioQbvH4FliVe8P9LNmoeqMNZjgXyzJMmkHW+11Cdm piN037SeBVhYcCgtw6y+HYiMeZVOdDVYGJqJHsmoyg== X-Received: by 2002:a81:dd07:0:b0:2eb:f701:286e with SMTP id e7-20020a81dd07000000b002ebf701286emr11872882ywn.341.1651517222179; Mon, 02 May 2022 11:47:02 -0700 (PDT) MIME-Version: 1.0 References: <20220429201131.3397875-1-yosryahmed@google.com> <20220429201131.3397875-2-yosryahmed@google.com> <87ilqoi77b.wl-maz@kernel.org> In-Reply-To: <87ilqoi77b.wl-maz@kernel.org> From: Yosry Ahmed Date: Mon, 2 May 2022 11:46:26 -0700 Message-ID: Subject: Re: [PATCH v4 1/4] mm: add NR_SECONDARY_PAGETABLE to count secondary page table uses. To: Marc Zyngier Cc: Tejun Heo , Johannes Weiner , Zefan Li , 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 , cgroups@vger.kernel.org, Linux Kernel Mailing List , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, Linux-MM Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 2, 2022 at 3:01 AM Marc Zyngier wrote: > > On Fri, 29 Apr 2022 21:11:28 +0100, > Yosry Ahmed wrote: > > > > Add NR_SECONDARY_PAGETABLE stat to count secondary page table uses, e.g. > > KVM mmu. This provides more insights on the kernel memory used > > by a workload. > > > > This stat will be used by subsequent patches to count KVM mmu > > memory usage. > > > > Signed-off-by: Yosry Ahmed > > --- > > Documentation/admin-guide/cgroup-v2.rst | 5 +++++ > > Documentation/filesystems/proc.rst | 4 ++++ > > drivers/base/node.c | 2 ++ > > fs/proc/meminfo.c | 2 ++ > > include/linux/mmzone.h | 1 + > > mm/memcontrol.c | 1 + > > mm/page_alloc.c | 6 +++++- > > mm/vmstat.c | 1 + > > 8 files changed, 21 insertions(+), 1 deletion(-) > > > > diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst > > index 69d7a6983f78..828cb6b6f918 100644 > > --- a/Documentation/admin-guide/cgroup-v2.rst > > +++ b/Documentation/admin-guide/cgroup-v2.rst > > @@ -1312,6 +1312,11 @@ PAGE_SIZE multiple when read back. > > pagetables > > Amount of memory allocated for page tables. > > > > + secondary_pagetables > > + Amount of memory allocated for secondary page tables, > > + this currently includes KVM mmu allocations on x86 > > + and arm64. > > Can you please explain what the rationale is for this? We already > account for the (arm64) S2 PTs as a userspace allocation (see This can be considered as continuation for that work. The mentioned commit accounts S2 PTs to the VM process cgroup kernel memory. We have stats for the total kernel memory, and some fine-grained categories of that, like (pagetables, stack, slab, etc.). This patch just adds another category to give further insights into what exactly is using kernel memory. > 115bae923ac8bb29ee635). You are saying that this is related to a > 'workload', but given that the accounting is global, I fail to see how > you can attribute these allocations on a particular VM. The main motivation is having the memcg stats, which give attribution to workloads. If you think it's more appropriate, we can add it as a memcg-only stat, like MEMCG_VMALLOC (see 4e5aa1f4c2b4 ("memcg: add per-memcg vmalloc stat")). The only reason I made this as a global stat too is to be consistent with NR_PAGETABLE. > > What do you plan to do for IOMMU page tables? After all, they serve > the exact same purpose, and I'd expect these to be handled the same > way (i.e. why is this KVM specific?). The reason this was named NR_SECONDARY_PAGTABLE instead of NR_KVM_PAGETABLE is exactly that. To leave room to incrementally account other types of secondary page tables to this stat. It is just that we are currently interested in the KVM MMU usage. > > Thanks, > > M. > > -- > Without deviation from the norm, progress is not possible.