Skip to content

Commit e8e5f81

Browse files
author
Ralph Castain
committed
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 <[email protected]>
1 parent be3ef77 commit e8e5f81

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

opal/dss/dss_internal_functions.c

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ char* opal_dss_buffer_extend(opal_buffer_t *buffer, size_t bytes_to_add)
3636
{
3737
size_t required, to_alloc;
3838
size_t pack_offset, unpack_offset;
39-
char *tmp;
4039

4140
/* Check to see if we have enough space already */
4241

@@ -45,19 +44,34 @@ char* opal_dss_buffer_extend(opal_buffer_t *buffer, size_t bytes_to_add)
4544
}
4645

4746
required = buffer->bytes_used + bytes_to_add;
48-
if (required >= (size_t)opal_dss_threshold_size) {
49-
to_alloc = (required + opal_dss_threshold_size - 1) & ~(opal_dss_threshold_size - 1);
47+
if(required >= (size_t)opal_dss_threshold_size) {
48+
to_alloc = ((required + opal_dss_threshold_size - 1)
49+
/ opal_dss_threshold_size) * opal_dss_threshold_size;
5050
} else {
51-
to_alloc = buffer->bytes_allocated ? buffer->bytes_allocated : (size_t)opal_dss_initial_size;
51+
to_alloc = buffer->bytes_allocated;
52+
if(0 == to_alloc) {
53+
to_alloc = opal_dss_initial_size;
54+
}
55+
while(to_alloc < required) {
56+
to_alloc <<= 1;
57+
}
5258
}
5359

54-
pack_offset = ((char*) buffer->pack_ptr) - ((char*) buffer->base_ptr);
55-
unpack_offset = ((char*) buffer->unpack_ptr) - ((char*) buffer->base_ptr);
56-
tmp = (char*)realloc(buffer->base_ptr, to_alloc);
57-
if (NULL == tmp) {
60+
if (NULL != buffer->base_ptr) {
61+
pack_offset = ((char*) buffer->pack_ptr) - ((char*) buffer->base_ptr);
62+
unpack_offset = ((char*) buffer->unpack_ptr) -
63+
((char*) buffer->base_ptr);
64+
buffer->base_ptr = (char*)realloc(buffer->base_ptr, to_alloc);
65+
} else {
66+
pack_offset = 0;
67+
unpack_offset = 0;
68+
buffer->bytes_used = 0;
69+
buffer->base_ptr = (char*)malloc(to_alloc);
70+
}
71+
72+
if (NULL == buffer->base_ptr) {
5873
return NULL;
5974
}
60-
buffer->base_ptr = tmp;
6175
buffer->pack_ptr = ((char*) buffer->base_ptr) + pack_offset;
6276
buffer->unpack_ptr = ((char*) buffer->base_ptr) + unpack_offset;
6377
buffer->bytes_allocated = to_alloc;

0 commit comments

Comments
 (0)