From e8e5f81abd5627545a155899ff97a0aa0a5812a4 Mon Sep 17 00:00:00 2001 From: Ralph Castain Date: Sat, 21 Jan 2017 14:37:45 -0800 Subject: [PATCH] Something not quite right about the revised allocation algos, so revert them while retaining the larger initial and threshold sizes Signed-off-by: Ralph Castain --- opal/dss/dss_internal_functions.c | 32 ++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/opal/dss/dss_internal_functions.c b/opal/dss/dss_internal_functions.c index 3c8b62c663..7f5e788282 100644 --- a/opal/dss/dss_internal_functions.c +++ b/opal/dss/dss_internal_functions.c @@ -36,7 +36,6 @@ char* opal_dss_buffer_extend(opal_buffer_t *buffer, size_t bytes_to_add) { size_t required, to_alloc; size_t pack_offset, unpack_offset; - char *tmp; /* Check to see if we have enough space already */ @@ -45,19 +44,34 @@ char* opal_dss_buffer_extend(opal_buffer_t *buffer, size_t bytes_to_add) } required = buffer->bytes_used + bytes_to_add; - if (required >= (size_t)opal_dss_threshold_size) { - to_alloc = (required + opal_dss_threshold_size - 1) & ~(opal_dss_threshold_size - 1); + if(required >= (size_t)opal_dss_threshold_size) { + to_alloc = ((required + opal_dss_threshold_size - 1) + / opal_dss_threshold_size) * opal_dss_threshold_size; } else { - to_alloc = buffer->bytes_allocated ? buffer->bytes_allocated : (size_t)opal_dss_initial_size; + to_alloc = buffer->bytes_allocated; + if(0 == to_alloc) { + to_alloc = opal_dss_initial_size; + } + while(to_alloc < required) { + to_alloc <<= 1; + } } - pack_offset = ((char*) buffer->pack_ptr) - ((char*) buffer->base_ptr); - unpack_offset = ((char*) buffer->unpack_ptr) - ((char*) buffer->base_ptr); - tmp = (char*)realloc(buffer->base_ptr, to_alloc); - if (NULL == tmp) { + if (NULL != buffer->base_ptr) { + pack_offset = ((char*) buffer->pack_ptr) - ((char*) buffer->base_ptr); + unpack_offset = ((char*) buffer->unpack_ptr) - + ((char*) buffer->base_ptr); + buffer->base_ptr = (char*)realloc(buffer->base_ptr, to_alloc); + } else { + pack_offset = 0; + unpack_offset = 0; + buffer->bytes_used = 0; + buffer->base_ptr = (char*)malloc(to_alloc); + } + + if (NULL == buffer->base_ptr) { return NULL; } - buffer->base_ptr = tmp; buffer->pack_ptr = ((char*) buffer->base_ptr) + pack_offset; buffer->unpack_ptr = ((char*) buffer->base_ptr) + unpack_offset; buffer->bytes_allocated = to_alloc;