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 3849BC3ABBF for ; Tue, 6 May 2025 09:41:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 76E2C6B0089; Tue, 6 May 2025 05:41:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 71C266B008A; Tue, 6 May 2025 05:41:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5E2C36B008C; Tue, 6 May 2025 05:41:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 3F31B6B0089 for ; Tue, 6 May 2025 05:41:12 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 309BD82030 for ; Tue, 6 May 2025 09:41:13 +0000 (UTC) X-FDA: 83411989626.27.CF444BC Received: from out-177.mta1.migadu.com (out-177.mta1.migadu.com [95.215.58.177]) by imf04.hostedemail.com (Postfix) with ESMTP id 4C58A4000B for ; Tue, 6 May 2025 09:41:11 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=vqJXirJ+; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf04.hostedemail.com: domain of yosry.ahmed@linux.dev designates 95.215.58.177 as permitted sender) smtp.mailfrom=yosry.ahmed@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1746524471; 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=p9JEQ5MEIGdY5HQTIeFYZw6nNX1hJPlNSluNRhYlSsM=; b=oiER9LCk5r2eZNiB8qSHFempgyJqF2C1DXfuKLDHOJ7SFgwJivNveInVYoWylWZWlerUQd 5vUqb97wghM4zjqjoKQuZMnP2RJRal3J1BHB2P/TB1JPZcimK+mlJnxyaCDFn1gCdZmWOG Y+Md+/Q5dK/eZBGVV+JpZcC7B6i2Y90= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1746524471; a=rsa-sha256; cv=none; b=49GNGRhCQ7h4mDP/oQbNhl9whUAQ9aePkhtQatzEduTCIjLVpMY0d28NAtgQGHoM1rVhhS pGPHlGLp3X088htYFWJ8Jbpx6jgF7H1SJJVYVvOmNDsYdkEGUCTa3gKNYTvukiF1iT26X8 RFBSDf9SOZsGabgGZe/TMwIiZHvMsmo= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=vqJXirJ+; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf04.hostedemail.com: domain of yosry.ahmed@linux.dev designates 95.215.58.177 as permitted sender) smtp.mailfrom=yosry.ahmed@linux.dev Date: Tue, 6 May 2025 09:41:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1746524469; 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=p9JEQ5MEIGdY5HQTIeFYZw6nNX1hJPlNSluNRhYlSsM=; b=vqJXirJ+udQtoPHrcNBzmk2NUAB3/MCs3MuuKQuAiVoBygBttFPgI28D5TEBo/MSwzrB/M p5BSjXS4U3JgiW/vkd33EyqaOQaTk5I4OzbRiNtajIf6EaNFyLAVXFj6wgC8nbvc0kXCnd Pyc0+N8FWoQj9hqf4qUDcV4sketLqeQ= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Yosry Ahmed To: Shakeel Butt Cc: Tejun Heo , Andrew Morton , Alexei Starovoitov , Johannes Weiner , Michal Hocko , Roman Gushchin , Muchun Song , Michal =?utf-8?Q?Koutn=C3=BD?= , Vlastimil Babka , Sebastian Andrzej Siewior , JP Kobryn , bpf@vger.kernel.org, linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Meta kernel team Subject: Re: [RFC PATCH 3/3] cgroup: make css_rstat_updated nmi safe Message-ID: References: <20250429061211.1295443-1-shakeel.butt@linux.dev> <20250429061211.1295443-4-shakeel.butt@linux.dev> <6u7ccequ5ye3e4iqblcdeqsigindo3xjpsvkdb6hyaw7cpjddc@u2ujv7ymlxc6> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6u7ccequ5ye3e4iqblcdeqsigindo3xjpsvkdb6hyaw7cpjddc@u2ujv7ymlxc6> X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 4C58A4000B X-Rspam-User: X-Stat-Signature: mohao3fuqfex3edyxizhdjhqqguxom7z X-HE-Tag: 1746524471-523602 X-HE-Meta: U2FsdGVkX18VI1mPU6gieVTbfuABOpgziI541cEadPjVH0fgbKL7PkCpMhhVbv1Cy2BsBY3niaWd8FjM3IgP4J0nPu7wWmzjO4W9A5khvt1+t++1ocBeZTQ32RsPGAkX/5WhxJ661LBVv4BLv64VMoRrRp3y+jJ4sT2JkrkxFrrtMhFkYF/5iOCWyMQnh6SCbM4sonaYwXjIIPYgw7l2oml8b9FlRo3B57FhyxQZRGfKoy4tgiMrZT1Ea4BLrOw99inxzi8s1Hv+SCZjRm6J2zzxtUWpkiKjhY1IadbXsfCin0PLg5987WJz4Y2vX89wNDPXWmJCbRb+QvpxJ9dcQOxSE9WARy6idonpvIOG0kno4NeUK8nfkSO7uhfVEqFM3BYDRd4Q5x66QD2sJjPhMWjn1mVLQJ4njVCpADDdw3aICoQxB/NlJOsn6wWAiEHT7DYTVvZmtw0lgAjUFTUFB6TAwNaTaBIDOK4EESjDDQVqy+SMsvDr2V2za6VEWL0g5JIi+RtOhrsnkK8djzPqjYagNvhtyWRz3LpQhkVD5Ys5L/hugWdq4EpNH68YKiNoJy8yqKXmm0BEvXwK8n46dR16CEeRcXTy9nb+CZUDa0stGHHbAN6FiygTz6GuRtvTyyDpkbIZzsjamFOwPxzffZM0gFCdCCR3pTu0Kfl7Eyjv6GgJRwRfFl6COlaNR4Ro2OG/w7jdOsKGE1a7DvqL6K1aVNun8ywXvYdYgnM6EWdiiAfam8UzYK3fzV/KfefwYhLpYyeHpo4fuSQHoZM7OJzBRZqGm5TTlOgOTu0gkNURQ7Y+h24k6+NCeWFW3ESNYACwQP7xqFNzgjD4darrE+6ta/T2G3dlcXfj2s5I652yhXQNZetmEVlSb8ABnAJJs4Ah25A8QZH6GryyndWbEpjryiM7OnobuMfkDgG8cfGSVrnOR8IHeSv/AOYecUDV/lbCG63fEjYJ+WEYFPA sr5tTxaA qhKZoEzSaraRollCxoaaL0FxVc30xsn4iryIxExmp4wENlfzl0mrnm/po4RRTxa4bnWnOzCZM/BBPKgn3aamHrfpnfNt1M1Y0sfCtE8oqcUgx7lH5sY2qYgxfG9HJSpgwfWEn/5UdjoeBK/ZXTAzeFGGTxWSBN8SAocmDbui5Tgd49qT2avLxlE6/oOVumW4yTjF44WacYipbYBuTpeE1aSUxDYLr9PJegRn91fXvI99pHWbaqNme/dBqSFcBWfltE9Ti00oNSEghcRU= 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 Thu, May 01, 2025 at 03:10:20PM -0700, Shakeel Butt wrote: > On Wed, Apr 30, 2025 at 06:14:28AM -0700, Yosry Ahmed wrote: > [...] > > > + > > > + if (!_css_rstat_cpu_trylock(css, cpu, &flags)) { > > > > > > IIUC this trylock will only fail if a BPF program runs in NMI context > > and tries to update cgroup stats, interrupting a context that is already > > holding the lock (i.e. updating or flushing stats). > > > > Correct (though note that flushing side can be on a different CPU). > > > How often does this happen in practice tho? Is it worth the complexity? > > This is about correctness, so even a chance of occurance need the > solution. Right, my question was more about the need to special case NMIs, see below. > > > > > I wonder if it's better if we make css_rstat_updated() inherently > > lockless instead. > > > > What if css_rstat_updated() always just adds to a lockless tree, > > Here I assume you meant lockless list instead of tree. Yeah, in a sense. I meant using lockless lists to implement the rstat tree instead of normal linked lists. > > > and we > > defer constructing the proper tree to the flushing side? This should > > make updates generally faster and avoids locking or disabling interrupts > > in the fast path. We essentially push more work to the flushing side. > > > > We may be able to consolidate some of the code too if all the logic > > manipulating the tree is on the flushing side. > > > > WDYT? Am I missing something here? > > > > Yes this can be done but I don't think we need to tie that to current > series. I think we can start with lockless in the nmi context and then > iteratively make css_rstat_updated() lockless for all contexts. My question is basically whether it would be simpler to actually make it all lockless than special casing NMIs. With this patch we have two different paths and a deferred list that we process at a later point. I think it may be simpler if we just make it all lockless to begin with. Then we would have a single path and no special deferred processing. WDYT?