Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

add default_gfp() helper macro and use it in the new *alloc_obj() helpers

Most simple allocations use GFP_KERNEL, and with the new allocation
helpers being introduced, let's just take advantage of that to simplify
that default case.

It's a numbers game:

git grep 'alloc_obj(' |
sed 's/.*\(GFP_[_A-Z]*\).*/\1/' |
sort | uniq -c | sort -n | tail

shows that about 90% of all those new allocator instances just use that
standard GFP_KERNEL.

Those helpers are already macros, and we can easily just make it be the
default case when the gfp argument is missing.

And yes, we could do that for all the legacy interfaces too, but let's
keep it to just the new ones at least for now, since those all got
converted recently anyway, so this is not any "extra" noise outside of
that limited conversion.

And, in fact, I want to do this before doing the -rc1 release, exactly
so that we don't get extra merge conflicts.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

+28 -24
+4
include/linux/gfp.h
··· 13 13 struct vm_area_struct; 14 14 struct mempolicy; 15 15 16 + /* Helper macro to avoid gfp flags if they are the default one */ 17 + #define __default_gfp(a,...) a 18 + #define default_gfp(...) __default_gfp(__VA_ARGS__ __VA_OPT__(,) GFP_KERNEL) 19 + 16 20 /* Convert GFP flags to their corresponding migrate type */ 17 21 #define GFP_MOVABLE_MASK (__GFP_RECLAIMABLE|__GFP_MOVABLE) 18 22 #define GFP_MOVABLE_SHIFT 3
+24 -24
include/linux/slab.h
··· 1017 1017 * Returns: newly allocated pointer to a @VAR_OR_TYPE on success, or NULL 1018 1018 * on failure. 1019 1019 */ 1020 - #define kmalloc_obj(VAR_OR_TYPE, GFP) \ 1021 - __alloc_objs(kmalloc, GFP, typeof(VAR_OR_TYPE), 1) 1020 + #define kmalloc_obj(VAR_OR_TYPE, ...) \ 1021 + __alloc_objs(kmalloc, default_gfp(__VA_ARGS__), typeof(VAR_OR_TYPE), 1) 1022 1022 1023 1023 /** 1024 1024 * kmalloc_objs - Allocate an array of the given type ··· 1029 1029 * Returns: newly allocated pointer to array of @VAR_OR_TYPE on success, 1030 1030 * or NULL on failure. 1031 1031 */ 1032 - #define kmalloc_objs(VAR_OR_TYPE, COUNT, GFP) \ 1033 - __alloc_objs(kmalloc, GFP, typeof(VAR_OR_TYPE), COUNT) 1032 + #define kmalloc_objs(VAR_OR_TYPE, COUNT, ...) \ 1033 + __alloc_objs(kmalloc, default_gfp(__VA_ARGS__), typeof(VAR_OR_TYPE), COUNT) 1034 1034 1035 1035 /** 1036 1036 * kmalloc_flex - Allocate a single instance of the given flexible structure ··· 1044 1044 * will immediately fail if @COUNT is larger than what the type of the 1045 1045 * struct's counter variable can represent. 1046 1046 */ 1047 - #define kmalloc_flex(VAR_OR_TYPE, FAM, COUNT, GFP) \ 1048 - __alloc_flex(kmalloc, GFP, typeof(VAR_OR_TYPE), FAM, COUNT) 1047 + #define kmalloc_flex(VAR_OR_TYPE, FAM, COUNT, ...) \ 1048 + __alloc_flex(kmalloc, default_gfp(__VA_ARGS__), typeof(VAR_OR_TYPE), FAM, COUNT) 1049 1049 1050 1050 /* All kzalloc aliases for kmalloc_(obj|objs|flex). */ 1051 - #define kzalloc_obj(P, GFP) \ 1052 - __alloc_objs(kzalloc, GFP, typeof(P), 1) 1053 - #define kzalloc_objs(P, COUNT, GFP) \ 1054 - __alloc_objs(kzalloc, GFP, typeof(P), COUNT) 1055 - #define kzalloc_flex(P, FAM, COUNT, GFP) \ 1056 - __alloc_flex(kzalloc, GFP, typeof(P), FAM, COUNT) 1051 + #define kzalloc_obj(P, ...) \ 1052 + __alloc_objs(kzalloc, default_gfp(__VA_ARGS__), typeof(P), 1) 1053 + #define kzalloc_objs(P, COUNT, ...) \ 1054 + __alloc_objs(kzalloc, default_gfp(__VA_ARGS__), typeof(P), COUNT) 1055 + #define kzalloc_flex(P, FAM, COUNT, ...) \ 1056 + __alloc_flex(kzalloc, default_gfp(__VA_ARGS__), typeof(P), FAM, COUNT) 1057 1057 1058 1058 /* All kvmalloc aliases for kmalloc_(obj|objs|flex). */ 1059 - #define kvmalloc_obj(P, GFP) \ 1060 - __alloc_objs(kvmalloc, GFP, typeof(P), 1) 1061 - #define kvmalloc_objs(P, COUNT, GFP) \ 1062 - __alloc_objs(kvmalloc, GFP, typeof(P), COUNT) 1063 - #define kvmalloc_flex(P, FAM, COUNT, GFP) \ 1064 - __alloc_flex(kvmalloc, GFP, typeof(P), FAM, COUNT) 1059 + #define kvmalloc_obj(P, ...) \ 1060 + __alloc_objs(kvmalloc, default_gfp(__VA_ARGS__), typeof(P), 1) 1061 + #define kvmalloc_objs(P, COUNT, ...) \ 1062 + __alloc_objs(kvmalloc, default_gfp(__VA_ARGS__), typeof(P), COUNT) 1063 + #define kvmalloc_flex(P, FAM, COUNT, ...) \ 1064 + __alloc_flex(kvmalloc, default_gfp(__VA_ARGS__), typeof(P), FAM, COUNT) 1065 1065 1066 1066 /* All kvzalloc aliases for kmalloc_(obj|objs|flex). */ 1067 - #define kvzalloc_obj(P, GFP) \ 1068 - __alloc_objs(kvzalloc, GFP, typeof(P), 1) 1069 - #define kvzalloc_objs(P, COUNT, GFP) \ 1070 - __alloc_objs(kvzalloc, GFP, typeof(P), COUNT) 1071 - #define kvzalloc_flex(P, FAM, COUNT, GFP) \ 1072 - __alloc_flex(kvzalloc, GFP, typeof(P), FAM, COUNT) 1067 + #define kvzalloc_obj(P, ...) \ 1068 + __alloc_objs(kvzalloc, default_gfp(__VA_ARGS__), typeof(P), 1) 1069 + #define kvzalloc_objs(P, COUNT, ...) \ 1070 + __alloc_objs(kvzalloc, default_gfp(__VA_ARGS__), typeof(P), COUNT) 1071 + #define kvzalloc_flex(P, FAM, COUNT, ...) \ 1072 + __alloc_flex(kvzalloc, default_gfp(__VA_ARGS__), typeof(P), FAM, COUNT) 1073 1073 1074 1074 #define kmem_buckets_alloc(_b, _size, _flags) \ 1075 1075 alloc_hooks(__kmalloc_node_noprof(PASS_BUCKET_PARAMS(_size, _b), _flags, NUMA_NO_NODE))