Skip to content

Commit ed4cd17

Browse files
hygonitehcaster
authored andcommitted
mm/sl[au]b: introduce common alloc/free functions without tracepoint
To unify kmalloc functions in later patch, introduce common alloc/free functions that does not have tracepoint. Signed-off-by: Hyeonggon Yoo <[email protected]> Reviewed-by: Vlastimil Babka <[email protected]> Signed-off-by: Vlastimil Babka <[email protected]>
1 parent d6a7164 commit ed4cd17

File tree

3 files changed

+47
-7
lines changed

3 files changed

+47
-7
lines changed

mm/slab.c

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3560,6 +3560,14 @@ void *kmem_cache_alloc_node(struct kmem_cache *cachep, gfp_t flags, int nodeid)
35603560
}
35613561
EXPORT_SYMBOL(kmem_cache_alloc_node);
35623562

3563+
void *__kmem_cache_alloc_node(struct kmem_cache *cachep, gfp_t flags,
3564+
int nodeid, size_t orig_size,
3565+
unsigned long caller)
3566+
{
3567+
return slab_alloc_node(cachep, NULL, flags, nodeid,
3568+
orig_size, caller);
3569+
}
3570+
35633571
#ifdef CONFIG_TRACING
35643572
void *kmem_cache_alloc_node_trace(struct kmem_cache *cachep,
35653573
gfp_t flags,
@@ -3645,6 +3653,26 @@ void *__kmalloc(size_t size, gfp_t flags)
36453653
}
36463654
EXPORT_SYMBOL(__kmalloc);
36473655

3656+
static __always_inline
3657+
void __do_kmem_cache_free(struct kmem_cache *cachep, void *objp,
3658+
unsigned long caller)
3659+
{
3660+
unsigned long flags;
3661+
3662+
local_irq_save(flags);
3663+
debug_check_no_locks_freed(objp, cachep->object_size);
3664+
if (!(cachep->flags & SLAB_DEBUG_OBJECTS))
3665+
debug_check_no_obj_freed(objp, cachep->object_size);
3666+
__cache_free(cachep, objp, caller);
3667+
local_irq_restore(flags);
3668+
}
3669+
3670+
void __kmem_cache_free(struct kmem_cache *cachep, void *objp,
3671+
unsigned long caller)
3672+
{
3673+
__do_kmem_cache_free(cachep, objp, caller);
3674+
}
3675+
36483676
/**
36493677
* kmem_cache_free - Deallocate an object
36503678
* @cachep: The cache the allocation was from.
@@ -3655,18 +3683,12 @@ EXPORT_SYMBOL(__kmalloc);
36553683
*/
36563684
void kmem_cache_free(struct kmem_cache *cachep, void *objp)
36573685
{
3658-
unsigned long flags;
36593686
cachep = cache_from_obj(cachep, objp);
36603687
if (!cachep)
36613688
return;
36623689

36633690
trace_kmem_cache_free(_RET_IP_, objp, cachep->name);
3664-
local_irq_save(flags);
3665-
debug_check_no_locks_freed(objp, cachep->object_size);
3666-
if (!(cachep->flags & SLAB_DEBUG_OBJECTS))
3667-
debug_check_no_obj_freed(objp, cachep->object_size);
3668-
__cache_free(cachep, objp, _RET_IP_);
3669-
local_irq_restore(flags);
3691+
__do_kmem_cache_free(cachep, objp, _RET_IP_);
36703692
}
36713693
EXPORT_SYMBOL(kmem_cache_free);
36723694

mm/slab.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,11 @@ void create_kmalloc_caches(slab_flags_t);
273273

274274
/* Find the kmalloc slab corresponding for a certain size */
275275
struct kmem_cache *kmalloc_slab(size_t, gfp_t);
276+
277+
void *__kmem_cache_alloc_node(struct kmem_cache *s, gfp_t gfpflags,
278+
int node, size_t orig_size,
279+
unsigned long caller);
280+
void __kmem_cache_free(struct kmem_cache *s, void *x, unsigned long caller);
276281
#endif
277282

278283
void *kmalloc_large_node_notrace(size_t size, gfp_t flags, int node);

mm/slub.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3262,6 +3262,14 @@ void *kmem_cache_alloc_lru(struct kmem_cache *s, struct list_lru *lru,
32623262
}
32633263
EXPORT_SYMBOL(kmem_cache_alloc_lru);
32643264

3265+
void *__kmem_cache_alloc_node(struct kmem_cache *s, gfp_t gfpflags,
3266+
int node, size_t orig_size,
3267+
unsigned long caller)
3268+
{
3269+
return slab_alloc_node(s, NULL, gfpflags, node,
3270+
caller, orig_size);
3271+
}
3272+
32653273
#ifdef CONFIG_TRACING
32663274
void *kmem_cache_alloc_trace(struct kmem_cache *s, gfp_t gfpflags, size_t size)
32673275
{
@@ -3526,6 +3534,11 @@ void ___cache_free(struct kmem_cache *cache, void *x, unsigned long addr)
35263534
}
35273535
#endif
35283536

3537+
void __kmem_cache_free(struct kmem_cache *s, void *x, unsigned long caller)
3538+
{
3539+
slab_free(s, virt_to_slab(x), x, NULL, &x, 1, caller);
3540+
}
3541+
35293542
void kmem_cache_free(struct kmem_cache *s, void *x)
35303543
{
35313544
s = cache_from_obj(s, x);

0 commit comments

Comments
 (0)