Skip to content

Commit

Permalink
Minor code tidying
Browse files Browse the repository at this point in the history
  • Loading branch information
mjp41 committed Jan 29, 2020
1 parent 7467e87 commit 4003805
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/ds/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 3 additions & 2 deletions src/mem/largealloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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++)
{
Expand Down Expand Up @@ -408,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();
Expand Down
4 changes: 2 additions & 2 deletions src/mem/metaslab.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
26 changes: 13 additions & 13 deletions src/mem/superslab.h
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
{
Expand All @@ -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);
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
for (size_t i = 0; i < SLAB_COUNT; i++)
{
assert(meta[i].is_unused());
}
#endif
}

bool is_empty()
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 4003805

Please sign in to comment.