This commit is contained in:
Matthew Parkinson
2020-02-26 21:24:02 +00:00
parent c1c8a7bfee
commit be47aea0c8
2 changed files with 27 additions and 16 deletions

View File

@@ -57,19 +57,44 @@ namespace snmalloc
template<class PAL>
class MemoryProviderStateMixin : public PAL
{
/**
* Flag to protect the bump allocator
**/
std::atomic_flag lock = ATOMIC_FLAG_INIT;
/**
* Pointer to block being bump allocated
**/
void* bump = nullptr;
/**
* Space remaining in this block being bump allocated
**/
size_t remaining = 0;
/**
* The last time we saw a low memory notification.
*/
std::atomic<uint64_t> last_low_memory_epoch = 0;
/**
* Simple flag for checking if another instance of lazy-decommit is
* running
**/
std::atomic_flag lazy_decommit_guard = {};
public:
/**
* Stack of large allocations that have been returned for reuse.
*/
ModArray<NUM_LARGE_CLASSES, MPMCStack<Largeslab, RequiresInit>> large_stack;
/**
* Make a new memory provide for this PAL.
**/
static MemoryProviderStateMixin<PAL>* make() noexcept
{
// Temporary storage to start the allocator in.
// Temporary stack-based storage to start the allocator in.
MemoryProviderStateMixin<PAL> local;
// Allocate permanent storage for the allocator usung temporary allocator
@@ -84,12 +109,6 @@ namespace snmalloc
}
private:
/**
* The last time we saw a low memory notification.
*/
std::atomic<uint64_t> last_low_memory_epoch = 0;
std::atomic_flag lazy_decommit_guard = {};
void new_block()
{
// Reserve the smallest large_class which is SUPERSLAB_SIZE
@@ -290,8 +309,6 @@ namespace snmalloc
}
}
// printf("Alloc %zx (size = %zx)\n", start, size);
void* result = pointer_cast<void>(start);
if (committed)
PAL::template notify_using<NoZero>(result, size);

View File

@@ -26,17 +26,11 @@ int main()
{
setup();
MemoryProviderStateMixin<DefaultPal> mp;
// 28 is large enough to produce a nested allocator.
// It is also large enough for the example to run in.
// For 1MiB superslabs, SUPERSLAB_BITS + 4 is not big enough for the example.
auto a = ThreadAlloc::get();
for (size_t i = 0; i < 1000; i++)
{
auto r1 = a->alloc(100);
auto r1 = a->alloc(i);
a->dealloc(r1);
}