Post large deallocations to original thread (#441)
* Post large deallocations to original thread This change sets all large allocations to be owned by the originating thread. This means they will be messaged back to the original thread before they can be reused. The following reason for making this change: * This will improve producer/consumer apps involving large allocations. * It enables the implementation of a more complex chunk allocator that reassembles chunks. * It addresses an issue with compartmentalisation where the handling of large allocations can result in meta-data ownership changing.
This commit is contained in:
committed by
GitHub
parent
3fb7c98364
commit
61314f2260
@@ -60,6 +60,12 @@ namespace snmalloc
|
||||
*/
|
||||
bool sleeping_ = false;
|
||||
|
||||
/**
|
||||
* Flag to indicate this is actually a large allocation rather than a slab
|
||||
* of small allocations.
|
||||
*/
|
||||
bool large_ = false;
|
||||
|
||||
uint16_t& needed()
|
||||
{
|
||||
return needed_;
|
||||
@@ -82,6 +88,25 @@ namespace snmalloc
|
||||
// allocated from. Hence, the bump allocator slab will never be returned
|
||||
// for use in another size class.
|
||||
set_sleeping(sizeclass, 0);
|
||||
|
||||
large_ = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make this a chunk represent a large allocation.
|
||||
*
|
||||
* Set needed so immediately moves to slow path.
|
||||
*/
|
||||
void initialise_large()
|
||||
{
|
||||
// We will push to this just to make the fast path clean.
|
||||
free_queue.init();
|
||||
|
||||
// Flag to detect that it is a large alloc on the slow path
|
||||
large_ = true;
|
||||
|
||||
// Jump to slow path on first deallocation.
|
||||
needed() = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,6 +131,11 @@ namespace snmalloc
|
||||
return sleeping();
|
||||
}
|
||||
|
||||
bool is_large()
|
||||
{
|
||||
return large_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to set this metaslab to sleep. If the remaining elements are fewer
|
||||
* than the threshold, then it will actually be set to the sleeping state,
|
||||
@@ -144,14 +174,6 @@ namespace snmalloc
|
||||
sleeping() = false;
|
||||
}
|
||||
|
||||
static SNMALLOC_FAST_PATH bool
|
||||
is_start_of_object(smallsizeclass_t sizeclass, address_t p)
|
||||
{
|
||||
return divisible_by_sizeclass(
|
||||
sizeclass,
|
||||
p - (bits::align_down(p, sizeclass_to_slab_size(sizeclass))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocates a free list from the meta data.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user