static THREAD_LOCAL uint64_t last_dealloc = 0;
static THREAD_LOCAL uint64_t start_dealloc = 0;
+static THREAD_LOCAL uint64_t start_alloc = 0;
static THREAD_LOCAL uint64_t start_epoch = 0;
static HeapInterface* heap = nullptr;
return;
start_dealloc = last_dealloc = mc.deallocated;
+ start_alloc = mc.allocated;
start_epoch = current_epoch;
mc.reap_cycles++;
}
mc.pruned += (mc.deallocated - last_dealloc);
last_dealloc = mc.deallocated;
- if ( mc.deallocated - start_dealloc >= config.prune_target )
+ uint64_t alloc = mc.allocated - start_alloc;
+ uint64_t dealloc = mc.deallocated - start_dealloc;
+ if ( dealloc > alloc and ( ( dealloc - alloc ) >= config.prune_target ) )
{
start_dealloc = 0;
return;
const MemoryCounts& mc = MemoryCap::get_mem_stats();
CHECK(mc.start_up_use == start);
- flows = 1;
+ flows = 2;
free_space();
- CHECK(flows == 1);
+ CHECK(flows == 2);
heap->total = cap + 1;
periodic_check();
CHECK(heap->epoch == 2);
- CHECK(flows == 1);
+ CHECK(flows == 2);
free_space();
- CHECK(flows == 0);
+ CHECK(flows == 1);
heap->total = cap;
periodic_check();
free_space();
CHECK(flows == 0);
+ heap->dealloc++;
+ free_space();
+ CHECK(flows == 0);
+
CHECK(mc.start_up_use == start);
CHECK(mc.max_in_use == cap + 1);
CHECK(mc.cur_in_use == cap);
CHECK(mc.deallocated == heap->dealloc);
CHECK(mc.reap_cycles == 1);
- CHECK(mc.reap_attempts == 1);
+ CHECK(mc.reap_attempts == 2);
CHECK(mc.reap_failures == 0);
- CHECK(mc.pruned == 1);
+ CHECK(mc.pruned == 2);
heap->total = start;
MemoryCap::stop();