mm/vmscan: reclaim only affects managed_zones
Subsystems (5)
PATCH 1/2 mm/vmscan: reclaim only affects managed_zones
As mentioned in commit 6aa303defb74 ("mm, vmscan: only allocate and reclaim from zones with pages managed by the buddy allocator") , reclaim only affects managed_zones.
Let's adjust the code and comment accordingly.
--- mm/vmscan.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
mm/vmscan.c +2 -2
@@ -1031,7 +1031,7 @@ static bool skip_throttle_noprogress(pg_data_t *pgdat)for (i =0 ; i <MAX_NR_ZONES ; i++) {struct zone *zone = pgdat->node_zones + i; -if (!populated_zone (zone)) +if (!managed_zone (zone))continue ; reclaimable +=zone_reclaimable_pages (zone);
@@ -3912,7 +3912,7 @@ static bool pgdat_balanced(pg_data_t *pgdat, int order, int highest_zoneidx) }/* -* If a node has no populated zone within highest_zoneidx, it does not +* If a node has no managed zone within highest_zoneidx, it does not * need balancing by definition. This can happen if a zone-restricted * allocation tries to wake a remote kswapd. */
Signature · 1 line
2.33.1
PATCH 2/2 mm/vmscan: make sure wakeup_kswapd with managed zone
wakeup_kswapd() only wake up kswapd when the zone is managed.
For two callers of wakeup_kswapd(), they are node perspective.
* wake_all_kswapds
* numamigrate_isolate_page
If we picked up a !managed zone, this is not we expected.
This patch makes sure we pick up a managed zone for wakeup_kswapd().
--- mm/migrate.c | 2 +- mm/page_alloc.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)
mm/migrate.c +1 -1
@@ -2046,7 +2046,7 @@ static int numamigrate_isolate_page(pg_data_t *pgdat, struct page *page)if (!(sysctl_numa_balancing_mode &NUMA_BALANCING_MEMORY_TIERING ))return 0 ;for (z = pgdat->nr_zones -1 ; z >=0 ; z--) { -if (populated_zone (pgdat->node_zones + z)) +if (managed_zone (pgdat->node_zones + z))break ; }wakeup_kswapd (pgdat->node_zones + z,0 , order,ZONE_MOVABLE );
mm/page_alloc.c +2 -0
@@ -4674,6 +4674,8 @@ static void wake_all_kswapds(unsigned int order, gfp_t gfp_mask,for_each_zone_zonelist_nodemask (zone, z, ac->zonelist, highest_zoneidx, ac->nodemask) { +if (!managed_zone (zone)) +continue ;if (last_pgdat != zone->zone_pgdat)wakeup_kswapd (zone, gfp_mask, order, highest_zoneidx); last_pgdat = zone->zone_pgdat;
Signature · 1 line
2.33.1
Re: [PATCH 2/2] mm/vmscan: make sure wakeup_kswapd with managed zone
Hi, Wei,
Quoted 22 lines · Wei Yang
wakeup_kswapd()only wake up kswapd when the zone is managed.For two callers of
wakeup_kswapd(), they are node perspective.*
wake_all_kswapds
*numamigrate_isolate_pageIf we picked up a !managed zone, this is not we expected.
This patch makes sure we pick up a managed zone for
wakeup_kswapd().Signed-off-by Wei Yang <[email protected]>--- mm/migrate.c | 2 +- mm/page_alloc.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)mm/migrate.c +0
-0
mm/migrate.c static int numamigrate_isolate_page(pg_data_t *pgdat, struct page *page) · line 2049
Quoted 5 lines
mm/migrate.c +1
-1@@ -2046,7 +2046,7 @@ static int numamigrate_isolate_page(pg_data_t *pgdat, struct page *page)if (!(sysctl_numa_balancing_mode &NUMA_BALANCING_MEMORY_TIERING ))return 0 ;for (z = pgdat->nr_zones -1 ; z >=0 ; z--) { -if (populated_zone (pgdat->node_zones + z)) +if (managed_zone (pgdat->node_zones + z))
This looks good to me! Thanks! It seems that we can replace populated_zone() in migrate_balanced_pgdat() too. Right?
Quoted 8 lines
mm/migrate.c +0
-0break ; }wakeup_kswapd (pgdat->node_zones + z,0 , order,ZONE_MOVABLE );mm/page_alloc.c +0
-0
mm/page_alloc.c static void wake_all_kswapds(unsigned int order, gfp_t gfp_mask, · line 4681
Quoted 8 lines
mm/page_alloc.c +2
-0@@ -4674,6 +4674,8 @@ static void wake_all_kswapds(unsigned int order, gfp_t gfp_mask,for_each_zone_zonelist_nodemask (zone, z, ac->zonelist, highest_zoneidx, ac->nodemask) { +if (!managed_zone (zone)) +continue ;if (last_pgdat != zone->zone_pgdat)wakeup_kswapd (zone, gfp_mask, order, highest_zoneidx); last_pgdat = zone->zone_pgdat;
Best Regards,
Huang, Ying
Re: [PATCH 2/2] mm/vmscan: make sure wakeup_kswapd with managed zone
Quoted 21 lines · Ying
Hi, Wei,
Quoted 17 lines · Wei Yang
wakeup_kswapd()only wake up kswapd when the zone is managed.For two callers of
wakeup_kswapd(), they are node perspective.*
wake_all_kswapds
*numamigrate_isolate_pageIf we picked up a !managed zone, this is not we expected.
This patch makes sure we pick up a managed zone for
wakeup_kswapd().Signed-off-by Wei Yang <[email protected]>--- mm/migrate.c | 2 +- mm/page_alloc.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)
Quoted 13 lines
mm/migrate.c static int numamigrate_isolate_page(pg_data_t *pgdat, struct page *page) · line 2049
Quoted 10 lines
mm/migrate.c +1
-1@@ -2046,7 +2046,7 @@ static int numamigrate_isolate_page(pg_data_t *pgdat, struct page *page)if (!(sysctl_numa_balancing_mode &NUMA_BALANCING_MEMORY_TIERING ))return 0 ;for (z = pgdat->nr_zones -1 ; z >=0 ; z--) { -if (populated_zone (pgdat->node_zones + z)) +if (managed_zone (pgdat->node_zones + z))This looks good to me! Thanks! It seems that we can replace
populated_zone()inmigrate_balanced_pgdat()too. Right?
This patch looks good to me too. Thanks!
BTW: This makes me remember the bewilderment when I read the relevant code. It's very kind of you if you could tell me the difference between managed_zone and populated_zone. IIUC, when the caller relies on the activity from buddy system, managed_zone should always be used. I think there're many places like compaction need to use managed_zone but populated_zone is used now. They might need to change to use managed_zone too. Or am I miss something?
Many Thanks. :)
Quoted 23 lines
Quoted 9 lines
mm/migrate.c +0
-0break ; }wakeup_kswapd (pgdat->node_zones + z,0 , order,ZONE_MOVABLE );mm/page_alloc.c +0
-0mm/page_alloc.c static void wake_all_kswapds(unsigned int order, gfp_t gfp_mask, · line 4681
Quoted 8 lines
mm/page_alloc.c +2
-0@@ -4674,6 +4674,8 @@ static void wake_all_kswapds(unsigned int order, gfp_t gfp_mask,for_each_zone_zonelist_nodemask (zone, z, ac->zonelist, highest_zoneidx, ac->nodemask) { +if (!managed_zone (zone)) +continue ;if (last_pgdat != zone->zone_pgdat)wakeup_kswapd (zone, gfp_mask, order, highest_zoneidx); last_pgdat = zone->zone_pgdat;Best Regards,
Huang, Ying.
Re: [PATCH 2/2] mm/vmscan: make sure wakeup_kswapd with managed zone
Quoted 36 lines · Miaohe Lin
Quoted 21 lines · Ying
Hi, Wei,
Quoted 17 lines · Wei Yang
wakeup_kswapd()only wake up kswapd when the zone is managed.For two callers of
wakeup_kswapd(), they are node perspective.*
wake_all_kswapds
*numamigrate_isolate_pageIf we picked up a !managed zone, this is not we expected.
This patch makes sure we pick up a managed zone for
wakeup_kswapd().Signed-off-by Wei Yang <[email protected]>--- mm/migrate.c | 2 +- mm/page_alloc.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)Quoted 13 lines
mm/migrate.c static int numamigrate_isolate_page(pg_data_t *pgdat, struct page *page) · line 2049
Quoted 10 lines
mm/migrate.c +1
-1@@ -2046,7 +2046,7 @@ static int numamigrate_isolate_page(pg_data_t *pgdat, struct page *page)if (!(sysctl_numa_balancing_mode &NUMA_BALANCING_MEMORY_TIERING ))return 0 ;for (z = pgdat->nr_zones -1 ; z >=0 ; z--) { -if (populated_zone (pgdat->node_zones + z)) +if (managed_zone (pgdat->node_zones + z))This looks good to me! Thanks! It seems that we can replace
populated_zone()inmigrate_balanced_pgdat()too. Right?
Quoted 5 lines
This patch looks good to me too. Thanks!
BTW: This makes me remember the bewilderment when I read the relevant code. It's very kind of you if you could tell me the difference between
managed_zoneandpopulated_zone. IIUC, when the caller relies on the
The difference is managed_zone means the zone has pages managed by buddy, while populated_zone means the zone has pages but may be reserved.
Quoted 4 lines
activity from buddy system,
managed_zoneshould always be used. I think there're many places like compaction need to usemanaged_zonebutpopulated_zoneis used now. They might need to change to usemanaged_zonetoo. Or am I miss something?
This thread comes from the read of commit 6aa303defb74, which adjust the vmscan code. It looks like there is some mis-use in compaction, but I didn't get time to go through it.
Quoted 2 lines
Many Thanks. :)
Signature · 2 lines
Wei Yang Help you, Help me
Re: [PATCH 2/2] mm/vmscan: make sure wakeup_kswapd with managed zone
Quoted 37 lines · Wei Yang
Quoted 36 lines · Miaohe Lin
Quoted 34 lines · Ying
Hi, Wei,
Quoted 22 lines · Wei Yang
wakeup_kswapd()only wake up kswapd when the zone is managed.For two callers of
wakeup_kswapd(), they are node perspective.*
wake_all_kswapds
*numamigrate_isolate_pageIf we picked up a !managed zone, this is not we expected.
This patch makes sure we pick up a managed zone for
wakeup_kswapd().Signed-off-by Wei Yang <[email protected]>--- mm/migrate.c | 2 +- mm/page_alloc.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)mm/migrate.c +0
-0mm/migrate.c static int numamigrate_isolate_page(pg_data_t *pgdat, struct page *page) · line 2049
Quoted 5 lines
mm/migrate.c +1
-1@@ -2046,7 +2046,7 @@ static int numamigrate_isolate_page(pg_data_t *pgdat, struct page *page)if (!(sysctl_numa_balancing_mode &NUMA_BALANCING_MEMORY_TIERING ))return 0 ;for (z = pgdat->nr_zones -1 ; z >=0 ; z--) { -if (populated_zone (pgdat->node_zones + z)) +if (managed_zone (pgdat->node_zones + z))This looks good to me! Thanks! It seems that we can replace
populated_zone()inmigrate_balanced_pgdat()too. Right?
Quoted 8 lines
Quoted 5 lines
This patch looks good to me too. Thanks!
BTW: This makes me remember the bewilderment when I read the relevant code. It's very kind of you if you could tell me the difference between
managed_zoneandpopulated_zone. IIUC, when the caller relies on theThe difference is
managed_zonemeans the zone has pages managed by buddy, whilepopulated_zonemeans the zone has pages but may be reserved.
That's just what I understand. Thanks. :)
Quoted 9 lines
Quoted 5 lines
activity from buddy system,
managed_zoneshould always be used. I think there're many places like compaction need to usemanaged_zonebutpopulated_zoneis used now. They might need to change to usemanaged_zonetoo. Or am I miss something?This thread comes from the read of commit
6aa303defb74, which adjust the vmscan code. It looks like there is some mis-use in compaction, but I didn't get time to go through it.
I see. Thanks for the work.
Quoted 4 lines
Quoted 3 lines
Many Thanks. :)
Re: [PATCH 2/2] mm/vmscan: make sure wakeup_kswapd with managed zone
In reply to Huang, YingQuoted 21 lines · Ying
Hi, Wei,
Quoted 17 lines · Wei Yang
wakeup_kswapd()only wake up kswapd when the zone is managed.For two callers of
wakeup_kswapd(), they are node perspective.*
wake_all_kswapds
*numamigrate_isolate_pageIf we picked up a !managed zone, this is not we expected.
This patch makes sure we pick up a managed zone for
wakeup_kswapd().Signed-off-by Wei Yang <[email protected]>--- mm/migrate.c | 2 +- mm/page_alloc.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)
Quoted 14 lines
mm/migrate.c static int numamigrate_isolate_page(pg_data_t *pgdat, struct page *page) · line 2049
Quoted 10 lines
mm/migrate.c +1
-1@@ -2046,7 +2046,7 @@ static int numamigrate_isolate_page(pg_data_t *pgdat, struct page *page)if (!(sysctl_numa_balancing_mode &NUMA_BALANCING_MEMORY_TIERING ))return 0 ;for (z = pgdat->nr_zones -1 ; z >=0 ; z--) { -if (populated_zone (pgdat->node_zones + z)) +if (managed_zone (pgdat->node_zones + z))This looks good to me! Thanks! It seems that we can replace
populated_zone()inmigrate_balanced_pgdat()too. Right?
Yes, you are right. I didn't spot this.
While this patch comes from the clue of wakeup_kswapd(), I am not sure it is nice to put it in this patch together.
Which way you prefer to include this: merge the change into this one, or a separate one?
Signature · 2 lines
Wei Yang Help you, Help me
Re: [PATCH 2/2] mm/vmscan: make sure wakeup_kswapd with managed zone
Quoted 37 lines · Wei Yang
Quoted 21 lines · Ying
Hi, Wei,
Quoted 17 lines · Wei Yang
wakeup_kswapd()only wake up kswapd when the zone is managed.For two callers of
wakeup_kswapd(), they are node perspective.*
wake_all_kswapds
*numamigrate_isolate_pageIf we picked up a !managed zone, this is not we expected.
This patch makes sure we pick up a managed zone for
wakeup_kswapd().Signed-off-by Wei Yang <[email protected]>--- mm/migrate.c | 2 +- mm/page_alloc.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)Quoted 14 lines
mm/migrate.c static int numamigrate_isolate_page(pg_data_t *pgdat, struct page *page) · line 2049
Quoted 10 lines
mm/migrate.c +1
-1@@ -2046,7 +2046,7 @@ static int numamigrate_isolate_page(pg_data_t *pgdat, struct page *page)if (!(sysctl_numa_balancing_mode &NUMA_BALANCING_MEMORY_TIERING ))return 0 ;for (z = pgdat->nr_zones -1 ; z >=0 ; z--) { -if (populated_zone (pgdat->node_zones + z)) +if (managed_zone (pgdat->node_zones + z))This looks good to me! Thanks! It seems that we can replace
populated_zone()inmigrate_balanced_pgdat()too. Right?
Quoted 7 lines
Yes, you are right. I didn't spot this.
While this patch comes from the clue of
wakeup_kswapd(), I am not sure it is nice to put it in this patch together.Which way you prefer to include this: merge the change into this one, or a separate one?
Either is OK for me.
Best Regards,
Huang, Ying
Re: [PATCH 2/2] mm/vmscan: make sure wakeup_kswapd with managed zone
On Tue, Mar 29, 2022 at 08:43:23AM +0800, Huang, Ying wrote:
[...]
Quoted 15 lines
Quoted 15 lines
Quoted 12 lines
mm/migrate.c static int numamigrate_isolate_page(pg_data_t *pgdat, struct page *page) · line 2049
Quoted 8 lines
mm/migrate.c +1
-1@@ -2046,7 +2046,7 @@ static int numamigrate_isolate_page(pg_data_t *pgdat, struct page *page)if (!(sysctl_numa_balancing_mode &NUMA_BALANCING_MEMORY_TIERING ))return 0 ;for (z = pgdat->nr_zones -1 ; z >=0 ; z--) { -if (populated_zone (pgdat->node_zones + z)) +if (managed_zone (pgdat->node_zones + z))This looks good to me! Thanks! It seems that we can replace
populated_zone()inmigrate_balanced_pgdat()too. Right?Yes, you are right. I didn't spot this.
Quoted 8 lines
Quoted 5 lines
While this patch comes from the clue of
wakeup_kswapd(), I am not sure it is nice to put it in this patch together.Which way you prefer to include this: merge the change into this one, or a separate one?
Either is OK for me.
After reading the code, I am willing to do a little simplification. Does this look good to you?
From 85c8a5cd708ada3e9f5b0409413407b7be1bc446 Mon Sep 17 00:00:00 2001
From: Wei Yang <[email protected]>
Date: Tue, 29 Mar 2022 09:24:36 +0800
Subject: [PATCH] mm/migrate.c: return valid zone for wakeup_kswapd from
migrate_balanced_pgdat()
To wakeup kswapd, we need to iterate pgdat->node_zones and get the proper zone. While this work has already been done in migrate_balanced_pgdat().
Let's return the valid zone directly instead of do the iteration again.
--- mm/migrate.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-)
mm/migrate.c +8 -13
@@ -1973,7 +1973,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,* Returns true if this is a safe migration target node for misplaced NUMA * pages. Currently it only checks the watermarks which is crude. */ -static bool migrate_balanced_pgdat (struct pglist_data *pgdat, +static struct zone *migrate_balanced_pgdat (struct pglist_data *pgdat,unsigned long nr_migrate_pages) {int z;
@@ -1985,14 +1985,13 @@ static bool migrate_balanced_pgdat(struct pglist_data *pgdat,continue ;/* Avoid waking kswapd by allocating pages_to_migrate pages. */ -if (!zone_watermark_ok (zone,0 , +if (zone_watermark_ok (zone,0 ,high_wmark_pages (zone) + nr_migrate_pages,ZONE_MOVABLE ,0 )) -continue ; -return true; +return zone; } -return false; +return NULL ; } static struct page *alloc_misplaced_dst_page(struct page *page,
@@ -2032,6 +2031,7 @@ static int numamigrate_isolate_page(pg_data_t *pgdat, struct page *page)int page_lru;int nr_pages =thp_nr_pages (page);int order =compound_order (page); +struct zone *zone;VM_BUG_ON_PAGE (order && !PageTransHuge (page), page);
@@ -2040,16 +2040,11 @@ static int numamigrate_isolate_page(pg_data_t *pgdat, struct page *page)return 0 ;/* Avoid migrating to a node that is nearly full */ -if (!migrate_balanced_pgdat (pgdat, nr_pages)) { -int z; - +if ((zone =migrate_balanced_pgdat (pgdat, nr_pages))) {if (!(sysctl_numa_balancing_mode &NUMA_BALANCING_MEMORY_TIERING ))return 0 ; -for (z = pgdat->nr_zones -1 ; z >=0 ; z--) { -if (managed_zone (pgdat->node_zones + z)) -break ; - } -wakeup_kswapd (pgdat->node_zones + z,0 , order,ZONE_MOVABLE ); + +wakeup_kswapd (zone,0 , order,ZONE_MOVABLE );return 0 ; }
Signature · 1 line
2.33.1
Quoted 2 lines
Best Regards,
Huang, Ying
Signature · 2 lines
Wei Yang Help you, Help me
Re: [PATCH 2/2] mm/vmscan: make sure wakeup_kswapd with managed zone
Quoted 86 lines · Wei Yang
On Tue, Mar 29, 2022 at 08:43:23AM +0800, Huang, Ying wrote:
[...]Quoted 15 lines
Quoted 15 lines
Quoted 12 lines
mm/migrate.c static int numamigrate_isolate_page(pg_data_t *pgdat, struct page *page) · line 2049
Quoted 8 lines
mm/migrate.c +1
-1@@ -2046,7 +2046,7 @@ static int numamigrate_isolate_page(pg_data_t *pgdat, struct page *page)if (!(sysctl_numa_balancing_mode &NUMA_BALANCING_MEMORY_TIERING ))return 0 ;for (z = pgdat->nr_zones -1 ; z >=0 ; z--) { -if (populated_zone (pgdat->node_zones + z)) +if (managed_zone (pgdat->node_zones + z))This looks good to me! Thanks! It seems that we can replace
populated_zone()inmigrate_balanced_pgdat()too. Right?Yes, you are right. I didn't spot this.
Quoted 8 lines
Quoted 5 lines
While this patch comes from the clue of
wakeup_kswapd(), I am not sure it is nice to put it in this patch together.Which way you prefer to include this: merge the change into this one, or a separate one?
Either is OK for me.
After reading the code, I am willing to do a little simplification. Does this look good to you?
From
85c8a5cd708ada3e9f5b0409413407b7be1bc446Mon Sep 17 00:00:00 2001
From: Wei Yang <[email protected]>
Date: Tue, 29 Mar 2022 09:24:36 +0800
Subject: [PATCH]mm/migrate.c: return valid zone forwakeup_kswapdfrom
migrate_balanced_pgdat()To wakeup kswapd, we need to iterate
pgdat->node_zonesand get the proper zone. While this work has already been done inmigrate_balanced_pgdat().Let's return the valid zone directly instead of do the iteration again.
Signed-off-by Wei Yang <[email protected]>--- mm/migrate.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-)mm/migrate.c +5
-5@@ -1973,7 +1973,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,* Returns true if this is a safe migration target node for misplaced NUMA * pages. Currently it only checks the watermarks which is crude. */ -static bool migrate_balanced_pgdat (struct pglist_data *pgdat, +static struct zone *migrate_balanced_pgdat (struct pglist_data *pgdat,unsigned long nr_migrate_pages) {int z;@@ -1985,14 +1985,13 @@ static bool migrate_balanced_pgdat(struct pglist_data *pgdat,continue ;/* Avoid waking kswapd by allocating pages_to_migrate pages. */ -if (!zone_watermark_ok (zone,0 , +if (zone_watermark_ok (zone,0 ,high_wmark_pages (zone) + nr_migrate_pages,ZONE_MOVABLE ,0 )) -continue ; -return true; +return zone; } -return false; +return NULL ; } static struct page *alloc_misplaced_dst_page(struct page *page,@@ -2032,6 +2031,7 @@ static int numamigrate_isolate_page(pg_data_t *pgdat, struct page *page)int page_lru;int nr_pages =thp_nr_pages (page);int order =compound_order (page); +struct zone *zone;VM_BUG_ON_PAGE (order && !PageTransHuge (page), page);
mm/migrate.c static int numamigrate_isolate_page(pg_data_t *pgdat, struct page *page) · line 2043
Quoted 7 lines
mm/migrate.c +1
-3@@ -2040,16 +2040,11 @@ static int numamigrate_isolate_page(pg_data_t *pgdat, struct page *page)return 0 ;/* Avoid migrating to a node that is nearly full */ -if (!migrate_balanced_pgdat (pgdat, nr_pages)) { -int z; - +if ((zone =migrate_balanced_pgdat (pgdat, nr_pages))) {
I think that this reverses the original semantics. Originally, we give up and wake up kswapd if there's no enough free pages on the target node. But now, you give up and wake up if there's enough free pages.
Best Regards,
Huang, Ying
Quoted 15 lines
mm/migrate.c +2
-5if (!(sysctl_numa_balancing_mode &NUMA_BALANCING_MEMORY_TIERING ))return 0 ; -for (z = pgdat->nr_zones -1 ; z >=0 ; z--) { -if (managed_zone (pgdat->node_zones + z)) -break ; - } -wakeup_kswapd (pgdat->node_zones + z,0 , order,ZONE_MOVABLE ); + +wakeup_kswapd (zone,0 , order,ZONE_MOVABLE );return 0 ; }Signature · 1 line
2.33.1
Re: [PATCH 2/2] mm/vmscan: make sure wakeup_kswapd with managed zone
Quoted 90 lines · Ying
Quoted 88 lines · Wei Yang
On Tue, Mar 29, 2022 at 08:43:23AM +0800, Huang, Ying wrote:
[...]Quoted 15 lines
Quoted 15 lines
Quoted 12 lines
mm/migrate.c static int numamigrate_isolate_page(pg_data_t *pgdat, struct page *page) · line 2049
Quoted 8 lines
mm/migrate.c +1
-1@@ -2046,7 +2046,7 @@ static int numamigrate_isolate_page(pg_data_t *pgdat, struct page *page)if (!(sysctl_numa_balancing_mode &NUMA_BALANCING_MEMORY_TIERING ))return 0 ;for (z = pgdat->nr_zones -1 ; z >=0 ; z--) { -if (populated_zone (pgdat->node_zones + z)) +if (managed_zone (pgdat->node_zones + z))This looks good to me! Thanks! It seems that we can replace
populated_zone()inmigrate_balanced_pgdat()too. Right?Yes, you are right. I didn't spot this.
Quoted 8 lines
Quoted 5 lines
While this patch comes from the clue of
wakeup_kswapd(), I am not sure it is nice to put it in this patch together.Which way you prefer to include this: merge the change into this one, or a separate one?
Either is OK for me.
After reading the code, I am willing to do a little simplification. Does this look good to you?
From
85c8a5cd708ada3e9f5b0409413407b7be1bc446Mon Sep 17 00:00:00 2001
From: Wei Yang <[email protected]>
Date: Tue, 29 Mar 2022 09:24:36 +0800
Subject: [PATCH]mm/migrate.c: return valid zone forwakeup_kswapdfrom
migrate_balanced_pgdat()To wakeup kswapd, we need to iterate
pgdat->node_zonesand get the proper zone. While this work has already been done inmigrate_balanced_pgdat().Let's return the valid zone directly instead of do the iteration again.
Signed-off-by Wei Yang <[email protected]>--- mm/migrate.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-)mm/migrate.c +5
-5@@ -1973,7 +1973,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,* Returns true if this is a safe migration target node for misplaced NUMA * pages. Currently it only checks the watermarks which is crude. */ -static bool migrate_balanced_pgdat (struct pglist_data *pgdat, +static struct zone *migrate_balanced_pgdat (struct pglist_data *pgdat,unsigned long nr_migrate_pages) {int z;@@ -1985,14 +1985,13 @@ static bool migrate_balanced_pgdat(struct pglist_data *pgdat,continue ;/* Avoid waking kswapd by allocating pages_to_migrate pages. */ -if (!zone_watermark_ok (zone,0 , +if (zone_watermark_ok (zone,0 ,high_wmark_pages (zone) + nr_migrate_pages,ZONE_MOVABLE ,0 )) -continue ; -return true; +return zone; } -return false; +return NULL ; } static struct page *alloc_misplaced_dst_page(struct page *page,@@ -2032,6 +2031,7 @@ static int numamigrate_isolate_page(pg_data_t *pgdat, struct page *page)int page_lru;int nr_pages =thp_nr_pages (page);int order =compound_order (page); +struct zone *zone;VM_BUG_ON_PAGE (order && !PageTransHuge (page), page);@@ -2040,16 +2040,11 @@ static int numamigrate_isolate_page(pg_data_t *pgdat, struct page *page)return 0 ;
Quoted 10 lines
mm/migrate.c static int numamigrate_isolate_page(pg_data_t *pgdat, struct page *page) · line 2043
Quoted 5 lines
mm/migrate.c +1
-3/* Avoid migrating to a node that is nearly full */ -if (!migrate_balanced_pgdat (pgdat, nr_pages)) { -int z; - +if ((zone =migrate_balanced_pgdat (pgdat, nr_pages))) {I think that this reverses the original semantics. Originally, we give up and wake up kswapd if there's no enough free pages on the target node. But now, you give up and wake up if there's enough free pages.
You are right, I misunderstand it.
Sorry
Signature · 2 lines
Wei Yang Help you, Help me
Re: [PATCH 2/2] mm/vmscan: make sure wakeup_kswapd with managed zone
In reply to Wei Yangmm/migrate.c static bool migrate_balanced_pgdat(struct pglist_data *pgdat, · line 1991
Quoted 9 lines · Wei Yang
mm/migrate.c +1
-1@@ -1985,14 +1985,13 @@ static bool migrate_balanced_pgdat(struct pglist_data *pgdat,continue ;/* Avoid waking kswapd by allocating pages_to_migrate pages. */ -if (!zone_watermark_ok (zone,0 , +if (zone_watermark_ok (zone,0 ,high_wmark_pages (zone) + nr_migrate_pages,ZONE_MOVABLE ,0 ))
Someone's done the silly thing of lining up all of these with spaces, so either all these lines also need to be shrunk by one space, or you need to break that convention and just go to a reasonable number of tabs. I'd do it like this:
if (zone_watermark_ok(zone, 0,
high_wmark_pages(zone) + nr_migrate_pages, ZONE_MOVABLE, 0))
but not everybody would.
mm/migrate.c static int numamigrate_isolate_page(pg_data_t *pgdat, struct page *page) · line 2043
Quoted 8 lines
mm/migrate.c +1
-3@@ -2040,16 +2040,11 @@ static int numamigrate_isolate_page(pg_data_t *pgdat, struct page *page)return 0 ;/* Avoid migrating to a node that is nearly full */ -if (!migrate_balanced_pgdat (pgdat, nr_pages)) { -int z; - +if ((zone =migrate_balanced_pgdat (pgdat, nr_pages))) {
Linus had a rant about this style recently. He much prefers:
zone = migrate_balanced_pgdat(pgdat, nr_pages);
if (zone) {(the exception is for while loops:
while ((zone = migrate_balanced_pgdat(pgdat, nr_pages)) != NULL)
where he wants to see the comparison against NULL instead of the awkard double-bracket)
Re: [PATCH 2/2] mm/vmscan: make sure wakeup_kswapd with managed zone
Quoted 36 lines · Matthew Wilcox
mm/migrate.c static bool migrate_balanced_pgdat(struct pglist_data *pgdat, · line 1991
Quoted 9 lines · Wei Yang
mm/migrate.c +1
-1@@ -1985,14 +1985,13 @@ static bool migrate_balanced_pgdat(struct pglist_data *pgdat,continue ;/* Avoid waking kswapd by allocating pages_to_migrate pages. */ -if (!zone_watermark_ok (zone,0 , +if (zone_watermark_ok (zone,0 ,high_wmark_pages (zone) + nr_migrate_pages,ZONE_MOVABLE ,0 ))Someone's done the silly thing of lining up all of these with spaces, so either all these lines also need to be shrunk by one space, or you need to break that convention and just go to a reasonable number of tabs. I'd do it like this:
if (zone_watermark_ok(zone, 0,
high_wmark_pages(zone)+nr_migrate_pages,ZONE_MOVABLE, 0))but not everybody would.
mm/migrate.c static int numamigrate_isolate_page(pg_data_t *pgdat, struct page *page) · line 2043
Quoted 8 lines
mm/migrate.c +1
-3@@ -2040,16 +2040,11 @@ static int numamigrate_isolate_page(pg_data_t *pgdat, struct page *page)return 0 ;/* Avoid migrating to a node that is nearly full */ -if (!migrate_balanced_pgdat (pgdat, nr_pages)) { -int z; - +if ((zone =migrate_balanced_pgdat (pgdat, nr_pages))) {Linus had a rant about this style recently. He much prefers:
zone = migrate_balanced_pgdat(pgdat, nr_pages); if (zone) {
Quoted 6 lines
(the exception is for while loops:
while ((zone = migrate_balanced_pgdat(pgdat, nr_pages)) != NULL)where he wants to see the comparison against NULL instead of the awkard double-bracket)
Matthew,
Thanks for your suggestion, I would change this later.
Signature · 2 lines
Wei Yang Help you, Help me
Quoted 7 lines · Wei Yang
As mentioned in commit
6aa303defb74("mm, vmscan: only allocate and reclaim from zones with pages managed by the buddy allocator") , reclaim only affectsmanaged_zones.Let's adjust the code and comment accordingly.
Signed-off-by Wei Yang <[email protected]>
Looks good to me. Thanks.
Quoted 27 lines
--- mm/vmscan.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)mm/vmscan.c +2
-2@@ -1031,7 +1031,7 @@ static bool skip_throttle_noprogress(pg_data_t *pgdat)for (i =0 ; i <MAX_NR_ZONES ; i++) {struct zone *zone = pgdat->node_zones + i; -if (!populated_zone (zone)) +if (!managed_zone (zone))continue ; reclaimable +=zone_reclaimable_pages (zone);@@ -3912,7 +3912,7 @@ static bool pgdat_balanced(pg_data_t *pgdat, int order, int highest_zoneidx) }/* -* If a node has no populated zone within highest_zoneidx, it does not +* If a node has no managed zone within highest_zoneidx, it does not * need balancing by definition. This can happen if a zone-restricted * allocation tries to wake a remote kswapd. */
Quoted 25 lines · Wei Yang
As mentioned in commit
6aa303defb74("mm, vmscan: only allocate and reclaim from zones with pages managed by the buddy allocator") , reclaim only affectsmanaged_zones.Let's adjust the code and comment accordingly.
Signed-off-by Wei Yang <[email protected]>--- mm/vmscan.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)mm/vmscan.c +1
-1@@ -1031,7 +1031,7 @@ static bool skip_throttle_noprogress(pg_data_t *pgdat)for (i =0 ; i <MAX_NR_ZONES ; i++) {struct zone *zone = pgdat->node_zones + i; -if (!populated_zone (zone)) +if (!managed_zone (zone))continue ; reclaimable +=zone_reclaimable_pages (zone);
mm/vmscan.c static bool pgdat_balanced(pg_data_t *pgdat, int order, int highest_zoneidx) · line 3918
Quoted 8 lines
mm/vmscan.c +1
-1@@ -3912,7 +3912,7 @@ static bool pgdat_balanced(pg_data_t *pgdat, int order, int highest_zoneidx) }/* -* If a node has no populated zone within highest_zoneidx, it does not +* If a node has no managed zone within highest_zoneidx, it does not * need balancing by definition. This can happen if a zone-restricted * allocation tries to wake a remote kswapd. */
Signature · 3 lines
Thanks, David / dhildenb
Quoted 7 lines · Wei Yang
As mentioned in commit
6aa303defb74("mm, vmscan: only allocate and reclaim from zones with pages managed by the buddy allocator") , reclaim only affectsmanaged_zones.Let's adjust the code and comment accordingly.
Signed-off-by Wei Yang <[email protected]>
LGTM,
We still have some other places scattered all over where we use populated_zone().
I think it should be great to check whether all those usages are right.
Signature · 2 lines
Oscar Salvador SUSE Labs
Quoted 9 lines · Oscar Salvador
Quoted 7 lines · Wei Yang
As mentioned in commit
6aa303defb74("mm, vmscan: only allocate and reclaim from zones with pages managed by the buddy allocator") , reclaim only affectsmanaged_zones.Let's adjust the code and comment accordingly.
Signed-off-by Wei Yang <[email protected]>
Quoted 9 lines
LGTM,
Reviewed-by Oscar Salvador <[email protected]>We still have some other places scattered all over where we use
populated_zone().
I think it should be great to check whether all those usages are right.
Thanks.
This time I have checked vmscan related places, it looks all related part are fixed. For others, I didn't get a chance to catch them.
Quoted 4 lines
Signature · 3 lines
-- Oscar Salvador SUSE Labs
Signature · 2 lines
Wei Yang Help you, Help me