Skip to content

Commit b0b3478

Browse files
Zhenhua Huangjfvogel
authored andcommitted
mm, slab: clean up slab->obj_exts always
commit be8250786ca94952a19ce87f98ad9906448bc9ef upstream. 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]> [surenb: fixed trivial merge conflict in alloc_tagging_slab_alloc_hook(), skipped inlining free_slab_obj_exts() as it's already inline in 6.12] Signed-off-by: Suren Baghdasaryan <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> (cherry picked from commit dab2a13059a475b6392550f882276e170fe2fcff) Signed-off-by: Jack Vogel <[email protected]>
1 parent 84fae2f commit b0b3478

File tree

1 file changed

+7
-20
lines changed

1 file changed

+7
-20
lines changed

mm/slub.c

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2039,18 +2039,6 @@ static inline void free_slab_obj_exts(struct slab *slab)
20392039
slab->obj_exts = 0;
20402040
}
20412041

2042-
static inline bool need_slab_obj_ext(void)
2043-
{
2044-
if (mem_alloc_profiling_enabled())
2045-
return true;
2046-
2047-
/*
2048-
* CONFIG_MEMCG creates vector of obj_cgroup objects conditionally
2049-
* inside memcg_slab_post_alloc_hook. No other users for now.
2050-
*/
2051-
return false;
2052-
}
2053-
20542042
#else /* CONFIG_SLAB_OBJ_EXT */
20552043

20562044
static inline void init_slab_obj_exts(struct slab *slab)
@@ -2067,11 +2055,6 @@ static inline void free_slab_obj_exts(struct slab *slab)
20672055
{
20682056
}
20692057

2070-
static inline bool need_slab_obj_ext(void)
2071-
{
2072-
return false;
2073-
}
2074-
20752058
#endif /* CONFIG_SLAB_OBJ_EXT */
20762059

20772060
#ifdef CONFIG_MEM_ALLOC_PROFILING
@@ -2103,7 +2086,7 @@ prepare_slab_obj_exts_hook(struct kmem_cache *s, gfp_t flags, void *p)
21032086
static inline void
21042087
alloc_tagging_slab_alloc_hook(struct kmem_cache *s, void *object, gfp_t flags)
21052088
{
2106-
if (need_slab_obj_ext()) {
2089+
if (mem_alloc_profiling_enabled()) {
21072090
struct slabobj_ext *obj_exts;
21082091

21092092
obj_exts = prepare_slab_obj_exts_hook(s, flags, object);
@@ -2581,8 +2564,12 @@ static __always_inline void account_slab(struct slab *slab, int order,
25812564
static __always_inline void unaccount_slab(struct slab *slab, int order,
25822565
struct kmem_cache *s)
25832566
{
2584-
if (memcg_kmem_online() || need_slab_obj_ext())
2585-
free_slab_obj_exts(slab);
2567+
/*
2568+
* The slab object extensions should now be freed regardless of
2569+
* whether mem_alloc_profiling_enabled() or not because profiling
2570+
* might have been disabled after slab->obj_exts got allocated.
2571+
*/
2572+
free_slab_obj_exts(slab);
25862573

25872574
mod_node_page_state(slab_pgdat(slab), cache_vmstat_idx(s),
25882575
-(PAGE_SIZE << order));

0 commit comments

Comments
 (0)