From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1557337DAC0 for ; Mon, 29 Jun 2026 18:20:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782757216; cv=none; b=qu7cdrXqzBbynJd5yKqKFnguca4ksTB3gg+7rbt//ppMkfrUvZQDU6SAqQ7a6YhlgOFEyfk3B4vQ9KQpcLZ1GKkP3EGeg5Kw+2HRwDJFY8H624lu1zayFVGvlGdsPUDY8D4eCX0ReA0qquiLZRi4cd7U2cnPEk4Jh29lp8Y818k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782757216; c=relaxed/simple; bh=3zaO3hDc+I0XBm27RWpBQ2PFnFdwu+N3yEscuAeSC4A=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=K+zwdqzLfPhyE4HFri8OEcohUMyYgf+XtoKQf6Md7127w6tvlO448Ep3pdWd/OwOYHRP8GqG9gTAkSyLRtRizfI0NOMylAlzA8h/zPjJaAvw17Gp7JkJ8ND2RYrCcAdonNqZcCGFP3D6AD53fKlxfRCwoiT5OXK1Ih4OMaj8BEk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=VBx6Go9V; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=h4tlWpoq; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=U9PHprco; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=Tb4wgHhX; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="VBx6Go9V"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="h4tlWpoq"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="U9PHprco"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="Tb4wgHhX" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id A759C758B1; Mon, 29 Jun 2026 18:20:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1782757211; h=from:from:reply-to: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=52IgFMOwkd7eriRsZwUPQpeZD1+MN1y/keLJNnBYVKw=; b=VBx6Go9V4Z/2WdxoGsIajBgRyxGs51T2zdrn5kyeSY5D0lOoCvb4NQ/9p10HX0WDBcZUWA 2U+RL9jpLs+WNgXV5v7nJneQeFFViOAB+4XLhlxflnOQwgv8Iv7QIUptrnabC/GHjkUXtu AchlE6MveWFQaV67x5iuJtqFrCZnSv0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1782757211; h=from:from:reply-to: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=52IgFMOwkd7eriRsZwUPQpeZD1+MN1y/keLJNnBYVKw=; b=h4tlWpoqlaXYVfDSY/fzkzUFqLQ+rrMqs/isZ2iw4IMP7lEEVBV6kzORggOQwSRzXvvfvp 6Gy3GKVLHMjLVkDg== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1782757209; h=from:from:reply-to: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=52IgFMOwkd7eriRsZwUPQpeZD1+MN1y/keLJNnBYVKw=; b=U9PHprcoWiVDaHulvM/v56i2Hwpo+KEo4FNn1ptTMPBl5hGeeh3hUp5hUhsTcr3uE+EyPA q5moh5oZZFpigbqa8Vql5deANlGwuTrFlEukiGo5Mqawe18eVGo5Y9mAo1eOx1XakB4LUH n/okYa5mutt2kSH4pyJaDXMOAoZsquU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1782757209; h=from:from:reply-to: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=52IgFMOwkd7eriRsZwUPQpeZD1+MN1y/keLJNnBYVKw=; b=Tb4wgHhXz5ILT5wwi16vtUCYlEoySq02kFyYurCi8zZhDaVdIplCnIbFvdsDlvdRzB5TuA +q6vqj6Cse9mlODA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 4F0CF779A8; Mon, 29 Jun 2026 18:20:08 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id q42DD1i3QmqFbQAAD6G6ig (envelope-from ); Mon, 29 Jun 2026 18:20:08 +0000 Date: Mon, 29 Jun 2026 19:20:06 +0100 From: Pedro Falcato To: Lorenzo Stoakes Cc: Andrew Morton , "David Hildenbrand (Arm)" , Xuewen Wang , liam@infradead.org, vbabka@kernel.org, jannh@google.com, chrisl@kernel.org, kasong@tencent.com, shikemeng@huaweicloud.com, nphamcs@gmail.com, baoquan.he@linux.dev, baohua@kernel.org, youngjun.park@lge.com, qi.zheng@linux.dev, shakeel.butt@linux.dev, axelrasmussen@google.com, yuanchu@google.com, weixugc@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3] mm: annotate data-race in cpu_needs_drain() Message-ID: References: <20260626053700.2036899-1-wangxuewen@kylinos.cn> <04ea3e05-5b83-4c2d-8759-67c544a7b484@kernel.org> <20260629093402.a4d14d4f95ccde7d4c804115@linux-foundation.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Flag: NO X-Spamd-Result: default: False [-4.30 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-0.999]; MIME_GOOD(-0.10)[text/plain]; ARC_NA(0.00)[]; RCPT_COUNT_TWELVE(0.00)[21]; MIME_TRACE(0.00)[0:+]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FUZZY_RATELIMITED(0.00)[rspamd.com]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; RCVD_TLS_ALL(0.00)[]; TO_DN_SOME(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; FREEMAIL_CC(0.00)[linux-foundation.org,kernel.org,kylinos.cn,infradead.org,google.com,tencent.com,huaweicloud.com,gmail.com,linux.dev,lge.com,kvack.org,vger.kernel.org]; RCVD_COUNT_TWO(0.00)[2]; MISSING_XM_UA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[pedro-suse.lan:mid,imap1.dmz-prg2.suse.org:helo] X-Spam-Level: X-Spam-Score: -4.30 On Mon, Jun 29, 2026 at 05:45:22PM +0100, Lorenzo Stoakes wrote: > On Mon, Jun 29, 2026 at 09:34:02AM -0700, Andrew Morton wrote: > > On Mon, 29 Jun 2026 11:23:26 +0100 Lorenzo Stoakes wrote: > > > > > > > folio_batch_count(&fbatches->lru_lazyfree) || > > > > > folio_batch_count(&fbatches->lru_activate) || > > > > > - need_mlock_drain(cpu) || > > > > > + need_mlock_drain(cpu)) || > > > > > > > > The indentation is a bit suboptimal now. > > > > > > > > Would read nicer as > > > > > > > > diff --git a/mm/swap.c b/mm/swap.c > > > > index 588f50d8f1a8c..5958e6fdd3593 100644 > > > > --- a/mm/swap.c > > > > +++ b/mm/swap.c > > > > @@ -828,13 +828,13 @@ static bool cpu_needs_drain(unsigned int cpu) > > > > struct cpu_fbatches *fbatches = &per_cpu(cpu_fbatches, cpu); > > > > > > > > /* Check these in order of likelihood that they're not zero */ > > > > - return folio_batch_count(&fbatches->lru_add) || > > > > - folio_batch_count(&fbatches->lru_move_tail) || > > > > - folio_batch_count(&fbatches->lru_deactivate_file) || > > > > - folio_batch_count(&fbatches->lru_deactivate) || > > > > - folio_batch_count(&fbatches->lru_lazyfree) || > > > > - folio_batch_count(&fbatches->lru_activate) || > > > > - need_mlock_drain(cpu) || > > > > + return data_race(folio_batch_count(&fbatches->lru_add) || > > > > + folio_batch_count(&fbatches->lru_move_tail) || > > > > + folio_batch_count(&fbatches->lru_deactivate_file) || > > > > + folio_batch_count(&fbatches->lru_deactivate) || > > > > + folio_batch_count(&fbatches->lru_lazyfree) || > > > > + folio_batch_count(&fbatches->lru_activate) || > > > > + need_mlock_drain(cpu)) || > > > > has_bh_in_lru(cpu, NULL); > > > > > > Yeah that works for me. > > > > > > Andrew - maybe easier if you fix that up? :) > > > > > > > Sure. > > > > --- a/mm/swap.c~mm-annotate-data-race-in-cpu_needs_drain-fix > > +++ a/mm/swap.c > > @@ -832,12 +832,12 @@ static bool cpu_needs_drain(unsigned int > > > > /* Check these in order of likelihood that they're not zero */ > > return data_race(folio_batch_count(&fbatches->lru_add) || > > - folio_batch_count(&fbatches->lru_move_tail) || > > - folio_batch_count(&fbatches->lru_deactivate_file) || > > - folio_batch_count(&fbatches->lru_deactivate) || > > - folio_batch_count(&fbatches->lru_lazyfree) || > > - folio_batch_count(&fbatches->lru_activate) || > > - need_mlock_drain(cpu)) || > > + folio_batch_count(&fbatches->lru_move_tail) || > > + folio_batch_count(&fbatches->lru_deactivate_file) || > > + folio_batch_count(&fbatches->lru_deactivate) || > > + folio_batch_count(&fbatches->lru_lazyfree) || > > + folio_batch_count(&fbatches->lru_activate) || > > + need_mlock_drain(cpu)) || > > has_bh_in_lru(cpu, NULL); > > } > > > > > > The removal of data_race() in need_mlock_drain() is a little worrisome > > - perhaps any future callers would have needed it? > > > > need_mlock_drain() has only a single caller. How about I remove it and > > open-code it within cpu_needs_drain()? > > That references a static per-CPU variable (mlock_fbatch) in mlock.c's > compilation unit so I think it has to stay as it us unfortunately. > > And it's better I think to only use the data_race() here where we definitely > know we need it (and as the only instance of that). I agree. FWIW something that would perhaps be nice to pull off would be: lockdep_assert_held_or_data_race(), or something with a less excrutiating name. Which could assert "either we hold a lock, or the caller is aware that this can race". Which sounds nice. In that case, we could simply slap that on need_mlock_drain() as requiring the mlock_fbatch's local lock, or data_race(). It night be too special purpose though. -- Pedro