From a967fae362f55ee7162fb48776dfac69d4f28d1c Mon Sep 17 00:00:00 2001 From: Jason Evans Date: Thu, 3 Nov 2016 23:49:21 -0700 Subject: [PATCH] Fix/simplify extent_recycle() allocation size computations. Do not call s2u() during alloc_size computation, since any necessary ceiling increase is taken care of later by extent_first_best_fit() --> extent_size_quantize_ceil(), and the s2u() call may erroneously cause a higher quantization result. Remove an overly strict overflow check that was added in 4a7852137d8b6598fdb90ea8e1fd3bc8a8b94a3a (Fix extent_recycle()'s cache-oblivious padding support.). --- src/extent.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/extent.c b/src/extent.c index e190adc4..4027e8b7 100644 --- a/src/extent.c +++ b/src/extent.c @@ -405,6 +405,7 @@ extent_recycle(tsdn_t *tsdn, arena_t *arena, extent_hooks_t **r_extent_hooks, malloc_mutex_assert_owner(tsdn, &arena->extents_mtx); assert(new_addr == NULL || !slab); assert(pad == 0 || !slab); + assert(alignment > 0); if (config_debug && new_addr != NULL) { extent_t *prev; @@ -427,13 +428,11 @@ extent_recycle(tsdn_t *tsdn, arena_t *arena, extent_hooks_t **r_extent_hooks, assert(prev == NULL || extent_past_get(prev) == new_addr); } - 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; + alloc_size = size + PAGE_CEILING(alignment) - PAGE; + /* Beware size_t wrap-around. */ + if (alloc_size < usize) + return (NULL); if (!locked) malloc_mutex_lock(tsdn, &arena->extents_mtx); extent_hooks_assure_initialized(arena, r_extent_hooks);