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=1796321614; b=yUqwakew+p4/Mr1YFTHsdf+PDo+e+eR0WcXbKqVpZzKUhodhtTzATTseBimqm9J0r4eT XpuS+JekLpYHBz8w/Jx6jS6FXbanRggLQM3F0tQD01pph7F4LXzfZkGDkBx8utHPm0eOG R966Ti84nZLfk0y4/FhH8duSzXL9IjI9cpQTfJyWAOQ28FmFoj4i0ecpOh6IhrbQ+8Q4M 8PnW61eAg/hFLZyUHXrvZAB3DV9acuyKlGNOqMkhDskZdXVsNadTI3lQ8tLydo+qchnJF Hh6Cr2Q0EFZDdG07+PYEbJX+snN035uxKpxuni2QO1wm7oTflNIfxDc+czoyRj2R6Dg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796321614; h=Received:DKIM-Signature:Date:To:From:In-Reply-To:References:Subject: Message-Id; bh=dnaAgUs9lMTGdEEWlD4Y9GL4vTjwp0kGY2mx50sujho=; b=eLO84a5N8h6Pg3WIbDRsbh/jbMvv/dRJ4kXtA6XZnyDZK1nzNXR93ekVBFfKD3o7cL3l SVCaGp5fP6IAvqNRFdlpXt/Y1gQ4TUzA435S4/1Vjkty6fcfODQ3Hsz3TTqjHMHFG3NeH 2nDfn5LULP/KIFwOl6pmmQ1gT5c1Mxlc3euaFCk0dIxPv2MGPhZFFgFNIqJyDVZucD20V jz8Gpl/o9kjqCChF+KEFWZdk1CAMvGUmm8A8V+nsCDS1d5OU/VIGHvacBCu4HOh6iu42w 0SlWQPaQ5Ridb6ietniLR0384avcooNC403apimQ/XfNpaPL/oY3CmD23L50GJwT1Kw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=HPuuvcvN; 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 6205A606A32C for ; Thu, 3 Dec 2026 18:13:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=HPuuvcvN Received: by smtp.kernel.org (Postfix) with ESMTPSA id DF1ED1F008A0; Thu, 3 Dec 2026 18:13:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1796321614; bh=dnaAgUs9lMTGdEEWlD4Y9GL4vTjwp0kGY2mx50sujho=; h=Date:To:From:In-Reply-To:References:Subject; b=HPuuvcvN1YV4SmqLjfgH0gvsdQf+U8tM135DAenI4iCZ+xer1xGk0VBbX/U6qE1Q4 PuM3eJo+pGaQFBUvXz7ue0rcXCKQs6QwkrtDWMjnWx68u0YNK4DHkUyWd0WPjE8ccD yNNkTr97GYVJkAFGdhL24WCnBh8oWSz2TLCVIdv4= Date: Thu, 03 Dec 2026 10:13:33 -0800 To: mm-commits@vger.kernel.org,kasong@tencent.com,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20261202-mglru-fg-v7-5-5965a96d86d0@tencent.com> References: <20261202-mglru-fg-v7-5-5965a96d86d0@tencent.com> Subject: [to-be-updated] mm-memcg-add-folio-based-lruvec-live-helper.patch removed from -mm tree Message-Id: <20261203181333.DF1ED1F008A0@smtp.kernel.org> X-Mailing-List: mm-commits@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list The quilt patch titled Subject: mm/memcg: add folio-based lruvec live helper has been removed from the -mm tree. Its filename was mm-memcg-add-folio-based-lruvec-live-helper.patch This patch was dropped because an updated version will be issued ------------------------------------------------------ From: Kairui Song Subject: mm/memcg: add folio-based lruvec live helper Date: Wed, 02 Dec 2026 04:18:45 +0800 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. 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. 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. No functional change for existing callers. Link: https://patch.msgid.link/20261202-mglru-fg-v7-5-5965a96d86d0@tencent.com Signed-off-by: Kairui Song Signed-off-by: Andrew Morton Tested-by: Zhao Zhengzhuo Reviewed-by: Kunwu Chan Tested-by: Andrew Morton Reviewed-by: Qi Zheng Reviewed-by: Muchun Song (ByteDance) Reviewed-by: Ridong Chen Cc: Johannes Weiner Cc: Ying Huang Cc: Christopher Li Cc: Baoquan He Cc: Nico Pache Cc: Usama Arif Cc: Michal Hocko Cc: Roman Gushchin Cc: Shakeel Butt Cc: David Hildenbrand Cc: Lorenzo Stoakes Cc: Liam R. Howlett Cc: Barry Song Cc: Axel Rasmussen Cc: Yuanchu Xie Cc: Wei Xu Cc: Vlastimil Babka Cc: Suren Baghdasaryan Cc: Nhat Pham Cc: Youngjun Park Cc: Zi Yan Cc: Gregory Price Cc: Matthew Wilcox (Oracle) Cc: Baolin Wang Cc: Ryan Roberts Cc: Dev Jain Cc: Lance Yang Cc: Hugh Dickins Cc: SJ Park Cc: David Rientjes Cc: Yu Zhao Cc: Vernon Yang Cc: wangzicheng Cc: Tal Zussman Cc: Kairui Song Cc: Xiang Liu Cc: Ehab Ababneh Cc: wang lian Cc: Joanne Koong Cc: Hui Zhu Cc: Maxim Muzafarov Cc: Tianyi Chen include/linux/memcontrol.h | 71 +++++++++++++++++++++++++++-------- 1 file changed, 56 insertions(+), 15 deletions(-) --- a/include/linux/memcontrol.h~mm-memcg-add-folio-based-lruvec-live-helper +++ a/include/linux/memcontrol.h @@ -573,6 +573,11 @@ static inline bool mem_cgroup_disabled(v return !cgroup_subsys_enabled(memory_cgrp_subsys); } +static inline bool memcg_is_dying(struct mem_cgroup *memcg) +{ + return memcg ? css_is_dying(&memcg->css) : false; +} + static inline void mem_cgroup_protection(const struct mem_cgroup *root, const struct mem_cgroup *memcg, unsigned long *min, @@ -1352,6 +1357,11 @@ static inline bool mem_cgroup_online(str return true; } +static inline bool memcg_is_dying(struct mem_cgroup *memcg) +{ + return false; +} + static inline unsigned long mem_cgroup_get_zone_lru_size(const struct lruvec *lruvec, enum lru_list lru, int zone_idx) @@ -1517,28 +1527,41 @@ static inline void lruvec_lock_irq(struc 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) { #ifdef CONFIG_MEMCG struct pglist_data *pgdat = lruvec_pgdat(lruvec); struct mem_cgroup *memcg = lruvec_memcg(lruvec); - rcu_read_lock(); - /* * The memcg can be NULL when the memory controller is disabled. * Otherwise, the caller keeps the memcg owning @lruvec alive. */ - while (unlikely(memcg && css_is_dying(&memcg->css))) { + while (unlikely(memcg_is_dying(memcg))) { memcg = parent_mem_cgroup(memcg); lruvec = mem_cgroup_lruvec(memcg, pgdat); } +#endif + return lruvec; +} +static inline struct lruvec *lruvec_live_lock_irq(struct lruvec *lruvec) +{ +#ifdef CONFIG_MEMCG + rcu_read_lock(); + lruvec = __lruvec_get_live(lruvec); spin_lock_irq(&lruvec->lru_lock); #else lruvec_lock_irq(lruvec); #endif - return lruvec; } @@ -1568,6 +1591,34 @@ static inline bool folio_matches_lruvec( lruvec_memcg(lruvec) == 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(const struct folio *folio) +{ +#ifdef CONFIG_MEMCG + rcu_read_lock(); + return __lruvec_get_live(folio_lruvec(folio)); +#else + return folio_lruvec(folio); +#endif +} + +static inline void folio_lruvec_live_put(const struct lruvec *lruvec) +{ +#ifdef CONFIG_MEMCG + rcu_read_unlock(); +#endif +} + /* Don't lock again iff page's lruvec locked */ static inline struct lruvec *folio_lruvec_relock_irq(const struct folio *folio, struct lruvec *locked_lruvec) @@ -1833,11 +1884,6 @@ void mem_cgroup_node_filter_allowed(stru void mem_cgroup_show_protected_memory(struct mem_cgroup *memcg); -static inline bool memcg_is_dying(struct mem_cgroup *memcg) -{ - return memcg ? css_is_dying(&memcg->css) : false; -} - #else static inline bool mem_cgroup_kmem_disabled(void) { @@ -1908,11 +1954,6 @@ static inline void mem_cgroup_node_filte static inline void mem_cgroup_show_protected_memory(struct mem_cgroup *memcg) { } - -static inline bool memcg_is_dying(struct mem_cgroup *memcg) -{ - return false; -} #endif /* CONFIG_MEMCG */ #if defined(CONFIG_MEMCG) && defined(CONFIG_LRU_GEN) _ Patches currently in -mm which might be from kasong@tencent.com are mm-mglru-report-evictable-sizes-per-type.patch mm-mglru-extract-lruvec_populated_min_seq-helper.patch mm-mglru-reclaim-from-the-oldest-populated-gen.patch mm-mglru-lift-the-forced-protection-of-reclaimer.patch mm-mglru-skip-zones-above-reclaim_idx-instead-of-rotating-them.patch mm-mglru-return-for-unavailable-anon-reclaim-earlier.patch mm-mglru-balance-anon-and-file-scan-budget-by-refault-rate.patch mm-mglru-lift-youngest-gen-protection-for-higher-priority.patch mm-mglru-frequency-guided-workingset-promotion-mglru-fg.patch mm-mglru-make-folio-lru-referenced-times-count-a-generic-api.patch mm-mglru-move-add-del-lru-size-accounting-out-of-lru_gen_update_size.patch mm-mglru-gup-mark-folios-referenced-via-a-fast-helper.patch mm-mglru-smaps-convert-to-lru-refs-based-operations-for-mglru.patch mm-damon-convert-to-lru-refs-based-operations-for-mglru.patch mm-khugepaged-convert-to-lru-refs-based-operations-for-mglru.patch mm-madvise-adapt-for-lru-refs-based-operations-for-mglru.patch mm-factor-out-folio_mark_accessed_vma.patch mm-huge_memory-mark-folio-as-accessed-more-accurately-on-split.patch mm-mglru-make-pg_workingset-helpers-work-based-on-folio-lru-refs.patch mm-mglru-folio-lru-refs-based-active-inactive-number-accounting.patch mm-mglru-make-folio_inc_lru_refs-lruvec-lockless.patch