Remove at_least

The Pal was providing policy for overallocating a block of memory to
achieve alignment make that part of the backend.
The backend should be responsible for layout policy.
This commit is contained in:
Matthew Parkinson
2021-07-19 11:20:02 +01:00
committed by Matthew Parkinson
parent 9df0101dfd
commit 5d0ae71423
10 changed files with 50 additions and 68 deletions

View File

@@ -96,12 +96,21 @@ namespace snmalloc
else if constexpr (!pal_supports<NoAllocation, PAL>)
{
// Need at least 2 times the space to guarantee alignment.
// Hold lock here as a race could cause additional requests to
// the PAL, and this could lead to suprious OOM. This is
// particularly bad if the PAL gives all the memory on first call.
auto block_and_size = PAL::reserve_at_least(size * 2);
block = CapPtr<void, CBChunk>(block_and_size.first);
block_size = block_and_size.second;
size_t needed_size = size * 2;
// Magic number (27) for over-allocating a block of memory
// These should be further refined based on experiments.
constexpr size_t min_size = bits::one_at_bit(27);
for (size_t size_request = bits::max(needed_size, min_size);
size_request >= needed_size;
size_request = size_request / 2)
{
block = CapPtr<void, CBChunk>(PAL::reserve(size_request));
if (block != nullptr)
{
block_size = size_request;
break;
}
}
// Ensure block is pointer aligned.
if (

View File

@@ -11,7 +11,7 @@ namespace snmalloc
* This class implements the standard backend for handling allocations.
* It abstracts page table management and address space management.
*/
template<typename PAL, bool fixed_range>
template<SNMALLOC_CONCEPT(ConceptPAL) PAL, bool fixed_range>
class BackendAllocator
{
public:

View File

@@ -119,9 +119,7 @@ namespace snmalloc
// TODO request additional space, and move to random offset.
// TODO wasting space if size2 bigger than needed.
auto [new_body_untyped, size2] =
Pal::reserve_at_least(ENTRIES * sizeof(T));
auto new_body_untyped = Pal::reserve(ENTRIES * sizeof(T));
auto new_body = reinterpret_cast<T*>(new_body_untyped);