diff options
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 |