Skip to content

Commit

Permalink
NFC: backend_helper: generalize chunk bounds
Browse files Browse the repository at this point in the history
Most ranges just deal with whatever kinds of ranges their parent deal with, but
that might be Chunk- or (soon) Arena-bounded.  This commit does not yet
introduce nuance, but just sets the stage.
  • Loading branch information
nwf-msr committed Jun 9, 2022
1 parent e17672d commit 6a5f3c2
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/snmalloc/backend/standard_range.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace snmalloc
template<
typename PAL,
typename Pagemap,
typename Base = EmptyRange,
typename Base = EmptyRange<>,
size_t MinSizeBits = MinBaseSizeBits<PAL>()>
struct StandardLocalState : BaseLocalStateConstants
{
Expand Down
9 changes: 7 additions & 2 deletions src/snmalloc/backend_helpers/commitrange.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@ namespace snmalloc

static constexpr bool ConcurrencySafe = ParentRange::ConcurrencySafe;

using ChunkBounds = typename ParentRange::ChunkBounds;
static_assert(
ChunkBounds::address_space_control ==
capptr::dimension::AddressSpaceControl::Full);

constexpr Type() = default;

capptr::Chunk<void> alloc_range(size_t size)
CapPtr<void, ChunkBounds> alloc_range(size_t size)
{
SNMALLOC_ASSERT_MSG(
(size % PAL::page_size) == 0,
Expand All @@ -33,7 +38,7 @@ namespace snmalloc
return range;
}

void dealloc_range(capptr::Chunk<void> base, size_t size)
void dealloc_range(CapPtr<void, ChunkBounds> base, size_t size)
{
SNMALLOC_ASSERT_MSG(
(size % PAL::page_size) == 0,
Expand Down
5 changes: 4 additions & 1 deletion src/snmalloc/backend_helpers/empty_range.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@

namespace snmalloc
{
template<SNMALLOC_CONCEPT(capptr::ConceptBound) B = capptr::bounds::Chunk>
class EmptyRange
{
public:
static constexpr bool Aligned = true;

static constexpr bool ConcurrencySafe = true;

using ChunkBounds = B;

constexpr EmptyRange() = default;

capptr::Chunk<void> alloc_range(size_t)
CapPtr<void, ChunkBounds> alloc_range(size_t)
{
return nullptr;
}
Expand Down
8 changes: 5 additions & 3 deletions src/snmalloc/backend_helpers/globalrange.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace snmalloc
*/
struct GlobalRange
{
template<typename ParentRange = EmptyRange>
template<typename ParentRange = EmptyRange<>>
class Type : public StaticParent<ParentRange>
{
using StaticParent<ParentRange>::parent;
Expand All @@ -27,15 +27,17 @@ namespace snmalloc

static constexpr bool ConcurrencySafe = true;

using ChunkBounds = typename ParentRange::ChunkBounds;

constexpr Type() = default;

capptr::Chunk<void> alloc_range(size_t size)
CapPtr<void, ChunkBounds> alloc_range(size_t size)
{
FlagLock lock(spin_lock);
return parent.alloc_range(size);
}

void dealloc_range(capptr::Chunk<void> base, size_t size)
void dealloc_range(CapPtr<void, ChunkBounds> base, size_t size)
{
FlagLock lock(spin_lock);
parent.dealloc_range(base, size);
Expand Down
4 changes: 3 additions & 1 deletion src/snmalloc/backend_helpers/largebuddyrange.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ namespace snmalloc
bits::one_at_bit(MIN_REFILL_SIZE_BITS);

public:
template<typename ParentRange = EmptyRange>
template<typename ParentRange = EmptyRange<>>
class Type : public ContainsParent<ParentRange>
{
using ContainsParent<ParentRange>::parent;
Expand Down Expand Up @@ -341,6 +341,8 @@ namespace snmalloc

static constexpr bool ConcurrencySafe = false;

using ChunkBounds = capptr::bounds::Chunk;

constexpr Type() = default;

capptr::Chunk<void> alloc_range(size_t size)
Expand Down
8 changes: 5 additions & 3 deletions src/snmalloc/backend_helpers/logrange.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace snmalloc
template<size_t RangeName>
struct LogRange
{
template<typename ParentRange = EmptyRange>
template<typename ParentRange = EmptyRange<>>
class Type : public ContainsParent<ParentRange>
{
using ContainsParent<ParentRange>::parent;
Expand All @@ -24,9 +24,11 @@ namespace snmalloc

static constexpr bool ConcurrencySafe = ParentRange::ConcurrencySafe;

using ChunkBounds = typename ParentRange::ChunkBounds;

constexpr Type() = default;

capptr::Chunk<void> alloc_range(size_t size)
CapPtr<void, ChunkBounds> alloc_range(size_t size)
{
#ifdef SNMALLOC_TRACING
message<1024>("Call alloc_range({}) on {}", size, RangeName);
Expand All @@ -39,7 +41,7 @@ namespace snmalloc
return range;
}

void dealloc_range(capptr::Chunk<void> base, size_t size)
void dealloc_range(CapPtr<void, ChunkBounds> base, size_t size)
{
#ifdef SNMALLOC_TRACING
message<1024>(
Expand Down
6 changes: 4 additions & 2 deletions src/snmalloc/backend_helpers/pagemapregisterrange.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace snmalloc
bool CanConsolidate = true>
struct PagemapRegisterRange
{
template<typename ParentRange = EmptyRange>
template<typename ParentRange = EmptyRange<>>
class Type : public ContainsParent<ParentRange>
{
using ContainsParent<ParentRange>::parent;
Expand All @@ -23,7 +23,9 @@ namespace snmalloc

static constexpr bool ConcurrencySafe = ParentRange::ConcurrencySafe;

capptr::Chunk<void> alloc_range(size_t size)
using ChunkBounds = typename ParentRange::ChunkBounds;

CapPtr<void, ChunkBounds> alloc_range(size_t size)
{
auto base = parent.alloc_range(size);

Expand Down
2 changes: 2 additions & 0 deletions src/snmalloc/backend_helpers/palrange.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace snmalloc
// need to be changed.
static constexpr bool ConcurrencySafe = true;

using ChunkBounds = capptr::bounds::Chunk;

constexpr PalRange() = default;

capptr::Chunk<void> alloc_range(size_t size)
Expand Down
4 changes: 3 additions & 1 deletion src/snmalloc/backend_helpers/smallbuddyrange.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ namespace snmalloc

struct SmallBuddyRange
{
template<typename ParentRange = EmptyRange>
template<typename ParentRange = EmptyRange<>>
class Type : public ContainsParent<ParentRange>
{
using ContainsParent<ParentRange>::parent;
Expand Down Expand Up @@ -187,6 +187,8 @@ namespace snmalloc

static constexpr bool ConcurrencySafe = false;

using ChunkBounds = capptr::bounds::Chunk;

constexpr Type() = default;

capptr::Chunk<void> alloc_range(size_t size)
Expand Down
8 changes: 5 additions & 3 deletions src/snmalloc/backend_helpers/statsrange.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace snmalloc
*/
struct StatsRange
{
template<typename ParentRange = EmptyRange>
template<typename ParentRange = EmptyRange<>>
class Type : public ContainsParent<ParentRange>
{
using ContainsParent<ParentRange>::parent;
Expand All @@ -25,9 +25,11 @@ namespace snmalloc

static constexpr bool ConcurrencySafe = ParentRange::ConcurrencySafe;

using ChunkBounds = typename ParentRange::ChunkBounds;

constexpr Type() = default;

capptr::Chunk<void> alloc_range(size_t size)
CapPtr<void, ChunkBounds> alloc_range(size_t size)
{
auto result = parent.alloc_range(size);
if (result != nullptr)
Expand All @@ -43,7 +45,7 @@ namespace snmalloc
return result;
}

void dealloc_range(capptr::Chunk<void> base, size_t size)
void dealloc_range(CapPtr<void, ChunkBounds> base, size_t size)
{
current_usage -= size;
parent.dealloc_range(base, size);
Expand Down
6 changes: 4 additions & 2 deletions src/snmalloc/backend_helpers/subrange.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace snmalloc
template<typename PAL, size_t RATIO_BITS>
struct SubRange
{
template<typename ParentRange = EmptyRange>
template<typename ParentRange = EmptyRange<>>
class Type : public ContainsParent<ParentRange>
{
using ContainsParent<ParentRange>::parent;
Expand All @@ -24,7 +24,9 @@ namespace snmalloc

static constexpr bool ConcurrencySafe = ParentRange::ConcurrencySafe;

capptr::Chunk<void> alloc_range(size_t sub_size)
using ChunkBounds = typename ParentRange::ChunkBounds;

CapPtr<void, ChunkBounds> alloc_range(size_t sub_size)
{
SNMALLOC_ASSERT(bits::is_pow2(sub_size));

Expand Down

0 comments on commit 6a5f3c2

Please sign in to comment.