All of lore.kernel.org
 help / color / mirror / Atom feed
From: tip-bot for Sebastian Andrzej Siewior <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: penberg@kernel.org, mingo@kernel.org, akpm@linux-foundation.org,
	linux-kernel@vger.kernel.org, tglx@linutronix.de,
	rientjes@google.com, peterz@infradead.org, hpa@zytor.com,
	cl@linux.com, richard@nod.at, bigeasy@linutronix.de,
	iamjoonsoo.kim@lge.com
Subject: [tip:smp/hotplug] slab: Convert to hotplug state machine
Date: Tue, 6 Sep 2016 08:21:16 -0700	[thread overview]
Message-ID: <tip-e37b94bdb19a66c1164b0916c648da15c44ff39a@git.kernel.org> (raw)
In-Reply-To: <20160823125319.abeapfjapf2kfezp@linutronix.de>

Commit-ID:  e37b94bdb19a66c1164b0916c648da15c44ff39a
Gitweb:     http://git.kernel.org/tip/e37b94bdb19a66c1164b0916c648da15c44ff39a
Author:     Sebastian Andrzej Siewior <bigeasy@linutronix.de>
AuthorDate: Tue, 23 Aug 2016 14:53:19 +0200
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Tue, 6 Sep 2016 16:20:29 +0200

slab: Convert to hotplug state machine

Install the callbacks via the state machine.

Signed-off-by: Richard Weinberger <richard@nod.at>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Reviewed-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: linux-mm@kvack.org
Cc: rt@linutronix.de
Cc: David Rientjes <rientjes@google.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Christoph Lameter <cl@linux.com>
Link: http://lkml.kernel.org/r/20160823125319.abeapfjapf2kfezp@linutronix.de
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>

---
 include/linux/slab.h |   8 ++++
 kernel/cpu.c         |   6 +++
 mm/slab.c            | 114 +++++++++++++++++++++++----------------------------
 3 files changed, 65 insertions(+), 63 deletions(-)

diff --git a/include/linux/slab.h b/include/linux/slab.h
index 4293808..084b12b 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -650,4 +650,12 @@ static inline void *kzalloc_node(size_t size, gfp_t flags, int node)
 unsigned int kmem_cache_size(struct kmem_cache *s);
 void __init kmem_cache_init_late(void);
 
+#if defined(CONFIG_SMP) && defined(CONFIG_SLAB)
+int slab_prepare_cpu(unsigned int cpu);
+int slab_dead_cpu(unsigned int cpu);
+#else
+#define slab_prepare_cpu	NULL
+#define slab_dead_cpu		NULL
+#endif
+
 #endif	/* _LINUX_SLAB_H */
diff --git a/kernel/cpu.c b/kernel/cpu.c
index 09f66cc..c70fae3 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -24,6 +24,7 @@
 #include <linux/irq.h>
 #include <linux/smpboot.h>
 #include <linux/relay.h>
+#include <linux/slab.h>
 
 #include <trace/events/power.h>
 #define CREATE_TRACE_POINTS
@@ -1278,6 +1279,11 @@ static struct cpuhp_step cpuhp_bp_states[] = {
 		.startup		= relay_prepare_cpu,
 		.teardown		= NULL,
 	},
+	[CPUHP_SLAB_PREPARE] = {
+		.name			= "slab:prepare",
+		.startup		= slab_prepare_cpu,
+		.teardown		= slab_dead_cpu,
+	},
 	[CPUHP_RCUTREE_PREP] = {
 		.name			= "RCU/tree:prepare",
 		.startup.single		= rcutree_prepare_cpu,
diff --git a/mm/slab.c b/mm/slab.c
index b672710..090fb26 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)
 	return 0;
 }
 
+#if (defined(CONFIG_NUMA) && defined(CONFIG_MEMORY_HOTPLUG)) || defined(CONFIG_SMP)
 /*
  * Allocates and initializes node for a node on each slab cache, used for
  * 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)
 
 	return 0;
 }
+#endif
 
 static int setup_kmem_cache_node(struct kmem_cache *cachep,
 				int node, gfp_t gfp, bool force_change)
@@ -975,6 +977,8 @@ fail:
 	return ret;
 }
 
+#ifdef CONFIG_SMP
+
 static void cpuup_canceled(long cpu)
 {
 	struct kmem_cache *cachep;
@@ -1075,65 +1079,54 @@ bad:
 	return -ENOMEM;
 }
 
-static int cpuup_callback(struct notifier_block *nfb,
-				    unsigned long action, void *hcpu)
+int slab_prepare_cpu(unsigned int cpu)
 {
-	long cpu = (long)hcpu;
-	int err = 0;
+	int err;
 
-	switch (action) {
-	case CPU_UP_PREPARE:
-	case CPU_UP_PREPARE_FROZEN:
-		mutex_lock(&slab_mutex);
-		err = cpuup_prepare(cpu);
-		mutex_unlock(&slab_mutex);
-		break;
-	case CPU_ONLINE:
-	case CPU_ONLINE_FROZEN:
-		start_cpu_timer(cpu);
-		break;
-#ifdef CONFIG_HOTPLUG_CPU
-  	case CPU_DOWN_PREPARE:
-  	case CPU_DOWN_PREPARE_FROZEN:
-		/*
-		 * Shutdown cache reaper. Note that the slab_mutex is
-		 * held so that if cache_reap() is invoked it cannot do
-		 * anything expensive but will only modify reap_work
-		 * and reschedule the timer.
-		*/
-		cancel_delayed_work_sync(&per_cpu(slab_reap_work, cpu));
-		/* Now the cache_reaper is guaranteed to be not running. */
-		per_cpu(slab_reap_work, cpu).work.func = NULL;
-  		break;
-  	case CPU_DOWN_FAILED:
-  	case CPU_DOWN_FAILED_FROZEN:
-		start_cpu_timer(cpu);
-  		break;
-	case CPU_DEAD:
-	case CPU_DEAD_FROZEN:
-		/*
-		 * Even if all the cpus of a node are down, we don't free the
-		 * kmem_cache_node of any cache. This to avoid a race between
-		 * cpu_down, and a kmalloc allocation from another cpu for
-		 * memory from the node of the cpu going down.  The node
-		 * structure is usually allocated from kmem_cache_create() and
-		 * gets destroyed at kmem_cache_destroy().
-		 */
-		/* fall through */
+	mutex_lock(&slab_mutex);
+	err = cpuup_prepare(cpu);
+	mutex_unlock(&slab_mutex);
+	return err;
+}
+
+/*
+ * This is called for a failed online attempt and for a successful
+ * offline.
+ *
+ * Even if all the cpus of a node are down, we don't free the
+ * kmem_list3 of any cache. This to avoid a race between cpu_down, and
+ * a kmalloc allocation from another cpu for memory from the node of
+ * the cpu going down.  The list3 structure is usually allocated from
+ * kmem_cache_create() and gets destroyed at kmem_cache_destroy().
+ */
+int slab_dead_cpu(unsigned int cpu)
+{
+	mutex_lock(&slab_mutex);
+	cpuup_canceled(cpu);
+	mutex_unlock(&slab_mutex);
+	return 0;
+}
 #endif
-	case CPU_UP_CANCELED:
-	case CPU_UP_CANCELED_FROZEN:
-		mutex_lock(&slab_mutex);
-		cpuup_canceled(cpu);
-		mutex_unlock(&slab_mutex);
-		break;
-	}
-	return notifier_from_errno(err);
+
+static int slab_online_cpu(unsigned int cpu)
+{
+	start_cpu_timer(cpu);
+	return 0;
 }
 
-static struct notifier_block cpucache_notifier = {
-	&cpuup_callback, NULL, 0
-};
+static int slab_offline_cpu(unsigned int cpu)
+{
+	/*
+	 * Shutdown cache reaper. Note that the slab_mutex is held so
+	 * that if cache_reap() is invoked it cannot do anything
+	 * expensive but will only modify reap_work and reschedule the
+	 * timer.
+	 */
+	cancel_delayed_work_sync(&per_cpu(slab_reap_work, cpu));
+	/* Now the cache_reaper is guaranteed to be not running. */
+	per_cpu(slab_reap_work, cpu).work.func = NULL;
+	return 0;
+}
 
 #if defined(CONFIG_NUMA) && defined(CONFIG_MEMORY_HOTPLUG)
 /*
@@ -1336,12 +1329,6 @@ void __init kmem_cache_init_late(void)
 	/* Done! */
 	slab_state = FULL;
 
-	/*
-	 * Register a cpu startup notifier callback that initializes
-	 * cpu_cache_get for all new cpus
-	 */
-	register_cpu_notifier(&cpucache_notifier);
-
 #ifdef CONFIG_NUMA
 	/*
 	 * Register a memory hotplug callback that initializes and frees
@@ -1358,13 +1345,14 @@ void __init kmem_cache_init_late(void)
 
 static int __init cpucache_init(void)
 {
-	int cpu;
+	int ret;
 
 	/*
 	 * Register the timers that return unneeded pages to the page allocator
 	 */
-	for_each_online_cpu(cpu)
-		start_cpu_timer(cpu);
+	ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "SLAB online",
+				slab_online_cpu, slab_offline_cpu);
+	WARN_ON(ret < 0);
 
 	/* Done! */
 	slab_state = FULL;

  reply	other threads:[~2016-09-06 15:23 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-18 12:57 cpu hotplug: convert more drivers Sebastian Andrzej Siewior
2016-08-18 12:57 ` [PATCH 01/16] cpuhotplug: Remove CPU_STARTING and CPU_DYING notifier Sebastian Andrzej Siewior
2016-09-06 15:19   ` [tip:smp/hotplug] cpu/hotplug: " tip-bot for Thomas Gleixner
2016-09-06 16:37   ` tip-bot for Thomas Gleixner
2016-08-18 12:57 ` [PATCH 02/16] relayfs: Convert to hotplug state machine Sebastian Andrzej Siewior
2016-09-06 15:20   ` [tip:smp/hotplug] " tip-bot for Richard Weinberger
2016-09-06 16:38   ` tip-bot for Richard Weinberger
2016-08-18 12:57 ` [PATCH 03/16] slab: " Sebastian Andrzej Siewior
2016-08-18 12:57   ` Sebastian Andrzej Siewior
2016-08-18 17:08   ` Sebastian Andrzej Siewior
2016-08-18 17:08     ` Sebastian Andrzej Siewior
2016-08-23 12:53     ` [PATCH 03/16 v2] " Sebastian Andrzej Siewior
2016-08-23 12:53       ` Sebastian Andrzej Siewior
2016-09-06 15:21       ` tip-bot for Sebastian Andrzej Siewior [this message]
2016-09-06 16:38       ` [tip:smp/hotplug] " tip-bot for Sebastian Andrzej Siewior
2016-08-18 12:57 ` [PATCH 04/16] slub: " Sebastian Andrzej Siewior
2016-08-18 12:57   ` Sebastian Andrzej Siewior
2016-09-06 15:21   ` [tip:smp/hotplug] " tip-bot for Sebastian Andrzej Siewior
2016-09-06 16:38   ` tip-bot for Sebastian Andrzej Siewior
2016-08-18 12:57 ` [PATCH 05/16] mm: writeback: " Sebastian Andrzej Siewior
2016-08-18 12:57   ` Sebastian Andrzej Siewior
2016-09-06 15:22   ` [tip:smp/hotplug] mm/writeback: " tip-bot for Sebastian Andrzej Siewior
2016-09-06 16:39   ` tip-bot for Sebastian Andrzej Siewior
2016-08-18 12:57 ` [PATCH 06/16] kernel: softirq: " Sebastian Andrzej Siewior
2016-09-06 15:22   ` [tip:smp/hotplug] kernel/softirq: " tip-bot for Sebastian Andrzej Siewior
2016-09-06 16:39   ` tip-bot for Sebastian Andrzej Siewior
2016-08-18 12:57 ` [PATCH 07/16] rcu: rcutorture: " Sebastian Andrzej Siewior
2016-08-18 16:20   ` Paul E. McKenney
2016-08-18 12:57 ` [PATCH 08/16] net: mvneta: " Sebastian Andrzej Siewior
2016-09-06 15:23   ` [tip:smp/hotplug] net/mvneta: " tip-bot for Sebastian Andrzej Siewior
2016-09-06 16:40   ` tip-bot for Sebastian Andrzej Siewior
2016-08-18 12:57 ` [PATCH 09/16] md: raid5: " Sebastian Andrzej Siewior
2016-09-06 15:23   ` [tip:smp/hotplug] md/raid5: " tip-bot for Sebastian Andrzej Siewior
2016-09-06 16:40   ` tip-bot for Sebastian Andrzej Siewior
2016-08-18 12:57 ` [PATCH 10/16] cpuidle: pseries: " Sebastian Andrzej Siewior
2016-08-22 16:09   ` Daniel Lezcano
2016-08-22 19:04     ` Sebastian Andrzej Siewior
2016-08-23 14:16       ` Daniel Lezcano
2016-08-23 16:32         ` Sebastian Andrzej Siewior
2016-08-24  9:09           ` [PATCH 10/16 v2] " Sebastian Andrzej Siewior
2016-09-06 15:24   ` [tip:smp/hotplug] cpuidle/pseries: " tip-bot for Sebastian Andrzej Siewior
2016-09-06 16:41   ` tip-bot for Sebastian Andrzej Siewior
2016-08-18 12:57 ` [PATCH 11/16] cpuidle: powernv: " Sebastian Andrzej Siewior
2016-08-24  9:12   ` Sebastian Andrzej Siewior
2016-09-06 15:24     ` [tip:smp/hotplug] cpuidle/powernv: " tip-bot for Sebastian Andrzej Siewior
2016-09-06 16:41     ` tip-bot for Sebastian Andrzej Siewior
2016-08-18 12:57 ` [PATCH 12/16] cpuidle: coupled: " Sebastian Andrzej Siewior
2016-08-23 14:24   ` Daniel Lezcano
2016-08-24  9:14     ` [PATCH 12/16 v2] " Sebastian Andrzej Siewior
2016-09-06 15:25       ` [tip:smp/hotplug] cpuidle/coupled: " tip-bot for Sebastian Andrzej Siewior
2016-09-06 16:42       ` tip-bot for Sebastian Andrzej Siewior
2016-08-18 12:57 ` [PATCH 13/16] MIPS: BUS: CDMM: " Sebastian Andrzej Siewior
2016-09-06 15:25   ` [tip:smp/hotplug] MIPS/BUS/CDMM: " tip-bot for Sebastian Andrzej Siewior
2016-09-06 16:42   ` tip-bot for Sebastian Andrzej Siewior
2016-08-18 12:57 ` [PATCH 14/16] x86: kvm: " Sebastian Andrzej Siewior
2016-08-18 17:06   ` Paolo Bonzini
2016-09-06 15:25   ` [tip:smp/hotplug] x86/kvm: " tip-bot for Sebastian Andrzej Siewior
2016-09-06 16:43   ` tip-bot for Sebastian Andrzej Siewior
2016-08-18 12:57 ` [PATCH 15/16] powerpc: powermac: " Sebastian Andrzej Siewior
2016-09-06 15:26   ` [tip:smp/hotplug] powerpc/powermac: " tip-bot for Sebastian Andrzej Siewior
2016-09-06 16:43   ` tip-bot for Sebastian Andrzej Siewior
2016-08-18 12:57 ` [PATCH 16/16] powerpc: mmu nohash: " Sebastian Andrzej Siewior
2016-09-06 15:26   ` [tip:smp/hotplug] powerpc/mmu " tip-bot for Sebastian Andrzej Siewior
2016-09-06 16:44   ` tip-bot for Sebastian Andrzej Siewior
2016-08-18 13:40 ` cpu hotplug: convert more drivers Ingo Molnar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tip-e37b94bdb19a66c1164b0916c648da15c44ff39a@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=akpm@linux-foundation.org \
    --cc=bigeasy@linutronix.de \
    --cc=cl@linux.com \
    --cc=hpa@zytor.com \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=penberg@kernel.org \
    --cc=peterz@infradead.org \
    --cc=richard@nod.at \
    --cc=rientjes@google.com \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.