aboutsummaryrefslogtreecommitdiffstats
path: root/mm/slab.c
diff options
context:
space:
mode:
Diffstat (limited to 'mm/slab.c')
-rw-r--r--mm/slab.c114
1 files changed, 51 insertions, 63 deletions
diff --git a/mm/slab.c b/mm/slab.c
index b67271024135..090fb26b3a39 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -886,6 +886,7 @@ static int init_cache_node(struct kmem_cache *cachep, int node, gfp_t gfp)
886 return 0; 886 return 0;
887} 887}
888 888
889#if (defined(CONFIG_NUMA) && defined(CONFIG_MEMORY_HOTPLUG)) || defined(CONFIG_SMP)
889/* 890/*
890 * Allocates and initializes node for a node on each slab cache, used for 891 * Allocates and initializes node for a node on each slab cache, used for
891 * either memory or cpu hotplug. If memory is being hot-added, the kmem_cache_node 892 * either memory or cpu hotplug. If memory is being hot-added, the kmem_cache_node
@@ -908,6 +909,7 @@ static int init_cache_node_node(int node)
908 909
909 return 0; 910 return 0;
910} 911}
912#endif
911 913
912static int setup_kmem_cache_node(struct kmem_cache *cachep, 914static int setup_kmem_cache_node(struct kmem_cache *cachep,
913 int node, gfp_t gfp, bool force_change) 915 int node, gfp_t gfp, bool force_change)
@@ -975,6 +977,8 @@ fail:
975 return ret; 977 return ret;
976} 978}
977 979
980#ifdef CONFIG_SMP
981
978static void cpuup_canceled(long cpu) 982static void cpuup_canceled(long cpu)
979{ 983{
980 struct kmem_cache *cachep; 984 struct kmem_cache *cachep;
@@ -1075,65 +1079,54 @@ bad:
1075 return -ENOMEM; 1079 return -ENOMEM;
1076} 1080}
1077 1081
1078static int cpuup_callback(struct notifier_block *nfb, 1082int slab_prepare_cpu(unsigned int cpu)
1079 unsigned long action, void *hcpu)
1080{ 1083{
1081 long cpu = (long)hcpu; 1084 int err;
1082 int err = 0;
1083 1085
1084 switch (action) { 1086 mutex_lock(&slab_mutex);
1085 case CPU_UP_PREPARE: 1087 err = cpuup_prepare(cpu);
1086 case CPU_UP_PREPARE_FROZEN: 1088 mutex_unlock(&slab_mutex);
1087 mutex_lock(&slab_mutex); 1089 return err;
1088 err = cpuup_prepare(cpu); 1090}
1089 mutex_unlock(&slab_mutex); 1091
1090 break; 1092/*
1091 case CPU_ONLINE: 1093 * This is called for a failed online attempt and for a successful
1092 case CPU_ONLINE_FROZEN: 1094 * offline.
1093 start_cpu_timer(cpu); 1095 *
1094 break; 1096 * Even if all the cpus of a node are down, we don't free the
1095#ifdef CONFIG_HOTPLUG_CPU 1097 * kmem_list3 of any cache. This to avoid a race between cpu_down, and
1096 case CPU_DOWN_PREPARE: 1098 * a kmalloc allocation from another cpu for memory from the node of
1097 case CPU_DOWN_PREPARE_FROZEN: 1099 * the cpu going down. The list3 structure is usually allocated from
1098 /* 1100 * kmem_cache_create() and gets destroyed at kmem_cache_destroy().
1099 * Shutdown cache reaper. Note that the slab_mutex is 1101 */
1100 * held so that if cache_reap() is invoked it cannot do 1102int slab_dead_cpu(unsigned int cpu)
1101 * anything expensive but will only modify reap_work 1103{
1102 * and reschedule the timer. 1104 mutex_lock(&slab_mutex);
1103 */ 1105 cpuup_canceled(cpu);
1104 cancel_delayed_work_sync(&per_cpu(slab_reap_work, cpu)); 1106 mutex_unlock(&slab_mutex);
1105 /* Now the cache_reaper is guaranteed to be not running. */ 1107 return 0;
1106 per_cpu(slab_reap_work, cpu).work.func = NULL; 1108}
1107 break;
1108 case CPU_DOWN_FAILED:
1109 case CPU_DOWN_FAILED_FROZEN:
1110 start_cpu_timer(cpu);
1111 break;
1112 case CPU_DEAD:
1113 case CPU_DEAD_FROZEN:
1114 /*
1115 * Even if all the cpus of a node are down, we don't free the
1116 * kmem_cache_node of any cache. This to avoid a race between
1117 * cpu_down, and a kmalloc allocation from another cpu for
1118 * memory from the node of the cpu going down. The node
1119 * structure is usually allocated from kmem_cache_create() and
1120 * gets destroyed at kmem_cache_destroy().
1121 */
1122 /* fall through */
1123#endif 1109#endif
1124 case CPU_UP_CANCELED: 1110
1125 case CPU_UP_CANCELED_FROZEN: 1111static int slab_online_cpu(unsigned int cpu)
1126 mutex_lock(&slab_mutex); 1112{
1127 cpuup_canceled(cpu); 1113 start_cpu_timer(cpu);
1128 mutex_unlock(&slab_mutex); 1114 return 0;
1129 break;
1130 }
1131 return notifier_from_errno(err);
1132} 1115}
1133 1116
1134static struct notifier_block cpucache_notifier = { 1117static int slab_offline_cpu(unsigned int cpu)
1135 &cpuup_callback, NULL, 0 1118{
1136}; 1119 /*
1120 * Shutdown cache reaper. Note that the slab_mutex is held so
1121 * that if cache_reap() is invoked it cannot do anything
1122 * expensive but will only modify reap_work and reschedule the
1123 * timer.
1124 */
1125 cancel_delayed_work_sync(&per_cpu(slab_reap_work, cpu));
1126 /* Now the cache_reaper is guaranteed to be not running. */
1127 per_cpu(slab_reap_work, cpu).work.func = NULL;
1128 return 0;
1129}
1137 1130
1138#if defined(CONFIG_NUMA) && defined(CONFIG_MEMORY_HOTPLUG) 1131#if defined(CONFIG_NUMA) && defined(CONFIG_MEMORY_HOTPLUG)
1139/* 1132/*
@@ -1336,12 +1329,6 @@ void __init kmem_cache_init_late(void)
1336 /* Done! */ 1329 /* Done! */
1337 slab_state = FULL; 1330 slab_state = FULL;
1338 1331
1339 /*
1340 * Register a cpu startup notifier callback that initializes
1341 * cpu_cache_get for all new cpus
1342 */
1343 register_cpu_notifier(&cpucache_notifier);
1344
1345#ifdef CONFIG_NUMA 1332#ifdef CONFIG_NUMA
1346 /* 1333 /*
1347 * Register a memory hotplug callback that initializes and frees 1334 * Register a memory hotplug callback that initializes and frees
@@ -1358,13 +1345,14 @@ void __init kmem_cache_init_late(void)
1358 1345
1359static int __init cpucache_init(void) 1346static int __init cpucache_init(void)
1360{ 1347{
1361 int cpu; 1348 int ret;
1362 1349
1363 /* 1350 /*
1364 * Register the timers that return unneeded pages to the page allocator 1351 * Register the timers that return unneeded pages to the page allocator
1365 */ 1352 */
1366 for_each_online_cpu(cpu) 1353 ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "SLAB online",
1367 start_cpu_timer(cpu); 1354 slab_online_cpu, slab_offline_cpu);
1355 WARN_ON(ret < 0);
1368 1356
1369 /* Done! */ 1357 /* Done! */
1370 slab_state = FULL; 1358 slab_state = FULL;