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 BF2F3C3ABD8 for ; Fri, 16 May 2025 15:37:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CC1F66B01A9; Fri, 16 May 2025 11:37:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C726D6B01AA; Fri, 16 May 2025 11:37:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B5F7E6B01AB; Fri, 16 May 2025 11:37:34 -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 9D4876B01A9 for ; Fri, 16 May 2025 11:37:34 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 666821CFDC6 for ; Fri, 16 May 2025 15:37:34 +0000 (UTC) X-FDA: 83449175628.22.C0449B8 Received: from out-178.mta1.migadu.com (out-178.mta1.migadu.com [95.215.58.178]) by imf19.hostedemail.com (Postfix) with ESMTP id 957821A000C for ; Fri, 16 May 2025 15:37:32 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=Zi62pArT; spf=pass (imf19.hostedemail.com: domain of shakeel.butt@linux.dev designates 95.215.58.178 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=1747409852; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=GUmB6MysdwfVDrB19QMncGfwBZNU3SIATJ4OxtHukM8=; b=1AKVd2Mi8b7DDTKgJrvZJ/IPPwBhgek82q+4wTHWzxH0DuE5qxWbZyfdJ5QyyHXk6cpgTY jrpVyd2ORNvQQKDghwTx9ntQmlY0NZdd3BgFc9bVfNr/ANeuNEBXs+n5s9yB+xtknEmZvs 2gkU7h9lcINcYniq2Aj0GNZd9zAlY1M= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=Zi62pArT; spf=pass (imf19.hostedemail.com: domain of shakeel.butt@linux.dev designates 95.215.58.178 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=1747409852; a=rsa-sha256; cv=none; b=cW9VOVZ8oxIZDOLqZf/ES/z2oHvMNSsyaqntO18JJZmqrGQb0cGFJcb/vLcHSg4XjZUTLa ppB1uC8qMGclz9xgYfq3FNEoMStWDx9UVR9BfLh4G6RL7ZQQ99yPXtgsi1z1+EZ/GQqRpM BtDKMYvIPIQMvGNhIlbrTIJVMURTtY4= Date: Fri, 16 May 2025 08:37:23 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1747409850; 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: in-reply-to:in-reply-to:references:references; bh=GUmB6MysdwfVDrB19QMncGfwBZNU3SIATJ4OxtHukM8=; b=Zi62pArTD9nQONyMVoTOTkWzLtXfSpFp1vYJssLs+SioqtfVLUfCo5UPKpokDCEIRHJ7V7 MkjHQSHV01HKIeXg6u3ofnddU32/7s5zv5PrTQE4G2sgZBxxA3wxVfw3XPyZCJncMHcPwF 67ljLHnnIhccyilTXh9PP/QLo7HiSOQ= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Shakeel Butt To: Vlastimil Babka Cc: Andrew Morton , Johannes Weiner , Michal Hocko , Roman Gushchin , Muchun Song , Alexei Starovoitov , Sebastian Andrzej Siewior , Harry Yoo , Yosry Ahmed , Peter Zijlstra , Mathieu Desnoyers , bpf@vger.kernel.org, linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Meta kernel team Subject: Re: [PATCH 1/5] memcg: disable kmem charging in nmi for unsupported arch Message-ID: References: <20250516064912.1515065-1-shakeel.butt@linux.dev> <20250516064912.1515065-2-shakeel.butt@linux.dev> <050484a9-c08c-40d2-b431-76903a639222@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <050484a9-c08c-40d2-b431-76903a639222@suse.cz> X-Migadu-Flow: FLOW_OUT X-Stat-Signature: 7mqpjdqdkk478eiut8nrj44sfo4jsfeg X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 957821A000C X-HE-Tag: 1747409852-847711 X-HE-Meta: U2FsdGVkX19B8kC3+394uRZx4mKvGobgXkcftZ49RAJ6dTzaybNQgTVxFUz9rBeIorCAqbrY61RZt/FC6aj/Ku/sEyKJM1ZAh1mlg6dhTk+x8d2uHnvPtbPXBXiOc5XQII4xF9KRRqL6c0t2EoS0Jv36CUg+Q6EjQ2fK6BXlgN0ld59NljJTmJ4nQDE3Z/4InNcZkowHVQOAEM13/qWevF8g2w3vhSNgTDcfbAeknrbTskKndKFdk21lvEeSLPW6LlyYQL67txxo1JxaMeoUb9sej5DOeXjPC1yjmEtZbhoxBmmmOiBKT5EhRJdhKTjjXjEkGzKcO+ITGh3fTJI2wLKsXjAvPy2VusZ0cdPQuKeYJO7yAg+cn7VEaET9EZjp9cjnAjx7LCcfV6uE9HTsCc+zP1F9PZ1nYOZghuJF5nz8k21FWuioCFxspwbTSVNuqsyLI1SglK/Bw4zmhL50YZBOsme6YIW+f5DFBN2qz3XzjpRSC3tZhbZ/wE/eN9OQreLb0AczNXtC0eIxSdiuL7V57xCqJWJ25Nsx4DscNjLtRZ9cg+PvdGQF9uzQ3YawTt4tQATk4O3gNjNxloidbMSXtHJIk4Z3dpT95HO19Wqt7pNCV/yWhYbJRpnu6J9V6tb/LKTIEIpo07JEZLcQlWoPi6b/g7KuWze0vo96zXA5GN4SYidef0QiNKP9YIeG0IcHOzg3gSVDX5S9cxI9BD0mgL5EqK8I0172alaPLc1ozS0IxCDTX8fdY4oEAuou9pF8a14POB79ePj+QqvEPNVs34i5cgCKmkCVN0XHrxQmMIO1oFkKkJ5jopJrXzZg3izHcYU0MnQ0FmunbZNmN+q7tW1zyQLuVAcSW67qxY4NtOnpg637C1drA1lzXumkOBpxe+Ti6GvoBRRiIcCC9ee+ulrHmWHr1OcmzSNY7DsKeQGNFzidmdgPwKwfWPNu2bBipqj+iERKi5koPZn LL6TAfGB HxwGOJr7rhlQXtZbluDBEp33QTb/u7xAoMEb93h9av6QtAUN3UqHCUTo7FZqBiOFitpptxHiGTsSIG1sm+dvS+CYq/UhCCNEScO1sVFJlZu5E6XjSyTCGBq9rIeGub8hpUGjiJX1VAmgTsrIWn184tyYNjgYuIgu0ButNw/dGIa2XqvA/OMxyX2KM6w== 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 Fri, May 16, 2025 at 11:30:17AM +0200, Vlastimil Babka wrote: > On 5/16/25 08:49, Shakeel Butt wrote: > > The memcg accounting and stats uses this_cpu* and atomic* ops. There are > > archs which define CONFIG_HAVE_NMI but does not define > > CONFIG_ARCH_HAS_NMI_SAFE_THIS_CPU_OPS and ARCH_HAVE_NMI_SAFE_CMPXCHG, so > > memcg accounting for such archs in nmi context is not possible to > > support. Let's just disable memcg accounting in nmi context for such > > archs. > > > > Signed-off-by: Shakeel Butt > > --- > > include/linux/memcontrol.h | 5 +++++ > > mm/memcontrol.c | 15 +++++++++++++++ > > 2 files changed, 20 insertions(+) > > > > diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h > > index f7848f73f41c..53920528821f 100644 > > --- a/include/linux/memcontrol.h > > +++ b/include/linux/memcontrol.h > > @@ -62,6 +62,11 @@ struct mem_cgroup_reclaim_cookie { > > > > #ifdef CONFIG_MEMCG > > > > +#if defined(CONFIG_ARCH_HAS_NMI_SAFE_THIS_CPU_OPS) || \ > > + !defined(CONFIG_HAVE_NMI) || defined(ARCH_HAVE_NMI_SAFE_CMPXCHG) > > +#define MEMCG_SUPPORTS_NMI_CHARGING > > +#endif > > + > > #define MEM_CGROUP_ID_SHIFT 16 > > > > struct mem_cgroup_id { > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > > index e17b698f6243..dface07f69bb 100644 > > --- a/mm/memcontrol.c > > +++ b/mm/memcontrol.c > > @@ -2647,11 +2647,26 @@ static struct obj_cgroup *current_objcg_update(void) > > return objcg; > > } > > > > +#ifdef MEMCG_SUPPORTS_NMI_CHARGING > > +static inline bool nmi_charging_allowed(void) > > +{ > > + return true; > > +} > > +#else > > +static inline bool nmi_charging_allowed(void) > > +{ > > + return false; > > +} > > +#endif > > + > > __always_inline struct obj_cgroup *current_obj_cgroup(void) > > { > > struct mem_cgroup *memcg; > > struct obj_cgroup *objcg; > > > > + if (in_nmi() && !nmi_charging_allowed()) > > Exchange the two as the latter is compile-time constant, so it can shortcut > the in_nmi() check away in all the good cases? > Oh I thought compiler would figure that out but now that I think about it, it can only do so if the first condition does not have any side-effects and though in_nmi() does not, I am not sure if compiler can extract that information. I will fix this and make sure that compiler is doing the right thing.