[PATCH 1/2] mm/slab: move obj_exts_in_slab() definition to slab.h

ranxiaokai627
2026-03-10T11:38:45Z

Move the definition of obj_exts_in_slab() to slab.h. This is in
preparation for the next patch, which needs to access this helper
from memcontrol.c.

No functional change intended.

Signed-off-by: Ran Xiaokai <ran.xiaokai@zte.com.cn>
---
mm/slab.h | 19 +++++++++++++++++++
mm/slub.c | 19 -------------------
2 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/mm/slab.h b/mm/slab.h
index 77242024e7d5..8354d5669ee7 100644
--- a/mm/slab.h
+++ b/mm/slab.h
@@ -597,6 +597,21 @@ static inline struct slabobj_ext *slab_obj_ext(struct slab *slab,
return kasan_reset_tag(obj_ext);
}

+static inline bool obj_exts_in_slab(struct kmem_cache *s, struct slab *slab)
+{
+ unsigned long obj_exts;
+ unsigned long start;
+ unsigned long end;
+
+ obj_exts = slab_obj_exts(slab);
+ if (!obj_exts)
+ return false;
+
+ start = (unsigned long)slab_address(slab);
+ end = start + slab_size(slab);
+ return (obj_exts >= start) && (obj_exts < end);
+}
+
int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s,
gfp_t gfp, bool new_slab);

@@ -617,6 +632,10 @@ static inline struct slabobj_ext *slab_obj_ext(struct slab *slab,
static inline void slab_set_stride(struct slab *slab, unsigned int stride) { }
static inline unsigned int slab_get_stride(struct slab *slab) { return 0; }

+static inline bool obj_exts_in_slab(struct kmem_cache *s, struct slab *slab)
+{
+ return false;
+}

#endif /* CONFIG_SLAB_OBJ_EXT */

diff --git a/mm/slub.c b/mm/slub.c
index 1871c5ef354a..845a67736688 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -808,20 +808,6 @@ static inline bool obj_exts_fit_within_slab_leftover(struct kmem_cache *s,
return objext_offset + objext_size <= slab_size(slab);
}

-static inline bool obj_exts_in_slab(struct kmem_cache *s, struct slab *slab)
-{
- unsigned long obj_exts;
- unsigned long start;
- unsigned long end;
-
- obj_exts = slab_obj_exts(slab);
- if (!obj_exts)
- return false;
-
- start = (unsigned long)slab_address(slab);
- end = start + slab_size(slab);
- return (obj_exts >= start) && (obj_exts < end);
-}
#else
static inline bool need_slab_obj_exts(struct kmem_cache *s)
{
@@ -845,11 +831,6 @@ static inline bool obj_exts_fit_within_slab_leftover(struct kmem_cache *s,
return false;
}

-static inline bool obj_exts_in_slab(struct kmem_cache *s, struct slab *slab)
-{
- return false;
-}
-
#endif

#if defined(CONFIG_SLAB_OBJ_EXT) && defined(CONFIG_64BIT)
--
2.25.1