FAILED: patch "[PATCH] mm/memcg: migrate per-node hugetlb lruvec stat together with hugetlb folio" failed to apply to 6.18-stable tree
Subsystems (4)
Sasha Levin
maintainerThe patch below does not apply to the 6.18-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.18.y
git checkout FETCH_HEAD
git cherry-pick -x 02e0c8cc2815f0082b5b5aabafe3b46688082adc
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 6.18.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From 02e0c8cc2815f0082b5b5aabafe3b46688082adc Mon Sep 17 00:00:00 2001
From: Hongfu Li <[email protected]>
Date: Wed, 23 Sep 2026 10:05:16 +0800
Subject: [PATCH] mm/memcg: migrate per-node hugetlb lruvec stat together with
hugetlb folio
memory.numa_stat exposes per-node hugetlb counters from per-node lruvec stats. These stats are accounted against folio_nid(): incremented on the folio's node when handed to a user, decremented when the folio is returned to the pool.
During hugetlb folio migration, mem_cgroup_migrate() moves the charge to the new folio and drops the memcg data of the old one, so the free of the old folio right after the migration skips the memcg per-node lruvec decrement. The hugetlb count stays attributed to the old node for the rest of the life of the charge, while the target folio gets no increment on the new node; its later free decrements a counter that was never incremented.
Migrate the per-node lruvec accounting alongside migration. Global memcg totals remain balanced because they track resource consumption, not node placement.
--- include/linux/memcontrol.h | 8 ++++++++ mm/hugetlb.c | 25 +++++++++++++++++++++++++ mm/memcontrol.c | 5 ++--- 3 files changed, 35 insertions(+), 3 deletions(-)
include/linux/memcontrol.h +8 -0
@@ -983,6 +983,9 @@ unsigned long lruvec_page_state_monotonic(const struct lruvec *lruvec,unsigned long lruvec_page_state_local (const struct lruvec *lruvec,enum node_stat_item idx); +void mod_memcg_lruvec_state (struct lruvec *lruvec, +enum node_stat_item idx,int val); +void mem_cgroup_flush_stats (struct mem_cgroup *memcg);void mem_cgroup_flush_stats_ratelimited (struct mem_cgroup *memcg);
@@ -1451,6 +1454,11 @@ static inline unsigned long lruvec_page_state_local(const struct lruvec *lruvec,return node_page_state (lruvec_pgdat (lruvec), idx); } +static inline void mod_memcg_lruvec_state (struct lruvec *lruvec, +enum node_stat_item idx,int val) +{ +} +static inline void mem_cgroup_flush_stats (struct mem_cgroup *memcg) { }
mm/hugetlb.c +25 -0
@@ -23,6 +23,7 @@#include <linux/mmdebug.h> #include <linux/sched/signal.h> #include <linux/rmap.h> +#include <linux/rcupdate.h> #include <linux/string_choices.h> #include <linux/string_helpers.h> #include <linux/swap.h>
@@ -7396,12 +7397,36 @@ void folio_putback_hugetlb(struct folio *folio)folio_put (folio); } +static void move_hugetlb_lruvec_stat (struct folio *old_folio, +struct folio *new_folio) +{ +struct mem_cgroup *memcg; +long nr_pages =folio_nr_pages (old_folio); +int old_nid =folio_nid (old_folio); +int new_nid =folio_nid (new_folio); + +if (old_nid == new_nid) +return ; + +guard (rcu)(); + + memcg =folio_memcg (new_folio); +if (!memcg) +return ; + +mod_memcg_lruvec_state (mem_cgroup_lruvec (memcg,NODE_DATA (old_nid)), +NR_HUGETLB , -nr_pages); +mod_memcg_lruvec_state (mem_cgroup_lruvec (memcg,NODE_DATA (new_nid)), +NR_HUGETLB , nr_pages); +} +void move_hugetlb_state (struct folio *old_folio,struct folio *new_folio,enum migrate_reason reason) {struct hstate *h =folio_hstate (old_folio);hugetlb_cgroup_migrate (old_folio, new_folio); +move_hugetlb_lruvec_stat (old_folio, new_folio);folio_set_owner_migrate_reason (new_folio, reason);/*
mm/memcontrol.c +2 -3
@@ -1015,9 +1015,8 @@ static void __mod_memcg_lruvec_state(struct mem_cgroup_per_node *pn,put_cpu (); } -static void mod_memcg_lruvec_state (struct lruvec *lruvec, -enum node_stat_item idx, -int val) +void mod_memcg_lruvec_state (struct lruvec *lruvec, +enum node_stat_item idx,int val) {struct pglist_data *pgdat =lruvec_pgdat (lruvec);struct mem_cgroup_per_node *pn;
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 1/3 mm: memcontrol: refactor mod_memcg_state() and mod_memcg_lruvec_state()
From: Qi Zheng <[email protected]>
[ Upstream commit 5371e350fda70bbdbee364215ca37b7fea25047b ]
Refactor the memcg_reparent_objcgs() to facilitate subsequent reparenting non-hierarchical stats.
Stable-dep-of: 02e0c8cc2815 ("mm/memcg: migrate per-node hugetlb lruvec stat together with hugetlb folio")
--- mm/memcontrol.c | 50 ++++++++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 19 deletions(-)
mm/memcontrol.c +31 -19
@@ -678,21 +678,12 @@ static int memcg_state_val_in_pages(int idx, int val)return max (val * unit /PAGE_SIZE ,1UL ); } -/** -* mod_memcg_state - update cgroup memory statistics -* @memcg: the memory cgroup -* @idx: the stat item - can be enum memcg_stat_item or enum node_stat_item -* @val: delta to add to the counter, can be negative -*/ -void mod_memcg_state (struct mem_cgroup *memcg,enum memcg_stat_item idx, -int val) +static void __mod_memcg_state (struct mem_cgroup *memcg, +enum memcg_stat_item idx,int val) {int i =memcg_stats_index (idx);int cpu; -if (mem_cgroup_disabled ()) -return ; -if (WARN_ONCE (BAD_STAT_IDX (i),"%s: missing stat item %d\n" , __func__, idx))return ;
@@ -706,6 +697,21 @@ void mod_memcg_state(struct mem_cgroup *memcg, enum memcg_stat_item idx,put_cpu (); } +/** +* mod_memcg_state - update cgroup memory statistics +* @memcg: the memory cgroup +* @idx: the stat item - can be enum memcg_stat_item or enum node_stat_item +* @val: delta to add to the counter, can be negative +*/ +void mod_memcg_state (struct mem_cgroup *memcg,enum memcg_stat_item idx, +int val) +{ +if (mem_cgroup_disabled ()) +return ; + +__mod_memcg_state (memcg, idx, val); +} +#ifdef CONFIG_MEMCG_V1 /* idx can be of type enum memcg_stat_item or node_stat_item. */ unsigned long memcg_page_state_local (struct mem_cgroup *memcg,int idx)
@@ -725,21 +731,16 @@ unsigned long memcg_page_state_local(struct mem_cgroup *memcg, int idx) }#endif -static void mod_memcg_lruvec_state (struct lruvec *lruvec, -enum node_stat_item idx, -int val) +static void __mod_memcg_lruvec_state (struct mem_cgroup_per_node *pn, +enum node_stat_item idx,int val) { -struct mem_cgroup_per_node *pn; -struct mem_cgroup *memcg; +struct mem_cgroup *memcg = pn->memcg;int i =memcg_stats_index (idx);int cpu;if (WARN_ONCE (BAD_STAT_IDX (i),"%s: missing stat item %d\n" , __func__, idx))return ; - pn = container_of(lruvec, struct mem_cgroup_per_node, lruvec); - memcg = pn->memcg; - cpu =get_cpu ();/* Update memcg */
@@ -755,6 +756,17 @@ static void mod_memcg_lruvec_state(struct lruvec *lruvec,put_cpu (); } +static void mod_memcg_lruvec_state (struct lruvec *lruvec, +enum node_stat_item idx, +int val) +{ +struct mem_cgroup_per_node *pn; + + pn = container_of(lruvec, struct mem_cgroup_per_node, lruvec); + +__mod_memcg_lruvec_state (pn, idx, val); +} +/** * __mod_lruvec_state - update lruvec memory statistics * @lruvec: the lruvec
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/3 mm: use enum migrate_reason instead of int for migration reason parameters
From: Ye Liu <[email protected]>
[ Upstream commit c95dc0a84b4c84103bd688a93b28d84e8b752568 ]
Replace all 'int reason' function parameters that carry migrate_reason values with the proper 'enum migrate_reason' type. This makes the intent explicit and leverages compiler type checking. The affected subsystems are:
- page_owner: __folio_set_owner_migrate_reason(), folio_set_owner_migrate_reason()
- migrate: migrate_pages(), migrate_pages_sync(), migrate_pages_batch(), migrate_folios_move(), migrate_hugetlbs(), unmap_and_move_huge_page()
- hugetlb: move_hugetlb_state(), htlb_allow_alloc_fallback()
- trace: mm_migrate_pages and mm_migrate_pages_start events
The 'short last_migrate_reason' struct field and internal helper parameter in page_owner are intentionally left as 'short' since they store per-page metadata where size matters.
No functional change.
Stable-dep-of: 02e0c8cc2815 ("mm/memcg: migrate per-node hugetlb lruvec stat together with hugetlb folio")
--- include/linux/hugetlb.h | 9 +++++---- include/linux/migrate.h | 8 +++++--- include/linux/page_owner.h | 7 ++++--- include/trace/events/migrate.h | 8 ++++---- mm/hugetlb.c | 3 ++- mm/migrate.c | 12 ++++++------ mm/page_owner.c | 2 +- 7 files changed, 27 insertions(+), 22 deletions(-)
include/linux/hugetlb.h +5 -4
@@ -156,7 +156,8 @@ long hugetlb_unreserve_pages(struct inode *inode, long start, long end,bool folio_isolate_hugetlb (struct folio *folio,struct list_head *list);int get_hwpoison_hugetlb_folio (struct folio *folio,bool *hugetlb,bool unpoison);void folio_putback_hugetlb (struct folio *folio); -void move_hugetlb_state (struct folio *old_folio,struct folio *new_folio,int reason); +void move_hugetlb_state (struct folio *old_folio,struct folio *new_folio, +enum migrate_reason reason);void hugetlb_fix_reserve_counts (struct inode *inode);extern struct mutex *hugetlb_fault_mutex_table;u32 hugetlb_fault_mutex_hash (struct address_space *mapping,pgoff_t idx);
@@ -425,7 +426,7 @@ static inline void folio_putback_hugetlb(struct folio *folio) }static inline void move_hugetlb_state (struct folio *old_folio, -struct folio *new_folio,int reason) +struct folio *new_folio,enum migrate_reason reason) { }
@@ -960,7 +961,7 @@ static inline gfp_t htlb_modify_alloc_mask(struct hstate *h, gfp_t gfp_mask)return modified_mask; } -static inline bool htlb_allow_alloc_fallback (int reason) +static inline bool htlb_allow_alloc_fallback (enum migrate_reason reason) {bool allowed_fallback = false;
@@ -1252,7 +1253,7 @@ static inline gfp_t htlb_modify_alloc_mask(struct hstate *h, gfp_t gfp_mask)return 0 ; } -static inline bool htlb_allow_alloc_fallback (int reason) +static inline bool htlb_allow_alloc_fallback (enum migrate_reason reason) {return false; }
include/linux/migrate.h +5 -3
@@ -57,8 +57,9 @@ void putback_movable_pages(struct list_head *l);int migrate_folio (struct address_space *mapping,struct folio *dst,struct folio *src,enum migrate_mode mode);int migrate_pages (struct list_head *l,new_folio_t new,free_folio_t free, -unsigned long private,enum migrate_mode mode,int reason, -unsigned int *ret_succeeded); +unsigned long private,enum migrate_mode mode, +enum migrate_reason reason, +unsigned int *ret_succeeded);struct folio *alloc_migration_target (struct folio *src,unsigned long private);bool isolate_movable_ops_page (struct page *page,isolate_mode_t mode);bool isolate_folio_to_list (struct folio *folio,struct list_head *list);
@@ -77,7 +78,8 @@ int set_movable_ops(const struct movable_operations *ops, enum pagetype type);static inline void putback_movable_pages (struct list_head *l) {}static inline int migrate_pages (struct list_head *l,new_folio_t new,free_folio_t free,unsigned long private, -enum migrate_mode mode,int reason,unsigned int *ret_succeeded) +enum migrate_mode mode,enum migrate_reason reason, +unsigned int *ret_succeeded) {return -ENOSYS ; }static inline struct folio *alloc_migration_target (struct folio *src,unsigned long private)
include/linux/page_owner.h +4 -3
@@ -3,6 +3,7 @@#define __LINUX_PAGE_OWNER_H#include <linux/jump_label.h> +#include <linux/migrate_mode.h> #ifdef CONFIG_PAGE_OWNER extern struct static_key_false page_owner_inited;
@@ -14,7 +15,7 @@ extern void __set_page_owner(struct page *page,extern void __split_page_owner (struct page *page,int old_order,int new_order);extern void __folio_copy_owner (struct folio *newfolio,struct folio *old); -extern void __folio_set_owner_migrate_reason (struct folio *folio,int reason); +void __folio_set_owner_migrate_reason (struct folio *folio,enum migrate_reason reason);extern void __dump_page_owner (const struct page *page);extern void pagetypeinfo_showmixedcount_print (struct seq_file *m,pg_data_t *pgdat,struct zone *zone);
@@ -43,7 +44,7 @@ static inline void folio_copy_owner(struct folio *newfolio, struct folio *old)if (static_branch_unlikely (&page_owner_inited))__folio_copy_owner (newfolio, old); } -static inline void folio_set_owner_migrate_reason (struct folio *folio,int reason) +static inline void folio_set_owner_migrate_reason (struct folio *folio,enum migrate_reason reason) {if (static_branch_unlikely (&page_owner_inited))__folio_set_owner_migrate_reason (folio, reason);
@@ -68,7 +69,7 @@ static inline void split_page_owner(struct page *page, int old_order,static inline void folio_copy_owner (struct folio *newfolio,struct folio *folio) { } -static inline void folio_set_owner_migrate_reason (struct folio *folio,int reason) +static inline void folio_set_owner_migrate_reason (struct folio *folio,enum migrate_reason reason) { }static inline void dump_page_owner (const struct page *page)
include/trace/events/migrate.h +4 -4
@@ -51,7 +51,7 @@ TRACE_EVENT(mm_migrate_pages, TP_PROTO(unsigned long succeeded, unsigned long failed, unsigned long thp_succeeded, unsigned long thp_failed, unsigned long thp_split, unsigned long large_folio_split, - enum migrate_mode mode, int reason), + enum migrate_mode mode, enum migrate_reason reason),TP_ARGS (succeeded, failed, thp_succeeded, thp_failed, thp_split, large_folio_split, mode, reason),
@@ -64,7 +64,7 @@ TRACE_EVENT(mm_migrate_pages, __field( unsigned long, thp_split) __field( unsigned long, large_folio_split) __field( enum migrate_mode, mode) - __field( int, reason) + __field( enum migrate_reason, reason) ), TP_fast_assign(
@@ -91,13 +91,13 @@ TRACE_EVENT(mm_migrate_pages, TRACE_EVENT(mm_migrate_pages_start, - TP_PROTO(enum migrate_mode mode, int reason), + TP_PROTO(enum migrate_mode mode, enum migrate_reason reason), TP_ARGS(mode, reason), TP_STRUCT__entry( __field(enum migrate_mode, mode) - __field(int, reason) + __field(enum migrate_reason, reason) ), TP_fast_assign(
mm/hugetlb.c +2 -1
@@ -7957,7 +7957,8 @@ void folio_putback_hugetlb(struct folio *folio)folio_put (folio); } -void move_hugetlb_state (struct folio *old_folio,struct folio *new_folio,int reason) +void move_hugetlb_state (struct folio *old_folio,struct folio *new_folio, +enum migrate_reason reason) {struct hstate *h =folio_hstate (old_folio);
mm/migrate.c +6 -6
@@ -1465,7 +1465,7 @@ static int migrate_folio_move(free_folio_t put_new_folio, unsigned long private,static int unmap_and_move_huge_page (new_folio_t get_new_folio,free_folio_t put_new_folio,unsigned long private,struct folio *src,int force,enum migrate_mode mode, -int reason,struct list_head *ret) +enum migrate_reason reason,struct list_head *ret) {struct folio *dst;int rc = -EAGAIN ;
@@ -1622,7 +1622,7 @@ struct migrate_pages_stats {*/ static int migrate_hugetlbs (struct list_head *from,new_folio_t get_new_folio,free_folio_t put_new_folio,unsigned long private, -enum migrate_mode mode,int reason, +enum migrate_mode mode,enum migrate_reason reason,struct migrate_pages_stats *stats,struct list_head *ret_folios) {
@@ -1712,7 +1712,7 @@ static int migrate_hugetlbs(struct list_head *from, new_folio_t get_new_folio, static void migrate_folios_move(struct list_head *src_folios, struct list_head *dst_folios, free_folio_t put_new_folio, unsigned long private, - enum migrate_mode mode, int reason, + enum migrate_mode mode, enum migrate_reason reason, struct list_head *ret_folios, struct migrate_pages_stats *stats, int *retry, int *thp_retry, int *nr_failed,
@@ -1795,7 +1795,7 @@ static void migrate_folios_undo(struct list_head *src_folios,*/ static int migrate_pages_batch (struct list_head *from,new_folio_t get_new_folio,free_folio_t put_new_folio, -unsigned long private,enum migrate_mode mode,int reason, +unsigned long private,enum migrate_mode mode,enum migrate_reason reason,struct list_head *ret_folios,struct list_head *split_folios,struct migrate_pages_stats *stats,int nr_pass) {
@@ -2007,7 +2007,7 @@ static int migrate_pages_batch(struct list_head *from,static int migrate_pages_sync (struct list_head *from,new_folio_t get_new_folio,free_folio_t put_new_folio,unsigned long private, -enum migrate_mode mode,int reason, +enum migrate_mode mode,enum migrate_reason reason,struct list_head *ret_folios,struct list_head *split_folios,struct migrate_pages_stats *stats) {
@@ -2084,7 +2084,7 @@ static int migrate_pages_sync(struct list_head *from, new_folio_t get_new_folio,*/ int migrate_pages (struct list_head *from,new_folio_t get_new_folio,free_folio_t put_new_folio,unsigned long private, -enum migrate_mode mode,int reason,unsigned int *ret_succeeded) +enum migrate_mode mode,enum migrate_reason reason,unsigned int *ret_succeeded) {int rc, rc_gather;int nr_pages;
mm/page_owner.c +1 -1
@@ -336,7 +336,7 @@ noinline void __set_page_owner(struct page *page, unsigned short order,inc_stack_record_count (handle, gfp_mask,1 << order); } -void __folio_set_owner_migrate_reason (struct folio *folio,int reason) +void __folio_set_owner_migrate_reason (struct folio *folio,enum migrate_reason reason) {struct page_ext *page_ext =page_ext_get (&folio->page);struct page_owner *page_owner;
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 3/3 mm/memcg: migrate per-node hugetlb lruvec stat together with hugetlb folio
In reply to Sasha LevinFrom: Hongfu Li <[email protected]>
[ Upstream commit 02e0c8cc2815f0082b5b5aabafe3b46688082adc ]
memory.numa_stat exposes per-node hugetlb counters from per-node lruvec stats. These stats are accounted against folio_nid(): incremented on the folio's node when handed to a user, decremented when the folio is returned to the pool.
During hugetlb folio migration, mem_cgroup_migrate() moves the charge to the new folio and drops the memcg data of the old one, so the free of the old folio right after the migration skips the memcg per-node lruvec decrement. The hugetlb count stays attributed to the old node for the rest of the life of the charge, while the target folio gets no increment on the new node; its later free decrements a counter that was never incremented.
Migrate the per-node lruvec accounting alongside migration. Global memcg totals remain balanced because they track resource consumption, not node placement.
--- include/linux/memcontrol.h | 8 ++++++++ mm/hugetlb.c | 25 +++++++++++++++++++++++++ mm/memcontrol.c | 5 ++--- 3 files changed, 35 insertions(+), 3 deletions(-)
include/linux/memcontrol.h +8 -0
@@ -953,6 +953,9 @@ unsigned long lruvec_page_state(struct lruvec *lruvec, enum node_stat_item idx);unsigned long lruvec_page_state_local (struct lruvec *lruvec,enum node_stat_item idx); +void mod_memcg_lruvec_state (struct lruvec *lruvec, +enum node_stat_item idx,int val); +void mem_cgroup_flush_stats (struct mem_cgroup *memcg);void mem_cgroup_flush_stats_ratelimited (struct mem_cgroup *memcg);
@@ -1422,6 +1425,11 @@ static inline unsigned long lruvec_page_state_local(struct lruvec *lruvec,return node_page_state (lruvec_pgdat (lruvec), idx); } +static inline void mod_memcg_lruvec_state (struct lruvec *lruvec, +enum node_stat_item idx,int val) +{ +} +static inline void mem_cgroup_flush_stats (struct mem_cgroup *memcg) { }
mm/hugetlb.c +25 -0
@@ -25,6 +25,7 @@#include <linux/mmdebug.h> #include <linux/sched/signal.h> #include <linux/rmap.h> +#include <linux/rcupdate.h> #include <linux/string_choices.h> #include <linux/string_helpers.h> #include <linux/swap.h>
@@ -7957,12 +7958,36 @@ void folio_putback_hugetlb(struct folio *folio)folio_put (folio); } +static void move_hugetlb_lruvec_stat (struct folio *old_folio, +struct folio *new_folio) +{ +struct mem_cgroup *memcg; +long nr_pages =folio_nr_pages (old_folio); +int old_nid =folio_nid (old_folio); +int new_nid =folio_nid (new_folio); + +if (old_nid == new_nid) +return ; + +guard (rcu)(); + + memcg =folio_memcg (new_folio); +if (!memcg) +return ; + +mod_memcg_lruvec_state (mem_cgroup_lruvec (memcg,NODE_DATA (old_nid)), +NR_HUGETLB , -nr_pages); +mod_memcg_lruvec_state (mem_cgroup_lruvec (memcg,NODE_DATA (new_nid)), +NR_HUGETLB , nr_pages); +} +void move_hugetlb_state (struct folio *old_folio,struct folio *new_folio,enum migrate_reason reason) {struct hstate *h =folio_hstate (old_folio);hugetlb_cgroup_migrate (old_folio, new_folio); +move_hugetlb_lruvec_stat (old_folio, new_folio);folio_set_owner_migrate_reason (new_folio, reason);/*
mm/memcontrol.c +2 -3
@@ -756,9 +756,8 @@ static void __mod_memcg_lruvec_state(struct mem_cgroup_per_node *pn,put_cpu (); } -static void mod_memcg_lruvec_state (struct lruvec *lruvec, -enum node_stat_item idx, -int val) +void mod_memcg_lruvec_state (struct lruvec *lruvec, +enum node_stat_item idx,int val) {struct mem_cgroup_per_node *pn;
Signature · 1 line
2.53.0