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 f3fdbbfa92.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2020-05-23 17:28:52 +01:00
parent f8d4cbe40b
commit 69413acbdc

View File

@ -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);