Skip to content

Commit 1e8d0bd

Browse files
nwf-msrmjp41
authored andcommitted
MemoryProviderStateMixin is not a PAL
1 parent d79a818 commit 1e8d0bd

File tree

5 files changed

+26
-27
lines changed

5 files changed

+26
-27
lines changed

src/mem/alloc.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,7 @@ namespace snmalloc
10631063
void* p = remove_cache_friendly_offset(head, sizeclass);
10641064
if constexpr (zero_mem == YesZero)
10651065
{
1066-
large_allocator.memory_provider.zero(p, sizeclass_to_size(sizeclass));
1066+
MemoryProvider::Pal::zero(p, sizeclass_to_size(sizeclass));
10671067
}
10681068
return p;
10691069
}
@@ -1109,8 +1109,8 @@ namespace snmalloc
11091109
SlabLink* link = sl.get_next();
11101110
slab = get_slab(link);
11111111
auto& ffl = small_fast_free_lists[sizeclass];
1112-
return slab->alloc<zero_mem>(
1113-
sl, ffl, rsize, large_allocator.memory_provider);
1112+
return slab->alloc<zero_mem, typename MemoryProvider::Pal>(
1113+
sl, ffl, rsize);
11141114
}
11151115
return small_alloc_rare<zero_mem, allow_reserve>(sizeclass, size);
11161116
}
@@ -1182,7 +1182,7 @@ namespace snmalloc
11821182

11831183
if constexpr (zero_mem == YesZero)
11841184
{
1185-
large_allocator.memory_provider.zero(p, sizeclass_to_size(sizeclass));
1185+
MemoryProvider::Pal::zero(p, sizeclass_to_size(sizeclass));
11861186
}
11871187
return p;
11881188
}
@@ -1313,7 +1313,7 @@ namespace snmalloc
13131313

13141314
if (slab != nullptr)
13151315
{
1316-
p = slab->alloc<zero_mem>(size, large_allocator.memory_provider);
1316+
p = slab->alloc<zero_mem, typename MemoryProvider::Pal>(size);
13171317

13181318
if (slab->full())
13191319
sc->pop();
@@ -1336,7 +1336,7 @@ namespace snmalloc
13361336

13371337
slab->init(public_state(), sizeclass, rsize);
13381338
chunkmap().set_slab(slab);
1339-
p = slab->alloc<zero_mem>(size, large_allocator.memory_provider);
1339+
p = slab->alloc<zero_mem, typename MemoryProvider::Pal>(size);
13401340

13411341
if (!slab->full())
13421342
sc->insert(slab);

src/mem/largealloc.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ namespace snmalloc
5757
// global state of the allocator. This is currently stored in the memory
5858
// provider, so we add this in.
5959
template<SNMALLOC_CONCEPT(ConceptPAL) PAL>
60-
class MemoryProviderStateMixin : public PalNotificationObject, public PAL
60+
class MemoryProviderStateMixin : public PalNotificationObject
6161
{
6262
/**
6363
* Simple flag for checking if another instance of lazy-decommit is
@@ -76,6 +76,8 @@ namespace snmalloc
7676
std::atomic<size_t> peak_memory_used_bytes{0};
7777

7878
public:
79+
using Pal = PAL;
80+
7981
/**
8082
* Memory current available in large_stacks
8183
*/
@@ -258,7 +260,7 @@ namespace snmalloc
258260
p = memory_provider.template reserve<false>(large_class);
259261
if (p == nullptr)
260262
return nullptr;
261-
memory_provider.template notify_using<zero_mem>(p, rsize);
263+
MemoryProvider::Pal::template notify_using<zero_mem>(p, rsize);
262264
}
263265
else
264266
{
@@ -276,19 +278,19 @@ namespace snmalloc
276278
// The first page is already in "use" for the stack element,
277279
// this will need zeroing for a YesZero call.
278280
if constexpr (zero_mem == YesZero)
279-
memory_provider.template zero<true>(p, OS_PAGE_SIZE);
281+
MemoryProvider::Pal::template zero<true>(p, OS_PAGE_SIZE);
280282

281283
// Notify we are using the rest of the allocation.
282284
// Passing zero_mem ensures the PAL provides zeroed pages if
283285
// required.
284-
memory_provider.template notify_using<zero_mem>(
286+
MemoryProvider::Pal::template notify_using<zero_mem>(
285287
pointer_offset(p, OS_PAGE_SIZE), rsize - OS_PAGE_SIZE);
286288
}
287289
else
288290
{
289291
// This is a superslab that has not been decommitted.
290292
if constexpr (zero_mem == YesZero)
291-
memory_provider.template zero<true>(
293+
MemoryProvider::Pal::template zero<true>(
292294
p, bits::align_up(size, OS_PAGE_SIZE));
293295
else
294296
UNUSED(size);
@@ -304,7 +306,7 @@ namespace snmalloc
304306
if constexpr (decommit_strategy == DecommitSuperLazy)
305307
{
306308
static_assert(
307-
pal_supports<LowMemoryNotification, MemoryProvider>,
309+
pal_supports<LowMemoryNotification, typename MemoryProvider::Pal>,
308310
"A lazy decommit strategy cannot be implemented on platforms "
309311
"without low memory notifications");
310312
}
@@ -316,7 +318,7 @@ namespace snmalloc
316318
(decommit_strategy != DecommitNone) &&
317319
(large_class != 0 || decommit_strategy == DecommitSuper))
318320
{
319-
memory_provider.notify_not_using(
321+
MemoryProvider::Pal::notify_not_using(
320322
pointer_offset(p, OS_PAGE_SIZE), rsize - OS_PAGE_SIZE);
321323
}
322324

src/mem/mediumslab.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ namespace snmalloc
7676
return sizeclass;
7777
}
7878

79-
template<ZeroMem zero_mem, typename MemoryProvider>
80-
void* alloc(size_t size, MemoryProvider& memory_provider)
79+
template<ZeroMem zero_mem, SNMALLOC_CONCEPT(ConceptPAL) PAL>
80+
void* alloc(size_t size)
8181
{
8282
SNMALLOC_ASSERT(!full());
8383

@@ -86,7 +86,7 @@ namespace snmalloc
8686
free--;
8787

8888
if constexpr (zero_mem == YesZero)
89-
memory_provider.zero(p, size);
89+
PAL::zero(p, size);
9090
else
9191
UNUSED(size);
9292

src/mem/slab.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,9 @@ namespace snmalloc
3636
* Returns the link as the allocation, and places the free list into the
3737
* `fast_free_list` for further allocations.
3838
*/
39-
template<ZeroMem zero_mem, typename MemoryProvider>
40-
SNMALLOC_FAST_PATH void* alloc(
41-
SlabList& sl,
42-
FreeListHead& fast_free_list,
43-
size_t rsize,
44-
MemoryProvider& memory_provider)
39+
template<ZeroMem zero_mem, SNMALLOC_CONCEPT(ConceptPAL) PAL>
40+
SNMALLOC_FAST_PATH void*
41+
alloc(SlabList& sl, FreeListHead& fast_free_list, size_t rsize)
4542
{
4643
// Read the head from the metadata stored in the superslab.
4744
Metaslab& meta = get_meta();
@@ -73,9 +70,9 @@ namespace snmalloc
7370
if constexpr (zero_mem == YesZero)
7471
{
7572
if (rsize < PAGE_ALIGNED_SIZE)
76-
memory_provider.zero(p, rsize);
73+
PAL::zero(p, rsize);
7774
else
78-
memory_provider.template zero<true>(p, rsize);
75+
PAL::template zero<true>(p, rsize);
7976
}
8077
else
8178
{

src/test/perf/low_memory/low-memory.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,17 @@ void reduce_pressure(Queue& allocations)
9898
* Template parameter required to handle `if constexpr` always evaluating both
9999
* sides.
100100
*/
101-
template<typename PAL>
101+
template<typename MemoryProvider>
102102
void register_for_pal_notifications()
103103
{
104-
PAL::register_for_low_memory_callback(&update_epoch);
104+
MemoryProvider::Pal::register_for_low_memory_callback(&update_epoch);
105105
}
106106

107107
int main(int argc, char** argv)
108108
{
109109
opt::Opt opt(argc, argv);
110110

111-
if constexpr (pal_supports<LowMemoryNotification, GlobalVirtual>)
111+
if constexpr (pal_supports<LowMemoryNotification, GlobalVirtual::Pal>)
112112
{
113113
register_for_pal_notifications<GlobalVirtual>();
114114
}

0 commit comments

Comments
 (0)