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 A2AADC282EC for ; Fri, 14 Mar 2025 15:56:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 63F37280002; Fri, 14 Mar 2025 11:56:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5C80E280001; Fri, 14 Mar 2025 11:56:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4699A280002; Fri, 14 Mar 2025 11:56:02 -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 0A59A280001 for ; Fri, 14 Mar 2025 11:56:01 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id BCC7C1A01C5 for ; Fri, 14 Mar 2025 15:56:01 +0000 (UTC) X-FDA: 83220607722.11.ACB9825 Received: from out-178.mta1.migadu.com (out-178.mta1.migadu.com [95.215.58.178]) by imf02.hostedemail.com (Postfix) with ESMTP id CCCF280020 for ; Fri, 14 Mar 2025 15:55:59 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=SYsDYedX; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf02.hostedemail.com: domain of shakeel.butt@linux.dev designates 95.215.58.178 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1741967760; a=rsa-sha256; cv=none; b=Pbq9GJlp3iwThvQo6tyXiD49YHxHyHny1BZMzCwL8DuyuBQoteosKAvZPAjAHiOIzphoYR lsLOelLEGN+NgHNz0OURx+Cwp2ZRQsodWFUhJjta3wvV50c6J/rLMghSvE1vhoo1NBQIjo 3LwAYPE2LENSjMflpLv7MKu+oi6wtCg= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=SYsDYedX; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf02.hostedemail.com: domain of shakeel.butt@linux.dev designates 95.215.58.178 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1741967760; 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=6/90O0V+OacosFxzAPbv1bKZqaK+9Vyy7YEsU/KBtck=; b=m03PMo2YAqAn2GNG8RT21rXRiVcAyR8Ql3H1NF3hyNbqGXdM0e/rtDrZurOTdvdPRPivgN MZMoU0tBcZd8QfpLzx0g1MqabOHOxpSp5wIRDo0TRdlXf071CpLLiHUvlgKeggpFr6F6BY AQuC4CBYYh9CbUsKfzkSrx3g3FP0eYA= Date: Fri, 14 Mar 2025 08:55:51 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1741967758; 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=6/90O0V+OacosFxzAPbv1bKZqaK+9Vyy7YEsU/KBtck=; b=SYsDYedXLXq+vuA8ZPxhgob8cxepEESL3mycHq3vy/1mlX0dGbJSeLeGQCv8jAQU9eisUY HJEK1V3hF/0J/NpGdOOaHTKJ3UONKP8cjEh7ozwN2hsqAPHQOaoE0sCTK6CEsjJ2cFHrfu ztoumi4fcxvM5sxwkuUCNwn2umxAdmE= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Shakeel Butt To: Sebastian Andrzej Siewior Cc: Vlastimil Babka , Andrew Morton , Johannes Weiner , Michal Hocko , Roman Gushchin , Muchun Song , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Meta kernel team Subject: Re: [RFC PATCH 10/10] memcg: no more irq disabling for stock locks Message-ID: <2c62mvfo4726x3ci3sze7u55encoycbbzbaatzslkbhur2dkvd@wlli7wrcjlik> References: <20250314061511.1308152-1-shakeel.butt@linux.dev> <20250314061511.1308152-11-shakeel.butt@linux.dev> <9e1e3877-55ae-4546-a5c1-08ea730ea638@suse.cz> <20250314115802.DESa-C1z@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20250314115802.DESa-C1z@linutronix.de> X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Queue-Id: CCCF280020 X-Stat-Signature: fe3kyi6a57xbxu5hppajtbwbomwqwjp3 X-Rspamd-Server: rspam06 X-HE-Tag: 1741967759-60345 X-HE-Meta: U2FsdGVkX1/ZZWhGhi+uu8tRdytwHhh9tkZVETj9U9+3vZbjB6hbHnPfY3vDR0aLWvVtEwjr1goRm18mc9B/PflkN7oQCnhAZgAuE8VndN1GOD5PK0OvvVNj68Ckt2EaLb3zvR5dplESPEB2/zEtI9wVMu7pv+NJPetU0dWCLqi8M2WRI3F17YkYZTppTu0CyXjertDbkma7Mv7JwuPCutd1djnnjrcxOZX9lgdfl8UNSIAbSTd3xeRkB8NdDKJHIdPZBP4dUmzhb6IxRTcJlCIPEdSplztZ2fHOBd0zvTX/JUB4Z9XPluLj6OwIYggiaLUhE2B6OzfvoLGAOdv9xj4sJ/ZEAEZDaKMmPlW8rC34zxZ1IK+hXALBWRl6QqLUczCW/FyIyBlh4DR8k+b7vIPGF7CrRhjNIfTwiyCqBLgS0ef0FrtucuSUeNF/GV6uu6HDdp9ShihJB5xPudU7go9PMW4fWkjb2lFhnSZxAn87ZFfxzECJEJ5YpcyiQ876/YfW34nVn/s26p5EcF1RzD/QI9x6Tv5qvmjd4AAAb3VC84PTwvEGhQt2GZF8OTT9bYfh68VDlUKqKpeoQNf+LWIwcWrrB1PlXCoSi2lUN0nZBl5vyku+mq0gNXrLzVVKHwaod9m2VL3rhNYGgj4kWcqaRnbvzVfB7gYPZhTMZhRQEMWFjWExfkf8PV53fR/RHShb82OspqfMHmBfTvuwiW0IY5F9P/qWqRhPH5pAmI/CUTZCKFEfr4T6jACA/sXcm5p0rkwlQfW8MtiwwFCRje6i4mWiqlHWEwR5DD0+2P+QAJPmd5uLIK3SVdItwD9w6wRau9MZwVxbmzFVXiJsc6gq2mQ49IBUmWGvkScOJmpuRQg0KM43TKq+oBtw01B91+pk5Jk7OUHYBqsTwq/oA0fEorKv/oEan0A9HrZrgBWkNrBRiWxBFBlzAYowBck5V/lLLKh/87fNAIdDOo1 wbuktOiy c9Cu9cl1OU2oD+Q5CWv0KYjNRcIQkV2acptQ0U2MxvUlUONjipZUIVORzBQrNKYfZVX3gxAoNEbb69cxNxyxSYRNkDV4ozTC2EeY4xxy6048xWyMvkPWsJ+5eEjRPjuBI/RBVk1yBoX1RrOe9yvllQmpuvqgFRLOjoCCZGF6hA20LgQ1P+oGD6M1fUP0/0vsibKB+K+0JctOZOI8= 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, Mar 14, 2025 at 12:58:02PM +0100, Sebastian Andrzej Siewior wrote: > On 2025-03-14 11:54:34 [+0100], Vlastimil Babka wrote: > > On 3/14/25 07:15, Shakeel Butt wrote: > > > Let's switch all memcg_stock locks acquire and release places to not > > > disable and enable irqs. There are two still functions (i.e. > > > mod_objcg_state() and drain_obj_stock) which needs to disable irqs to > > > update the stats on non-RT kernels. For now add a simple wrapper for > > > that functionality. > > > > BTW, which part of __mod_objcg_mlstate() really needs disabled irqs and not > > just preemption? I see it does rcu_read_lock() anyway, which disables > > preemption. Then in __mod_memcg_lruvec_state() we do some __this_cpu_add() > > updates. I think these also are fine with just disabled preemption as they > > are atomic vs irqs (but don't need LOCK prefix to be atomic vs other cpus > > updates). > > __this_cpu_add() is not safe if also used in interrupt context. Some > architectures (not x86) implemented as read, add, write. > this_cpu_add()() does the same but disables interrupts during the > operation. > So __this_cpu_add() should not be used if interrupts are not disabled > and a modification can happen from interrupt context. So, if I use this_cpu_add() instead of __this_cpu_add() in __mod_memcg_state(), __mod_memcg_lruvec_state(), __count_memcg_events() then I can call these functions without disabling interrupts. Also this_cpu_add() does not disable interrupts for x86 and arm64, correct? For x86 and arm64, can I assume that the cost of this_cpu_add() is the same as __this_cpu_add()? > > > Is it just memcg_rstat_updated() which does READ_ONCE/WRITE_ONCE? Could we > > perhaps just change it to operations where disabled preemption is enough? Yes, I will look into it. > > > > > Signed-off-by: Shakeel Butt > … > > > @@ -2757,6 +2745,28 @@ static void replace_stock_objcg(struct memcg_stock_pcp *stock, > > > WRITE_ONCE(stock->cached_objcg, objcg); > > > } > > > > > > +static unsigned long rt_lock(void) > > > +{ > > No, we don't name it rt_lock(). We have local_lock() for this exact > reason. And migrate_disable() does not protect vs re-enter of the > function on the CPU while local_irq_save() does. Thanks for clarification. Here do nothing for RT kernel and disable interrupts for non-RT kernels. (Let'e see how the other conversation goes, maybe we can remove the interrupt disabling requirement)