NFC: backend_helper: generalize chunk bounds
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.
This commit is contained in:
committed by
Nathaniel Filardo
parent
e17672d3c1
commit
6a5f3c2b82
@@ -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
|
||||
{
|
||||
|
||||
@@ -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,
|
||||
@@ -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,
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
namespace snmalloc
|
||||
{
|
||||
template<SNMALLOC_CONCEPT(capptr::ConceptBound) B = capptr::bounds::Chunk>
|
||||
class EmptyRange
|
||||
{
|
||||
public:
|
||||
@@ -10,9 +11,11 @@ namespace snmalloc
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
@@ -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);
|
||||
@@ -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>(
|
||||
|
||||
@@ -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;
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
@@ -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)
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
@@ -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));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user