Skip to content

Commit adfd21e

Browse files
committed
Clangformat and Concurrency Safety.
1 parent 509f7bc commit adfd21e

13 files changed

Lines changed: 42 additions & 12 deletions

src/backend/backend.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@ namespace snmalloc
303303
return {p, meta};
304304
}
305305

306-
static void dealloc_chunk(
307-
LocalState& local_state, MetaCommon& meta_common, size_t size)
306+
static void
307+
dealloc_chunk(LocalState& local_state, MetaCommon& meta_common, size_t size)
308308
{
309309
auto chunk = meta_common.chunk;
310310

src/backend/commitrange.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ namespace snmalloc
2525

2626
static constexpr bool Aligned = ParentRange::Aligned;
2727

28+
static constexpr bool ConcurrencySafe = ParentRange::ConcurrencySafe;
29+
2830
constexpr CommitRange() = default;
2931

3032
capptr::Chunk<void> alloc_range(size_t size)

src/backend/decayrange.h

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ namespace snmalloc
5050
{
5151
auto next = get_next();
5252

53-
f (curr.get_capability());
53+
f(curr.get_capability());
5454

5555
curr = next;
5656
}
@@ -120,6 +120,12 @@ namespace snmalloc
120120
}
121121
};
122122

123+
/**
124+
* This range slowly filters back memory to the parent range.
125+
* It locally caches memory and after it hasn't been used for some time
126+
* it goes back to its parent range.
127+
*/
128+
123129
template<typename ParentRange, typename PAL, typename Pagemap>
124130
class DecayRange
125131
{
@@ -173,16 +179,21 @@ namespace snmalloc
173179

174180
static void handle_decay_tick()
175181
{
176-
auto new_epoch = (epoch + 1) % NUM_EPOCHS;
182+
static_assert(
183+
ParentRange::ConcurrencySafe,
184+
"Parent must be concurrency safe, as dealloc_range is called here on "
185+
"potentially another thread's state.");
186+
auto new_epoch =
187+
(epoch + 1) % NUM_EPOCHS;
177188
// Flush old index for all threads.
178189
auto curr = all_local.load(std::memory_order_acquire);
179190
while (curr != nullptr)
180191
{
181192
for (size_t sc = 0; sc < NUM_SLAB_SIZES; sc++)
182193
{
183194
auto old_stack = curr->chunk_stack[sc][new_epoch].pop_all();
184-
185-
old_stack.forall([curr, sc](auto cap){
195+
196+
old_stack.forall([curr, sc](auto cap) {
186197
curr->parent->dealloc_range(cap, MIN_CHUNK_SIZE << sc);
187198
});
188199
}
@@ -228,6 +239,8 @@ namespace snmalloc
228239

229240
static constexpr bool Aligned = ParentRange::Aligned;
230241

242+
static constexpr bool ConcurrencySafe = false;
243+
231244
constexpr DecayRange() = default;
232245

233246
capptr::Chunk<void> alloc_range(size_t size)

src/backend/empty_range.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ namespace snmalloc
1919

2020
static constexpr bool Aligned = true;
2121

22+
static constexpr bool ConcurrencySafe = true;
23+
2224
constexpr EmptyRange() = default;
2325

2426
capptr::Chunk<void> alloc_range(size_t)

src/backend/globalrange.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ namespace snmalloc
3737

3838
static constexpr bool Aligned = ParentRange::Aligned;
3939

40+
static constexpr bool ConcurrencySafe = true;
41+
4042
constexpr GlobalRange() = default;
4143

4244
capptr::Chunk<void> alloc_range(size_t size)

src/backend/largebuddyrange.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,8 @@ namespace snmalloc
271271

272272
static constexpr bool Aligned = true;
273273

274+
static constexpr bool ConcurrencySafe = false;
275+
274276
constexpr LargeBuddyRange() = default;
275277

276278
capptr::Chunk<void> alloc_range(size_t size)

src/backend/pagemapregisterrange.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ namespace snmalloc
3030

3131
static constexpr bool Aligned = ParentRange::Aligned;
3232

33+
static constexpr bool ConcurrencySafe = ParentRange::ConcurrencySafe;
34+
3335
capptr::Chunk<void> alloc_range(size_t size)
3436
{
3537
auto base = state->alloc_range(size);

src/backend/palrange.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ namespace snmalloc
2424

2525
static constexpr bool Aligned = pal_supports<AlignedAllocation, PAL>;
2626

27+
static constexpr bool ConcurrencySafe = true;
28+
2729
constexpr PalRange() = default;
2830

2931
capptr::Chunk<void> alloc_range(size_t size)

src/backend/smallbuddyrange.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ namespace snmalloc
175175
static constexpr bool Aligned = true;
176176
static_assert(ParentRange::Aligned, "ParentRange must be aligned");
177177

178+
static constexpr bool ConcurrencySafe = false;
179+
178180
constexpr SmallBuddyRange() = default;
179181

180182
capptr::Chunk<void> alloc_range(size_t size)

src/backend/statsrange.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ namespace snmalloc
3131

3232
static constexpr bool Aligned = ParentRange::Aligned;
3333

34+
static constexpr bool ConcurrencySafe = ParentRange::ConcurrencySafe;
35+
3436
constexpr StatsRange() = default;
3537

3638
capptr::Chunk<void> alloc_range(size_t size)

0 commit comments

Comments
 (0)