]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
slab: annotate on-slab caches nodelist locks
authorGlauber Costa <glommer@parallels.com>
Fri, 9 Nov 2012 03:04:14 +0000 (14:04 +1100)
committerStephen Rothwell <sfr@canb.auug.org.au>
Tue, 13 Nov 2012 05:15:28 +0000 (16:15 +1100)
We currently provide lockdep annotation for kmalloc caches, and also
caches that have SLAB_DEBUG_OBJECTS enabled.  The reason for this is that
we can quite frequently nest in the l3->list_lock lock, which is not
something trivial to avoid.

My proposal with this patch, is to extend this to caches whose slab
management object lives within the slab as well ("on_slab").  The need for
this arose in the context of testing kmemcg-slab patches.  With such
patchset, we can have per-memcg kmalloc caches.  So the same path that led
to nesting between kmalloc caches will could then lead to in-memcg
nesting.  Because they are not annotated, lockdep will trigger.

Signed-off-by: Glauber Costa <glommer@parallels.com>
Cc: Christoph Lameter <cl@linux.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Frederic Weisbecker <fweisbec@redhat.com>
Cc: Greg Thelen <gthelen@google.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: JoonSoo Kim <js1304@gmail.com>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Mel Gorman <mel@csn.ul.ie>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: Pekka Enberg <penberg@cs.helsinki.fi>
Cc: Rik van Riel <riel@redhat.com>
Cc: Suleiman Souhlal <suleiman@google.com>
Cc: Tejun Heo <tj@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/slab.c

index 6ebb9515a3e96b607d7a1863054882e8c994911a..cb9fb9c1de68b3384c2f77cb43c28720d72f1de7 100644 (file)
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -645,6 +645,26 @@ static void init_node_lock_keys(int q)
        }
 }
 
+static void on_slab_lock_classes_node(struct kmem_cache *cachep, int q)
+{
+       struct kmem_list3 *l3;
+       l3 = cachep->nodelists[q];
+       if (!l3)
+               return;
+
+       slab_set_lock_classes(cachep, &on_slab_l3_key,
+                       &on_slab_alc_key, q);
+}
+
+static inline void on_slab_lock_classes(struct kmem_cache *cachep)
+{
+       int node;
+
+       VM_BUG_ON(OFF_SLAB(cachep));
+       for_each_node(node)
+               on_slab_lock_classes_node(cachep, node);
+}
+
 static inline void init_lock_keys(void)
 {
        int node;
@@ -661,6 +681,14 @@ static inline void init_lock_keys(void)
 {
 }
 
+static inline void on_slab_lock_classes(struct kmem_cache *cachep)
+{
+}
+
+static inline void on_slab_lock_classes_node(struct kmem_cache *cachep, int node)
+{
+}
+
 static void slab_set_debugobj_lock_classes_node(struct kmem_cache *cachep, int node)
 {
 }
@@ -1389,6 +1417,9 @@ static int __cpuinit cpuup_prepare(long cpu)
                free_alien_cache(alien);
                if (cachep->flags & SLAB_DEBUG_OBJECTS)
                        slab_set_debugobj_lock_classes_node(cachep, node);
+               else if (!OFF_SLAB(cachep) &&
+                        !(cachep->flags & SLAB_DESTROY_BY_RCU))
+                       on_slab_lock_classes_node(cachep, node);
        }
        init_node_lock_keys(node);
 
@@ -2544,7 +2575,8 @@ __kmem_cache_create (struct kmem_cache *cachep, unsigned long flags)
                WARN_ON_ONCE(flags & SLAB_DESTROY_BY_RCU);
 
                slab_set_debugobj_lock_classes(cachep);
-       }
+       } else if (!OFF_SLAB(cachep) && !(flags & SLAB_DESTROY_BY_RCU))
+               on_slab_lock_classes(cachep);
 
        return 0;
 }