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 796C6C71135 for ; Wed, 11 Jun 2025 22:15:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DFCB66B0089; Wed, 11 Jun 2025 18:15:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DADBC6B008A; Wed, 11 Jun 2025 18:15:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CC3976B008C; Wed, 11 Jun 2025 18:15:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id AB4986B0089 for ; Wed, 11 Jun 2025 18:15:58 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 2258712175E for ; Wed, 11 Jun 2025 22:15:58 +0000 (UTC) X-FDA: 83544528396.18.1CEFAA4 Received: from out-179.mta0.migadu.com (out-179.mta0.migadu.com [91.218.175.179]) by imf30.hostedemail.com (Postfix) with ESMTP id 539D28000B for ; Wed, 11 Jun 2025 22:15:56 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=H4KFhf79; spf=pass (imf30.hostedemail.com: domain of shakeel.butt@linux.dev designates 91.218.175.179 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=1749680156; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=lYytpibLt4/Z7wsWilf15mdzCpQBPoxPKxpntneeV0s=; b=RzClnfoyIp9nQNtO4P8qbgNAWtLr6lHNSxn4BfBq02Z/ZLhXhLVMoLyU0Iv4m7OTRkc4+B uqTuLmSZ9huCw/uuoFEWAyGbgUPiN5YMKq4ZqDB1AIk83tLbZR5G1mekzXGg/DInRBrhWw R9uaNsroshgMc5lc4p/Nc8ghHRXq7S8= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=H4KFhf79; spf=pass (imf30.hostedemail.com: domain of shakeel.butt@linux.dev designates 91.218.175.179 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=1749680156; a=rsa-sha256; cv=none; b=jgc1IH/SwmeO8eKgaGo4XyGYgI6Sy9882X0//eI+SGxlWaUzInNy5Lt8lNXYerjIJvf2qk kRpTuZOnnkLALnaGFkgz9TWqJ/cl/sb0Tcah383+llCTaOpw4nifjPn8gP44DNl9goK0rO EeMXtNzLwUVpK3G5lk5isitoSEZIkx4= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1749680154; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=lYytpibLt4/Z7wsWilf15mdzCpQBPoxPKxpntneeV0s=; b=H4KFhf7971HKrGdif2KwiqK92xb+/SwP2ksEGNoh4wz57QCSWT8YmWoMcT6Pt/6N0+wpB/ Iw36uws2qtccUfqOAbMTtP7mYI/LbttTWzgnJ/IAZIH5m8LVNolgiL/F2dhWuVrnqX1DVH GQOum3dN6a4RzH/KhZXizuX8H62+r3M= From: Shakeel Butt To: Tejun Heo , Andrew Morton Cc: JP Kobryn , Johannes Weiner , Michal Hocko , Roman Gushchin , Muchun Song , Vlastimil Babka , Alexei Starovoitov , Sebastian Andrzej Siewior , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Harry Yoo , Yosry Ahmed , bpf@vger.kernel.org, linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Meta kernel team Subject: [PATCH v2 0/4] cgroup: nmi safe css_rstat_updated Date: Wed, 11 Jun 2025 15:15:28 -0700 Message-ID: <20250611221532.2513772-1-shakeel.butt@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 539D28000B X-Rspamd-Server: rspam03 X-Rspam-User: X-Stat-Signature: qk96dtze57wtxiiyzcacb6z5n3ipwo4r X-HE-Tag: 1749680156-316934 X-HE-Meta: U2FsdGVkX1/e79i+JVyKaooZZ2EQ2YgRnKzyeZXGBw2ymJSmfDNC+dDGKNqMxul+AmcNdAYi04bmzZBAdR/hHnlSkzWHIe94jC3ZRppn7lQSmmsG5/VlkaXy9nZZvOjpG8ZVp3ArNUc5imiRXn6QHdbe0ua7Tm0SKhpGR0hEXcziJSn77t0XUJWX60zTdI7rgOAbzzvstZxZEklskcQgyzjc2gXLOQlQxHMIulUZjaixnQI3cZlfy+iqVEcwcKtg52NODfvlxR/w90t/zRchL+Glfngnr25W/j1q3DAiE6RLaHkyAXitxHKZOlNDdZrIKzxAxqoGjIWJh9lUiup3WhHX9RiHuc1BMoTOwdjellic1yDd74KGbCjyoo/TI+aoAz5QhvVqDb8Zq6DQTsw9Xfsb1ExGBzGTrkUutMAI1IoYzJdl54KnN+htMhf8CTFegLxtcuZteC5PqkPfC/izlepMb7b1HhEjvvNNNt3oUhibc8fvXywnPrOivD1gbiXNe6Bdm0cKHZ6/75nGEeArLfv/gx7sNKop8n4JtcflrO6jvpapSqICRQng2pNc8uAazF+R2up8EHl+PLt2f2fnB54CPF5l5QjbsQgRKPjtWM5sB1iTiyMpvpIFVNNR6Hn7NuFUQKxNHE4dh5kKR6IEGRZGCyVP13iIhLEVwkUrStPuv8SfSDjzzkwE7NB3sZgFUW7sW4jooDeqw/lFjgqGTJo93ge90LYVvb8z7yEMWRuVtTa8eEXEi6T724mYnksOT9d2/QY1x6mjHMLLzM2jtvWF3ERwxq5pEAxC3Nr8nplFVEF419EkAzPjSdrtgmN5zZeDjNth3gwHHDmG3+dJk9pjjqXyY1NCIKa8CreM4Z4MQSIIxMa506We2wRbZYlM40TPSNo8UDdZDDth8bHqxQEMcma4b15WpRmBt0cNnZVdfHbaJ8ZkEOe7hn78eFL0hYRPMFz8pCeYz0+cczy 7faQ2Vmh VWf0rShHVO3cdvqqYo6BqmPwR3WXeoU1VkEoDDDTe06zaH7Ln4yNYyKkpW700u5LEjN7ExUA+3zSDlcuaZcylg/F0ewRNDLKX+/07fnszOmI/Dxh+Qp8B9ErDw/ZrvX0R6MAqAFlVoTnAczibPe+BooIfMY0qqpA7mz7pxf3VDl1DYDViNXcGm/RSwa2z5tGij3TKGSV5nrtPB+UJnNsYnJPrbK2v9J7Dx+1FWiQIvmhJUEu+5bWwO2b+pTvVR/wK7v++Bj9qziutxJCt5HKW4NRIBg== 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: BPF programs can run in nmi context and may trigger memcg charged memory allocation in such context. Recently linux added support to nmi safe page allocation along with memcg charging of such allocations. However the kmalloc/slab support and corresponding memcg charging is still lacking, To provide nmi safe support for memcg charging for kmalloc/slab allocations, we need nmi safe memcg stats because for kernel memory charging and stats happen together. At the moment, memcg charging and memcg stats are nmi safe and the only thing which is not nmi safe is adding the cgroup to the per-cpu rstat update tree. i.e. css_rstat_updated() which this series is doing. This series made css_rstat_updated by using per-cpu lockless lists whose node in embedded in individual struct cgroup_subsys_state and the per-cpu head is placed in struct cgroup_subsys. For rstat users without cgroup_subsys, a global per-cpu lockless list head is created. The main challenge to use lockless in this scenario was the potential multiple inserters from the stacked context i.e. process, softirq, hardirq & nmi, potentially using the same per-cpu lockless node of a given cgroup_subsys_state. The normal lockless list does not protect against such scenario. The multiple stacked inserters using potentially same lockless node was resolved by making one of them succeed on reset the lockless node and the winner gets to insert the lockless node in the corresponding lockless list. The losers can assume the lockless list insertion will eventually succeed and continue their operation. Changelog since v2: - Add more clear explanation in cover letter and in the comment as suggested by Andrew, Michal & Tejun. - Use this_cpu_cmpxchg() instead of try_cmpxchg() as suggested by Tejun. - Remove the per-cpu ss locks as they are not needed anymore. Changelog since v1: - Based on Yosry's suggestion always use llist on the update side and create the update tree on flush side [v1] https://lore.kernel.org/cgroups/20250429061211.1295443-1-shakeel.butt@linux.dev/ Shakeel Butt (4): cgroup: support to enable nmi-safe css_rstat_updated cgroup: make css_rstat_updated nmi safe cgroup: remove per-cpu per-subsystem locks memcg: cgroup: call css_rstat_updated irrespective of in_nmi() include/linux/cgroup-defs.h | 11 +-- include/trace/events/cgroup.h | 47 ---------- kernel/cgroup/rstat.c | 169 +++++++++++++--------------------- mm/memcontrol.c | 10 +- 4 files changed, 74 insertions(+), 163 deletions(-) -- 2.47.1