Skip to content

Commit 2e4b289

Browse files
committed
Removed DecommitAll strategy
The DecommitAll strategy performs badly. We are not functionally testing it, and it does not seem investing in it due to its performance.
1 parent a2b56f9 commit 2e4b289

File tree

5 files changed

+18
-56
lines changed

5 files changed

+18
-56
lines changed

src/mem/alloc.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -930,8 +930,7 @@ namespace snmalloc
930930

931931
if (super != nullptr)
932932
{
933-
Slab* slab =
934-
super->alloc_short_slab(sizeclass, large_allocator.memory_provider);
933+
Slab* slab = super->alloc_short_slab(sizeclass);
935934
assert(super->is_full());
936935
return slab;
937936
}
@@ -941,8 +940,7 @@ namespace snmalloc
941940
if ((allow_reserve == NoReserve) && (super == nullptr))
942941
return nullptr;
943942

944-
Slab* slab =
945-
super->alloc_short_slab(sizeclass, large_allocator.memory_provider);
943+
Slab* slab = super->alloc_short_slab(sizeclass);
946944
reposition_superslab(super);
947945
return slab;
948946
}
@@ -952,8 +950,7 @@ namespace snmalloc
952950
if ((allow_reserve == NoReserve) && (super == nullptr))
953951
return nullptr;
954952

955-
Slab* slab =
956-
super->alloc_slab(sizeclass, large_allocator.memory_provider);
953+
Slab* slab = super->alloc_slab(sizeclass);
957954
reposition_superslab(super);
958955
return slab;
959956
}
@@ -1074,7 +1071,7 @@ namespace snmalloc
10741071
SlabList* sl = &small_classes[sizeclass];
10751072
Slab* slab = Metaslab::get_slab(p);
10761073
Superslab::Action a =
1077-
slab->dealloc_slow(sl, super, p, large_allocator.memory_provider);
1074+
slab->dealloc_slow(sl, super, p);
10781075
if (likely(a == Superslab::NoSlabReturn))
10791076
return;
10801077
stats().sizeclass_dealloc_slab(sizeclass);
@@ -1191,7 +1188,7 @@ namespace snmalloc
11911188
{
11921189
MEASURE_TIME(medium_dealloc, 4, 16);
11931190
stats().sizeclass_dealloc(sizeclass);
1194-
bool was_full = slab->dealloc(p, large_allocator.memory_provider);
1191+
bool was_full = slab->dealloc(p);
11951192

11961193
#ifdef CHECK_CLIENT
11971194
if (!is_multiple_of_sizeclass(

src/mem/allocconfig.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,6 @@ namespace snmalloc
6868
* Decommit superslabs when they are entirely empty.
6969
*/
7070
DecommitSuper,
71-
/**
72-
* Decommit all slabs once they are empty.
73-
*/
74-
DecommitAll,
7571
/**
7672
* Decommit superslabs only when we are informed of memory pressure by the
7773
* OS, do not decommit anything in normal operation.

src/mem/mediumslab.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,13 @@ namespace snmalloc
8787
assert(is_aligned_block<OS_PAGE_SIZE>(p, OS_PAGE_SIZE));
8888
size = bits::align_up(size, OS_PAGE_SIZE);
8989

90-
if constexpr (decommit_strategy == DecommitAll)
91-
memory_provider.template notify_using<zero_mem>(p, size);
92-
else if constexpr (zero_mem == YesZero)
90+
if constexpr (zero_mem == YesZero)
9391
memory_provider.template zero<true>(p, size);
9492

9593
return p;
9694
}
9795

98-
template<typename MemoryProvider>
99-
bool dealloc(void* p, MemoryProvider& memory_provider)
96+
bool dealloc(void* p)
10097
{
10198
assert(head > 0);
10299

@@ -105,9 +102,6 @@ namespace snmalloc
105102
free++;
106103
stack[--head] = pointer_to_index(p);
107104

108-
if constexpr (decommit_strategy == DecommitAll)
109-
memory_provider.notify_not_using(p, sizeclass_to_size(sizeclass));
110-
111105
return was_full;
112106
}
113107

src/mem/slab.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,8 @@ namespace snmalloc
178178
// This does not need to remove the "use" as done by the fast path.
179179
// Returns a complex return code for managing the superslab meta data.
180180
// i.e. This deallocation could make an entire superslab free.
181-
template<typename MemoryProvider>
182181
SNMALLOC_SLOW_PATH typename Superslab::Action dealloc_slow(
183-
SlabList* sl, Superslab* super, void* p, MemoryProvider& memory_provider)
182+
SlabList* sl, Superslab* super, void* p)
184183
{
185184
Metaslab& meta = super->get_meta(this);
186185

@@ -191,9 +190,9 @@ namespace snmalloc
191190
{
192191
// Dealloc on the superslab.
193192
if (is_short())
194-
return super->dealloc_short_slab(memory_provider);
193+
return super->dealloc_short_slab();
195194

196-
return super->dealloc_slab(this, memory_provider);
195+
return super->dealloc_slab(this);
197196
}
198197
// Update the head and the sizeclass link.
199198
uint16_t index = pointer_to_index(p);
@@ -212,10 +211,11 @@ namespace snmalloc
212211
sl->remove(meta.get_link(this));
213212

214213
if (is_short())
215-
return super->dealloc_short_slab(memory_provider);
214+
return super->dealloc_short_slab();
216215

217-
return super->dealloc_slab(this, memory_provider);
216+
return super->dealloc_slab(this);
218217
}
218+
219219
bool is_short()
220220
{
221221
return Metaslab::is_short(this);

src/mem/superslab.h

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -154,29 +154,21 @@ namespace snmalloc
154154
return meta[slab_to_index(slab)];
155155
}
156156

157-
template<typename MemoryProvider>
158-
Slab*
159-
alloc_short_slab(sizeclass_t sizeclass, MemoryProvider& memory_provider)
157+
Slab* alloc_short_slab(sizeclass_t sizeclass)
160158
{
161159
if ((used & 1) == 1)
162-
return alloc_slab(sizeclass, memory_provider);
160+
return alloc_slab(sizeclass);
163161

164162
meta[0].allocated = 1;
165163
meta[0].head = nullptr;
166164
meta[0].sizeclass = static_cast<uint8_t>(sizeclass);
167165
meta[0].link = get_initial_offset(sizeclass, true);
168166

169-
{
170-
memory_provider.template notify_using<NoZero>(
171-
pointer_offset(this, OS_PAGE_SIZE), SLAB_SIZE - OS_PAGE_SIZE);
172-
}
173-
174167
used++;
175168
return (Slab*)this;
176169
}
177170

178-
template<typename MemoryProvider>
179-
Slab* alloc_slab(sizeclass_t sizeclass, MemoryProvider& memory_provider)
171+
Slab* alloc_slab(sizeclass_t sizeclass)
180172
{
181173
uint8_t h = head;
182174
Slab* slab = pointer_cast<Slab>(
@@ -192,17 +184,11 @@ namespace snmalloc
192184
head = h + n + 1;
193185
used += 2;
194186

195-
if constexpr (decommit_strategy == DecommitAll)
196-
{
197-
memory_provider.template notify_using<NoZero>(slab, SLAB_SIZE);
198-
}
199-
200187
return slab;
201188
}
202189

203190
// Returns true, if this alters the value of get_status
204-
template<typename MemoryProvider>
205-
Action dealloc_slab(Slab* slab, MemoryProvider& memory_provider)
191+
Action dealloc_slab(Slab* slab)
206192
{
207193
// This is not the short slab.
208194
uint8_t index = static_cast<uint8_t>(slab_to_index(slab));
@@ -214,9 +200,6 @@ namespace snmalloc
214200
bool was_almost_full = is_almost_full();
215201
used -= 2;
216202

217-
if constexpr (decommit_strategy == DecommitAll)
218-
memory_provider.notify_not_using(slab, SLAB_SIZE);
219-
220203
assert(meta[index].is_unused());
221204
if (was_almost_full || is_empty())
222205
return StatusChange;
@@ -225,16 +208,8 @@ namespace snmalloc
225208
}
226209

227210
// Returns true, if this alters the value of get_status
228-
template<typename MemoryProvider>
229-
Action dealloc_short_slab(MemoryProvider& memory_provider)
211+
Action dealloc_short_slab()
230212
{
231-
// This is the short slab.
232-
if constexpr (decommit_strategy == DecommitAll)
233-
{
234-
memory_provider.notify_not_using(
235-
pointer_offset(this, OS_PAGE_SIZE), SLAB_SIZE - OS_PAGE_SIZE);
236-
}
237-
238213
bool was_full = is_full();
239214
used--;
240215

0 commit comments

Comments
 (0)