]> git.sesse.net Git - bcachefs-tools-debian/commitdiff
Align allocations like the kernel does
authorKent Overstreet <kent.overstreet@gmail.com>
Mon, 25 Mar 2019 03:38:17 +0000 (23:38 -0400)
committerKent Overstreet <kent.overstreet@gmail.com>
Mon, 25 Mar 2019 03:38:17 +0000 (23:38 -0400)
include/linux/slab.h

index c19f190b1fb0d95cb73fee10ad3697419939df21..d8832c6cdae9260b91a7325c08f7efce8122f54f 100644 (file)
@@ -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);