[Devel] [PATCH RHEL10 COMMIT] mm/memcontrol: move nr_to_scan fallback out of __memcg_numa_migrate_pages()

Konstantin Khorenko khorenko at virtuozzo.com
Fri Sep 5 22:58:11 MSK 2025


The commit is pushed to "branch-rh10-6.12.0-55.13.1.2.x.vz10-ovz" and will appear at git at bitbucket.org:openvz/vzkernel.git
after rh10-6.12.0-55.13.1.2.3.vz10
------>
commit 8e0ac9b4aaaca9c00277bb0b6f536db0f7f5d9c6
Author: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
Date:   Tue Sep 2 18:59:16 2025 +0800

    mm/memcontrol: move nr_to_scan fallback out of __memcg_numa_migrate_pages()
    
    To make __memcg_numa_migrate_pages() lru type agnostic we need to remove
    all uses of "lru" variable, which is old lru specific. So let's move
    nr_to_scan calculation based on "lru" variable out of
    __memcg_numa_migrate_pages().
    
    https://virtuozzo.atlassian.net/browse/VSTOR-114298
    Fixes: c92459bc18307 ("mm: memcontrol: add memory.numa_migrate file")
    Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
    
    Feature: mm: interface to migrate memory between NUMA nodes upon userspace request
---
 mm/memcontrol.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 4321ac0ef7cb0..f93c70e4a2315 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -3651,13 +3651,6 @@ static long __memcg_numa_migrate_pages(struct lruvec *lruvec, enum lru_list lru,
 	LIST_HEAD(pages);
 	long total_scanned = 0;
 
-	/*
-	 * If no limit on the maximal number of migrated pages is specified,
-	 * assume the caller wants to migrate them all.
-	 */
-	if (nr_to_scan < 0)
-		nr_to_scan = lruvec_page_state_local(lruvec, NR_LRU_BASE + lru);
-
 	while (total_scanned < nr_to_scan) {
 		int ret;
 		long scanned;
@@ -3702,6 +3695,7 @@ static int memcg_numa_migrate_pages(struct mem_cgroup *memcg,
 		for_each_online_node(nid) {
 			struct lruvec *lruvec;
 			enum lru_list lru;
+			long scan, ret;
 
 			if (node_isset(nid, *target_nodes))
 				continue;
@@ -3713,10 +3707,15 @@ static int memcg_numa_migrate_pages(struct mem_cgroup *memcg,
 			 * aren't too many of them, which is usually true.
 			 */
 			for_each_evictable_lru(lru) {
-				long ret = __memcg_numa_migrate_pages(lruvec,
-						lru, target_nodes,
-						nr_to_scan > 0 ?
-						SWAP_CLUSTER_MAX : -1);
+				/*
+				 * If no limit on the maximal number of
+				 * migrated pages is specified assume the
+				 * caller wants to migrate them all.
+				 */
+				scan = nr_to_scan > 0 ? SWAP_CLUSTER_MAX :
+				       lruvec_page_state_local(lruvec, NR_LRU_BASE + lru);
+
+				ret = __memcg_numa_migrate_pages(lruvec, lru, target_nodes, scan);
 				if (ret < 0) {
 					mem_cgroup_iter_break(memcg, iter);
 					return ret;


More information about the Devel mailing list