From 365d3450058ba0a8d282d8155bfcc2057837ab95 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Sun, 24 Mar 2019 23:38:17 -0400 Subject: [PATCH] Align allocations like the kernel does --- include/linux/slab.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 #include +#include #include #include #include @@ -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);