Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp5155867iob; Mon, 9 May 2022 09:45:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwgQfrptes8OklXp7GOs27KgygC6WJGCmmLQHjMtk9FNU6aES5c9NhGCxKEBM8GSUdYlTkK X-Received: by 2002:a05:620a:14b2:b0:69f:9cc3:a6df with SMTP id x18-20020a05620a14b200b0069f9cc3a6dfmr12221168qkj.406.1652114705247; Mon, 09 May 2022 09:45:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652114705; cv=none; d=google.com; s=arc-20160816; b=bysO9aKi2sTINYmDeY0ZO9MUDc6nyJKn8/CcQevrs1sIHdsXp1lARRP4lJw/tvGbpu 1Qt7Yhrnxi/rqSObmvSFOey+NHrFSjjSKIaySZO4cQYTkIyH+pLvwGA6vPi6hk/ohZgu 7Qge7I2Sn92u0WK+ZoAD1UgVo5t22G0AAa13h2mEDO33lkr0muOLDchAZ+0RL9G8NGgg 11pwm+3Kh8zmDbV0C3YbK8sCnPY+pMdpXa5UVO3gMDU6QpSmwMIjh4KoRJvwFSuFFJIR fjP0OxD6q0L6eBeltVg8OoumjP0axV5FXrws4uvB2DMvtboEI2aSDZ7zOg+zMDTUfS+m GWQQ== 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=zHCy33IfC5TyILOeQkmukBylQEbte8TBRw0A+aY3Nnw=; b=0Vlwkb1QYqgua1eOL8ATnqLLlL3DuKi/mZqsi3yjrFRi2v9WVzp/fIwZDCwXEN64Q3 ZmqvL/bcTTq4MUuk3ZnT8HfC8Cg4XeBCHBDIUUnnhEa+2RhK47bUs6AtNgwZdGjzDssO D5RvFOT+dg7C8b0uDhUdGPCqVg0NPT/vJ2yf4ySlSyoW/LllWA+ZyVQb8yVwlpnRWGR2 OQs8mXBt5uUgJHYP3AR8HAD1mSUVmc9wHfnYzwFcY6acdaT84i4t4wEAJ88mdltFpzBW wVrO1GV84fM1EOXyaHDPx+C1bRvpS75yZpDrlEdsLLmaj9My8Pr3JemkbkwA/OBl/J4+ Xm+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=H6nlUcik; 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 b133-20020ae9eb8b000000b0069ed510b461si7128865qkg.725.2022.05.09.09.45.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 09:45:05 -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=H6nlUcik; 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 ED0D72CBF86; Mon, 9 May 2022 09:39:11 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239141AbiEIQmw (ORCPT + 99 others); Mon, 9 May 2022 12:42:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239113AbiEIQmu (ORCPT ); Mon, 9 May 2022 12:42:50 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D527111033C for ; Mon, 9 May 2022 09:38:55 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id b19so20251680wrh.11 for ; Mon, 09 May 2022 09:38:55 -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=zHCy33IfC5TyILOeQkmukBylQEbte8TBRw0A+aY3Nnw=; b=H6nlUcikiCWMQ0NyQpEOvAX9YWAzxJVOMo8TCOD+MTF5x++KFtykM38ezcNgkrqf/k HsEf3EJd5U1zetXK4vcQ2qXVxKjVLLmxk64eVHzC1lhLd+csiUOWanUBOMc0ehk+lL8Z 8kMOXwBH5hATNTPogQUXQIImHkrg03NEi/77hdTa1677HBxwaUfkv/QQ7yLseBE1HcJE YPtPpea4ak7+T4Dqx7q3oWEasv5JJswYYW1+IlWiL+SM1CpjXzbyzq9KKAOv4Z51ZAoC p4WvvEjdiEI05l2ZOHE80zU68Yi/ftR+9e3AoP2yMz5PBJyRJ0fD1vQ47PM6C0czbLOE 9nDg== 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=zHCy33IfC5TyILOeQkmukBylQEbte8TBRw0A+aY3Nnw=; b=uL5O0TFfObcs7UwFhTCx28FWgION37qowigwJng607A7MXgRqwu/lOAi2KHorHYTtx Ixbqq7tK45PHBdBVqs49rzRNKSiCadt800JBVjtwx+SMMv3jHxYg0wmAv+8XBsHAETzD 0jq/LGJdRk1EnL3P4oD18eBNjeUJPRnSu95wo8vEcjL0/w7W3A50qZcPMirguv8QFDrG 0GZ/xAEVYzj8tU4FE/VxTtahDkvx8R88fUYNBtlgMVGgqZE7x02FdDQGS1TTRA0/rFWN 5Odxkhobb4QHPFVRxHQsCkF2ErtXyiUdSKxF/6Wftnw+h/cqoBBvWR0DvHj0SwwwKdVD ONUw== X-Gm-Message-State: AOAM532Puu8Jy1Cu/IWzqoUfRIs5XC+/oq35GhEtjkf6LK/k+lEiyIxn AVvbuacdoA/uA9Rdu4O5QfvZWImGuj8ujR+aVKgQCQ== X-Received: by 2002:a05:6000:230:b0:209:87ac:4cf5 with SMTP id l16-20020a056000023000b0020987ac4cf5mr14646217wrz.80.1652114333976; Mon, 09 May 2022 09:38:53 -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: From: Yosry Ahmed Date: Mon, 9 May 2022 09:38:17 -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 11:46 AM Yosry Ahmed wrote: > > 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. > Any thoughts on this? Do you think MEMCG_SECONDARY_PAGETABLE would be more appropriate here?