Skip to content

Commit 053b5a3

Browse files
committed
Minor code tidying.
1 parent 2e28957 commit 053b5a3

File tree

4 files changed

+21
-19
lines changed

4 files changed

+21
-19
lines changed

src/ds/helpers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ namespace snmalloc
5656
length == bits::next_pow2_const(length), "Must be a power of two.");
5757

5858
private:
59-
T value;
59+
T value = 0;
6060

6161
public:
6262
operator T()

src/mem/largealloc.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ namespace snmalloc
8080
*/
8181
std::atomic<uint64_t> last_low_memory_epoch = 0;
8282
std::atomic_flag lazy_decommit_guard;
83-
void lazy_decommit()
83+
SNMALLOC_SLOW_PATH void lazy_decommit()
8484
{
8585
// If another thread is try to do lazy decommit, let it continue. If
8686
// we try to parallelise this, we'll most likely end up waiting on the
@@ -93,6 +93,7 @@ namespace snmalloc
9393
// the memory that we can. Start with the small size classes so that we
9494
// hit cached superslabs first.
9595
// FIXME: We probably shouldn't do this all at once.
96+
// FIXME: We currently Decommit all the sizeclasses larger than 0.
9697
for (size_t large_class = 0; large_class < NUM_LARGE_CLASSES;
9798
large_class++)
9899
{
@@ -327,7 +328,8 @@ namespace snmalloc
327328
void* alloc(size_t large_class, size_t size)
328329
{
329330
size_t rsize = bits::one_at_bit(SUPERSLAB_BITS) << large_class;
330-
if (size == 0)
331+
// For superslab size, we always commit the whole range.
332+
if (large_class == 0)
331333
size = rsize;
332334

333335
void* p = memory_provider.large_stack[large_class].pop();
@@ -407,7 +409,7 @@ namespace snmalloc
407409
size_t rsize = bits::one_at_bit(SUPERSLAB_BITS) << large_class;
408410

409411
memory_provider.notify_not_using(
410-
pointer_offset(p, OS_PAGE_SIZE), rsize - OS_PAGE_SIZE);
412+
pointer_offset(p, OS_PAGE_SIZE), rsize - OS_PAGE_SIZE);
411413
}
412414

413415
stats.superslab_push();

src/mem/metaslab.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace snmalloc
3636
* The list will be (allocated - needed - 1) long. The -1 is
3737
* for the `link` element which is not in the free list.
3838
*/
39-
void* head;
39+
void* head = nullptr;
4040

4141
/**
4242
* How many entries are not in the free list of slab, i.e.
@@ -51,7 +51,7 @@ namespace snmalloc
5151
/**
5252
* How many entries have been allocated from this slab.
5353
*/
54-
uint16_t allocated;
54+
uint16_t allocated = 0;
5555

5656
// When a slab has free space it will be on the has space list for
5757
// that size class. We use an empty block in this slab to be the

src/mem/superslab.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ namespace snmalloc
8484
{
8585
if (kind != Fresh)
8686
{
87-
// If this wasn't previously Fresh, we need to zero some things.
87+
// If this wasn't previously Fresh, we need to zero some things.
8888
used = 0;
8989
for (size_t i = 0; i < SLAB_COUNT; i++)
9090
{
@@ -97,21 +97,21 @@ namespace snmalloc
9797
kind = Super;
9898
// Point head at the first non-short slab.
9999
head = 1;
100+
}
100101

101102
#ifndef NDEBUG
102-
auto curr = head;
103-
for (size_t i = 0; i < SLAB_COUNT - used - 1; i++)
104-
{
105-
curr = (curr + meta[curr].next + 1) & (SLAB_COUNT - 1);
106-
}
107-
assert(curr == 0);
103+
auto curr = head;
104+
for (size_t i = 0; i < SLAB_COUNT - used - 1; i++)
105+
{
106+
curr = (curr + meta[curr].next + 1) & (SLAB_COUNT - 1);
107+
}
108+
if (curr != 0) abort();
108109

109-
for (size_t i = 0; i < SLAB_COUNT; i++)
110-
{
111-
assert(meta[i].is_unused());
112-
}
113-
#endif
110+
for (size_t i = 0; i < SLAB_COUNT; i++)
111+
{
112+
assert(meta[i].is_unused());
114113
}
114+
#endif
115115
}
116116

117117
bool is_empty()
@@ -165,7 +165,7 @@ namespace snmalloc
165165
meta[0].link = get_initial_offset(sizeclass, true);
166166

167167
used++;
168-
return (Slab*)this;
168+
return reinterpret_cast<Slab*>(this);
169169
}
170170

171171
Slab* alloc_slab(sizeclass_t sizeclass)

0 commit comments

Comments
 (0)