Skip to contentSkip to conversation

mm/migrate: fix CPUHP state to update node demotion order

PATCH In review Huang Ying 3 participants 5 messages Sep 18, 2021 – Sep 21, 2021

Subsystems (3)
lore
Share & tools
lore

Huang Ying

author
#0 lore raw

PATCH 1/1 mm/migrate: fix CPUHP state to update node demotion order

The node demotion order needs to be updated during CPU hotplug. Because whether a NUMA node has CPU may influence the demotion order. The update function should be called during CPU online/offline after the node_states[N_CPU] has been updated. That is done in CPUHP_AP_ONLINE_DYN during CPU online and in CPUHP_MM_VMSTAT_DEAD during CPU offline. But in commit 884a6e5d1f93 ("mm/migrate: update node demotion order on hotplug events"), the function to update node demotion order is called in CPUHP_AP_ONLINE_DYN during CPU online/offline. This doesn't satisfy the order requirement. So in this patch, we added CPUHP_AP_MM_DEMOTION_ONLINE and CPUHP_MM_DEMOTION_OFFLINE to be called after CPUHP_AP_ONLINE_DYN and CPUHP_MM_VMSTAT_DEAD during CPU online/offline, and register the update function on them.

Fixes 884a6e5d1f93 ("mm/migrate: update node demotion order on hotplug events")
Cc Dave Hansen <[email protected]>
Cc Yang Shi <[email protected]>
Cc Zi Yan <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Wei Xu <[email protected]>
Cc Oscar Salvador <[email protected]>
Cc David Rientjes <[email protected]>
Cc Dan Williams <[email protected]>
Cc David Hildenbrand <[email protected]>
Cc Greg Thelen <[email protected]>
Cc Keith Busch <[email protected]>
---
 include/linux/cpuhotplug.h | 2 ++
 mm/migrate.c               | 8 +++++---
 2 files changed, 7 insertions(+), 3 deletions(-)
include/linux/cpuhotplug.h +2 -0
index 832d8a74fa59..5a92ea56f21b 100644
@@ -72,6 +72,7 @@ enum cpuhp_state {
 	CPUHP_SLUB_DEAD,
 	CPUHP_DEBUG_OBJ_DEAD,
 	CPUHP_MM_WRITEBACK_DEAD,
+	CPUHP_MM_DEMOTION_OFFLINE,
 	CPUHP_MM_VMSTAT_DEAD,
 	CPUHP_SOFTIRQ_DEAD,
 	CPUHP_NET_MVNETA_DEAD,
@@ -240,6 +241,7 @@ enum cpuhp_state {
 	CPUHP_AP_BASE_CACHEINFO_ONLINE,
 	CPUHP_AP_ONLINE_DYN,
 	CPUHP_AP_ONLINE_DYN_END		= CPUHP_AP_ONLINE_DYN + 30,
+	CPUHP_AP_MM_DEMOTION_ONLINE,
 	CPUHP_AP_X86_HPET_ONLINE,
 	CPUHP_AP_X86_KVM_CLK_ONLINE,
 	CPUHP_AP_DTPM_CPU_ONLINE,
mm/migrate.c +5 -3
index a6a7743ee98f..77d107a4577f 100644
@@ -3278,9 +3278,8 @@ static int __init migrate_on_reclaim_init(void)
 {
 	int ret;
 
-	ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "migrate on reclaim",
-				migration_online_cpu,
-				migration_offline_cpu);
+	ret = cpuhp_setup_state_nocalls(CPUHP_MM_DEMOTION_OFFLINE, "mm/demotion:offline",
+					NULL, migration_offline_cpu);
 	/*
 	 * In the unlikely case that this fails, the automatic
 	 * migration targets may become suboptimal for nodes
@@ -3288,6 +3287,9 @@ static int __init migrate_on_reclaim_init(void)
 	 * rare case, do not bother trying to do anything special.
 	 */
 	WARN_ON(ret < 0);
+	ret = cpuhp_setup_state_nocalls(CPUHP_AP_MM_DEMOTION_ONLINE, "mm/demotion:online",
+					migration_online_cpu, NULL);
+	WARN_ON(ret < 0);
 
 	hotplug_memory_notifier(migrate_on_reclaim_callback, 100);
 	return 0;
Signature · 1 line
2.30.2
#1 lore raw

Hi!

Quoted 69 lines · Huang Ying

The node demotion order needs to be updated during CPU hotplug. Because whether a NUMA node has CPU may influence the demotion order. The update function should be called during CPU online/offline after the node_states[N_CPU] has been updated. That is done in CPUHP_AP_ONLINE_DYN during CPU online and in CPUHP_MM_VMSTAT_DEAD during CPU offline. But in commit 884a6e5d1f93 ("mm/migrate: update node demotion order on hotplug events"), the function to update node demotion order is called in CPUHP_AP_ONLINE_DYN during CPU online/offline. This doesn't satisfy the order requirement. So in this patch, we added CPUHP_AP_MM_DEMOTION_ONLINE and CPUHP_MM_DEMOTION_OFFLINE to be called after CPUHP_AP_ONLINE_DYN and CPUHP_MM_VMSTAT_DEAD during CPU online/offline, and register the update function on them.

Fixes 884a6e5d1f93 ("mm/migrate: update node demotion order on hotplug events")
Cc Dave Hansen <[email protected]>
Cc Yang Shi <[email protected]>
Cc Zi Yan <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Wei Xu <[email protected]>
Cc Oscar Salvador <[email protected]>
Cc David Rientjes <[email protected]>
Cc Dan Williams <[email protected]>
Cc David Hildenbrand <[email protected]>
Cc Greg Thelen <[email protected]>
Cc Keith Busch <[email protected]>
---
  include/linux/cpuhotplug.h | 2 ++
  mm/migrate.c               | 8 +++++---
  2 files changed, 7 insertions(+), 3 deletions(-)
include/linux/cpuhotplug.h +2 -0
index 832d8a74fa59..5a92ea56f21b 100644
@@ -72,6 +72,7 @@ enum cpuhp_state {
  	CPUHP_SLUB_DEAD,
  	CPUHP_DEBUG_OBJ_DEAD,
  	CPUHP_MM_WRITEBACK_DEAD,
+	CPUHP_MM_DEMOTION_OFFLINE,
  	CPUHP_MM_VMSTAT_DEAD,
  	CPUHP_SOFTIRQ_DEAD,
  	CPUHP_NET_MVNETA_DEAD,
@@ -240,6 +241,7 @@ enum cpuhp_state {
  	CPUHP_AP_BASE_CACHEINFO_ONLINE,
  	CPUHP_AP_ONLINE_DYN,
  	CPUHP_AP_ONLINE_DYN_END		= CPUHP_AP_ONLINE_DYN + 30,
+	CPUHP_AP_MM_DEMOTION_ONLINE,
  	CPUHP_AP_X86_HPET_ONLINE,
  	CPUHP_AP_X86_KVM_CLK_ONLINE,
  	CPUHP_AP_DTPM_CPU_ONLINE,
mm/migrate.c +2 -3
index a6a7743ee98f..77d107a4577f 100644
@@ -3278,9 +3278,8 @@ static int __init migrate_on_reclaim_init(void)
  {
  	int ret;
 
-	ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "migrate on reclaim",
-				migration_online_cpu,
-				migration_offline_cpu);
+	ret = cpuhp_setup_state_nocalls(CPUHP_MM_DEMOTION_OFFLINE, "mm/demotion:offline",
+					NULL, migration_offline_cpu);
  	/*
  	 * In the unlikely case that this fails, the automatic
  	 * migration targets may become suboptimal for nodes

mm/migrate.c static int __init migrate_on_reclaim_init(void) · line 3292

Quoted 6 lines
mm/migrate.c +2 -0
@@ -3288,6 +3287,9 @@ static int __init migrate_on_reclaim_init(void)
  	 * rare case, do not bother trying to do anything special.
  	 */
  	WARN_ON(ret < 0);
+	ret = cpuhp_setup_state_nocalls(CPUHP_AP_MM_DEMOTION_ONLINE, "mm/demotion:online",
+					migration_online_cpu, NULL);
 

You changed to _nocalls variant, how does this handle initialization for cpus present at boot?

Thanks,
Mika

#2 lore raw
Quoted 73 lines · Mika Penttilä

Hi!

Quoted 70 lines · Huang Ying

The node demotion order needs to be updated during CPU hotplug. Because whether a NUMA node has CPU may influence the demotion order. The update function should be called during CPU online/offline after the node_states[N_CPU] has been updated. That is done in CPUHP_AP_ONLINE_DYN during CPU online and in CPUHP_MM_VMSTAT_DEAD during CPU offline. But in commit 884a6e5d1f93 ("mm/migrate: update node demotion order on hotplug events"), the function to update node demotion order is called in CPUHP_AP_ONLINE_DYN during CPU online/offline. This doesn't satisfy the order requirement. So in this patch, we added CPUHP_AP_MM_DEMOTION_ONLINE and CPUHP_MM_DEMOTION_OFFLINE to be called after CPUHP_AP_ONLINE_DYN and CPUHP_MM_VMSTAT_DEAD during CPU online/offline, and register the update function on them.

Fixes 884a6e5d1f93 ("mm/migrate: update node demotion order on hotplug events")
Cc Dave Hansen <[email protected]>
Cc Yang Shi <[email protected]>
Cc Zi Yan <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Wei Xu <[email protected]>
Cc Oscar Salvador <[email protected]>
Cc David Rientjes <[email protected]>
Cc Dan Williams <[email protected]>
Cc David Hildenbrand <[email protected]>
Cc Greg Thelen <[email protected]>
Cc Keith Busch <[email protected]>
---
  include/linux/cpuhotplug.h | 2 ++
  mm/migrate.c               | 8 +++++---
  2 files changed, 7 insertions(+), 3 deletions(-)
include/linux/cpuhotplug.h +2 -0
index 832d8a74fa59..5a92ea56f21b 100644
@@ -72,6 +72,7 @@ enum cpuhp_state {
  	CPUHP_SLUB_DEAD,
  	CPUHP_DEBUG_OBJ_DEAD,
  	CPUHP_MM_WRITEBACK_DEAD,
+	CPUHP_MM_DEMOTION_OFFLINE,
  	CPUHP_MM_VMSTAT_DEAD,
  	CPUHP_SOFTIRQ_DEAD,
  	CPUHP_NET_MVNETA_DEAD,
@@ -240,6 +241,7 @@ enum cpuhp_state {
  	CPUHP_AP_BASE_CACHEINFO_ONLINE,
  	CPUHP_AP_ONLINE_DYN,
  	CPUHP_AP_ONLINE_DYN_END		= CPUHP_AP_ONLINE_DYN + 30,
+	CPUHP_AP_MM_DEMOTION_ONLINE,
  	CPUHP_AP_X86_HPET_ONLINE,
  	CPUHP_AP_X86_KVM_CLK_ONLINE,
  	CPUHP_AP_DTPM_CPU_ONLINE,
mm/migrate.c +2 -2
index a6a7743ee98f..77d107a4577f 100644
@@ -3278,9 +3278,8 @@ static int __init migrate_on_reclaim_init(void)
  {
  	int ret;
  -	ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "migrate on
 reclaim",
-				migration_online_cpu,
-				migration_offline_cpu);
+	ret = cpuhp_setup_state_nocalls(CPUHP_MM_DEMOTION_OFFLINE, "mm/demotion:offline",
+					NULL, migration_offline_cpu);
  	/*
  	 * In the unlikely case that this fails, the automatic
  	 * migration targets may become suboptimal for nodes
@@ -3288,6 +3287,9 @@ static int __init migrate_on_reclaim_init(void)
  	 * rare case, do not bother trying to do anything special.
Quoted 8 lines

mm/migrate.c static int __init migrate_on_reclaim_init(void) · line 3293

Quoted 5 lines
mm/migrate.c +2 -0
  	 */
  	WARN_ON(ret < 0);
+	ret = cpuhp_setup_state_nocalls(CPUHP_AP_MM_DEMOTION_ONLINE, "mm/demotion:online",
+					migration_online_cpu, NULL);
 

You changed to _nocalls variant, how does this handle initialization for cpus present at boot?

You are right! Thanks!

There are some discussion about CPUHUP in anther thread as follows,

https://lore.kernel.org/lkml/CAAPL-u_Tig1jK=mv_r=j-A-hR3Kpu7txiSFbPR3a8O1qhM1s-Q@mail.gmail.com/

I will wait for discussion in that thread too before the next step.

Best Regards,
Huang, Ying

#3 lore raw
In reply to Huang Ying

include/linux/cpuhotplug.h enum cpuhp_state { · line 75

Quoted 5 lines · Huang Ying
include/linux/cpuhotplug.h +1 -0
@@ -72,6 +72,7 @@ enum cpuhp_state {
 	CPUHP_SLUB_DEAD,
 	CPUHP_DEBUG_OBJ_DEAD,
 	CPUHP_MM_WRITEBACK_DEAD,
+	CPUHP_MM_DEMOTION_OFFLINE,

Please keep the _DEAD convention in that section. The plugged CPU is already gone.

include/linux/cpuhotplug.h enum cpuhp_state { · line 244

Quoted 8 lines
include/linux/cpuhotplug.h +1 -0
 	CPUHP_MM_VMSTAT_DEAD,
 	CPUHP_SOFTIRQ_DEAD,
 	CPUHP_NET_MVNETA_DEAD,
@@ -240,6 +241,7 @@ enum cpuhp_state {
 	CPUHP_AP_BASE_CACHEINFO_ONLINE,
 	CPUHP_AP_ONLINE_DYN,
 	CPUHP_AP_ONLINE_DYN_END		= CPUHP_AP_ONLINE_DYN + 30,
+	CPUHP_AP_MM_DEMOTION_ONLINE,

Are there any ordering requirements of these states vs. other CPU hotplug states?

If not, then please use the dynamically allocated states.

If so, then please add a comment:

+ /* Must be before CPUHP_XXX and after CPUHP_YYY */
+ CPUHP_MM_DEMOTION_OFFLINE,

Thanks,

tglx

#4 lore raw
Quoted 9 lines · Thomas Gleixner

include/linux/cpuhotplug.h enum cpuhp_state { · line 75

Quoted 5 lines · Huang Ying
include/linux/cpuhotplug.h +1 -0
@@ -72,6 +72,7 @@ enum cpuhp_state {
 	CPUHP_SLUB_DEAD,
 	CPUHP_DEBUG_OBJ_DEAD,
 	CPUHP_MM_WRITEBACK_DEAD,
+	CPUHP_MM_DEMOTION_OFFLINE,

Please keep the _DEAD convention in that section. The plugged CPU is already gone.

Sure. Will do that.

Quoted 16 lines

include/linux/cpuhotplug.h enum cpuhp_state { · line 244

Quoted 8 lines
include/linux/cpuhotplug.h +1 -0
 	CPUHP_MM_VMSTAT_DEAD,
 	CPUHP_SOFTIRQ_DEAD,
 	CPUHP_NET_MVNETA_DEAD,
@@ -240,6 +241,7 @@ enum cpuhp_state {
 	CPUHP_AP_BASE_CACHEINFO_ONLINE,
 	CPUHP_AP_ONLINE_DYN,
 	CPUHP_AP_ONLINE_DYN_END		= CPUHP_AP_ONLINE_DYN + 30,
+	CPUHP_AP_MM_DEMOTION_ONLINE,

Are there any ordering requirements of these states vs. other CPU hotplug states?

If not, then please use the dynamically allocated states.

If so, then please add a comment:

Review

Quoted 2 lines
(quoted diff) +2 -0
+	/* Must be before CPUHP_XXX and after CPUHP_YYY */
+	CPUHP_MM_DEMOTION_OFFLINE,

The callbacks need to be called after node_states[N_CPU] has been updated during CPU online/offline. While node_states[N_CPU] is updated in CPUHP_AP_ONLINE_DYN and CPUHP_MM_VMSTAT_DEAD. So the new state must be before CPUHP_MM_VMSTAT_DEAD for offline and after CPUHP_AP_ONLINE_DYN for online. I will update the patch and add the comments.

Best Regards,
Huang, Ying