From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796337556; b=1J7YPMo1CO7VJlza8LCJ34Wsc9VKypWc48GqJ0d5pF1IPOzBLT7NqS5cqnsDDK4OJjFB wfCRmqNJSY6wxkwBIJN7cJocdFbZldrEnYvVh1Y6Ai1iylY9DvMarNcZTC0bUL9C6Ds5t Y6QtQlHb4q2lGMOsrvg7Yf+sb7nJ/Wwx2hUclEbz/DJ0zRXFXWHEszMcYCpgKCdClvG29 /DujHjd17N0M6i5zeF0InHExuFVYDBR61xZIxtEZWG5u2DFgjAPR73wUQCvwLW1GXiKUT 57qafVByOCXOdzkz7yltSAIiUDiXkTlyK9UcsUjPLzC1q/m2mq0WGBEjMSDFd7pxjQg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796337556; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=aQkDhEcCCHBrzfkFPOgwTBX66TQYhJMKweCH7yr+cxs=; b=cXb2SbsIY3QoCuGkS5sM8IF8cFmRhG3Y/zTv92Nl9adyrQotpltZ6hwoqkArQp33t6FC 5A91yZ5QHmpMKJKKGu5Y9Ah1S4AVpa4CFsy1XOPRX7s6anfhOppiP6tffsaJWgLqnWcGg WExGwnHrwTRgvBn9woR1Atq76VXH8VvUCXJX+GO1zhM56HkDi76L+gtgvxFO/drHb4rCq syBRSya9gxeBkSZBu/LbWx1qsgC+29thyd5VWVXvtH/IoIEHXS9gFZDvl0ntWFBVVp5AD yyFmmTse6hyBDIF0R0pk8Qakw4ZWYkZpzOQI1/89VtDJ1j/jkH+LLDqXoRArt7dIbsA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=cv1Hx1bW; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0BC16606A322 for ; Thu, 3 Dec 2026 22:39:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=cv1Hx1bW Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5F8991F000CE; Thu, 3 Dec 2026 22:39:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796337555; bh=aQkDhEcCCHBrzfkFPOgwTBX66TQYhJMKweCH7yr+cxs=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=cv1Hx1bWJn88OvCSKPzsFjg77MEd+eaFgA8G/QgeaSfpAxrHNOPEMSwDfOpRCb7n0 XbecIk4E255ty9KKvP5GYngyPNGNWoRPT0b/4ue9YaJP+q1fYr1GgHynJ516s//LAA nMwpD2d7SzmKF/CI+Zk+XcwW80bLY0SLDYETWsJltu8pKoNgSoe1WiwvWd/daXhNc8 XTMR9q4od8pH5NleGqujHC0kG/xYnmj/wRvpTCAYUXXZypyyJOPW6UF0jTVhQlnv0j CyngSvAtwYDJeYmJZcv3OjL31+bGTaIBXDKRjAMNJ+Wf0gBLOJSC8IC9tn1dmpNo6+ 2059J2EqBhRRw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v8 19/19] mm/mglru: make folio_inc_lru_refs lruvec lockless Reply-To: sashiko-reviews@lists.linux.dev To: "Kairui Song" , linux-mm@kvack.org Cc: "Andrew Morton" , "Johannes Weiner" , "Muchun Song" , "Qi Zheng" , "Ying Huang" , "Chris Li" , "Baoquan He" , "Nico Pache" , "Usama Arif" , "Michal Hocko" , "Roman Gushchin" , "Shakeel Butt" , "David Hildenbrand" , "Lorenzo Stoakes" , "Liam R. Howlett" , "Barry Song" , "Axel Rasmussen" , "Yuanchu Xie" , "Wei Xu" , "Vlastimil Babka" , "Suren Baghdasaryan" , "Nhat Pham" , "Youngjun Park" , "Zi Yan" , "Gregory Price" , =?utf-8?b?TWF0dGhldyBXaWxjb3ggKE9yYWNsZSk=?= , "Baolin Wang" , "Ryan Roberts" , "Dev Jain" , "Lance Yang" , "Hugh Dickins" , "SJ Park" , "David Rientjes" , "Yu Zhao" , "Vernon Yang" , "Zicheng Wang" , "Tal Zussman" , "Kairui Song" , "Xiang Liu" , "Ehab Ababneh" , "Zhao Zhengzhuo" , "Lian Wang" , "Joanne Koong" , "Kunwu Chan" , "Hui Zhu" , "Maxim Muzafarov" , "Tianyi Chen" , "Aveline Noir" , damon@lists.linux.dev, "Ridong Chen" , tj@kernel.org, mkoutny@suse.com In-Reply-To: <20261204-mglru-fg-v8-19-64f81c876c15@tencent.com> References: <20261204-mglru-fg-v8-0-64f81c876c15@tencent.com> <20261204-mglru-fg-v8-19-64f81c876c15@tencent.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 22:39:12 +0000 X-Mailing-List: damon@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] mm/mglru: unnecessary lruvec/RCU work on first read in folio_inc_lru_refs() -- commit 7de20732c529ae133ce4e3d556fee78af099121c Author: Kairui Song mm/mglru: make folio_inc_lru_refs lruvec lockless This commit drops lruvec->lru_lock from folio_inc_lru_refs(), using RCU via folio_lruvec_live_get()/folio_lruvec_live_put() and lockless LRU size updates, and retries with LRU_REF_FORCE if concurrent aging moves max_seq. > diff --git a/mm/vmscan.c b/mm/vmscan.c > index f30c80c738ca3..8d365f80f43ea 100644 > --- a/mm/vmscan.c > +++ b/mm/vmscan.c > @@ -876,38 +876,35 @@ void folio_inc_lru_refs(struct folio *folio, unsign= ed int flags) > long nr_pages =3D folio_nr_pages(folio); > struct lru_gen_folio *lrugen; > struct lruvec *lruvec =3D NULL; > + bool aged =3D false; > =20 > +retry: > old_flags =3D READ_ONCE(*folio_flags(folio, 0)); > do { > new_flags =3D old_flags; > old_gen =3D lru_get_gen_flags(old_flags); > old_refs =3D lru_get_refs_flags(old_flags); > - file =3D folio_flags_is_file_lru(&old_flags); > refs =3D old_refs + 1; > gen =3D old_gen; > + file =3D folio_flags_is_file_lru(&old_flags); > if (old_gen < 0) > goto out; > - /* > - * Lock the lruvec if the folio is on-list. We are already > - * doing lazy promotion so in theory we don't need this, > - * but for now, concurrent aging would still corrupt the > - * size counters. This is a temporary limitation and > - * will be lifted very soon, so the lock here is not a > - * performance concern. > - */ > if (!lruvec) { > lruvec =3D folio_lruvec_live_get(folio); > - spin_lock_irq(&lruvec->lru_lock); > lrugen =3D &lruvec->lrugen; > } > + /* > + * Read the flags before max_seq, paired with the store of a > + * gen, which samples max_seq first. > + */ > + smp_rmb(); > max_seq =3D READ_ONCE(lrugen->max_seq); [Severity: Medium] Can folio_inc_lru_refs() skip the lruvec lookup, smp_rmb(), and max_seq read when !flags && !old_refs? On every first-access streaming read, filemap_read() -> folio_mark_accessed() calls folio_inc_lru_refs(folio, 0) with old_refs =3D=3D 0. Since refs becomes 1, neither gen nor active/inactive accounting can change, regressing the old lru_gen_inc_refs() fast path. In the else-if branch below, lru_gen_is_old(lruvec, file, old_gen) is also evaluated before lru_refs_is_workingset(refs), forcing a READ_ONCE(lruvec->lrugen.min_seq[file]) load even when refs =3D=3D 1. Jumping to out when old_gen < 0 || (!flags && !old_refs) and checking lru_refs_is_workingset(refs) before lru_gen_is_old() avoids this hot-path overhead while remaining safe if try_cmpxchg() retries with a newer old_refs. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204-mglru-fg-v= 8-0-64f81c876c15@tencent.com?part=3D19