From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795437164; b=gWHCL9Pi4rPMz+vc+ni2YcwBP4mqUzRxBe3vd2Xyl/Lgxw+aaAHeKmFlRgo3GhM4AKkw MIVyGTUMX3IcWUFGKlV0PyiWjUJAtdCTA8NcBLieyWOeukSBXzqghDkF/plwslpZiNI7A eaxVPNcyLBLnlhY/ycegSycvUu/awEypf5IFELam3Kimdhh8K17hehMmiAR6IeUnpcEke DRxVq/jTReRI/gs1IdUdoNqcIKySNhfE3/iwecnqNU/vzFNxwPwTBYJTgGUTa7qGKMsiZ Vu6fTqGkrD20DeJd9fZZ7K1JgmnHTmdF+fsxWZJCLkrfyV/LFrnpE/cVn1HA2VT32Iw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795437164; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:Content-Type:Mime-Version:Subject:From: In-Reply-To:Date:Cc:Content-Transfer-Encoding:Message-Id:References: To:X-Mailer; bh=e2RVQ3O8W1C8YW2wJ9aXaBh6gRelyzfxjUCFahQNfPU=; b=Ia7RJhOieWm1NyHqhw94JseUgszgl6fsdp7lIwxE1WAfhn2OIWEw5rha3FAEmzFTxH3t CPgQ+zK1w7grTCiAtEM+vYUbJeRz556y/12ayiW7isAMOVBZk7APIkXovQmGboOjfGYKT WB8TqqbMWSRXjXi2jbbKkd4BxKIdKAusJjiyF/nRRchpJJVsI5y0uzAoVGHEdA0OUoM/h F6gbKtjL1NgmHx79dSl7MuFnH1+RDoT917PJiv0BqFXCVeXIGe1o/w6MjOEKx+lrK5UBl OAVi5IF6bJ1ojHoKSXj74C9TYAb47kPjM9Nrx/S5R1kf1vbJrW9T+evqPJ62Jrv4kaA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=g6yK4vC5; arc=none smtp.remote-ip=91.218.175.124 Received: from mta0.migadu.com (out-124.mta0.migadu.com [91.218.175.124]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 97338606A321 for ; Mon, 23 Nov 2026 12:32:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 97338606A321 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=g6yK4vC5 X-Envelope-To: linux-doc@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=IaXfb5Hi/QpRbuwTQppmoutVL2pV2Zxy6b6NwmIDvTU=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1795437161; v=1; x=1796041961; b=g6yK4vC5n37WbsNdGMf0BkpnaNq+7uKBUXX15GD4SctWed5eePPBRCkJyQwRQZ4z/2o4XLKV YjmYuMufUFgSZOOqhTlUeP2HjKWGmRdRX2H20UrtpcOKL+huQpOCQUOCQ19bckPFv9Cpco69Ln0 n04OISklYq56LohQvRYFpXuk= X-Envelope-To: linux-doc@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 6fa58fd50eb09120; Mon, 23 Nov 2026 12:32:41 +0000 X-Mizu-Trace-ID: 6fa58fd50eb09120 X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset=us-ascii X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3901.200.71.1.16\)) Subject: Re: [PATCH v5 04/17] mm/memcg: add folio-based lruvec live helper From: Muchun Song In-Reply-To: Date: Mon, 23 Nov 2026 20:32:16 +0800 Cc: Muchun Song , kasong@tencent.com, Andrew Morton , Johannes Weiner , 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 , linux-mm@kvack.org, Nhat Pham , Youngjun Park , Zi Yan , Gregory Price , "Matthew Wilcox (Oracle)" , Baolin Wang , Ryan Roberts , Dev Jain , Lance Yang , Hugh Dickins , SJ Park , David Rientjes , Yu Zhao , Vernon Yang , Zicheng Wang , Chen Ridong , Tal Zussman , Xiang Liu , Ehab Ababneh , Zhao Zhenzhuo , Lian Wang , Joanne Koong , Kunwu Chan , Hui Zhu , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, damon@lists.linux.dev, linux-doc@vger.kernel.org Content-Transfer-Encoding: quoted-printable Message-Id: <71FD1E6D-6F79-42B7-AED8-FCFACAB541AB@linux.dev> References: <20261119-mglru-fg-v5-0-9eee2fe97a2d@tencent.com> <20261119-mglru-fg-v5-4-9eee2fe97a2d@tencent.com> <42207e26-ba7f-4df5-8c80-71fa1b84d26e@linux.dev> To: Kairui Song X-Mailer: Apple Mail (2.3901.200.71.1.16) > On Nov 23, 2026, at 01:03, Kairui Song wrote: >=20 > On Sun, Nov 22, 2026 at 03:53:44PM +0800, Muchun Song wrote: >>=20 >>=20 >> On 2026/11/19 05:03, Kairui Song via B4 Relay wrote: >>> From: Kairui Song >>>=20 >>> Add a helper that resolves a live lruvec for a folio under RCU >>> without taking the lruvec lock. It takes a folio directly so the >>> lruvec lookup happens inside the RCU read-side critical section, >>> which a lruvec-based interface cannot guarantee. The first user is >>> the lockless folio_inc_lru_refs() path later in the series. >>>=20 >>> Factor the ancestor walk out of lruvec_live_lock_irq() into >>> __lruvec_get_live(), so that both entry points share it, and spell >>> out why the walk is enough while only the RCU read lock is held: >>> reparenting of a memcg that starts dying waits for a grace period, >>> so it cannot race with the caller until the lock is released. >>>=20 >>> Move memcg_is_dying() up in memcontrol.h, next to the other memcg = state >>> predicates, and use it for the walk rather than repeating the open = coded >>> css_is_dying() test a few definitions away from where it is = explained. >>>=20 >>> No functional change for existing callers. >>>=20 >>> Tested-by: Zhao Zhenzhuo >>> Signed-off-by: Kairui Song >>=20 >> Reviewed-by: Muchun Song (ByteDance) >>=20 >> Some nits bellow: >>=20 >>> --- >>> include/linux/memcontrol.h | 71 = ++++++++++++++++++++++++++++++++++++---------- >>> 1 file changed, 56 insertions(+), 15 deletions(-) >>>=20 >>> diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h >>> index 980358bc6f49..441a5d57e723 100644 >>> --- a/include/linux/memcontrol.h >>> +++ b/include/linux/memcontrol.h >>> @@ -571,6 +571,11 @@ static inline bool mem_cgroup_disabled(void) >>> return !cgroup_subsys_enabled(memory_cgrp_subsys); >>> } >>> +static inline bool memcg_is_dying(struct mem_cgroup *memcg) >>=20 >> Let's make it const for @memcg along the way. >=20 > Good idea, but css_is_dying isn't constified, maybe we can do it later = I think. Fine. >=20 >>> @@ -1510,28 +1520,41 @@ static inline void lruvec_lock_irq(struct = lruvec *lruvec) >>> spin_lock_irq(&lruvec->lru_lock); >>> } >>> -static inline struct lruvec *lruvec_live_lock_irq(struct lruvec = *lruvec) >>> +/* >>> + * Reparenting moves a dying memcg's LRU state to its parent at any = time, >>> + * so anything added to that LRU afterwards would be lost. This = helper >>> + * walks up to the nearest live ancestor while the caller must hold = the >>> + * RCU read lock: reparenting of a memcg that starts dying waits = for a >>> + * grace period, so it cannot race with the caller until the lock = is >>> + * released. >>> + */ >>> +static inline struct lruvec *__lruvec_get_live(struct lruvec = *lruvec) >>=20 >> Cound @lruvec be const as well? >=20 > The argument is fine, but tricky for the return value: when nothing is = dying it > hands back @lruvec unchanged, so a const argument means a const return = (which > isn't right) or a cast dropping it again. A cast is not nice. Let's keep things as they are. Thanks, Muchun >=20 >>> @@ -1561,6 +1584,34 @@ static inline bool folio_matches_lruvec(const = struct folio *folio, >>> lruvec_memcg(lruvec) =3D=3D folio_memcg(folio); >>> } >>> +/** >>> + * folio_lruvec_live_get - get a live lruvec for a folio under RCU >>> + * @folio: the folio >>> + * >>> + * Same as folio_lruvec(), except that a folio whose memcg is dying = is >>> + * accounted to the nearest live ancestor, which is where = reparenting >>> + * would put it anyway. >>> + * >>> + * Return: the live lruvec, with rcu_read_lock() held. Pair it = with >>> + * folio_lruvec_live_put(). >>> + */ >>> +static inline struct lruvec *folio_lruvec_live_get(struct folio = *folio) >>=20 >> const folio? >=20 > This is doable, will do! >=20 > Thanks for the review!