Merge pull request #84 from microsoft/bug-fix

Bug fix
This commit is contained in:
David Chisnall
2019-08-13 16:57:21 +01:00
committed by GitHub
14 changed files with 128 additions and 33 deletions

View File

@@ -1084,13 +1084,13 @@ namespace snmalloc
SNMALLOC_ASSUME(size <= SLAB_SIZE);
sizeclass_t sizeclass = size_to_sizeclass(size);
stats().sizeclass_alloc(sizeclass);
assert(sizeclass < NUM_SMALL_CLASSES);
auto& fl = small_fast_free_lists[sizeclass];
void* head = fl.value;
if (likely(head != nullptr))
{
stats().sizeclass_alloc(sizeclass);
// Read the next slot from the memory that's about to be allocated.
fl.value = Metaslab::follow_next(head);
@@ -1113,6 +1113,9 @@ namespace snmalloc
return reinterpret_cast<Allocator*>(replacement)
->template small_alloc_slow<zero_mem, allow_reserve>(sizeclass);
}
stats().sizeclass_alloc(sizeclass);
handle_message_queue();
size_t rsize = sizeclass_to_size(sizeclass);
auto& sl = small_classes[sizeclass];

View File

@@ -141,7 +141,9 @@ namespace snmalloc
UNUSED(size);
#ifdef USE_SNMALLOC_STATS
bucketed_requests[bits::to_exp_mant<BUCKETS_BITS>(size)]++;
auto index = (size == 0) ? 0 : bits::to_exp_mant<BUCKETS_BITS>(size);
assert(index < TOTAL_BUCKETS);
bucketed_requests[index]++;
#endif
}

View File

@@ -107,28 +107,26 @@ namespace snmalloc
#endif
}
void debug_check_empty()
/**
If you pass a pointer to a bool, then it returns whether all the
allocators are empty. If you don't pass a pointer to a bool, then will
raise an error all the allocators are not empty.
*/
void debug_check_empty(bool* result = nullptr)
{
#ifndef USE_MALLOC
// This is a debugging function. It checks that all memory from all
// allocators has been freed.
size_t alloc_count = 0;
auto* alloc = Parent::iterate();
// Count the linked allocators.
while (alloc != nullptr)
{
alloc = Parent::iterate(alloc);
alloc_count++;
}
bool done = false;
size_t non_empty_count = 0;
while (!done)
{
done = true;
alloc = Parent::iterate();
non_empty_count = 0;
while (alloc != nullptr)
{
@@ -142,6 +140,10 @@ namespace snmalloc
p = next;
}
// Check that the allocator has freed all memory.
if (!alloc->stats().is_empty())
non_empty_count++;
// Place the static stub message on the queue.
alloc->init_message_queue();
@@ -158,20 +160,16 @@ namespace snmalloc
}
}
alloc = Parent::iterate();
size_t empty_count = 0;
while (alloc != nullptr)
if (result != nullptr)
{
// Check that the allocator has freed all memory.
if (alloc->stats().is_empty())
empty_count++;
alloc = Parent::iterate(alloc);
*result = non_empty_count == 0;
return;
}
if (alloc_count != empty_count)
error("Incorrect number of allocators");
if (non_empty_count != 0)
{
error("debug_check_empty: found non-empty allocators");
}
#endif
}
};