base: contain chunk_size heap consumption

Increase internal chunk size of heap only if an allocation succeeded
beforehand. Otherwise the chunk size increases with every unsuccessful
invocation and a upgrade of the used ram session will be insufficient and of
no use at all.

Fixes #1632
This commit is contained in:
Alexander Boettcher 2015-07-15 13:48:55 +02:00 committed by Norman Feske
parent 73f9bb73cd
commit fe4e0702d4

View File

@ -140,8 +140,7 @@ bool Heap::_unsynchronized_alloc(size_t size, void **out_addr)
*out_addr = ds->local_addr; *out_addr = ds->local_addr;
return true; return true;
}
} else {
/* try allocation at our local allocator */ /* try allocation at our local allocator */
if (_try_local_alloc(size, out_addr)) if (_try_local_alloc(size, out_addr))
@ -155,13 +154,14 @@ bool Heap::_unsynchronized_alloc(size_t size, void **out_addr)
*/ */
dataspace_size = size + META_DATA_SIZE; dataspace_size = size + META_DATA_SIZE;
if (dataspace_size < _chunk_size * sizeof(umword_t)) {
/* /*
* '_chunk_size' is a multiple of 4K, so 'dataspace_size' becomes * '_chunk_size' is a multiple of 4K, so 'dataspace_size' becomes
* 4K-aligned, too. * 4K-aligned, too.
*/ */
dataspace_size = _chunk_size * sizeof(umword_t); size_t const request_size = _chunk_size * sizeof(umword_t);
if ((dataspace_size < request_size) &&
_allocate_dataspace(request_size, false)) {
/* /*
* Exponentially increase chunk size with each allocated chunk until * Exponentially increase chunk size with each allocated chunk until
@ -173,17 +173,14 @@ bool Heap::_unsynchronized_alloc(size_t size, void **out_addr)
/* align to 4K page */ /* align to 4K page */
dataspace_size = align_addr(dataspace_size, 12); dataspace_size = align_addr(dataspace_size, 12);
if (!_allocate_dataspace(dataspace_size, false))
return false;
} }
_allocate_dataspace(dataspace_size, false);
/* allocate originally requested block */ /* allocate originally requested block */
return _try_local_alloc(size, out_addr); return _try_local_alloc(size, out_addr);
} }
}
bool Heap::alloc(size_t size, void **out_addr) bool Heap::alloc(size_t size, void **out_addr)
{ {