Skip to content

Commit bf37d79

Browse files
hygonitehcaster
authored andcommitted
mm/slab_common: kmalloc_node: pass large requests to page allocator
Now that kmalloc_large_node() is in common code, pass large requests to page allocator in kmalloc_node() using kmalloc_large_node(). One problem is that currently there is no tracepoint in kmalloc_large_node(). Instead of simply putting tracepoint in it, use kmalloc_large_node{,_notrace} depending on its caller to show useful address for both inlined kmalloc_node() and __kmalloc_node_track_caller() when large objects are allocated. Signed-off-by: Hyeonggon Yoo <[email protected]> Reviewed-by: Vlastimil Babka <[email protected]> Signed-off-by: Vlastimil Babka <[email protected]>
1 parent a0c3b94 commit bf37d79

File tree

4 files changed

+32
-9
lines changed

4 files changed

+32
-9
lines changed

include/linux/slab.h

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -571,23 +571,35 @@ static __always_inline __alloc_size(1) void *kmalloc(size_t size, gfp_t flags)
571571
return __kmalloc(size, flags);
572572
}
573573

574+
#ifndef CONFIG_SLOB
574575
static __always_inline __alloc_size(1) void *kmalloc_node(size_t size, gfp_t flags, int node)
575576
{
576-
#ifndef CONFIG_SLOB
577-
if (__builtin_constant_p(size) &&
578-
size <= KMALLOC_MAX_CACHE_SIZE) {
579-
unsigned int i = kmalloc_index(size);
577+
if (__builtin_constant_p(size)) {
578+
unsigned int index;
580579

581-
if (!i)
580+
if (size > KMALLOC_MAX_CACHE_SIZE)
581+
return kmalloc_large_node(size, flags, node);
582+
583+
index = kmalloc_index(size);
584+
585+
if (!index)
582586
return ZERO_SIZE_PTR;
583587

584588
return kmem_cache_alloc_node_trace(
585-
kmalloc_caches[kmalloc_type(flags)][i],
589+
kmalloc_caches[kmalloc_type(flags)][index],
586590
flags, node, size);
587591
}
588-
#endif
589592
return __kmalloc_node(size, flags, node);
590593
}
594+
#else
595+
static __always_inline __alloc_size(1) void *kmalloc_node(size_t size, gfp_t flags, int node)
596+
{
597+
if (__builtin_constant_p(size) && size > KMALLOC_MAX_CACHE_SIZE)
598+
return kmalloc_large_node(size, flags, node);
599+
600+
return __kmalloc_node(size, flags, node);
601+
}
602+
#endif
591603

592604
/**
593605
* kmalloc_array - allocate memory for an array.

mm/slab.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ void create_kmalloc_caches(slab_flags_t);
275275
struct kmem_cache *kmalloc_slab(size_t, gfp_t);
276276
#endif
277277

278+
void *kmalloc_large_node_notrace(size_t size, gfp_t flags, int node);
279+
278280
gfp_t kmalloc_fix_flags(gfp_t flags);
279281

280282
/* Functions provided by the slab allocators */

mm/slab_common.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ void *kmalloc_large(size_t size, gfp_t flags)
928928
}
929929
EXPORT_SYMBOL(kmalloc_large);
930930

931-
void *kmalloc_large_node(size_t size, gfp_t flags, int node)
931+
void *kmalloc_large_node_notrace(size_t size, gfp_t flags, int node)
932932
{
933933
struct page *page;
934934
void *ptr = NULL;
@@ -948,6 +948,15 @@ void *kmalloc_large_node(size_t size, gfp_t flags, int node)
948948

949949
return ptr;
950950
}
951+
952+
void *kmalloc_large_node(size_t size, gfp_t flags, int node)
953+
{
954+
void *ret = kmalloc_large_node_notrace(size, flags, node);
955+
956+
trace_kmalloc_node(_RET_IP_, ret, NULL, size,
957+
PAGE_SIZE << get_order(size), flags, node);
958+
return ret;
959+
}
951960
EXPORT_SYMBOL(kmalloc_large_node);
952961

953962
#ifdef CONFIG_SLAB_FREELIST_RANDOM

mm/slub.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4401,7 +4401,7 @@ void *__do_kmalloc_node(size_t size, gfp_t flags, int node, unsigned long caller
44014401
void *ret;
44024402

44034403
if (unlikely(size > KMALLOC_MAX_CACHE_SIZE)) {
4404-
ret = kmalloc_large_node(size, flags, node);
4404+
ret = kmalloc_large_node_notrace(size, flags, node);
44054405

44064406
trace_kmalloc_node(caller, ret, NULL,
44074407
size, PAGE_SIZE << get_order(size),

0 commit comments

Comments
 (0)