Skip to content

Commit 27125df

Browse files
hygonitehcaster
authored andcommitted
mm/slab: drop the OBJEXTS_NOSPIN_ALLOC flag from enum objext_flags
OBJEXTS_NOSPIN_ALLOC was used to remember whether a slabobj_ext vector was allocated via kmalloc_nolock(), so that free_slab_obj_exts() could call kfree_nolock() instead of kfree(). Now that kfree() supports freeing kmalloc_nolock() objects, this flag is no longer needed. Instead, pass the allow_spin parameter down to free_slab_obj_exts() to determine whether kfree_nolock() or kfree() should be called in the free path, and free one bit in enum objext_flags. Acked-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Harry Yoo <harry.yoo@oracle.com> Reviewed-by: Hao Li <hao.li@linux.dev> Link: https://patch.msgid.link/20260210044642.139482-3-harry.yoo@oracle.com Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
1 parent c4d6d78 commit 27125df

2 files changed

Lines changed: 9 additions & 12 deletions

File tree

include/linux/memcontrol.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,7 @@ enum objext_flags {
359359
* MEMCG_DATA_OBJEXTS.
360360
*/
361361
OBJEXTS_ALLOC_FAIL = __OBJEXTS_ALLOC_FAIL,
362-
/* slabobj_ext vector allocated with kmalloc_nolock() */
363-
OBJEXTS_NOSPIN_ALLOC = __FIRST_OBJEXT_FLAG,
362+
__OBJEXTS_FLAG_UNUSED = __FIRST_OBJEXT_FLAG,
364363
/* the next bit after the last actual flag */
365364
__NR_OBJEXTS_FLAGS = (__FIRST_OBJEXT_FLAG << 1),
366365
};

mm/slub.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2190,8 +2190,6 @@ int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s,
21902190
virt_to_slab(vec)->slab_cache == s);
21912191

21922192
new_exts = (unsigned long)vec;
2193-
if (unlikely(!allow_spin))
2194-
new_exts |= OBJEXTS_NOSPIN_ALLOC;
21952193
#ifdef CONFIG_MEMCG
21962194
new_exts |= MEMCG_DATA_OBJEXTS;
21972195
#endif
@@ -2229,7 +2227,7 @@ int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s,
22292227
return 0;
22302228
}
22312229

2232-
static inline void free_slab_obj_exts(struct slab *slab)
2230+
static inline void free_slab_obj_exts(struct slab *slab, bool allow_spin)
22332231
{
22342232
struct slabobj_ext *obj_exts;
22352233

@@ -2257,10 +2255,10 @@ static inline void free_slab_obj_exts(struct slab *slab)
22572255
* the extension for obj_exts is expected to be NULL.
22582256
*/
22592257
mark_objexts_empty(obj_exts);
2260-
if (unlikely(READ_ONCE(slab->obj_exts) & OBJEXTS_NOSPIN_ALLOC))
2261-
kfree_nolock(obj_exts);
2262-
else
2258+
if (allow_spin)
22632259
kfree(obj_exts);
2260+
else
2261+
kfree_nolock(obj_exts);
22642262
slab->obj_exts = 0;
22652263
}
22662264

@@ -2324,7 +2322,7 @@ static int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s,
23242322
return 0;
23252323
}
23262324

2327-
static inline void free_slab_obj_exts(struct slab *slab)
2325+
static inline void free_slab_obj_exts(struct slab *slab, bool allow_spin)
23282326
{
23292327
}
23302328

@@ -3404,14 +3402,14 @@ static __always_inline void account_slab(struct slab *slab, int order,
34043402
}
34053403

34063404
static __always_inline void unaccount_slab(struct slab *slab, int order,
3407-
struct kmem_cache *s)
3405+
struct kmem_cache *s, bool allow_spin)
34083406
{
34093407
/*
34103408
* The slab object extensions should now be freed regardless of
34113409
* whether mem_alloc_profiling_enabled() or not because profiling
34123410
* might have been disabled after slab->obj_exts got allocated.
34133411
*/
3414-
free_slab_obj_exts(slab);
3412+
free_slab_obj_exts(slab, allow_spin);
34153413

34163414
mod_node_page_state(slab_pgdat(slab), cache_vmstat_idx(s),
34173415
-(PAGE_SIZE << order));
@@ -3515,7 +3513,7 @@ static void __free_slab(struct kmem_cache *s, struct slab *slab, bool allow_spin
35153513
page->mapping = NULL;
35163514
__ClearPageSlab(page);
35173515
mm_account_reclaimed_pages(pages);
3518-
unaccount_slab(slab, order, s);
3516+
unaccount_slab(slab, order, s, allow_spin);
35193517
if (allow_spin)
35203518
free_frozen_pages(page, order);
35213519
else

0 commit comments

Comments
 (0)