Skip to content

Commit be82507

Browse files
Zhenhua Huangtehcaster
authored andcommitted
mm, slab: clean up slab->obj_exts always
When memory allocation profiling is disabled at runtime or due to an error, shutdown_mem_profiling() is called: slab->obj_exts which previously allocated remains. It won't be cleared by unaccount_slab() because of mem_alloc_profiling_enabled() not true. It's incorrect, slab->obj_exts should always be cleaned up in unaccount_slab() to avoid following error: [...]BUG: Bad page state in process... .. [...]page dumped because: page still charged to cgroup [[email protected]: fold need_slab_obj_ext() into its only user] Fixes: 21c690a ("mm: introduce slabobj_ext to support slab object extensions") Cc: [email protected] Signed-off-by: Zhenhua Huang <[email protected]> Acked-by: David Rientjes <[email protected]> Acked-by: Harry Yoo <[email protected]> Tested-by: Harry Yoo <[email protected]> Acked-by: Suren Baghdasaryan <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Vlastimil Babka <[email protected]>
1 parent d2f5819 commit be82507

File tree

1 file changed

+8
-22
lines changed

1 file changed

+8
-22
lines changed

mm/slub.c

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2028,8 +2028,7 @@ int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s,
20282028
return 0;
20292029
}
20302030

2031-
/* Should be called only if mem_alloc_profiling_enabled() */
2032-
static noinline void free_slab_obj_exts(struct slab *slab)
2031+
static inline void free_slab_obj_exts(struct slab *slab)
20332032
{
20342033
struct slabobj_ext *obj_exts;
20352034

@@ -2049,18 +2048,6 @@ static noinline void free_slab_obj_exts(struct slab *slab)
20492048
slab->obj_exts = 0;
20502049
}
20512050

2052-
static inline bool need_slab_obj_ext(void)
2053-
{
2054-
if (mem_alloc_profiling_enabled())
2055-
return true;
2056-
2057-
/*
2058-
* CONFIG_MEMCG creates vector of obj_cgroup objects conditionally
2059-
* inside memcg_slab_post_alloc_hook. No other users for now.
2060-
*/
2061-
return false;
2062-
}
2063-
20642051
#else /* CONFIG_SLAB_OBJ_EXT */
20652052

20662053
static inline void init_slab_obj_exts(struct slab *slab)
@@ -2077,11 +2064,6 @@ static inline void free_slab_obj_exts(struct slab *slab)
20772064
{
20782065
}
20792066

2080-
static inline bool need_slab_obj_ext(void)
2081-
{
2082-
return false;
2083-
}
2084-
20852067
#endif /* CONFIG_SLAB_OBJ_EXT */
20862068

20872069
#ifdef CONFIG_MEM_ALLOC_PROFILING
@@ -2129,7 +2111,7 @@ __alloc_tagging_slab_alloc_hook(struct kmem_cache *s, void *object, gfp_t flags)
21292111
static inline void
21302112
alloc_tagging_slab_alloc_hook(struct kmem_cache *s, void *object, gfp_t flags)
21312113
{
2132-
if (need_slab_obj_ext())
2114+
if (mem_alloc_profiling_enabled())
21332115
__alloc_tagging_slab_alloc_hook(s, object, flags);
21342116
}
21352117

@@ -2601,8 +2583,12 @@ static __always_inline void account_slab(struct slab *slab, int order,
26012583
static __always_inline void unaccount_slab(struct slab *slab, int order,
26022584
struct kmem_cache *s)
26032585
{
2604-
if (memcg_kmem_online() || need_slab_obj_ext())
2605-
free_slab_obj_exts(slab);
2586+
/*
2587+
* The slab object extensions should now be freed regardless of
2588+
* whether mem_alloc_profiling_enabled() or not because profiling
2589+
* might have been disabled after slab->obj_exts got allocated.
2590+
*/
2591+
free_slab_obj_exts(slab);
26062592

26072593
mod_node_page_state(slab_pgdat(slab), cache_vmstat_idx(s),
26082594
-(PAGE_SIZE << order));

0 commit comments

Comments
 (0)