From: Christoph Lameter <cl@linux.com>
To: Pekka Enberg <penberg@cs.helsinki.fi>
Cc: linux-mm@kvack.org
Subject: [RFC] slub: Defer sysfs processing into a separate worker thread
Date: Thu, 10 May 2012 14:39:06 -0500 (CDT) [thread overview]
Message-ID: <alpine.DEB.2.00.1205101438360.18664@router.home> (raw)
sysfs processing has been causing a lot of trouble in the past. In
particular sysfs can trigger user space events that then will interrupt
slab processing. We do not want that. Defer sysfs event processing
into a kernel thread and let the slab functions finish regardless of
sysfs's actions.
Signed-off-by: Christoph Lameter <cl@linux.com>
---
mm/slub.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 47 insertions(+), 9 deletions(-)
Index: linux-2.6/mm/slub.c
===================================================================
--- linux-2.6.orig/mm/slub.c 2012-05-10 04:57:46.962582494 -0500
+++ linux-2.6/mm/slub.c 2012-05-10 08:36:07.742311030 -0500
@@ -3921,6 +3921,28 @@ static struct kmem_cache *find_mergeable
return NULL;
}
+/*
+ * Defer sysfs work into a kernel event thread so that userspace actions by
+ * sysfs do not cause havoc.
+ */
+struct sysfs_work_struct {
+ struct work_struct w;
+ struct kmem_cache *s;
+};
+
+void sysfs_slab_add_work(struct work_struct *w)
+{
+ struct kmem_cache *s = ((struct sysfs_work_struct *)w)->s;
+
+ kfree(w);
+ down_write(&slub_lock);
+ if (sysfs_slab_add(s))
+ printk(KERN_ERR "SLUB: Unable to add slab %s to /sys/kernel/slab\n", s->name);
+ up_write(&slub_lock);
+ /* Decrease refcount and free the cache if it was freed in the meantime */
+ kmem_cache_destroy(s);
+}
+
struct kmem_cache *kmem_cache_create(const char *name, size_t size,
size_t align, unsigned long flags, void (*ctor)(void *))
{
@@ -3957,11 +3979,32 @@ struct kmem_cache *kmem_cache_create(con
if (s) {
if (kmem_cache_open(s, n,
size, align, flags, ctor)) {
- list_add(&s->list, &slab_caches);
+ /*
+ * Deferred adding to sysfs since we do not want
+ * to wait for potential userspace processing
+ */
+ struct sysfs_work_struct *w;
+
+ if (slab_state < UP) {
+ w = kmalloc(sizeof(*w), GFP_KERNEL);
+
+ if (w) {
+ list_add(&s->list, &slab_caches);
+ /*
+ * Prevent kmem_cache from being
+ * released until work is complete.
+ */
+ s->refcount++;
+ INIT_WORK(&w->w, sysfs_slab_add_work);
+ w->s = s;
+ queue_work(system_unbound_wq, &w->w);
+ }
+ } else
+ w = ZERO_SIZE_PTR;
+
up_write(&slub_lock);
- if (sysfs_slab_add(s)) {
+ if (!w) {
down_write(&slub_lock);
- list_del(&s->list);
kfree(n);
kfree(s);
goto err;
@@ -5281,13 +5324,8 @@ static int sysfs_slab_add(struct kmem_ca
{
int err;
const char *name;
- int unmergeable;
-
- if (slab_state < SYSFS)
- /* Defer until later */
- return 0;
+ int unmergeable = slab_unmergeable(s);
- unmergeable = slab_unmergeable(s);
if (unmergeable) {
/*
* Slabcache can never be merged so we can use the name proper.
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
reply other threads:[~2012-05-10 20:06 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=alpine.DEB.2.00.1205101438360.18664@router.home \
--to=cl@linux.com \
--cc=linux-mm@kvack.org \
--cc=penberg@cs.helsinki.fi \
/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