Subject: [PATCH] mm/migrate: separate CPU and memory hotplug notifiers Date: Wed, 6 Oct 2021 11:08:46 -0700 Message-ID: <20211006180846.3321352-1-dave.hansen@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210924161255.E5FE8F7E@davehans-spike.ostc.intel.com> References: <20210924161255.E5FE8F7E@davehans-spike.ostc.intel.com> From: Dave Hansen Once upon a time, the node demotion updates were driven solely by memory hotplug events. But now, there are handlers for both CPU and memory hotplug. However, the #ifdef around the code checks only memory hotplug. A system that has HOTPLUG_CPU=y but MEMORY_HOTPLUG=n would miss CPU hotplug events. Update the #ifdef around the common code. Add memory and CPU-specific option are off. Move some CPU-hotplug-specific functions to reside under their specific #ifdef. Link: https://lkml.kernel.org/r/20210924161255.E5FE8F7E@davehans-spike.ostc.intel.com Fixes: 884a6e5d1f93 ("mm/migrate: update node demotion order on hotplug events") Signed-off-by: Dave Hansen Cc: "Huang, Ying" Cc: Michal Hocko Cc: Wei Xu Cc: Oscar Salvador Cc: David Rientjes Cc: Dan Williams Cc: David Hildenbrand Cc: Greg Thelen Cc: Yang Shi Cc: Randy Dunlap --- mm/migrate.c | 78 +++++++++++++++++++++++++++++----------------------- 1 file changed, 44 insertions(+), 34 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index a6311e46f605..5282157575ba 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -3066,7 +3066,7 @@ void migrate_vma_finalize(struct migrate_vma *migrate) EXPORT_SYMBOL(migrate_vma_finalize); #endif /* CONFIG_DEVICE_PRIVATE */ -#if defined(CONFIG_MEMORY_HOTPLUG) +#if defined(CONFIG_MEMORY_HOTPLUG) || defined(CONFIG_HOTPLUG_CPU) /* Disable reclaim-based migration. */ static void __disable_all_migrate_targets(void) { @@ -3198,35 +3198,7 @@ static void __set_migration_target_nodes(void) goto again; } -/* - * For callers that do not hold get_online_mems() already. - */ -static void set_migration_target_nodes(void) -{ - get_online_mems(); - __set_migration_target_nodes(); - put_online_mems(); -} - -/* - * React to hotplug events that might affect the migration targets - * like events that online or offline NUMA nodes. - * - * The ordering is also currently dependent on which nodes have - * CPUs. That means we need CPU on/offline notification too. - */ -static int migration_online_cpu(unsigned int cpu) -{ - set_migration_target_nodes(); - return 0; -} - -static int migration_offline_cpu(unsigned int cpu) -{ - set_migration_target_nodes(); - return 0; -} - +#if defined(CONFIG_MEMORY_HOTPLUG) /* * This leaves migrate-on-reclaim transiently disabled between * the MEM_GOING_OFFLINE and MEM_OFFLINE events. This runs @@ -3284,7 +3256,45 @@ static int __meminit migrate_on_reclaim_callback(struct notifier_block *self, return notifier_from_errno(0); } -static int __init migrate_on_reclaim_init(void) +static int __init migrate_on_reclaim_init_memhp(void) +{ + hotplug_memory_notifier(migrate_on_reclaim_callback, 100); + return 0; +} +late_initcall(migrate_on_reclaim_init_memhp); +#endif /* CONFIG_MEMORY_HOTPLUG */ + +#ifdef CONFIG_HOTPLUG_CPU +/* + * For callers that do not hold get_online_mems() already. + */ +static void set_migration_target_nodes(void) +{ + get_online_mems(); + __set_migration_target_nodes(); + put_online_mems(); +} + +/* + * React to hotplug events that might affect the migration targets + * like events that online or offline NUMA nodes. + * + * The ordering is also currently dependent on which nodes have + * CPUs. That means we need CPU on/offline notification too. + */ +static int migration_online_cpu(unsigned int cpu) +{ + set_migration_target_nodes(); + return 0; +} + +static int migration_offline_cpu(unsigned int cpu) +{ + set_migration_target_nodes(); + return 0; +} + +static int __init migrate_on_reclaim_init_cpuhp(void) { int ret; @@ -3299,8 +3309,8 @@ static int __init migrate_on_reclaim_init(void) */ WARN_ON(ret < 0); - hotplug_memory_notifier(migrate_on_reclaim_callback, 100); return 0; } -late_initcall(migrate_on_reclaim_init); -#endif /* CONFIG_MEMORY_HOTPLUG */ +late_initcall(migrate_on_reclaim_init_cpuhp); +#endif /* CONFIG_HOTPLUG_CPU */ +#endif /* CONFIG_MEMORY_HOTPLUG || CONFIG_HOTPLUG_CPU */ -- 2.25.1