Skip to content

Commit 2e8000b

Browse files
keestehcaster
authored andcommitted
mm/slab: Introduce kvmalloc_buckets_node() that can take kmem_buckets argument
Plumb kmem_buckets arguments through kvmalloc_node_noprof() so it is possible to provide an API to perform kvmalloc-style allocations with a particular set of buckets. Introduce kvmalloc_buckets_node() that takes a kmem_buckets argument. Signed-off-by: Kees Cook <[email protected]> Signed-off-by: Vlastimil Babka <[email protected]>
1 parent 67f2df3 commit 2e8000b

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

include/linux/slab.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,9 @@ static inline __alloc_size(1) void *kzalloc_noprof(size_t size, gfp_t flags)
799799
#define kzalloc(...) alloc_hooks(kzalloc_noprof(__VA_ARGS__))
800800
#define kzalloc_node(_size, _flags, _node) kmalloc_node(_size, (_flags)|__GFP_ZERO, _node)
801801

802-
extern void *kvmalloc_node_noprof(size_t size, gfp_t flags, int node) __alloc_size(1);
802+
void *__kvmalloc_node_noprof(DECL_BUCKET_PARAMS(size, b), gfp_t flags, int node) __alloc_size(1);
803+
#define kvmalloc_node_noprof(size, flags, node) \
804+
__kvmalloc_node_noprof(PASS_BUCKET_PARAMS(size, NULL), flags, node)
803805
#define kvmalloc_node(...) alloc_hooks(kvmalloc_node_noprof(__VA_ARGS__))
804806

805807
#define kvmalloc(_size, _flags) kvmalloc_node(_size, _flags, NUMA_NO_NODE)

mm/util.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -594,9 +594,10 @@ unsigned long vm_mmap(struct file *file, unsigned long addr,
594594
EXPORT_SYMBOL(vm_mmap);
595595

596596
/**
597-
* kvmalloc_node - attempt to allocate physically contiguous memory, but upon
597+
* __kvmalloc_node - attempt to allocate physically contiguous memory, but upon
598598
* failure, fall back to non-contiguous (vmalloc) allocation.
599599
* @size: size of the request.
600+
* @b: which set of kmalloc buckets to allocate from.
600601
* @flags: gfp mask for the allocation - must be compatible (superset) with GFP_KERNEL.
601602
* @node: numa node to allocate from
602603
*
@@ -609,7 +610,7 @@ EXPORT_SYMBOL(vm_mmap);
609610
*
610611
* Return: pointer to the allocated memory of %NULL in case of failure
611612
*/
612-
void *kvmalloc_node_noprof(size_t size, gfp_t flags, int node)
613+
void *__kvmalloc_node_noprof(DECL_BUCKET_PARAMS(size, b), gfp_t flags, int node)
613614
{
614615
gfp_t kmalloc_flags = flags;
615616
void *ret;
@@ -631,7 +632,7 @@ void *kvmalloc_node_noprof(size_t size, gfp_t flags, int node)
631632
kmalloc_flags &= ~__GFP_NOFAIL;
632633
}
633634

634-
ret = kmalloc_node_noprof(size, kmalloc_flags, node);
635+
ret = __kmalloc_node_noprof(PASS_BUCKET_PARAMS(size, b), kmalloc_flags, node);
635636

636637
/*
637638
* It doesn't really make sense to fallback to vmalloc for sub page
@@ -660,7 +661,7 @@ void *kvmalloc_node_noprof(size_t size, gfp_t flags, int node)
660661
flags, PAGE_KERNEL, VM_ALLOW_HUGE_VMAP,
661662
node, __builtin_return_address(0));
662663
}
663-
EXPORT_SYMBOL(kvmalloc_node_noprof);
664+
EXPORT_SYMBOL(__kvmalloc_node_noprof);
664665

665666
/**
666667
* kvfree() - Free memory.

0 commit comments

Comments
 (0)