From: Yasunori Goto <y-goto@jp.fujitsu.com>
To: Andrew Morton <akpm@osdl.org>
Cc: Christoph Lameter <clameter@sgi.com>,
Linux Kernel ML <linux-kernel@vger.kernel.org>,
linux-mm <linux-mm@kvack.org>
Subject: [Patch / 002](memory hotplug) Callback function to create kmem_cache_node.
Date: Mon, 01 Oct 2007 18:34:39 +0900 [thread overview]
Message-ID: <20071001183316.7A9B.Y-GOTO@jp.fujitsu.com> (raw)
In-Reply-To: <20071001182329.7A97.Y-GOTO@jp.fujitsu.com>
This is to make kmem_cache_nodes of all SLUBs for new node when
memory-hotadd is called. This fixes panic due to access NULL pointer at
discard_slab() after memory hot-add.
If pages on the new node available, slub can use it before making
new kmem_cache_nodes. So, this callback should be called
BEFORE pages on the node are available.
Signed-off-by: Yasunori Goto <y-goto@jp.fujitsu.com>
---
mm/slub.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 79 insertions(+)
Index: current/mm/slub.c
===================================================================
--- current.orig/mm/slub.c 2007-09-28 11:23:50.000000000 +0900
+++ current/mm/slub.c 2007-09-28 11:23:59.000000000 +0900
@@ -20,6 +20,7 @@
#include <linux/mempolicy.h>
#include <linux/ctype.h>
#include <linux/kallsyms.h>
+#include <linux/memory.h>
/*
* Lock order:
@@ -2097,6 +2098,82 @@ static int init_kmem_cache_nodes(struct
}
return 1;
}
+
+#ifdef CONFIG_MEMORY_HOTPLUG
+static void __slab_callback_offline(int nid)
+{
+ struct kmem_cache_node *n;
+ struct kmem_cache *s;
+
+ list_for_each_entry(s, &slab_caches, list) {
+ if (s->node[nid]) {
+ n = get_node(s, nid);
+ s->node[nid] = NULL;
+ kmem_cache_free(kmalloc_caches, n);
+ }
+ }
+}
+
+static int slab_callback_going_online(void *arg)
+{
+ struct kmem_cache_node *n;
+ struct kmem_cache *s;
+ struct memory_notify *marg = arg;
+ int nid;
+
+ nid = page_to_nid(pfn_to_page(marg->start_pfn));
+
+ /* If the node already has memory, then nothing is necessary. */
+ if (node_state(nid, N_HIGH_MEMORY))
+ return 0;
+
+ /*
+ * New memory will be onlined on the node which has no memory so far.
+ * New kmem_cache_node is necssary for it.
+ */
+ down_read(&slub_lock);
+ list_for_each_entry(s, &slab_caches, list) {
+ /*
+ * XXX: The new node's memory can't be allocated yet,
+ * kmem_cache_node will be allocated other node.
+ */
+ n = kmem_cache_alloc(kmalloc_caches, GFP_KERNEL);
+ if (!n)
+ goto error;
+ init_kmem_cache_node(n);
+ s->node[nid] = n;
+ }
+ up_read(&slub_lock);
+
+ return 0;
+
+error:
+ __slab_callback_offline(nid);
+ up_read(&slub_lock);
+
+ return -ENOMEM;
+}
+
+static int slab_callback(struct notifier_block *self, unsigned long action,
+ void *arg)
+{
+ int ret = 0;
+
+ switch (action) {
+ case MEM_GOING_ONLINE:
+ ret = slab_callback_going_online(arg);
+ break;
+ case MEM_ONLINE:
+ case MEM_GOING_OFFLINE:
+ case MEM_MAPPING_INVALID:
+ break;
+ }
+
+ ret = notifier_from_errno(ret);
+ return ret;
+}
+
+#endif /* CONFIG_MEMORY_HOTPLUG */
#else
static void free_kmem_cache_nodes(struct kmem_cache *s)
{
@@ -2730,6 +2807,8 @@ void __init kmem_cache_init(void)
sizeof(struct kmem_cache_node), GFP_KERNEL);
kmalloc_caches[0].refcount = -1;
caches++;
+
+ hotplug_memory_notifier(slab_callback, 1);
#endif
/* Able to allocate the per node structures */
--
Yasunori Goto
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2007-10-01 9:34 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-10-01 9:30 [Patch / 000](memory hotplug) Fix NULL pointer access of kmem_cache_node when hot-add Yasunori Goto
2007-10-01 9:33 ` [Patch / 001](memory hotplug) fix some defects of memory notifer callback interface Yasunori Goto
2007-10-01 9:34 ` Yasunori Goto [this message]
2007-10-01 20:34 ` [Patch / 002](memory hotplug) Callback function to create kmem_cache_node Christoph Lameter
2007-10-02 2:20 ` Yasunori Goto
2007-10-02 18:29 ` Christoph Lameter
2007-10-03 14:59 ` Yasunori Goto
2007-10-03 18:00 ` Christoph Lameter
2007-10-04 2:00 ` Yasunori Goto
2007-10-01 9:38 ` [Patch 000/002](memory hotplug) Fix NULL pointer access of kmem_cache_node when hot-add Yasunori Goto
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=20071001183316.7A9B.Y-GOTO@jp.fujitsu.com \
--to=y-goto@jp.fujitsu.com \
--cc=akpm@osdl.org \
--cc=clameter@sgi.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox