From 4a7852137d8b6598fdb90ea8e1fd3bc8a8b94a3a Mon Sep 17 00:00:00 2001 From: Jason Evans Date: Thu, 3 Nov 2016 21:14:59 -0700 Subject: [PATCH] Fix extent_recycle()'s cache-oblivious padding support. Add padding *after* computing the size class, so that the optimal size class isn't skipped during search for a usable extent. This regression was caused by b46261d58b449cc4c099ed2384451a2499688f0e (Implement cache-oblivious support for huge size classes.). --- src/extent.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/extent.c b/src/extent.c index a802ad90..e190adc4 100644 --- a/src/extent.c +++ b/src/extent.c @@ -427,12 +427,13 @@ extent_recycle(tsdn_t *tsdn, arena_t *arena, extent_hooks_t **r_extent_hooks, assert(prev == NULL || extent_past_get(prev) == new_addr); } - size = usize + pad; - alloc_size = (new_addr != NULL) ? size : s2u(size + - PAGE_CEILING(alignment) - PAGE); - /* Beware size_t wrap-around. */ - if (alloc_size < usize) + alloc_size = ((new_addr != NULL) ? usize : s2u(usize + + PAGE_CEILING(alignment) - PAGE)) + pad; + if (alloc_size > LARGE_MAXCLASS + pad || alloc_size < usize) { + /* Too large, possibly wrapped around. */ return (NULL); + } + size = usize + pad; if (!locked) malloc_mutex_lock(tsdn, &arena->extents_mtx); extent_hooks_assure_initialized(arena, r_extent_hooks);