X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=mm%2Fslab.h;h=8184a7cde272b8aa9d6e08e6407482ca5d7bd7df;hb=ca2a650f3dfdc30d71d21bcbb04d2d057779f3f9;hp=0859c4241ba10b2ee602eca48af4e34dd82d6ae3;hpb=db8fbb49df8ae4da155d3b7abf39e79b41f72746;p=~andy%2Flinux diff --git a/mm/slab.h b/mm/slab.h index 0859c4241ba..8184a7cde27 100644 --- a/mm/slab.h +++ b/mm/slab.h @@ -160,12 +160,36 @@ static inline const char *cache_name(struct kmem_cache *s) return s->name; } +/* + * Note, we protect with RCU only the memcg_caches array, not per-memcg caches. + * That said the caller must assure the memcg's cache won't go away. Since once + * created a memcg's cache is destroyed only along with the root cache, it is + * true if we are going to allocate from the cache or hold a reference to the + * root cache by other means. Otherwise, we should hold either the slab_mutex + * or the memcg's slab_caches_mutex while calling this function and accessing + * the returned value. + */ static inline struct kmem_cache * cache_from_memcg_idx(struct kmem_cache *s, int idx) { + struct kmem_cache *cachep; + struct memcg_cache_params *params; + if (!s->memcg_params) return NULL; - return s->memcg_params->memcg_caches[idx]; + + rcu_read_lock(); + params = rcu_dereference(s->memcg_params); + cachep = params->memcg_caches[idx]; + rcu_read_unlock(); + + /* + * Make sure we will access the up-to-date value. The code updating + * memcg_caches issues a write barrier to match this (see + * memcg_register_cache()). + */ + smp_read_barrier_depends(); + return cachep; } static inline struct kmem_cache *memcg_root_cache(struct kmem_cache *s)