diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2019-03-24 23:38:17 -0400 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@gmail.com> | 2019-03-24 23:38:17 -0400 |
commit | 365d3450058ba0a8d282d8155bfcc2057837ab95 (patch) | |
tree | ae88984421b0c39acdecd82f097e35b749590310 /include/linux/slab.h | |
parent | 9b08492bc733f3b1b1eefc87a4c52d9673432e42 (diff) |
Align allocations like the kernel does
Diffstat (limited to 'include/linux/slab.h')
-rw-r--r-- | include/linux/slab.h | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/include/linux/slab.h b/include/linux/slab.h index c19f190b..d8832c6c 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -6,6 +6,7 @@ #include <string.h> #include <linux/kernel.h> +#include <linux/log2.h> #include <linux/page.h> #include <linux/shrinker.h> #include <linux/types.h> @@ -19,7 +20,10 @@ static inline void *kmalloc(size_t size, gfp_t flags) run_shrinkers(); - p = malloc(size); + p = size + ? aligned_alloc(min(rounddown_pow_of_two(size), + PAGE_SIZE), size) + : malloc(0); if (p && (flags & __GFP_ZERO)) memset(p, 0, size); |