Skip to content

Commit 2e28957

Browse files
committed
Move all decommit strategy into LargeAllocator
The code for decommit was distribured in the code base. Removing Decommit All means that it can logically reside in lthe arge allocator.
1 parent 2e4b289 commit 2e28957

File tree

2 files changed

+20
-28
lines changed

2 files changed

+20
-28
lines changed

src/mem/alloc.h

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,20 +1111,6 @@ namespace snmalloc
11111111
{
11121112
super_available.remove(super);
11131113

1114-
if constexpr (decommit_strategy == DecommitSuper)
1115-
{
1116-
large_allocator.memory_provider.notify_not_using(
1117-
pointer_offset(super, OS_PAGE_SIZE),
1118-
SUPERSLAB_SIZE - OS_PAGE_SIZE);
1119-
}
1120-
else if constexpr (decommit_strategy == DecommitSuperLazy)
1121-
{
1122-
static_assert(
1123-
pal_supports<LowMemoryNotification, MemoryProvider>,
1124-
"A lazy decommit strategy cannot be implemented on platforms "
1125-
"without low memory notifications");
1126-
}
1127-
11281114
chunkmap().clear_slab(super);
11291115
large_allocator.dealloc(super, 0);
11301116
stats().superslab_push();
@@ -1208,12 +1194,6 @@ namespace snmalloc
12081194
sc->remove(slab);
12091195
}
12101196

1211-
if constexpr (decommit_strategy == DecommitSuper)
1212-
{
1213-
large_allocator.memory_provider.notify_not_using(
1214-
pointer_offset(slab, OS_PAGE_SIZE), SUPERSLAB_SIZE - OS_PAGE_SIZE);
1215-
}
1216-
12171197
chunkmap().clear_slab(slab);
12181198
large_allocator.dealloc(slab, 0);
12191199
stats().superslab_push();
@@ -1261,19 +1241,13 @@ namespace snmalloc
12611241
MEASURE_TIME(large_dealloc, 4, 16);
12621242

12631243
size_t size_bits = bits::next_pow2_bits(size);
1264-
size_t rsize = bits::one_at_bit(size_bits);
1265-
assert(rsize >= SUPERSLAB_SIZE);
1244+
assert(bits::one_at_bit(size_bits) >= SUPERSLAB_SIZE);
12661245
size_t large_class = size_bits - SUPERSLAB_BITS;
12671246

12681247
chunkmap().clear_large_size(p, size);
12691248

12701249
stats().large_dealloc(large_class);
12711250

1272-
// Cross-reference largealloc's alloc() decommitted condition.
1273-
if ((decommit_strategy != DecommitNone) || (large_class > 0))
1274-
large_allocator.memory_provider.notify_not_using(
1275-
pointer_offset(p, OS_PAGE_SIZE), rsize - OS_PAGE_SIZE);
1276-
12771251
// Initialise in order to set the correct SlabKind.
12781252
Largeslab* slab = static_cast<Largeslab*>(p);
12791253
slab->init();

src/mem/largealloc.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ namespace snmalloc
362362
bool decommitted =
363363
((decommit_strategy == DecommitSuperLazy) &&
364364
(static_cast<Baseslab*>(p)->get_kind() == Decommitted)) ||
365-
(large_class > 0) || (decommit_strategy != DecommitNone);
365+
(large_class > 0) || (decommit_strategy == DecommitSuper);
366366

367367
if (decommitted)
368368
{
@@ -392,6 +392,24 @@ namespace snmalloc
392392

393393
void dealloc(void* p, size_t large_class)
394394
{
395+
if constexpr (decommit_strategy == DecommitSuperLazy)
396+
{
397+
static_assert(
398+
pal_supports<LowMemoryNotification, MemoryProvider>,
399+
"A lazy decommit strategy cannot be implemented on platforms "
400+
"without low memory notifications");
401+
}
402+
403+
// Cross-reference largealloc's alloc() decommitted condition.
404+
if ((decommit_strategy != DecommitNone)
405+
&& (large_class != 0 || decommit_strategy == DecommitSuper))
406+
{
407+
size_t rsize = bits::one_at_bit(SUPERSLAB_BITS) << large_class;
408+
409+
memory_provider.notify_not_using(
410+
pointer_offset(p, OS_PAGE_SIZE), rsize - OS_PAGE_SIZE);
411+
}
412+
395413
stats.superslab_push();
396414
memory_provider.large_stack[large_class].push(static_cast<Largeslab*>(p));
397415
memory_provider.lazy_decommit_if_needed();

0 commit comments

Comments
 (0)