Implements protection on remote messages queues

This extends the freelist protection to the remote message queues. They
effectively perform doubly linked list entries for the message queue
with the enqueue operation first linking in the previous pointer, and
then then atomically setting the next.  This ensures that the visible
states always satisfy the invariant that the forward and backward
pointers are correct for any visisble object.

There is a key_global that is used for all remote deallocations. The
remote cache uses the same protection to build the temporary lists
before forwarding to the next allocator.

The mpscq is integrated into the remoteallocator as it is no longer
a reusable datastructure, but a special purpose implementation.
This commit is contained in:
Matthew Parkinson
2021-07-14 19:49:21 +01:00
committed by Matthew Parkinson
parent c58b0a5f4d
commit b501da69db
10 changed files with 295 additions and 295 deletions

View File

@@ -76,6 +76,8 @@ namespace snmalloc
typename SharedStateHandle>
bool flush(DeallocFun dealloc, SharedStateHandle handle)
{
FreeListKey key(entropy.get_constant_key());
// Return all the free lists to the allocator.
// Used during thread teardown
for (size_t i = 0; i < NUM_SIZECLASSES; i++)
@@ -84,25 +86,27 @@ namespace snmalloc
// call.
while (!small_fast_free_lists[i].empty())
{
auto p = small_fast_free_lists[i].take(entropy);
auto p = small_fast_free_lists[i].take(key);
dealloc(finish_alloc_no_zero(p, i));
}
}
return remote_dealloc_cache.post<allocator_size>(
handle, remote_allocator->trunc_id());
handle, remote_allocator->trunc_id(), key_global);
}
template<ZeroMem zero_mem, typename SharedStateHandle, typename Slowpath>
SNMALLOC_FAST_PATH void* alloc(size_t size, Slowpath slowpath)
{
FreeListKey key(entropy.get_constant_key());
sizeclass_t sizeclass = size_to_sizeclass(size);
stats.alloc_request(size);
stats.sizeclass_alloc(sizeclass);
auto& fl = small_fast_free_lists[sizeclass];
if (likely(!fl.empty()))
{
auto p = fl.take(entropy);
auto p = fl.take(key);
return finish_alloc<zero_mem, SharedStateHandle>(p, sizeclass);
}
return slowpath(sizeclass, &fl);