mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-29 03:01:39 -04:00
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 <[email protected]> Cc: Christoph Lameter <[email protected]> Cc: David Rientjes <[email protected]> Cc: Frederic Weisbecker <[email protected]> Cc: Greg Thelen <[email protected]> Cc: Johannes Weiner <[email protected]> Cc: JoonSoo Kim <[email protected]> Cc: KAMEZAWA Hiroyuki <[email protected]> Cc: Mel Gorman <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Pekka Enberg <[email protected]> Cc: Rik van Riel <[email protected]> Cc: Suleiman Souhlal <[email protected]> Cc: Tejun Heo <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
This commit is contained in:
parent
0e9d92f2d0
commit
b9ce5ef49f
5 changed files with 53 additions and 14 deletions
39
mm/slab.h
39
mm/slab.h
|
|
@ -116,6 +116,13 @@ static inline bool cache_match_memcg(struct kmem_cache *cachep,
|
|||
return (is_root_cache(cachep) && !memcg) ||
|
||||
(cachep->memcg_params->memcg == memcg);
|
||||
}
|
||||
|
||||
static inline bool slab_equal_or_root(struct kmem_cache *s,
|
||||
struct kmem_cache *p)
|
||||
{
|
||||
return (p == s) ||
|
||||
(s->memcg_params && (p == s->memcg_params->root_cache));
|
||||
}
|
||||
#else
|
||||
static inline bool is_root_cache(struct kmem_cache *s)
|
||||
{
|
||||
|
|
@ -127,5 +134,37 @@ static inline bool cache_match_memcg(struct kmem_cache *cachep,
|
|||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline bool slab_equal_or_root(struct kmem_cache *s,
|
||||
struct kmem_cache *p)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
|
||||
{
|
||||
struct kmem_cache *cachep;
|
||||
struct page *page;
|
||||
|
||||
/*
|
||||
* When kmemcg is not being used, both assignments should return the
|
||||
* same value. but we don't want to pay the assignment price in that
|
||||
* case. If it is not compiled in, the compiler should be smart enough
|
||||
* to not do even the assignment. In that case, slab_equal_or_root
|
||||
* will also be a constant.
|
||||
*/
|
||||
if (!memcg_kmem_enabled() && !unlikely(s->flags & SLAB_DEBUG_FREE))
|
||||
return s;
|
||||
|
||||
page = virt_to_head_page(x);
|
||||
cachep = page->slab_cache;
|
||||
if (slab_equal_or_root(cachep, s))
|
||||
return cachep;
|
||||
|
||||
pr_err("%s: Wrong slab cache. %s but object is from %s\n",
|
||||
__FUNCTION__, cachep->name, s->name);
|
||||
WARN_ON_ONCE(1);
|
||||
return s;
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in a new issue