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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16723E6B278 for ; Fri, 1 Nov 2024 13:53:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A63F46B00A9; Fri, 1 Nov 2024 09:53:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9ED136B00AA; Fri, 1 Nov 2024 09:53:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 88F0A6B00AB; Fri, 1 Nov 2024 09:53:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 65B446B00A9 for ; Fri, 1 Nov 2024 09:53:52 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 0B05F4053E for ; Fri, 1 Nov 2024 13:53:52 +0000 (UTC) X-FDA: 82737668622.23.5631CCE Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf28.hostedemail.com (Postfix) with ESMTP id 9A9A2C0006 for ; Fri, 1 Nov 2024 13:53:21 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=GpuWICIL; spf=pass (imf28.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730469148; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=2cJUh3OTzbdPjJ6LObox3OS62Tfvc3Wly8ku/tceaDY=; b=kBCnXhxAuooBlhpqJpLEjbl2Wj8W/+hnbX2xXIxOfu1AzqDSWpITXrTqoAP6Qtd4lxIpNY LkmKZ83d8Ia80EhnOmqd4l+SFwRnw++sSealkNpci583RY/lLGSq/utXlW/pelW+arH94i odihY1VHLbyOata/3bQU3ymubvNVUBE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730469148; a=rsa-sha256; cv=none; b=p7BfQmt5WjcYUTvkc/T/T4O3sCyt/37tchR1ZTlrgc/VdqZjFZtnUS0dkDHF1PedrNA0O9 lXP1AzpfLM9pVjDPKB7B0Bp/UGFjJ1VEVEwtpRUUaKzZdU8vZTvc0flBe5FJPY9Bj3YFPs 24cfPRuU4jWwsjziZ9B9VAj7TQR2l/I= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=GpuWICIL; spf=pass (imf28.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id C802E5CAE65; Fri, 1 Nov 2024 01:33:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C871DC4CEC3; Fri, 1 Nov 2024 01:34:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1730424854; bh=iuRrKWaA7cQTIyPCJ6yJTE+QtMeoAL4LZfUWuyrYEsE=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=GpuWICIL+Q/CLeMoNRVbEARwd89pPGZ7xUCRu3cWVupQ6FST+77g34uuO/ZGFt77C 3L7u8bU287h7xhes3x2bSVREFmPHuxmutMmV7rv9SW+Nn5KAdMGUuxEmWCgoc9BymO MCnKk23Hfox75P0Hb1QKLPrAn3/CdIJpqPqBAgc8= Date: Thu, 31 Oct 2024 18:34:13 -0700 From: Andrew Morton To: Joshua Hahn Cc: Michal Hocko , Johannes Weiner , nphamcs@gmail.com, shakeel.butt@linux.dev, roman.gushchin@linux.dev, muchun.song@linux.dev, tj@kernel.org, lizefan.x@bytedance.com, mkoutny@suse.com, corbet@lwn.net, lnyng@meta.com, cgroups@vger.kernel.org, linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@meta.com Subject: Re: [PATCH v3 1/1] memcg/hugetlb: Adding hugeTLB counters to memcg Message-Id: <20241031183413.bb0bc34e8354cc14cdfc3c29@linux-foundation.org> In-Reply-To: References: <20241028210505.1950884-1-joshua.hahnjy@gmail.com> <20241030150102.GA706616@cmpxchg.org> <20241030183044.GA706387@cmpxchg.org> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam10 X-Stat-Signature: yy9d71xg3z4wa1i4aqn4bru4kxaurmk3 X-Rspamd-Queue-Id: 9A9A2C0006 X-Rspam-User: X-HE-Tag: 1730469201-164724 X-HE-Meta: U2FsdGVkX180Fdpls7jWVYlfp3X+fun073GEC53FWHtdvyStNq/I0N3gIMyuNW55kp50W4teZ3mCpwgUb7Ln9GRxPLf1d80FkRgnnnLoWkm5pZv1YllT82lZTsUSKtFGpNxEb+oFpwKGxB/+fSHe4hIrJflkdWFVvT78w9TPTD2Q+D7x3WpK9tju4kjZdxm6K+/eEwBywHCdG06Rf84f+Wfpww6UEWE0WfHTczO/zM4LYlFUsvM8tgbxSnlZJH2j+XWnvB9SMc4o6PxDLnnlm5XkYevubEJ86EbE5yqi7sS0deGFB53DgKSczY9AQglZMDK0AddhMt1LblyRfwvtyupAAXcVtBiu8v293nOurk5hNL0Iz6nNKGcYJG9E6fxOhYZt/Te/slgHAkNZLkI5oHB84E0GLOjI50qeVJLJRZyoLy5YexYSud0lZ8gqgfw8WHx6dAGTn4Co3X+dA48wqdCE7D8izgmqEXnZFUeoKIuZuem7Yo5F77WrEEDn8YA7AwBFmq0PQn9d5uPXekmKUCKNDa/M1BvKmJPiVUmuW1MutsY1nFJ9/HsUUJ+Mf77e9dzgkbdY1jdXjdLXMjHkwSzL2+eILjstW6KYLUAfXEACmDQrSS9Gxh4e++/8ooMO1upSeQPUedhxP67qiWE4QjSYZ5n5xwH+53BlLnnFxTEkLO1Km/osKgmQUV+xrMDia3ax9s0g9ak4bcUkhOBgglVUugiQXyokrxsABSb/5XJ5l7nwZS7nhKkivjI4L+AYEl8pgfKYFL6reR982rQPI3a6PGVG8YjwwOiLuzLwTjg6oO321Wp/QxvrXPxDGMDVhNYOSqnOdDQCmq9qmkxBM4YcnEKNhNZvRju+3sn1PZMTOf4NY9sU8mgOsWQxbGJ1Q+ssGz5qJuhZZwtkv9pZFhtcUGbuqoI0YgpaqLU0ekLJeTytR1WyQo/2L8bv82tVr77Dq6RA4Lh3n718OXz l/KUPuAG xw9x1NyZzPqzlBMsW/MqtvhMWgR7Gy+vY5g1MiPTlOzji0pWiL9IZFQK4FwHuyBuSbzqkDNP4aQFZeLei0mqZCfjFd84zQxwNL0Jeq4dJG5OXJpnbKnQIJhusvyOLqkonsnGtDGufSzEZaPrv0d3e8GxxoJLamGGQlzF2swcSyvil/0hyG8TgeoWj81oYEWVhc56eejqInYK//kwxlC8B8h4la33WJofcDw0i5ftEpLI7RFxTEkUS6lHHpqzKwY1W/c8wLVnEKjI17inzYsjZqWAwSIXr7hS5GJCMNVWQWwWSby44NwN6caeHiCY750KYUxREUCKFV6O7i2NtdhYAm6ZaxHMqiCtjaiIzguCJnj6P/H3hdG/niHFtbw== 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: List-Subscribe: List-Unsubscribe: On Thu, 31 Oct 2024 15:03:34 -0400 Joshua Hahn wrote: > Andrew -- I am sorry to ask again, but do you think you can replace > the 3rd section in the patch (3. Implementation Details) with the > following paragraphs? No problem. : This patch introduces a new counter to memory.stat that tracks hugeTLB : usage, only if hugeTLB accounting is done to memory.current. This feature : is enabled the same way hugeTLB accounting is enabled, via the : memory_hugetlb_accounting mount flag for cgroupsv2. : : 1. Why is this patch necessary? : Currently, memcg hugeTLB accounting is an opt-in feature [1] that adds : hugeTLB usage to memory.current. However, the metric is not reported in : memory.stat. Given that users often interpret memory.stat as a breakdown : of the value reported in memory.current, the disparity between the two : reports can be confusing. This patch solves this problem by including the : metric in memory.stat as well, but only if it is also reported in : memory.current (it would also be confusing if the value was reported in : memory.stat, but not in memory.current) : : Aside from the consistency between the two files, we also see benefits in : observability. Userspace might be interested in the hugeTLB footprint of : cgroups for many reasons. For instance, system admins might want to : verify that hugeTLB usage is distributed as expected across tasks: i.e. : memory-intensive tasks are using more hugeTLB pages than tasks that don't : consume a lot of memory, or are seen to fault frequently. Note that this : is separate from wanting to inspect the distribution for limiting purposes : (in which case, hugeTLB controller makes more sense). : : 2. We already have a hugeTLB controller. Why not use that? It is true : that hugeTLB tracks the exact value that we want. In fact, by enabling : the hugeTLB controller, we get all of the observability benefits that I : mentioned above, and users can check the total hugeTLB usage, verify if it : is distributed as expected, etc. : : 3. Implementation Details: : In the alloc / free hugetlb functions, we call lruvec_stat_mod_folio : regardless of whether memcg accounts hugetlb. mem_cgroup_commit_charge : which is called from alloc_hugetlb_folio will set memcg for the folio : only if the CGRP_ROOT_MEMORY_HUGETLB_ACCOUNTING cgroup mount option is : used, so lruvec_stat_mod_folio accounts per-memcg hugetlb counters only : if the feature is enabled. Regardless of whether memcg accounts for : hugetlb, the newly added global counter is updated and shown in : /proc/vmstat. : : The global counter is added because vmstats is the preferred framework : for cgroup stats. It makes stat items consistent between global and : cgroups. It also provides a per-node breakdown, which is useful. : Because it does not use cgroup-specific hooks, we also keep generic MM : code separate from memcg code. : : With this said, there are 2 problems: : (a) They are still not reported in memory.stat, which means the : disparity between the memcg reports are still there. : (b) We cannot reasonably expect users to enable the hugeTLB controller : just for the sake of hugeTLB usage reporting, especially since : they don't have any use for hugeTLB usage enforcing [2]. : : [1] https://lore.kernel.org/all/20231006184629.155543-1-nphamcs@gmail.com/ : [2] Of course, we can't make a new patch for every feature that can be : duplicated. However, since the existing solution of enabling the : hugeTLB controller is an imperfect solution that still leaves a : discrepancy between memory.stat and memory.curent, I think that it : is reasonable to isolate the feature in this case.