pid: tighten pidmap spinlock critical section by removing kfree()
authorAndré Goddard Rosa <andre.goddard@gmail.com>
Wed, 16 Dec 2009 00:47:39 +0000 (16:47 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 16 Dec 2009 15:20:12 +0000 (07:20 -0800)
Avoid calling kfree() under pidmap spinlock, calling it afterwards.

Normally kfree() is fast, but sometimes it can be slow, so avoid
calling it under the spinlock if we can do it.

Signed-off-by: André Goddard Rosa <andre.goddard@gmail.com>
Cc: Pekka Enberg <penberg@cs.helsinki.fi>
Cc: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
kernel/pid.c

index d3f722d20f9c6e8d849693a1754b616d3ba74bea..55fd5900bac87d2bfa6025c340478248e2429137 100644 (file)
@@ -141,11 +141,12 @@ static int alloc_pidmap(struct pid_namespace *pid_ns)
                         * installing it:
                         */
                        spin_lock_irq(&pidmap_lock);
-                       if (map->page)
-                               kfree(page);
-                       else
+                       if (!map->page) {
                                map->page = page;
+                               page = NULL;
+                       }
                        spin_unlock_irq(&pidmap_lock);
+                       kfree(page);
                        if (unlikely(!map->page))
                                break;
                }