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 A073AC282EC for ; Fri, 14 Mar 2025 16:42:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3AD06280002; Fri, 14 Mar 2025 12:42:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 35E14280001; Fri, 14 Mar 2025 12:42:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 226D9280002; Fri, 14 Mar 2025 12:42:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 08345280001 for ; Fri, 14 Mar 2025 12:42:38 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 39D27813E7 for ; Fri, 14 Mar 2025 16:42:39 +0000 (UTC) X-FDA: 83220725238.24.C57E14A Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by imf22.hostedemail.com (Postfix) with ESMTP id 81ECDC000A for ; Fri, 14 Mar 2025 16:42:37 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b=bgEqsRfc; dkim=pass header.d=linutronix.de header.s=2020e header.b=FI3StjOY; spf=pass (imf22.hostedemail.com: domain of bigeasy@linutronix.de designates 193.142.43.55 as permitted sender) smtp.mailfrom=bigeasy@linutronix.de; dmarc=pass (policy=none) header.from=linutronix.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1741970557; 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=tYlPwasXBzLfgEyJddys083H0WNthfCNPSsv0doG2Do=; b=UEa+LJBAQSGBwmOHbWsLc5j/hntI6nBhVrv3t85YEYrQSqwvcX1v6BH836Q52Fm9gUx2oC B2UUL/r9vtkjdJJVk1LmdKZ++J9DDRdjnf7VRrs+d3lxKLO172AQs/aRqFO6M7peXrEJTi eHenMbAp2OkYK0uObAIaOtiYKj3ZFFI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1741970557; a=rsa-sha256; cv=none; b=D4JNm4cZhMfDZYBpDFwCCiTv62k9f8jBg1tvdcy+U5SEjwM8RvuA8ciV7VJpvMdqa/WFPJ L2LBP2uzSl42z5O4faB0J/64/mIF7lrnq8Ax4O0M+q/vOWCT8Hvda8xobwLn57+kT+4ndj Y8i+AHJlAQ1TI7ECtx8d6DBvTP5eSdM= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b=bgEqsRfc; dkim=pass header.d=linutronix.de header.s=2020e header.b=FI3StjOY; spf=pass (imf22.hostedemail.com: domain of bigeasy@linutronix.de designates 193.142.43.55 as permitted sender) smtp.mailfrom=bigeasy@linutronix.de; dmarc=pass (policy=none) header.from=linutronix.de Date: Fri, 14 Mar 2025 17:42:34 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741970555; 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=tYlPwasXBzLfgEyJddys083H0WNthfCNPSsv0doG2Do=; b=bgEqsRfcBMtkfP0wbQPmmiEkCbQ15g6h3mpeVQZARg9564I5uBy+tB0VayJFeisXX8zXJ2 5oKgNf1KdiJ6SkINlyCr/B6rMgQ4G725dxP/3XSCMELmDqQzoawdKi+cZYX69Qht0u2MqA 9Y3IffYa6JVtsoeLFNPeS8wawEQf9ud0gRiWNRrIyaAQGNqflPsK1n3jGTaqgsfm4FiJKB BA3chkPe4/tVm7PrRz64hrbBZUJv7oVY43n++0ClkZvU+1RHrYvcXmK5OGlF5iCSF0CwSJ vKk3FnlTi4Xf+Y6a69wx5vu+ltNu+Yf46ml6reBFmGuXNg1+ZaoKxdPtMUPBmA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741970555; 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=tYlPwasXBzLfgEyJddys083H0WNthfCNPSsv0doG2Do=; b=FI3StjOYvtarRJPlbmUMnre0628h2cAhLZLpGcHRlRhbhgv2nEoyZgHFkTULCzvMbfKW7a /zo6VemKynZh9GAg== From: Sebastian Andrzej Siewior To: Shakeel Butt 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: <20250314164234.KHdt_CWt@linutronix.de> 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> <2c62mvfo4726x3ci3sze7u55encoycbbzbaatzslkbhur2dkvd@wlli7wrcjlik> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <2c62mvfo4726x3ci3sze7u55encoycbbzbaatzslkbhur2dkvd@wlli7wrcjlik> X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 81ECDC000A X-Stat-Signature: 9qnr98w9s9upkxarogh3w13t6efx4eor X-HE-Tag: 1741970557-834261 X-HE-Meta: U2FsdGVkX1/YhBLgEKoBRzWo4Gswbmum8xngeJn5U0DwqTvqUEuDd/OqZW++463LGyp7NASa6HqZ6OzPd6KxJBLeD+GVFOt66Bq2jayfdZ0oRuN1z7aB+EXppHtWa/tbnh+StXAjjbjwNowTjlVX8FW7xt+TtJdVxZ352RAXrrUY1SQUwnfuCzinR5/NycjzzVMnhBJ9gg3KYfCuFxsge3bqcU9tiQYM8lpFrbDCc3HgH4NxxzQLPcAR5qet9snCS1wi2rgSm0B/79fASYsylSlks7cAf6FDrGTbWK3My4ZyqLbOPlVhWodlq1qToY7QaZ3UVvNU+aOY+eXen6ojtFdtFJElgO4l90a7ExQcKTFFVW0IatOOl/rfhJyNxfyVKX4tvt8krNtgh5JzgvMrshYXe5A/GDo8CPz3pFQRgT8wobe2K5xaGM7j3+Qq5C3osFPakHCade5OAhfFAo0wALFWnEWpdzU+6nHKPKyojDgBK9R+uiqWMg/BwUJDnl4AXmejTaga0CD9/Mb4vcAIH3dzzsx0IoxpGl/44raAMupmlCxM94sYCpD1BuW1wTAuW4JJatkYnyES0PN3eoubDvn6rx0igxD81ZDvmyoJ+3eKcH15yVbhD2K9LZzh3fOFmwQptp8zpwxpqMcgohmbKf/j9qS5NT1sEPwguVz8Bzlketg6evYFKG5wq/BRNj+npWcTJF4wfJzlwGxFY5+EkR0LUOhopv4UgQMzxgCpGSSCzB4jn+cXevf+BA4iDYBSf7hyIpDgw+2oRIUnZVRe2Pgg3q7qqQBpJwz/rV8mBQe4Hx2mdVOqaVFEyVfuvWv1U85NoO8MeuQyYvov9wecA95mWXMjORRki9xGTcL++G2tA24VdU2nQ/5fgw74d6OJk3MMtbdFWJk= 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 2025-03-14 08:55:51 [-0700], Shakeel Butt wrote: > 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()? on arm64, __this_cpu_add will "load, add, store". preemptible. this_cpu_add() will "disable preemption, atomic-load, add, atomic-store or start over with atomic-load. if succeeded enable preemption and move an" so no, this is not the same. On x86 it is possible to increment a memory value directly with one opcode so you get preempted either before or after that operation. Sebastian