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 47827CFC5E7 for ; Thu, 10 Oct 2024 17:26:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A39DD6B0085; Thu, 10 Oct 2024 13:26:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9EA516B0088; Thu, 10 Oct 2024 13:26:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8B1D06B0089; Thu, 10 Oct 2024 13:26:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 6998C6B0085 for ; Thu, 10 Oct 2024 13:26:55 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id DC655120B14 for ; Thu, 10 Oct 2024 17:26:51 +0000 (UTC) X-FDA: 82658372790.28.76F7752 Received: from out-175.mta1.migadu.com (out-175.mta1.migadu.com [95.215.58.175]) by imf18.hostedemail.com (Postfix) with ESMTP id D9D801C0019 for ; Thu, 10 Oct 2024 17:26:52 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=Dic41h+A; spf=pass (imf18.hostedemail.com: domain of shakeel.butt@linux.dev designates 95.215.58.175 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728581031; 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=T74j4BfBpF8MtvJMwEYG2DbO+zpXeVI3CcEFUfNAPFM=; b=LaOdv9bE9/HcsEFsxjPyuSrvoba+yz1+vcfQ0Z4mxOywI82nvKjAHn3WWK5I5RRxyNFuAp NIPUIDxos9+YPJMRlFbZdu+TmMRKUvcfVruZHcZ1QI6HLAm/iUe6uOipGAZBe2CWtTcHog 3W4SV9PwBSDeBTRyWB/wg3BMY6ILP2I= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=Dic41h+A; spf=pass (imf18.hostedemail.com: domain of shakeel.butt@linux.dev designates 95.215.58.175 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728581031; a=rsa-sha256; cv=none; b=7Stp6r6Gl35J7SEuPvkxcPgQPmA2wm49t5G/BurBMLZzVtNeYwx0bCeH8Jgb+S/Hl8TRSl fnDqB1rO2R9Jn16EiSnVCA6PTOu4OTBAZsT9jUXeO5n2SqPVA6leqXL3eRV+XfRRJPb3bf P2SDjiHkhUUH85xelG4fXE9lbwtGN/0= Date: Thu, 10 Oct 2024 10:26:36 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1728581211; h=from:from: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; bh=T74j4BfBpF8MtvJMwEYG2DbO+zpXeVI3CcEFUfNAPFM=; b=Dic41h+AbX+RzAqWdAMNaEJikD2+y1U1sEX+56cJGZXBafhhQ2gfOqLMSq9P3REaA1v1st n8iqjSsfKysCfa2dtz/0HV4qjXztDK4hTlxWeVQW8PHL7JDwmPb89qvClg4lwNpZAaKOgn izA1d4jTrT6XeholR+OaDwgMg7nPJu0= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Shakeel Butt To: Yosry Ahmed Cc: Steven Rostedt , Andrew Morton , Johannes Weiner , Michal Hocko , Roman Gushchin , Muchun Song , JP Kobryn , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Meta kernel team , Daniel Xu , bpf@vger.kernel.org, Martin KaFai Lau Subject: Re: [PATCH] memcg: add tracing for memcg stat updates Message-ID: References: <20241010003550.3695245-1-shakeel.butt@linux.dev> <20241009210848.43adb0c3@gandalf.local.home> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: D9D801C0019 X-Stat-Signature: 8ipn6wobcifxgx8osnf8sxowgn5axae5 X-Rspam-User: X-HE-Tag: 1728581212-360534 X-HE-Meta: U2FsdGVkX19fFsH9ZhhIi2c4Eyp4+7njPkJaxOxhszY5667x84oQcoNUAvegQkq0LoichA1YiVGK62l0oT14QpQlObuQSMZQ27CjgyEskKDPSiMK1vS0FYs6HSU1xyAPo1R706vEhB8vS8Pn+86VpYUGiQCARW7WlEfnnavQbwUxHa0EdBRCVztcuiTQlAc/54C8d7IKPzL8D+FjFkXEwOpVOLdwA4ivF3jPBY3PIsAz79bWcXr1wEuDtLLluTIljBs3ICAr2WJSprWCaByCr7IHwkpLNrlVW8SfupBC5s5d5wudVbcFGi0t9tvKpUL2VbKCuWTerjQH3umr/6/aVmwRrlOXn9hHJBruizrY0/MY7xadWdaHz4jsf8l5SqOZdLaZU6qLKpu64a2TMTVHt0jTeVMSdVcPftSbtIaLJoU6KL4CrHlja63I8iq8s8H2QUyqUTKJ5tnE7nIbGjXhXeDkODkV81GCaO5uhSDnnexO1wW1/P7R5Kq7ay13/PP/CounM0NjAWAuC/b5/dJ9KPxXtI44S8uHTgA8Kopjgms77cVNBRQm7meSp73JuSv6WptLZvH+e9wCxSOMlcY4bR6S5bbYIMYJL76TxoVjZ/yJm34TXXumRMX2wiVer2pVLv1WORN9Ao3tOo8vcw6YeRDBFBrr3/2YTnc1q/DlmjLVGyyC0XqQ1uAwd81IpJ61LnWfAhM1uLksQnAEACHSQasBRUpMfGxcOF3wh9/8N2RuoWfGuIuCFvQYn10EW1zRtjW7C9LRxH7airfceBg+ZcUUo8xwzSMeuFmwdDwY1iJuXNHKcN6WMDIh07rafgbcYpPJnnFDgc0H90zRVQrOJiiy3mFmvIDQwWcKFT3ZAwXQo1VBL7Zt0a1dVkmvZ9msgnBwLIuc2meeBHBMnAN0IgeEsjk+Fu1HQXNyMemPrxHlw/BYJ4ZJJnlLXEOgT4kECiBnhYvz8nGANnplJ7Q jwI8WlMY g2OcCW2Fxk9CmEvGo8bDsKU+tXJNZ6YJ/HsOaZWZvtHo7JZZjrb8NIrDjk++l6wlx53bTDhAzeo+su74vIvupMIBjqaq2y4mnn48EidIhnIw/Dj1/rSSaAT9jDwyjSTlIAeodgPLshVuE4LHIv2JWVcBZHFyUCKcRdpIKodesqmKsz7ck7QqrUK3sovfqjBIXvjAx5izG6ywfisHtWVW0GlAvkVvaimncj9HWsMKTVxriEVXDhyXyaKOpEgDkGH8bsBIdqqkF3gsyjoC0AC9zlqjC8rjWcmjZRXHG 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 Wed, Oct 09, 2024 at 06:24:55PM GMT, Yosry Ahmed wrote: > On Wed, Oct 9, 2024 at 6:08 PM Steven Rostedt wrote: > > > > On Wed, 9 Oct 2024 17:46:22 -0700 > > Yosry Ahmed wrote: > > > > > > +++ b/mm/memcontrol.c > > > > @@ -71,6 +71,10 @@ > > > > > > > > #include > > > > > > > > +#define CREATE_TRACE_POINTS > > > > +#include > > > > +#undef CREATE_TRACE_POINTS > > > > + > > > > #include > > > > > > > > struct cgroup_subsys memory_cgrp_subsys __read_mostly; > > > > @@ -682,7 +686,9 @@ void __mod_memcg_state(struct mem_cgroup *memcg, enum memcg_stat_item idx, > > > > return; > > > > > > > > __this_cpu_add(memcg->vmstats_percpu->state[i], val); > > > > - memcg_rstat_updated(memcg, memcg_state_val_in_pages(idx, val)); > > > > + val = memcg_state_val_in_pages(idx, val); > > > > + memcg_rstat_updated(memcg, val); > > > > + trace_mod_memcg_state(memcg, idx, val); > > > > > > Is it too unreasonable to include the stat name? > > > > > > The index has to be correlated with the kernel config and perhaps even > > > version. It's not a big deal, but if performance is not a concern when > > > tracing is enabled anyway, maybe we can lookup the name here (or in > > > TP_fast_assign()). > > > > What name? Is it looked up from idx? If so, you can do it on the reading of Does reading side mean the one reading /sys/kernel/tracing/trace will do the translation from enums to string? > > the trace event where performance is not an issue. See the __print_symbolic() > > and friends in samples/trace_events/trace-events-sample.h > > Yeah they can be found using idx. Thanks for referring us to > __print_symbolic(), I suppose for this to work we need to construct an > array of {idx, name}. I think we can replace the existing memory_stats > and memcg1_stats/memcg1_stat_names arrays with something that we can > reuse for tracing, so we wouldn't need to consume extra space. > > Shakeel, what do you think? Cc Daniel & Martin I was planning to use bpftrace which can use dwarf/btf to convert the raw int to its enum string. Martin provided the following command to extract the translation from the kernel. $ bpftool btf dump file /sys/kernel/btf/vmlinux | grep -A10 node_stat_item [2264] ENUM 'node_stat_item' encoding=UNSIGNED size=4 vlen=46 'NR_LRU_BASE' val=0 'NR_INACTIVE_ANON' val=0 'NR_ACTIVE_ANON' val=1 'NR_INACTIVE_FILE' val=2 'NR_ACTIVE_FILE' val=3 'NR_UNEVICTABLE' val=4 'NR_SLAB_RECLAIMABLE_B' val=5 'NR_SLAB_UNRECLAIMABLE_B' val=6 'NR_ISOLATED_ANON' val=7 'NR_ISOLATED_FILE' val=8 ... My point is userspace tools can use existing infra to extract this information. However I am not against adding __print_symbolic() (but without any duplication), so users reading /sys/kernel/tracing/trace directly can see more useful information as well. Please post a follow up patch after this one. thanks for the review, Shakeel