diff options
author | Glauber Costa <glommer@parallels.com> | 2012-12-18 17:22:46 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-12-18 18:02:14 -0500 |
commit | b9ce5ef49f00daf2254c6953c8d31f79aabccd34 (patch) | |
tree | 1da6afdbb3dc2e2d31f588dbfbf502e984af48a6 /mm/slab.h | |
parent | 0e9d92f2d02d8c8320f0502307c688d07bdac2b3 (diff) |
sl[au]b: always get the cache from its page in kmem_cache_free()
struct page already has this information. If we start chaining caches,
this information will always be more trustworthy than whatever is passed
into the function.
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>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/slab.h')
-rw-r--r-- | mm/slab.h | 39 |
1 files changed, 39 insertions, 0 deletions
@@ -116,6 +116,13 @@ static inline bool cache_match_memcg(struct kmem_cache *cachep, | |||
116 | return (is_root_cache(cachep) && !memcg) || | 116 | return (is_root_cache(cachep) && !memcg) || |
117 | (cachep->memcg_params->memcg == memcg); | 117 | (cachep->memcg_params->memcg == memcg); |
118 | } | 118 | } |
119 | |||
120 | static inline bool slab_equal_or_root(struct kmem_cache *s, | ||
121 | struct kmem_cache *p) | ||
122 | { | ||
123 | return (p == s) || | ||
124 | (s->memcg_params && (p == s->memcg_params->root_cache)); | ||
125 | } | ||
119 | #else | 126 | #else |
120 | static inline bool is_root_cache(struct kmem_cache *s) | 127 | static inline bool is_root_cache(struct kmem_cache *s) |
121 | { | 128 | { |
@@ -127,5 +134,37 @@ static inline bool cache_match_memcg(struct kmem_cache *cachep, | |||
127 | { | 134 | { |
128 | return true; | 135 | return true; |
129 | } | 136 | } |
137 | |||
138 | static inline bool slab_equal_or_root(struct kmem_cache *s, | ||
139 | struct kmem_cache *p) | ||
140 | { | ||
141 | return true; | ||
142 | } | ||
130 | #endif | 143 | #endif |
144 | |||
145 | static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x) | ||
146 | { | ||
147 | struct kmem_cache *cachep; | ||
148 | struct page *page; | ||
149 | |||
150 | /* | ||
151 | * When kmemcg is not being used, both assignments should return the | ||
152 | * same value. but we don't want to pay the assignment price in that | ||
153 | * case. If it is not compiled in, the compiler should be smart enough | ||
154 | * to not do even the assignment. In that case, slab_equal_or_root | ||
155 | * will also be a constant. | ||
156 | */ | ||
157 | if (!memcg_kmem_enabled() && !unlikely(s->flags & SLAB_DEBUG_FREE)) | ||
158 | return s; | ||
159 | |||
160 | page = virt_to_head_page(x); | ||
161 | cachep = page->slab_cache; | ||
162 | if (slab_equal_or_root(cachep, s)) | ||
163 | return cachep; | ||
164 | |||
165 | pr_err("%s: Wrong slab cache. %s but object is from %s\n", | ||
166 | __FUNCTION__, cachep->name, s->name); | ||
167 | WARN_ON_ONCE(1); | ||
168 | return s; | ||
169 | } | ||
131 | #endif | 170 | #endif |