From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B3CB23F6C2E for ; Mon, 29 Jun 2026 16:34:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782750847; cv=none; b=mZidaftzjs0ol2WUqBPkCFftz18t74LQKF1Vkm0YcskO/voWJX3j+XX/6IJuCE6gg6fuOrnHLP4SFuTQd4F9vWuqnvUx+bb4MRT7e9jZKTmyJDFxmn3MTcnzdILoRJWUcez1FoAAGBcMmGy/N8dCgOAsn21jWDCkJAa7aYpweMI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782750847; c=relaxed/simple; bh=cV9wW9sCDYz6rQPR3PV8CteDK10PhmM1VyDWj0+xseA=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=Lm7bGAT8RuLYdEvAg4osMoK0BLSvPikNNQwFyJgANUHAngIvlRF/PYlw4zKY3rgRVDI5DzDtwbQeJsVW65ulMeIoY72/HVN2RPftwcCCW3aYURbpH2givWAtOa9ma5uM9VuCbiglfC/IQujFKXd/FOkPBxa/NDVUz0pELBJClug= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=uvduFPxh; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="uvduFPxh" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2707B1F000E9; Mon, 29 Jun 2026 16:34:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1782750843; bh=rSWd/bQSzHe8Iq/VNf2zewGegErxrGJT7kEbZKW8vaI=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=uvduFPxhRWXqREkwtY9s5rbK583t9aI3KTKK72sfnejBDFsjlclavo/yjshPxsc5k 0N75X4+6j3brru09lXqRqSjYHLcp14T4OWRMQCYJiP/lly2FMCprasmsMTFfxHJ+rW RZjKL1P9SZ3/pj3Fdy+3c2rp8zt2x9OGJ0CItxDg= Date: Mon, 29 Jun 2026 09:34:02 -0700 From: Andrew Morton To: Lorenzo Stoakes Cc: "David Hildenbrand (Arm)" , Xuewen Wang , liam@infradead.org, vbabka@kernel.org, jannh@google.com, pfalcato@suse.de, 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: <20260629093402.a4d14d4f95ccde7d4c804115@linux-foundation.org> In-Reply-To: References: <20260626053700.2036899-1-wangxuewen@kylinos.cn> <04ea3e05-5b83-4c2d-8759-67c544a7b484@kernel.org> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) 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-Transfer-Encoding: 7bit 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()?