Remote: store the sizeclass, too

Squeeze some bits out of allocator IDs so that we can land the sizeclass in
each Remote object.  The intent is that, on StrictProvenance architectures like
CHERI, we will be able to route Remote messages through RemoteCache-s without
needing to amplify back to read the sizeclass metadata field out of the slab
headers.
This commit is contained in:
Nathaniel Filardo
2020-12-14 18:34:08 +00:00
committed by Matthew Parkinson
parent e9ed219fd8
commit 7c04a9dad6
4 changed files with 62 additions and 43 deletions

View File

@@ -22,16 +22,34 @@ namespace snmalloc
std::atomic<Remote*> next{nullptr};
};
alloc_id_t allocator_id;
/*
* We embed the size class in the bottom 8 bits of an allocator ID (i.e.,
* the address of an Alloc's remote_alloc's message_queue; in practice we
* only need 7 bits, but using 8 is conjectured to be faster). The hashing
* algorithm of the Alloc's RemoteCache already ignores the bottom
* "initial_shift" bits, which is, in practice, well above 8. There's a
* static_assert() over there that helps ensure this stays true.
*
* This does mean that we might have message_queues that always collide in
* the hash algorithm, if they're within "initial_shift" of each other. Such
* pairings will substantially decrease performance and so we prohibit them
* and use SNMALLOC_ASSERT to verify that they do not exist in debug builds.
*/
alloc_id_t alloc_id_and_sizeclass;
void set_target_id(alloc_id_t id)
void set_info(alloc_id_t id, sizeclass_t sc)
{
allocator_id = id;
alloc_id_and_sizeclass = (id & ~SIZECLASS_MASK) | sc;
}
alloc_id_t target_id()
alloc_id_t trunc_target_id()
{
return allocator_id;
return alloc_id_and_sizeclass & ~SIZECLASS_MASK;
}
sizeclass_t sizeclass()
{
return alloc_id_and_sizeclass & SIZECLASS_MASK;
}
};
@@ -46,10 +64,11 @@ namespace snmalloc
// is read by other threads.
alignas(CACHELINE_SIZE) MPSCQ<Remote> message_queue;
alloc_id_t id()
alloc_id_t trunc_id()
{
return static_cast<alloc_id_t>(
reinterpret_cast<uintptr_t>(&message_queue));
reinterpret_cast<uintptr_t>(&message_queue)) &
~SIZECLASS_MASK;
}
};
} // namespace snmalloc