diff options
author | Yuxuan Shui <yshuiv7@gmail.com> | 2020-05-23 17:28:52 +0100 |
---|---|---|
committer | Yuxuan Shui <yshuiv7@gmail.com> | 2020-05-23 17:43:38 +0100 |
commit | 69413acbdc3d4cd699aa7e33af1b8cd13fd6a4d4 (patch) | |
tree | c866501aa4a6e363f12f32492da0b2890ed04b30 /include/linux/slab.h | |
parent | f8d4cbe40b2cfd3d1ad66afb621c5291ad74eafd (diff) |
kmalloc: use posix_memalign
posix_memalign doesn't have the restriction that size must be a multiply
of alignment.
This also reverts the fix in commit f3fdbbfa92defb1f1d12c0038513b69b52baf33e.
Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
Diffstat (limited to 'include/linux/slab.h')
-rw-r--r-- | include/linux/slab.h | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/include/linux/slab.h b/include/linux/slab.h index 67d52c9e..32ffa55b 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -20,12 +20,14 @@ static inline void *kmalloc(size_t size, gfp_t flags) run_shrinkers(); - size_t alignment = min(rounddown_pow_of_two(size), - (size_t)PAGE_SIZE); - size = roundup(size, alignment); - p = size - ? aligned_alloc(alignment, size) - : malloc(0); + if (size) { + size_t alignment = min(rounddown_pow_of_two(size), (size_t)PAGE_SIZE); + alignment = max(sizeof(void *), alignment); + if (posix_memalign(&p, alignment, size)) + p = NULL; + } else { + p = malloc(0); + } if (p && (flags & __GFP_ZERO)) memset(p, 0, size); |