Skip to content

Commit 0a3ea0d

Browse files
committed
Make Secondary Allocator a template parameter
This refactors the use of the Secondary Allocator, so that out of tree implementations can be used.
1 parent e600bf1 commit 0a3ea0d

File tree

9 files changed

+28
-33
lines changed

9 files changed

+28
-33
lines changed

src/snmalloc/backend/fixedglobalconfig.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include "../backend_helpers/backend_helpers.h"
4+
#include "../mem/secondary/default.h"
45
#include "snmalloc/stl/type_traits.h"
56
#include "standard_range.h"
67

@@ -13,12 +14,14 @@ namespace snmalloc
1314
*/
1415
template<
1516
SNMALLOC_CONCEPT(IsPAL) PAL,
16-
typename ClientMetaDataProvider = NoClientMetaDataProvider>
17+
typename ClientMetaDataProvider = NoClientMetaDataProvider,
18+
typename SecondaryAllocator_ = DefaultSecondaryAllocator>
1719
class FixedRangeConfig final : public CommonConfig
1820
{
1921
public:
2022
using PagemapEntry = DefaultPagemapEntry<ClientMetaDataProvider>;
2123
using ClientMeta = ClientMetaDataProvider;
24+
using SecondaryAllocator = SecondaryAllocator_;
2225

2326
private:
2427
using ConcretePagemap =

src/snmalloc/backend/globalconfig.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "../backend_helpers/backend_helpers.h"
44
#include "backend.h"
55
#include "meta_protected_range.h"
6-
#include "snmalloc/mem/secondary.h"
6+
#include "snmalloc/mem/secondary/default.h"
77
#include "standard_range.h"
88

99
namespace snmalloc
@@ -22,16 +22,19 @@ namespace snmalloc
2222
* The Configuration sets up a Pagemap for the backend to use, and the state
2323
* required to build new allocators (GlobalPoolState).
2424
*/
25-
template<typename ClientMetaDataProvider = NoClientMetaDataProvider>
25+
template<
26+
typename ClientMetaDataProvider = NoClientMetaDataProvider,
27+
typename SecondaryAllocator_ = DefaultSecondaryAllocator>
2628
class StandardConfigClientMeta final : public CommonConfig
2729
{
28-
using GlobalPoolState =
29-
PoolState<Allocator<StandardConfigClientMeta<ClientMetaDataProvider>>>;
30+
using GlobalPoolState = PoolState<Allocator<
31+
StandardConfigClientMeta<ClientMetaDataProvider, SecondaryAllocator_>>>;
3032

3133
public:
3234
using Pal = DefaultPal;
3335
using PagemapEntry = DefaultPagemapEntry<ClientMetaDataProvider>;
3436
using ClientMeta = ClientMetaDataProvider;
37+
using SecondaryAllocator = SecondaryAllocator_;
3538

3639
private:
3740
using ConcretePagemap =

src/snmalloc/global/globalalloc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,9 @@ namespace snmalloc
302302
const auto& entry = Config_::Backend::get_metaentry(address_cast(p_raw));
303303

304304
if (SNMALLOC_UNLIKELY(
305-
!SecondaryAllocator::pass_through && !entry.is_owned() &&
305+
!Config::SecondaryAllocator::pass_through && !entry.is_owned() &&
306306
p_raw != nullptr))
307-
return SecondaryAllocator::alloc_size(p_raw);
307+
return Config::SecondaryAllocator::alloc_size(p_raw);
308308
// TODO What's the domestication policy here? At the moment we just
309309
// probe the pagemap with the raw address, without checks. There could
310310
// be implicit domestication through the `Config::Pagemap` or

src/snmalloc/mem/corealloc.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include "metadata.h"
77
#include "pool.h"
88
#include "remotecache.h"
9-
#include "secondary.h"
109
#include "sizeclasstable.h"
1110
#include "snmalloc/stl/new.h"
1211
#include "ticker.h"
@@ -653,7 +652,7 @@ namespace snmalloc
653652
}
654653

655654
// Check if secondary allocator wants to offer the memory
656-
void* result = SecondaryAllocator::allocate(
655+
void* result = Config::SecondaryAllocator::allocate(
657656
[size]() -> stl::Pair<size_t, size_t> {
658657
return {size, natural_alignment(size)};
659658
});
@@ -710,7 +709,7 @@ namespace snmalloc
710709
SNMALLOC_FAST_PATH capptr::Alloc<void>
711710
small_refill(smallsizeclass_t sizeclass, freelist::Iter<>& fast_free_list)
712711
{
713-
void* result = SecondaryAllocator::allocate(
712+
void* result = Config::SecondaryAllocator::allocate(
714713
[sizeclass]() -> stl::Pair<size_t, size_t> {
715714
auto size = sizeclass_to_size(sizeclass);
716715
return {size, natural_alignment(size)};
@@ -1285,7 +1284,7 @@ namespace snmalloc
12851284
}
12861285

12871286
dealloc_cheri_checks(p_tame.unsafe_ptr());
1288-
SecondaryAllocator::deallocate(p_tame.unsafe_ptr());
1287+
Config::SecondaryAllocator::deallocate(p_tame.unsafe_ptr());
12891288
}
12901289

12911290
/**

src/snmalloc/mem/secondary.h

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/snmalloc/snmalloc.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,23 @@
66
// Provides the global configuration for the snmalloc implementation.
77
#include "backend/globalconfig.h"
88

9+
#ifdef SNMALLOC_ENABLE_GWP_ASAN_INTEGRATION
10+
# include "snmalloc/mem/secondary/gwp_asan.h"
11+
#endif
12+
913
namespace snmalloc
1014
{
1115
// If you define SNMALLOC_PROVIDE_OWN_CONFIG then you must provide your own
1216
// definition of `snmalloc::Alloc` before including any files that include
1317
// `snmalloc.h` or consume the global allocation APIs.
1418
#ifndef SNMALLOC_PROVIDE_OWN_CONFIG
19+
# ifdef SNMALLOC_ENABLE_GWP_ASAN_INTEGRATION
20+
using Config = snmalloc::StandardConfigClientMeta<
21+
NoClientMetaDataProvider,
22+
GwpAsanSecondaryAllocator>;
23+
# else
1524
using Config = snmalloc::StandardConfigClientMeta<NoClientMetaDataProvider>;
25+
# endif
1626
#endif
1727
/**
1828
* Create allocator type for this configuration.

src/test/func/domestication/domestication.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <snmalloc/backend/backend.h>
66
#include <snmalloc/backend/standard_range.h>
77
#include <snmalloc/backend_helpers/backend_helpers.h>
8+
#include <snmalloc/mem/secondary/default.h>
89
#include <snmalloc/snmalloc_core.h>
910

1011
// Specify type of allocator
@@ -18,6 +19,7 @@ namespace snmalloc
1819
using Pal = DefaultPal;
1920
using PagemapEntry = DefaultPagemapEntry<NoClientMetaDataProvider>;
2021
using ClientMeta = NoClientMetaDataProvider;
22+
using SecondaryAllocator = DefaultSecondaryAllocator;
2123

2224
private:
2325
using ConcretePagemap =

src/test/func/fixed_region/fixed_region.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include "snmalloc/mem/secondary.h"
21
#include "test/setup.h"
32

43
#include <iostream>

src/test/func/fixed_region_alloc/fixed_region_alloc.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include "snmalloc/mem/secondary.h"
21
#include "test/setup.h"
32

43
#include <iostream>

0 commit comments

Comments
 (0)