diff options
author | koverstreet <kent.overstreet@gmail.com> | 2020-05-23 12:55:02 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-23 12:55:02 -0400 |
commit | bae7a9ae8da70447bf62b764dfd124bea9161196 (patch) | |
tree | c866501aa4a6e363f12f32492da0b2890ed04b30 | |
parent | f8d4cbe40b2cfd3d1ad66afb621c5291ad74eafd (diff) | |
parent | 69413acbdc3d4cd699aa7e33af1b8cd13fd6a4d4 (diff) |
Merge pull request #31 from yshui/master
kmalloc: use posix_memalign
-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); |