Minor code tidying.

This commit is contained in:
Matthew Parkinson
2020-01-29 16:37:46 +00:00
parent 2e289573c8
commit 053b5a30ef
4 changed files with 22 additions and 20 deletions

View File

@@ -56,7 +56,7 @@ namespace snmalloc
length == bits::next_pow2_const(length), "Must be a power of two.");
private:
T value;
T value = 0;
public:
operator T()

View File

@@ -80,7 +80,7 @@ namespace snmalloc
*/
std::atomic<uint64_t> last_low_memory_epoch = 0;
std::atomic_flag lazy_decommit_guard;
void lazy_decommit()
SNMALLOC_SLOW_PATH void lazy_decommit()
{
// If another thread is try to do lazy decommit, let it continue. If
// we try to parallelise this, we'll most likely end up waiting on the
@@ -93,6 +93,7 @@ namespace snmalloc
// the memory that we can. Start with the small size classes so that we
// hit cached superslabs first.
// FIXME: We probably shouldn't do this all at once.
// FIXME: We currently Decommit all the sizeclasses larger than 0.
for (size_t large_class = 0; large_class < NUM_LARGE_CLASSES;
large_class++)
{
@@ -327,7 +328,8 @@ namespace snmalloc
void* alloc(size_t large_class, size_t size)
{
size_t rsize = bits::one_at_bit(SUPERSLAB_BITS) << large_class;
if (size == 0)
// For superslab size, we always commit the whole range.
if (large_class == 0)
size = rsize;
void* p = memory_provider.large_stack[large_class].pop();
@@ -407,7 +409,7 @@ namespace snmalloc
size_t rsize = bits::one_at_bit(SUPERSLAB_BITS) << large_class;
memory_provider.notify_not_using(
pointer_offset(p, OS_PAGE_SIZE), rsize - OS_PAGE_SIZE);
pointer_offset(p, OS_PAGE_SIZE), rsize - OS_PAGE_SIZE);
}
stats.superslab_push();

View File

@@ -36,7 +36,7 @@ namespace snmalloc
* The list will be (allocated - needed - 1) long. The -1 is
* for the `link` element which is not in the free list.
*/
void* head;
void* head = nullptr;
/**
* How many entries are not in the free list of slab, i.e.
@@ -51,7 +51,7 @@ namespace snmalloc
/**
* How many entries have been allocated from this slab.
*/
uint16_t allocated;
uint16_t allocated = 0;
// When a slab has free space it will be on the has space list for
// that size class. We use an empty block in this slab to be the

View File

@@ -84,7 +84,7 @@ namespace snmalloc
{
if (kind != Fresh)
{
// If this wasn't previously Fresh, we need to zero some things.
// If this wasn't previously Fresh, we need to zero some things.
used = 0;
for (size_t i = 0; i < SLAB_COUNT; i++)
{
@@ -97,21 +97,21 @@ namespace snmalloc
kind = Super;
// Point head at the first non-short slab.
head = 1;
}
#ifndef NDEBUG
auto curr = head;
for (size_t i = 0; i < SLAB_COUNT - used - 1; i++)
{
curr = (curr + meta[curr].next + 1) & (SLAB_COUNT - 1);
}
assert(curr == 0);
for (size_t i = 0; i < SLAB_COUNT; i++)
{
assert(meta[i].is_unused());
}
#endif
auto curr = head;
for (size_t i = 0; i < SLAB_COUNT - used - 1; i++)
{
curr = (curr + meta[curr].next + 1) & (SLAB_COUNT - 1);
}
if (curr != 0) abort();
for (size_t i = 0; i < SLAB_COUNT; i++)
{
assert(meta[i].is_unused());
}
#endif
}
bool is_empty()
@@ -165,7 +165,7 @@ namespace snmalloc
meta[0].link = get_initial_offset(sizeclass, true);
used++;
return (Slab*)this;
return reinterpret_cast<Slab*>(this);
}
Slab* alloc_slab(sizeclass_t sizeclass)