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 B710BC71136 for ; Mon, 16 Jun 2025 20:08:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 44A4F6B0095; Mon, 16 Jun 2025 16:08:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3FAD56B0099; Mon, 16 Jun 2025 16:08:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2E9946B00A2; Mon, 16 Jun 2025 16:08:56 -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 1E3B56B0095 for ; Mon, 16 Jun 2025 16:08:56 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 969FB1A0E04 for ; Mon, 16 Jun 2025 20:08:55 +0000 (UTC) X-FDA: 83562352230.25.625FFD6 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) by imf22.hostedemail.com (Postfix) with ESMTP id A04A0C0017 for ; Mon, 16 Jun 2025 20:08:53 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=duD28IFn; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf22.hostedemail.com: domain of inwardvessel@gmail.com designates 209.85.210.171 as permitted sender) smtp.mailfrom=inwardvessel@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1750104533; 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=i7cM7IpNYVMpXKnD6ovGoCFwerEZSHbA5k5p79ZUurg=; b=G7gP+UgZx5e9dM0DxuYPGsLoqdnLvBdOfS857kFfYKFRTFBPfiy1ahCkdOs7nqInlS9CH0 UnhUtazEORrXjkqSuTlIWU7g1euhnkY55HrP+6EXE1CtIoWAAuZSezHdO32sEHfRfiKGnl oBEZ9nRnINiFEdOCHHLhy+SnXmz0Qco= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=duD28IFn; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf22.hostedemail.com: domain of inwardvessel@gmail.com designates 209.85.210.171 as permitted sender) smtp.mailfrom=inwardvessel@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1750104533; a=rsa-sha256; cv=none; b=u/bJdGjsn+Q9al98abn64o6Lgxp1Vyb1fi2YCB2Bok2qsgsx2R6nKpULeboVsoYuXrEU9O l/3uDDupz9/0l5R1hT3jV6HJ8uLKJQw74CfIq7Iuxokii46MSYKwirOR224jmH8h1utFQa r9zwzsLiOOWthRGHUtvgz7ApnTTmTJc= Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-73972a54919so4291451b3a.3 for ; Mon, 16 Jun 2025 13:08:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750104532; x=1750709332; darn=kvack.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=i7cM7IpNYVMpXKnD6ovGoCFwerEZSHbA5k5p79ZUurg=; b=duD28IFnTNDlbxLPw0G71ipCVTi8azxtPRaKRDOOgn8voDPLVWrXTw0iqcrxy7hPLE udDb/079rpKTSeldgAMOCD5MOtl9FG6XqV0TBDT7EsB4ML0Hs1rVoUmdFosXuqB56Y06 arZmDECcIJkxWrINOneOJCxn7MEG/xPPfXpecOHhTPK+IC2Vueix+osTVyNjVj9qaZg7 0hvUA+TOceBNEeMDlo4DBZAMs2xybFkuQn9+VMIcbhcfLTmhVTdRai85C2zpquScMHqf 94aCGBGgONC3vtFkdGifJ8AnpajufPmAdPYEnJe4mB9y0N7Rz+4Yd0OIQ4c5ug4ctv8n Bnsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750104532; x=1750709332; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=i7cM7IpNYVMpXKnD6ovGoCFwerEZSHbA5k5p79ZUurg=; b=ZzWjMC2xOqRRvZzXF/2NJFFETADE65+ZGg/Qz4rBh8FR58aPt+LO9fOQkAb6Pv09O1 F52CwXDV7dr0iTgxeOz4oX8UgjQgjHIwpiCthqotMNWNdpU47eEiUu3PvaYx7YSlZy0B kPHBcsyxWfAts3Fr3PZMsfRV/zGQh3EThMyzqQp2AeGdJsgHlBFUcghuGhEUvVDkZRQp tbAivYDpqyaYDExbvjzZu0GzFR1sF7NcVZ5wTM0tSmEc4s3yYqZC7ZBDDmqnHqCFpe1C b3kfhufu1rvBr7EH0uqhd8UlITGfn7dAx3dYnTdX9VGQ/KH8v/drGkNs3A7DLueCNAZ6 NVwg== X-Forwarded-Encrypted: i=1; AJvYcCW7KZugAVo3GEipFJJU89ditwVbWJPsHADNA9HOXDB7sSYZyzFp8bD5cQLddTuQO9fxzjL0N0MNvA==@kvack.org X-Gm-Message-State: AOJu0YyfiwzuxeNdmKDWt6jK9Iv7j56FUnJSfytQQtLHaKuyEO/pvlQA N3DN1lPybAS8l9qgDreSRVOfCme2ON/ukeyp8juebsXZVAXuRVsgxpXS X-Gm-Gg: ASbGncs3EJvFHfL4Q/XKttIpl0vl5v2Klv1FoHIBCoTGHhAr18Ezj5YzTE/Iot5GjRO hBUn2yuCysz7dstqYIEyzLk7+yinNbwNs0strBZT1k6ZrHuWwTMYOGSbvnRCaJ2yVEzfBwOMA53 Ikn2tJnW2M2eXv9w4+UA/bqS81YvzprOZsP3mitAP7JGbEvoVrYzZyA9EmExl5BimflXGripszf TK190pB9ggp+4zhJ8Ys9JfgrFoNi1l3lbB7gVSTakh42k+4xkng2lRC6eINbm23/LnmuQXKbnbF csNi8WJcGrnbb9Az0yu8AJOnB7/gIoBAinEpA6MAhvo67y3zq2RHd4lbrpg4SI4BL8v4cpHaS+o z4vHUK4neuksGdO7ZsDd9SEABuirPxjWPnj4= X-Google-Smtp-Source: AGHT+IGtI2QbWLF8zRP92H+K4S5vcroON3TXx+J10ig5ZVF2nPlaF/o1jqE6UEeo9QAOopR27zzJ9g== X-Received: by 2002:a05:6a00:c89:b0:73f:ff25:90b3 with SMTP id d2e1a72fcca58-7489d056f18mr17312859b3a.24.1750104532330; Mon, 16 Jun 2025 13:08:52 -0700 (PDT) Received: from ?IPV6:2601:648:8100:3b5:c6ef:bbff:fec0:9e95? ([2601:648:8100:3b5:c6ef:bbff:fec0:9e95]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-748900d7e0asm7523151b3a.174.2025.06.16.13.08.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 16 Jun 2025 13:08:51 -0700 (PDT) Message-ID: <218e8b26-6b83-46a4-a57c-2346130a1597@gmail.com> Date: Mon, 16 Jun 2025 13:08:49 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 0/4] cgroup: nmi safe css_rstat_updated To: Shakeel Butt , Tejun Heo , Andrew Morton Cc: Johannes Weiner , Michal Hocko , Roman Gushchin , Muchun Song , Vlastimil Babka , Alexei Starovoitov , Sebastian Andrzej Siewior , =?UTF-8?Q?Michal_Koutn=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 References: <20250611221532.2513772-1-shakeel.butt@linux.dev> Content-Language: en-US From: JP Kobryn In-Reply-To: <20250611221532.2513772-1-shakeel.butt@linux.dev> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: A04A0C0017 X-Stat-Signature: 1d696wixfir4nprqcrtxknu1okfjpt7f X-Rspam-User: X-HE-Tag: 1750104533-26719 X-HE-Meta: U2FsdGVkX190nqjoAn9Ry9Bkz23V1gAY7EEqX125bK35oKsPW3yz68f++MknEaFFljLzKlhkB1E76llNtAFGRja4+x5YuywU4nlpKorvgQYvNRf2bc1ZBBDVaiUO+uLqrUjVqxMN+6vkz3mKPlwdVU5b89OwD51g4r9LK/UGCvDOKW+e2X6ecIBJ/OSypNy/LBeqW+8xaA2vy2f13hxlxXThvP02lLZLTUwUeO8UehfaOqtWqvRxwWjhEJizSeHWaGrnvOibY5L4sPyEM1AB8ePHCyFxBps/ioC6o3S2jiTv7EHs5F/Eod8XNmeDaW5DdMgWLyLvP5TiNK45WbE1J15TuYibqfaFtlFqfmkQVdDp3ypfT2iLm7LJTBKlRRLkvPrROpQmXGfRpfs2SmERUTta4cWyUTqCS6nxKutAlQK4NbQaZ42NnrGjP84QHQJbFUhGZLu1u+Q6McKLbmmDHkX7KxyHgP2ODxNAnPDQ6kDKR5hnr0IF3OfHvYnOABqIVrpdofZwdpuIzGCpLR5u05SfNtkN/zTN77HbZbf0vPkab6bc62aWJkboVZ7k7PdWhHeO1bdL28r8p564wUY+APxHOp5u5JaYX4kQQpqdFt9xE8nJ1B1HqTZ9xttJrQ9GIRlYHbUK7YJuezwH65HVsvIxnxwxfk3WIEiIOVSeiExl0xNL3fCS/sZptDCw7kfL+n+XEViqFf5BmNG2XAIVtBX2DJsWuDnY+61C6eKh0g1ZLUbmaN3hBe8wjg/Dlq+ZB6ihi5Y5R4tUG9fGeBokEb1P1M2jgzLD8lBnF2k/absi41CbSZ7j15nRsLi0qsa55mBHWmxPbg3dRjKvUQKFBphOvOyRG8RPLlLFg804mjzcASMhB9omNM5xpkAwtJzKMbBufWQIgT8Jd9x5/PAmSkgXl3E/IOJzg+DNrT1J/sfIBhMa2d9kBm7JTLW+Hegc5k1frvr471MvjZ1SJ7m nm4bSNtN btJPXkRS+ybp7aVNcaMgWJ6yqeZvCpZC/qSmlm+T/FX2uoTTKxArv30OUO43BZIRe0BjvunwB1HWvuDAmxBM/A3FzdU6z9XfCcnsHIONY/q3tVS+OLa5DCmmlOIRthWwc22R+ITfpBkX/9SNeyUhvuk9PvT1Vwvv7UgoFMlfxwt30LXZ2NYbfItEBBZLQJB3utAlj+aytuHwYP4pjufuNU5d3AvvN1VWAX0eLxKUf0whYTRSyjXyhoQnDkMVnZM5K/zfmQVgFLczdCBLSfInDHouHf79sCoGv4wbvJONjmuATVpwDjLw8JUEioFT182ec/JHGQYZcJb2R9bOtVRmJ3U6IYlnDYkXOJAVZlZLXlGCUyZTEkne3h72FiXrGNkCP8CAvjjhVU2VQIaRsdzvD8cGM6kuvm0no1DS6tiX28vsE+qZjYoBYP7BF1Rio8UBcrx/i3tfvpS8vvGC+csptDP9iyCihUXXJwirXi7nzh9yYYqt3gkA968nsMr3hiROO+uu1 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 6/11/25 3:15 PM, Shakeel Butt wrote: > 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(-) > I tested this series by doing some updates/flushes on a cgroup hierarchy with four levels. This tag can be added to the patches in this series. Tested-by: JP Kobryn