From nobody Tue Apr 7 22:03:12 2026 Received: from mslow3.mail.gandi.net (mslow3.mail.gandi.net [217.70.178.249]) (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 8CBC73D9025 for ; Wed, 11 Mar 2026 11:04:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.178.249 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773227076; cv=none; b=niV2tq0eh7i17axuC/Z/HYOdGFyooDd+GdDGRKIKXuiwgbxdG6SEWenceohwe8CZ/qoMJ5z9N8K66LcOR9K0FbL0VN0mnLpynT9scN4uV1HkmestXu7UHtz0y2FCqj9dM8/3Os7BAC+wASS/rzV1nR9BPJGYgRbJa0lfTbJ7QtU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773227076; c=relaxed/simple; bh=OsinLDao8OenrDWxvjx0tncPNkRRyQ4sm+SKTfSBkPs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UTklRBjNcJUKcl1XcpPhkmPfH94MfOs6J2G/V68cqL7nIZ3v0brFQfJz5lOXyvc3g/5gWlRJIkzJp/VQowWx3wUZ2KxHCGuI/pjUY8eO7xEeHGvxCwLHaKzP1xsSlCc8Ixjs6xvEj/RuKoKIFeyWdwJmgsOIQgzMp5v8hSTSD8A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ghiti.fr; spf=pass smtp.mailfrom=ghiti.fr; arc=none smtp.client-ip=217.70.178.249 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ghiti.fr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ghiti.fr Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by mslow3.mail.gandi.net (Postfix) with ESMTP id 6773A581EE8 for ; Wed, 11 Mar 2026 11:03:56 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 74F38432F6; Wed, 11 Mar 2026 11:03:44 +0000 (UTC) From: Alexandre Ghiti To: akpm@linux-foundation.org Cc: alexghiti@kernel.org, kernel-team@meta.com, akinobu.mita@gmail.com, david@kernel.org, lorenzo.stoakes@oracle.com, Liam.Howlett@oracle.com, vbabka@kernel.org, rppt@kernel.org, surenb@google.com, mhocko@suse.com, hannes@cmpxchg.org, zhengqi.arch@bytedance.com, shakeel.butt@linux.dev, axelrasmussen@google.com, yuanchu@google.com, weixugc@google.com, gourry@gourry.net, apopple@nvidia.com, byungchul@sk.com, joshua.hahnjy@gmail.com, matthew.brost@intel.com, rakie.kim@sk.com, ying.huang@linux.alibaba.com, ziy@nvidia.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Alexandre Ghiti Subject: [PATCH 1/4] mm: Move demotion related functions in memory-tiers.c Date: Wed, 11 Mar 2026 12:02:40 +0100 Message-ID: <20260311110314.237315-2-alex@ghiti.fr> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260311110314.237315-1-alex@ghiti.fr> References: <20260311110314.237315-1-alex@ghiti.fr> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-GND-Sasl: alex@ghiti.fr X-GND-Score: 0 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgddvkeefjeefucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecunecujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomheptehlvgigrghnughrvgcuifhhihhtihcuoegrlhgvgiesghhhihhtihdrfhhrqeenucggtffrrghtthgvrhhnpefhjeejtdelteefuedvffduheeifeeggeefudevfefhleduvdeutdeiteeukeegveenucfkphepvdeivddtmedutdgumegttdelvdemgedttdemmeehmeefrgeivgenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpedviedvtdemuddtugemtgdtledvmeegtddtmeemheemfegriegvpdhhvghloheprghlvgigghhhihhtihdqfhgvughorhgrqdfrhfegofekiedvrfdrthhhvghfrggtvggsohhokhdrtghomhdpmhgrihhlfhhrohhmpegrlhgvgiesghhhihhtihdrfhhrpdhqihgupeejgefhfeekgeefvdfhiedpmhhouggvpehsmhhtphhouhhtpdhnsggprhgtphhtthhopedvkedprhgtphhtthhopegrkhhpmheslhhinhhugidqfhhouhhnuggrthhiohhnrdhorhhgpdhrtghpthhtoheprghlvgigghhhihhtiheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepkhgvrhhnvghlqdhtvggrmhesmhgvthgrrdgtohhmpdhrtghpthhtoheprghkihhnohgsuhhmihhtr gesghhmrghilhdrtghomhdprhgtphhtthhopegurghvihgusehkvghrnhgvlhdrohhrghdprhgtphhtthhopehlohhrvghniihordhsthhorghkvghssehorhgrtghlvgdrtghomh X-GND-State: clean Content-Type: text/plain; charset="utf-8" Let's have all the demotion functions in this file, no functional change intended. Suggested-by: Gregory Price Signed-off-by: Alexandre Ghiti --- include/linux/memory-tiers.h | 18 ++++++++ mm/memory-tiers.c | 75 +++++++++++++++++++++++++++++++++ mm/vmscan.c | 80 +----------------------------------- 3 files changed, 94 insertions(+), 79 deletions(-) diff --git a/include/linux/memory-tiers.h b/include/linux/memory-tiers.h index 96987d9d95a8..0bf0d002939e 100644 --- a/include/linux/memory-tiers.h +++ b/include/linux/memory-tiers.h @@ -56,6 +56,9 @@ void mt_put_memory_types(struct list_head *memory_types); int next_demotion_node(int node, const nodemask_t *allowed_mask); void node_get_allowed_targets(pg_data_t *pgdat, nodemask_t *targets); bool node_is_toptier(int node); +unsigned int mt_demote_folios(struct list_head *demote_folios, + struct pglist_data *pgdat, + struct mem_cgroup *memcg); #else static inline int next_demotion_node(int node, const nodemask_t *allowed_m= ask) { @@ -71,6 +74,14 @@ static inline bool node_is_toptier(int node) { return true; } + +static inline unsigned int mt_demote_folios(struct list_head *demote_folio= s, + struct pglist_data *pgdat, + struct mem_cgroup *memcg) +{ + return 0; +} + #endif =20 #else @@ -116,6 +127,13 @@ static inline bool node_is_toptier(int node) return true; } =20 +static inline unsigned int mt_demote_folios(struct list_head *demote_folio= s, + struct pglist_data *pgdat, + struct mem_cgroup *memcg) +{ + return 0; +} + static inline int register_mt_adistance_algorithm(struct notifier_block *n= b) { return 0; diff --git a/mm/memory-tiers.c b/mm/memory-tiers.c index 986f809376eb..afdf21738a54 100644 --- a/mm/memory-tiers.c +++ b/mm/memory-tiers.c @@ -7,6 +7,7 @@ #include #include #include +#include =20 #include "internal.h" =20 @@ -373,6 +374,80 @@ int next_demotion_node(int node, const nodemask_t *all= owed_mask) return find_next_best_node(node, &mask); } =20 +static struct folio *alloc_demote_folio(struct folio *src, + unsigned long private) +{ + struct folio *dst; + nodemask_t *allowed_mask; + struct migration_target_control *mtc; + + mtc =3D (struct migration_target_control *)private; + + allowed_mask =3D mtc->nmask; + /* + * make sure we allocate from the target node first also trying to + * demote or reclaim pages from the target node via kswapd if we are + * low on free memory on target node. If we don't do this and if + * we have free memory on the slower(lower) memtier, we would start + * allocating pages from slower(lower) memory tiers without even forcing + * a demotion of cold pages from the target memtier. This can result + * in the kernel placing hot pages in slower(lower) memory tiers. + */ + mtc->nmask =3D NULL; + mtc->gfp_mask |=3D __GFP_THISNODE; + dst =3D alloc_migration_target(src, (unsigned long)mtc); + if (dst) + return dst; + + mtc->gfp_mask &=3D ~__GFP_THISNODE; + mtc->nmask =3D allowed_mask; + + return alloc_migration_target(src, (unsigned long)mtc); +} + +unsigned int mt_demote_folios(struct list_head *demote_folios, + struct pglist_data *pgdat, + struct mem_cgroup *memcg) +{ + int target_nid; + unsigned int nr_succeeded; + nodemask_t allowed_mask; + + struct migration_target_control mtc =3D { + /* + * Allocate from 'node', or fail quickly and quietly. + * When this happens, 'page' will likely just be discarded + * instead of migrated. + */ + .gfp_mask =3D (GFP_HIGHUSER_MOVABLE & ~__GFP_RECLAIM) | + __GFP_NOMEMALLOC | GFP_NOWAIT, + .nmask =3D &allowed_mask, + .reason =3D MR_DEMOTION, + }; + + if (list_empty(demote_folios)) + return 0; + + node_get_allowed_targets(pgdat, &allowed_mask); + mem_cgroup_node_filter_allowed(memcg, &allowed_mask); + if (nodes_empty(allowed_mask)) + return 0; + + target_nid =3D next_demotion_node(pgdat->node_id, &allowed_mask); + if (target_nid =3D=3D NUMA_NO_NODE) + /* No lower-tier nodes or nodes were hot-unplugged. */ + return 0; + + mtc.nid =3D target_nid; + + /* Demotion ignores all cpuset and mempolicy settings */ + migrate_pages(demote_folios, alloc_demote_folio, NULL, + (unsigned long)&mtc, MIGRATE_ASYNC, MR_DEMOTION, + &nr_succeeded); + + return nr_succeeded; +} + static void disable_all_demotion_targets(void) { struct memory_tier *memtier; diff --git a/mm/vmscan.c b/mm/vmscan.c index 0fc9373e8251..5e0138b94480 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -983,84 +983,6 @@ static void folio_check_dirty_writeback(struct folio *= folio, mapping->a_ops->is_dirty_writeback(folio, dirty, writeback); } =20 -static struct folio *alloc_demote_folio(struct folio *src, - unsigned long private) -{ - struct folio *dst; - nodemask_t *allowed_mask; - struct migration_target_control *mtc; - - mtc =3D (struct migration_target_control *)private; - - allowed_mask =3D mtc->nmask; - /* - * make sure we allocate from the target node first also trying to - * demote or reclaim pages from the target node via kswapd if we are - * low on free memory on target node. If we don't do this and if - * we have free memory on the slower(lower) memtier, we would start - * allocating pages from slower(lower) memory tiers without even forcing - * a demotion of cold pages from the target memtier. This can result - * in the kernel placing hot pages in slower(lower) memory tiers. - */ - mtc->nmask =3D NULL; - mtc->gfp_mask |=3D __GFP_THISNODE; - dst =3D alloc_migration_target(src, (unsigned long)mtc); - if (dst) - return dst; - - mtc->gfp_mask &=3D ~__GFP_THISNODE; - mtc->nmask =3D allowed_mask; - - return alloc_migration_target(src, (unsigned long)mtc); -} - -/* - * Take folios on @demote_folios and attempt to demote them to another nod= e. - * Folios which are not demoted are left on @demote_folios. - */ -static unsigned int demote_folio_list(struct list_head *demote_folios, - struct pglist_data *pgdat, - struct mem_cgroup *memcg) -{ - int target_nid; - unsigned int nr_succeeded; - nodemask_t allowed_mask; - - struct migration_target_control mtc =3D { - /* - * Allocate from 'node', or fail quickly and quietly. - * When this happens, 'page' will likely just be discarded - * instead of migrated. - */ - .gfp_mask =3D (GFP_HIGHUSER_MOVABLE & ~__GFP_RECLAIM) | - __GFP_NOMEMALLOC | GFP_NOWAIT, - .nmask =3D &allowed_mask, - .reason =3D MR_DEMOTION, - }; - - if (list_empty(demote_folios)) - return 0; - - node_get_allowed_targets(pgdat, &allowed_mask); - mem_cgroup_node_filter_allowed(memcg, &allowed_mask); - if (nodes_empty(allowed_mask)) - return 0; - - target_nid =3D next_demotion_node(pgdat->node_id, &allowed_mask); - if (target_nid =3D=3D NUMA_NO_NODE) - /* No lower-tier nodes or nodes were hot-unplugged. */ - return 0; - - mtc.nid =3D target_nid; - - /* Demotion ignores all cpuset and mempolicy settings */ - migrate_pages(demote_folios, alloc_demote_folio, NULL, - (unsigned long)&mtc, MIGRATE_ASYNC, MR_DEMOTION, - &nr_succeeded); - - return nr_succeeded; -} - static bool may_enter_fs(struct folio *folio, gfp_t gfp_mask) { if (gfp_mask & __GFP_FS) @@ -1573,7 +1495,7 @@ static unsigned int shrink_folio_list(struct list_hea= d *folio_list, /* 'folio_list' is always empty here */ =20 /* Migrate folios selected for demotion */ - nr_demoted =3D demote_folio_list(&demote_folios, pgdat, memcg); + nr_demoted =3D mt_demote_folios(&demote_folios, pgdat, memcg); nr_reclaimed +=3D nr_demoted; stat->nr_demoted +=3D nr_demoted; /* Folios that could not be demoted are still in @demote_folios */ --=20 2.53.0 From nobody Tue Apr 7 22:03:12 2026 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (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 75A823D6CAF for ; Wed, 11 Mar 2026 11:03:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773227041; cv=none; b=UbnuRceS6zZ6qsMMLE6PkNOQCLAEXKXRoCs1yIKO7NziI9p9SAKk9B1q/mD0A3G5b3zvMlyrjm0OZavR4/kYG/xvH/y0OY4EZrJlI5I3wMZ5fUP+5iS5uNLOMch4qtzyKsrB9G6dwX3PyYudAIEkX3lDfuGiHrnrER7XJwjm4UU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773227041; c=relaxed/simple; bh=AUR35bXv3yqO58cr+skSXzWxak3+d4HJaklN/PpmF+s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=a/Z+x1m9IOCg4hpYrhb0MvjboUr9UXezUrE0JTQ8CY5iFTpr1qroMm7zc1PzYolfwgAeT223ocj7o36Mznk6eaI57AnKwZwMhIU7T+hF2kUZuYs5TDPMO1TDHGpVQ3uFS5CyYZq7god/QT3lbwLPkzAMhcwXcX9jyxYZGTduxv0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ghiti.fr; spf=pass smtp.mailfrom=ghiti.fr; arc=none smtp.client-ip=217.70.183.197 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ghiti.fr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ghiti.fr Received: by mail.gandi.net (Postfix) with ESMTPSA id 26B45432F5; Wed, 11 Mar 2026 11:03:49 +0000 (UTC) From: Alexandre Ghiti To: akpm@linux-foundation.org Cc: alexghiti@kernel.org, kernel-team@meta.com, akinobu.mita@gmail.com, david@kernel.org, lorenzo.stoakes@oracle.com, Liam.Howlett@oracle.com, vbabka@kernel.org, rppt@kernel.org, surenb@google.com, mhocko@suse.com, hannes@cmpxchg.org, zhengqi.arch@bytedance.com, shakeel.butt@linux.dev, axelrasmussen@google.com, yuanchu@google.com, weixugc@google.com, gourry@gourry.net, apopple@nvidia.com, byungchul@sk.com, joshua.hahnjy@gmail.com, matthew.brost@intel.com, rakie.kim@sk.com, ying.huang@linux.alibaba.com, ziy@nvidia.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Alexandre Ghiti Subject: [PATCH 2/4] mm: Rename node_get_allowed_targets() to make it more explicit Date: Wed, 11 Mar 2026 12:02:41 +0100 Message-ID: <20260311110314.237315-3-alex@ghiti.fr> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260311110314.237315-1-alex@ghiti.fr> References: <20260311110314.237315-1-alex@ghiti.fr> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-GND-Sasl: alex@ghiti.fr X-GND-Score: 0 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgddvkeefjeefucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecunecujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomheptehlvgigrghnughrvgcuifhhihhtihcuoegrlhgvgiesghhhihhtihdrfhhrqeenucggtffrrghtthgvrhhnpefhjeejtdelteefuedvffduheeifeeggeefudevfefhleduvdeutdeiteeukeegveenucfkphepvdeivddtmedutdgumegttdelvdemgedttdemmeehmeefrgeivgenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepihhnvghtpedviedvtdemuddtugemtgdtledvmeegtddtmeemheemfegriegvpdhhvghloheprghlvgigghhhihhtihdqfhgvughorhgrqdfrhfegofekiedvrfdrthhhvghfrggtvggsohhokhdrtghomhdpmhgrihhlfhhrohhmpegrlhgvgiesghhhihhtihdrfhhrpdhqihgupedvieeugeehgeefvdfhhedpmhhouggvpehsmhhtphhouhhtpdhnsggprhgtphhtthhopedvkedprhgtphhtthhopegrkhhpmheslhhinhhugidqfhhouhhnuggrthhiohhnrdhorhhgpdhrtghpthhtoheprghlvgigghhhihhtiheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepkhgvrhhnvghlqdhtvggrmhesmhgvthgrrdgtohhmpdhrtghpthhtoheprghkihhnohgsuhhmihhtr gesghhmrghilhdrtghomhdprhgtphhtthhopegurghvihgusehkvghrnhgvlhdrohhrghdprhgtphhtthhopehlohhrvghniihordhsthhorghkvghssehorhgrtghlvgdrtghomh X-GND-State: clean Content-Type: text/plain; charset="utf-8" This function actually returns the tier nodes that are targeted during a demotion, so rename it to be more explicit. No functional change intended. Signed-off-by: Alexandre Ghiti Reviewed-by: Joshua Hahn --- include/linux/memory-tiers.h | 6 +++--- mm/memory-tiers.c | 4 ++-- mm/vmscan.c | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/linux/memory-tiers.h b/include/linux/memory-tiers.h index 0bf0d002939e..ec39dc3c39e6 100644 --- a/include/linux/memory-tiers.h +++ b/include/linux/memory-tiers.h @@ -54,7 +54,7 @@ struct memory_dev_type *mt_find_alloc_memory_type(int adi= st, void mt_put_memory_types(struct list_head *memory_types); #ifdef CONFIG_MIGRATION int next_demotion_node(int node, const nodemask_t *allowed_mask); -void node_get_allowed_targets(pg_data_t *pgdat, nodemask_t *targets); +void node_get_allowed_demotion_targets(pg_data_t *pgdat, nodemask_t *targe= ts); bool node_is_toptier(int node); unsigned int mt_demote_folios(struct list_head *demote_folios, struct pglist_data *pgdat, @@ -65,7 +65,7 @@ static inline int next_demotion_node(int node, const node= mask_t *allowed_mask) return NUMA_NO_NODE; } =20 -static inline void node_get_allowed_targets(pg_data_t *pgdat, nodemask_t *= targets) +static inline void node_get_allowed_demotion_targets(pg_data_t *pgdat, nod= emask_t *targets) { *targets =3D NODE_MASK_NONE; } @@ -117,7 +117,7 @@ static inline int next_demotion_node(int node, const no= demask_t *allowed_mask) return NUMA_NO_NODE; } =20 -static inline void node_get_allowed_targets(pg_data_t *pgdat, nodemask_t *= targets) +static inline void node_get_allowed_demotion_targets(pg_data_t *pgdat, nod= emask_t *targets) { *targets =3D NODE_MASK_NONE; } diff --git a/mm/memory-tiers.c b/mm/memory-tiers.c index afdf21738a54..19ecc9b6bbda 100644 --- a/mm/memory-tiers.c +++ b/mm/memory-tiers.c @@ -300,7 +300,7 @@ bool node_is_toptier(int node) return toptier; } =20 -void node_get_allowed_targets(pg_data_t *pgdat, nodemask_t *targets) +void node_get_allowed_demotion_targets(pg_data_t *pgdat, nodemask_t *targe= ts) { struct memory_tier *memtier; =20 @@ -428,7 +428,7 @@ unsigned int mt_demote_folios(struct list_head *demote_= folios, if (list_empty(demote_folios)) return 0; =20 - node_get_allowed_targets(pgdat, &allowed_mask); + node_get_allowed_demotion_targets(pgdat, &allowed_mask); mem_cgroup_node_filter_allowed(memcg, &allowed_mask); if (nodes_empty(allowed_mask)) return 0; diff --git a/mm/vmscan.c b/mm/vmscan.c index 5e0138b94480..11a97ee8f583 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -351,7 +351,7 @@ static bool can_demote(int nid, struct scan_control *sc, if (sc && sc->no_demotion) return false; =20 - node_get_allowed_targets(pgdat, &allowed_mask); + node_get_allowed_demotion_targets(pgdat, &allowed_mask); if (nodes_empty(allowed_mask)) return false; =20 --=20 2.53.0 From nobody Tue Apr 7 22:03:12 2026 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (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 1E05E3C0607; Wed, 11 Mar 2026 11:03:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773227044; cv=none; b=Wso8MDqFWa8REIs/f6G/UE4oaOCvIEbe/TLftqhilmOncM9rof2iaJ7BlPs5uRpoI8rdFRdvU6lNdJd8s2UF/S35WEfp9ureoUnNVzzXLBeAobMyegX4a/7e7GJK0S70P4gsXNXT5EaVQ84fTWAnb4xooaErO3UGX87qOtb96MI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773227044; c=relaxed/simple; bh=DiS/za7Xcx9BgyGTN/XlBOt/05ajBcBSWxbepSobKo8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=t8rDeszfTyhXnqVtGtzVAD397hgQQxn0QPhbbdcegDFbUeIlOOgQt0ZdakmadhkqHbtKwE1Jd9Q9+WywUycGPxgJN9jth3ewUrdgxbw3qdKEdl3Oz0SA92ZtKIlEK2lqBRWfG8fW+J6fS9mkkR4SXQAk8M03fnHLvc1HhK9+ohM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ghiti.fr; spf=pass smtp.mailfrom=ghiti.fr; arc=none smtp.client-ip=217.70.183.197 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ghiti.fr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ghiti.fr Received: by mail.gandi.net (Postfix) with ESMTPSA id B34EA4333F; Wed, 11 Mar 2026 11:03:53 +0000 (UTC) From: Alexandre Ghiti To: akpm@linux-foundation.org Cc: alexghiti@kernel.org, kernel-team@meta.com, akinobu.mita@gmail.com, david@kernel.org, lorenzo.stoakes@oracle.com, Liam.Howlett@oracle.com, vbabka@kernel.org, rppt@kernel.org, surenb@google.com, mhocko@suse.com, hannes@cmpxchg.org, zhengqi.arch@bytedance.com, shakeel.butt@linux.dev, axelrasmussen@google.com, yuanchu@google.com, weixugc@google.com, gourry@gourry.net, apopple@nvidia.com, byungchul@sk.com, joshua.hahnjy@gmail.com, matthew.brost@intel.com, rakie.kim@sk.com, ying.huang@linux.alibaba.com, ziy@nvidia.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Alexandre Ghiti , Bing Jiao , stable@vger.kernel.org Subject: [PATCH 3/4] mm: Fix demotion gfp by clearing GFP_RECLAIM after setting GFP_TRANSHUGE Date: Wed, 11 Mar 2026 12:02:42 +0100 Message-ID: <20260311110314.237315-4-alex@ghiti.fr> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260311110314.237315-1-alex@ghiti.fr> References: <20260311110314.237315-1-alex@ghiti.fr> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-GND-Sasl: alex@ghiti.fr X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgddvkeefjeefucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeetlhgvgigrnhgurhgvucfihhhithhiuceorghlvgigsehghhhithhirdhfrheqnecuggftrfgrthhtvghrnhepledufffftefhjeefhfefueekveffheejtdeilefgkeejtdeugeefudfhieefgfdunecuffhomhgrihhnpehkvghrnhgvlhdrohhrghenucfkphepvdeivddtmedutdgumegttdelvdemgedttdemmeehmeefrgeivgenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpedviedvtdemuddtugemtgdtledvmeegtddtmeemheemfegriegvpdhhvghloheprghlvgigghhhihhtihdqfhgvughorhgrqdfrhfegofekiedvrfdrthhhvghfrggtvggsohhokhdrtghomhdpmhgrihhlfhhrohhmpegrlhgvgiesghhhihhtihdrfhhrpdhqihgupeeufeeggfetgeeffeefhfdpmhhouggvpehsmhhtphhouhhtpdhnsggprhgtphhtthhopeeftddprhgtphhtthhopegrkhhpmheslhhinhhugidqfhhouhhnuggrthhiohhnrdhorhhgpdhrtghpthhtoheprghlvgigghhhihhtiheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepk hgvrhhnvghlqdhtvggrmhesmhgvthgrrdgtohhmpdhrtghpthhtoheprghkihhnohgsuhhmihhtrgesghhmrghilhdrtghomhdprhgtphhtthhopegurghvihgusehkvghrnhgvlhdrohhrghdprhgtphhtthhopehlohhrvghniihordhsthhorghkvghssehorhgrtghlvgdrtghomh X-GND-State: clean Content-Type: text/plain; charset="utf-8" GFP_TRANSHUGE sets __GFP_DIRECT_RECLAIM so we must clear GFP_RECLAIM after, not before. Reported-by: Bing Jiao Closes: https://lore.kernel.org/linux-mm/aXlKOxGGI9zne8sl@google.com/ Fixes: 9933a0c8a539 ("mm/migrate: clear __GFP_RECLAIM to make the migration= callback consistent with regular THP allocations") Cc: stable@vger.kernel.org Signed-off-by: Alexandre Ghiti --- mm/migrate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/migrate.c b/mm/migrate.c index 2c3d489ecf51..ee533a4d38db 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2190,12 +2190,12 @@ struct folio *alloc_migration_target(struct folio *= src, unsigned long private) } =20 if (folio_test_large(src)) { + gfp_mask |=3D GFP_TRANSHUGE; /* * clear __GFP_RECLAIM to make the migration callback * consistent with regular THP allocations. */ gfp_mask &=3D ~__GFP_RECLAIM; - gfp_mask |=3D GFP_TRANSHUGE; order =3D folio_order(src); } zidx =3D folio_zonenum(src); --=20 2.53.0 From nobody Tue Apr 7 22:03:12 2026 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (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 B54F33D669A; Wed, 11 Mar 2026 11:04:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773227051; cv=none; b=ukfosW+rthN8f9UDXTL2CsEV75lxh0bK6qkg7bpW6ikD4YW05Uxw0s4uU8jLj6p4UHCgDhZNJ99b6FfZxw4w5nHoyX8wdToLhbtFgQDR/Sn1wL3AKMjZQy92SZw13eoCYVDPtpkw59Fwzn7syJvC7yVJkzLSFyZCzaM42JVnTrk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773227051; c=relaxed/simple; bh=dUS30z5mwiHKFQ3rO9Ro70hyG3QRgNKWXiRNvl5lVB8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UvLoTTnysTcHnzPBmMOFsva+AdumGcMsYNReOIxZX2X7J3pJNA6HdgS0ISoVp8wdN2+iKUveox0nt9AUlZX2TEeEtz3+4mns3MVkpoAYrNOqu6HuXQtcnO3Dr8VtYVkkBkRMdwyqnBqpZ7aS/k7S4jkoejWGGVGuaclP7EfexJQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ghiti.fr; spf=pass smtp.mailfrom=ghiti.fr; arc=none smtp.client-ip=217.70.183.197 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ghiti.fr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ghiti.fr Received: by mail.gandi.net (Postfix) with ESMTPSA id 9A2D24329A; Wed, 11 Mar 2026 11:03:58 +0000 (UTC) From: Alexandre Ghiti To: akpm@linux-foundation.org Cc: alexghiti@kernel.org, kernel-team@meta.com, akinobu.mita@gmail.com, david@kernel.org, lorenzo.stoakes@oracle.com, Liam.Howlett@oracle.com, vbabka@kernel.org, rppt@kernel.org, surenb@google.com, mhocko@suse.com, hannes@cmpxchg.org, zhengqi.arch@bytedance.com, shakeel.butt@linux.dev, axelrasmussen@google.com, yuanchu@google.com, weixugc@google.com, gourry@gourry.net, apopple@nvidia.com, byungchul@sk.com, joshua.hahnjy@gmail.com, matthew.brost@intel.com, rakie.kim@sk.com, ying.huang@linux.alibaba.com, ziy@nvidia.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Alexandre Ghiti , stable@vger.kernel.org Subject: [PATCH 4/4] mm: Fix demotion gfp by preserving initial gfp reclaim policy Date: Wed, 11 Mar 2026 12:02:43 +0100 Message-ID: <20260311110314.237315-5-alex@ghiti.fr> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260311110314.237315-1-alex@ghiti.fr> References: <20260311110314.237315-1-alex@ghiti.fr> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-GND-Sasl: alex@ghiti.fr X-GND-Score: 0 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgddvkeefjeefucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecunecujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomheptehlvgigrghnughrvgcuifhhihhtihcuoegrlhgvgiesghhhihhtihdrfhhrqeenucggtffrrghtthgvrhhnpeeludffffethfejfefhfeeukeevffehjedtieelgfekjedtueegfeduhfeifefgudenucffohhmrghinhepkhgvrhhnvghlrdhorhhgnecukfhppedviedvtdemuddtugemtgdtledvmeegtddtmeemheemfegriegvnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepvdeivddtmedutdgumegttdelvdemgedttdemmeehmeefrgeivgdphhgvlhhopegrlhgvgihghhhithhiqdhfvgguohhrrgdqrffhgefokeeivdfrrdhthhgvfhgrtggvsghoohhkrdgtohhmpdhmrghilhhfrhhomheprghlvgigsehghhhithhirdhfrhdpqhhiugepleetvdffvdegfedvleetpdhmohguvgepshhmthhpohhuthdpnhgspghrtghpthhtohepvdelpdhrtghpthhtoheprghkphhmsehlihhnuhigqdhfohhunhgurghtihhonhdrohhrghdprhgtphhtthhopegrlhgvgihghhhithhisehkvghrnhgvlhdrohhrghdprhgtphhtthhopehkvghrnhgvlhdqthgvrghmsehmvghtrgdrtghom hdprhgtphhtthhopegrkhhinhhosghumhhithgrsehgmhgrihhlrdgtohhmpdhrtghpthhtohepuggrvhhiugeskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhorhgvnhiiohdrshhtohgrkhgvshesohhrrggtlhgvrdgtohhm X-GND-State: clean Content-Type: text/plain; charset="utf-8" When the src folio is a hugetlb page, htlb_modify_alloc_mask() will unconditionally enable reclaim. But we have to preserve initial gfp flags which, in the case of demotion, prevent direct reclaim. Reported-by: Gregory Price Closes: https://lore.kernel.org/linux-mm/aXkfBF5bdnTZ7t7e@gourry-fedora-PF4= VCD3F/ Fixes: 19fc7bed252c ("mm/migrate: introduce a standard migration target all= ocation function") Cc: stable@vger.kernel.org Signed-off-by: Alexandre Ghiti --- mm/migrate.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index ee533a4d38db..d44a34d37007 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2169,13 +2169,13 @@ int migrate_pages(struct list_head *from, new_folio= _t get_new_folio, struct folio *alloc_migration_target(struct folio *src, unsigned long priv= ate) { struct migration_target_control *mtc; - gfp_t gfp_mask; + gfp_t gfp_mask, gfp_entry; unsigned int order =3D 0; int nid; enum zone_type zidx; =20 mtc =3D (struct migration_target_control *)private; - gfp_mask =3D mtc->gfp_mask; + gfp_mask =3D gfp_entry =3D mtc->gfp_mask; nid =3D mtc->nid; if (nid =3D=3D NUMA_NO_NODE) nid =3D folio_nid(src); @@ -2184,6 +2184,8 @@ struct folio *alloc_migration_target(struct folio *sr= c, unsigned long private) struct hstate *h =3D folio_hstate(src); =20 gfp_mask =3D htlb_modify_alloc_mask(h, gfp_mask); + gfp_mask =3D (gfp_mask & ~__GFP_RECLAIM) | (gfp_entry & __GFP_RECLAIM); + return alloc_hugetlb_folio_nodemask(h, nid, mtc->nmask, gfp_mask, htlb_allow_alloc_fallback(mtc->reason)); --=20 2.53.0