Skip to content

Commit 4bc2c8f

Browse files
mjp41Copilot
andcommitted
Rename BackendArena → Arena and friends
With only one Arena type and a Small/Large pair of range adapters built on it, drop the redundant 'Backend' prefix and pair the range adapters by size: BackendArena -> Arena BackendArenaBins -> ArenaBins BackendArenaRange -> LargeArenaRange (pairs with SmallArenaRange) Files and test directories renamed to match (git mv, history preserved). The test-internal 'using Arena = ...<...>;' aliases become 'TestArena' to avoid colliding with the renamed class template. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 57e12b5 commit 4bc2c8f

16 files changed

Lines changed: 204 additions & 205 deletions

File tree

CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -549,10 +549,10 @@ if(NOT SNMALLOC_HEADER_ONLY_LIBRARY)
549549
# against both fast and check testlib variants.
550550
set(TESTLIB_ONLY_TESTS
551551
aligned_dealloc
552-
backend_arena
553-
backend_arena_bins
554-
backend_arena_inplace
555-
backend_arena_range
552+
arena
553+
arenabins
554+
largearenarange
555+
smallarenarange
556556
bits first_operation memory memory_usage multi_atexit multi_threadatexit
557557
redblack statistics teardown
558558
contention external_pointer large_alloc lotsofthreads post_teardown

src/snmalloc/backend/meta_protected_range.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace snmalloc
3333
// Global range of memory
3434
using GlobalR = Pipe<
3535
Base,
36-
BackendArenaRange<
36+
LargeArenaRange<
3737
GlobalCacheSizeBits,
3838
bits::BITS - 1,
3939
Pagemap,
@@ -52,7 +52,7 @@ namespace snmalloc
5252
// would be able to corrupt meta-data.
5353
using CentralObjectRange = Pipe<
5454
GlobalR,
55-
BackendArenaRange<GlobalCacheSizeBits, bits::BITS - 1, Pagemap>,
55+
LargeArenaRange<GlobalCacheSizeBits, bits::BITS - 1, Pagemap>,
5656
LogRange<3>,
5757
GlobalRange,
5858
CommitRange<PAL>,
@@ -68,7 +68,7 @@ namespace snmalloc
6868
GlobalR,
6969
SubRange<PAL, SubRangeRatioBits>, // Use SubRange to introduce guard
7070
// pages.
71-
BackendArenaRange<
71+
LargeArenaRange<
7272
GlobalCacheSizeBits,
7373
bits::BITS - 1,
7474
Pagemap,
@@ -78,7 +78,7 @@ namespace snmalloc
7878
// page, so commit in the global range.
7979
stl::conditional_t<
8080
(max_page_chunk_size_bits > MIN_CHUNK_BITS),
81-
BackendArenaRange<
81+
LargeArenaRange<
8282
max_page_chunk_size_bits,
8383
max_page_chunk_size_bits,
8484
Pagemap,
@@ -91,7 +91,7 @@ namespace snmalloc
9191
// Local caching of object range
9292
using ObjectRange = Pipe<
9393
CentralObjectRange,
94-
BackendArenaRange<
94+
LargeArenaRange<
9595
LocalCacheSizeBits,
9696
LocalCacheSizeBits,
9797
Pagemap,
@@ -101,7 +101,7 @@ namespace snmalloc
101101
// Local caching of meta-data range
102102
using MetaRange = Pipe<
103103
CentralMetaRange,
104-
BackendArenaRange<
104+
LargeArenaRange<
105105
LocalCacheSizeBits - SubRangeRatioBits,
106106
bits::BITS - 1,
107107
Pagemap>,

src/snmalloc/backend/standard_range.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace snmalloc
3030
// Global range of memory, expose this so can be filled by init.
3131
using GlobalR = Pipe<
3232
Base,
33-
BackendArenaRange<
33+
LargeArenaRange<
3434
GlobalCacheSizeBits,
3535
bits::BITS - 1,
3636
Pagemap,
@@ -46,11 +46,11 @@ namespace snmalloc
4646
bits::next_pow2_bits_const(PAL::page_size);
4747

4848
public:
49-
// Source for object allocations and metadata
50-
// Use buddy allocators to cache locally.
49+
// Source for object allocations and metadata; thread-local cache
50+
// for chunk-sized ranges.
5151
using LargeObjectRange = Pipe<
5252
Stats,
53-
StaticConditionalRange<BackendArenaRange<
53+
StaticConditionalRange<LargeArenaRange<
5454
LocalCacheSizeBits,
5555
LocalCacheSizeBits,
5656
Pagemap,

src/snmalloc/backend_helpers/backend_arena.h renamed to src/snmalloc/backend_helpers/arena.h

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
#include "../ds_core/sizeclassconfig.h"
55
#include "../stl/array.h"
66
#include "../stl/utility.h"
7-
#include "backend_arena_bins.h"
7+
#include "arenabins.h"
88

99
#include <stddef.h>
1010
#include <stdint.h>
1111

1212
namespace snmalloc
1313
{
14-
struct BackendArenaTestAccess;
14+
struct ArenaTestAccess;
1515

1616
/**
1717
* Size encoding for a free block's first pagemap entry.
@@ -21,7 +21,7 @@ namespace snmalloc
2121
* placed in a size-1 bin (cannot serve aligned size-2 requests).
2222
* Large: 3+ chunks; precise size stored in a separate entry.
2323
*/
24-
enum class BackendArenaVariant : uint8_t
24+
enum class ArenaVariant : uint8_t
2525
{
2626
Min = 0,
2727
EvenTwo = 1,
@@ -45,7 +45,7 @@ namespace snmalloc
4545
* - `using RangeRep` — full RBTree Rep for the range tree, same
4646
* shape as `BinRep`.
4747
* - `get_variant(addr)` / `set_variant(addr, v)` — the
48-
* `BackendArenaVariant` tag for the block starting at `addr`.
48+
* `ArenaVariant` tag for the block starting at `addr`.
4949
* - `get_large_size(addr)` / `set_large_size(addr, size)` —
5050
* exact byte size for `Large` blocks (3+ units).
5151
* - `can_consolidate(higher_addr) -> bool` — whether the block at
@@ -62,7 +62,7 @@ namespace snmalloc
6262
* returned to the caller.
6363
*/
6464
template<typename Rep, size_t MIN_SIZE_BITS, size_t MAX_SIZE_BITS>
65-
class BackendArena
65+
class Arena
6666
{
6767
static_assert(MAX_SIZE_BITS > MIN_SIZE_BITS);
6868
static_assert(MAX_SIZE_BITS < bits::BITS);
@@ -72,7 +72,7 @@ namespace snmalloc
7272
static constexpr size_t TWO_UNITS = size_t(2) << MIN_SIZE_BITS;
7373

7474
static constexpr size_t B = 2;
75-
using Bins = BackendArenaBins<B, MIN_SIZE_BITS>;
75+
using Bins = ArenaBins<B, MIN_SIZE_BITS>;
7676

7777
static_assert(
7878
bits::one_at_bit(MAX_SIZE_BITS) - 1 <= Bins::max_supported_size());
@@ -89,15 +89,15 @@ namespace snmalloc
8989

9090
// ---- Metadata helpers ----
9191

92-
static BackendArenaVariant variant_of(size_t size, uintptr_t addr)
92+
static ArenaVariant variant_of(size_t size, uintptr_t addr)
9393
{
9494
if (size == UNIT_SIZE)
95-
return BackendArenaVariant::Min;
95+
return ArenaVariant::Min;
9696
if (size == TWO_UNITS)
9797
return ((addr >> MIN_SIZE_BITS) & 1) == 0 ?
98-
BackendArenaVariant::EvenTwo :
99-
BackendArenaVariant::OddTwo;
100-
return BackendArenaVariant::Large;
98+
ArenaVariant::EvenTwo :
99+
ArenaVariant::OddTwo;
100+
return ArenaVariant::Large;
101101
}
102102

103103
static stl::Pair<uintptr_t, size_t> range_from_addr(uintptr_t a)
@@ -107,12 +107,12 @@ namespace snmalloc
107107
auto v = Rep::get_variant(a);
108108
switch (v)
109109
{
110-
case BackendArenaVariant::Min:
110+
case ArenaVariant::Min:
111111
return {a, UNIT_SIZE};
112-
case BackendArenaVariant::EvenTwo:
113-
case BackendArenaVariant::OddTwo:
112+
case ArenaVariant::EvenTwo:
113+
case ArenaVariant::OddTwo:
114114
return {a, TWO_UNITS};
115-
case BackendArenaVariant::Large:
115+
case ArenaVariant::Large:
116116
{
117117
size_t s = Rep::get_large_size(a);
118118
SNMALLOC_ASSERT(
@@ -129,7 +129,7 @@ namespace snmalloc
129129
{
130130
auto path = bin_trees[0].get_root_path();
131131
return bin_trees[0].find(path, a) &&
132-
Rep::get_variant(a) == BackendArenaVariant::Min;
132+
Rep::get_variant(a) == ArenaVariant::Min;
133133
}
134134

135135
void insert_block(uintptr_t addr, size_t size)
@@ -156,12 +156,12 @@ namespace snmalloc
156156
bitmap.clear(bin);
157157
}
158158

159-
friend struct BackendArenaTestAccess;
159+
friend struct ArenaTestAccess;
160160

161161
public:
162162
using addr_t = uintptr_t;
163163

164-
constexpr BackendArena() = default;
164+
constexpr Arena() = default;
165165

166166
/**
167167
* Add a free block at `addr` with `size` bytes. The block is
@@ -179,7 +179,7 @@ namespace snmalloc
179179
// Unit alignment is required: callers feeding parent ranges (e.g.
180180
// mmap-backed PalRange returns page-aligned but not chunk-aligned
181181
// memory) must trim their input to UNIT_SIZE before reaching here.
182-
// BackendArenaRange::add_range does this trim.
182+
// LargeArenaRange::add_range does this trim.
183183
SNMALLOC_ASSERT((addr & (UNIT_SIZE - 1)) == 0);
184184
SNMALLOC_ASSERT(size > 0);
185185
SNMALLOC_ASSERT((size & (UNIT_SIZE - 1)) == 0);
@@ -348,7 +348,7 @@ namespace snmalloc
348348
uintptr_t prev = 0;
349349
bool prev_valid = false;
350350
bin_trees[0].for_each([&](uintptr_t node) {
351-
if (Rep::get_variant(node) != BackendArenaVariant::Min)
351+
if (Rep::get_variant(node) != ArenaVariant::Min)
352352
return;
353353
if (prev_valid)
354354
SNMALLOC_CHECK(
@@ -414,7 +414,7 @@ namespace snmalloc
414414
auto v = Rep::get_variant(node);
415415
auto [a, s] = range_from_addr(node);
416416
SNMALLOC_CHECK(v == variant_of(s, a));
417-
if (v == BackendArenaVariant::Large)
417+
if (v == ArenaVariant::Large)
418418
SNMALLOC_CHECK(Rep::get_large_size(node) == s);
419419
});
420420
}

src/snmalloc/backend_helpers/backend_arena_bins.h renamed to src/snmalloc/backend_helpers/arenabins.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
namespace snmalloc
99
{
1010
template<size_t INTERMEDIATE_BITS, size_t MIN_SIZE_BITS>
11-
struct BackendArenaBinsTestAccess;
11+
struct ArenaBinsTestAccess;
1212

1313
/**
1414
* Size class enumeration and bin classification used by the
15-
* BackendArena.
15+
* Arena.
1616
*
1717
* Template parameter `B` (mantissa-bit width of snmalloc's
1818
* non-power-of-two size class scheme) determines the number of
@@ -40,14 +40,14 @@ namespace snmalloc
4040
* `add` / `find_for_request` / `clear`.
4141
*
4242
* Everything else is private; tests reach it via
43-
* `BackendArenaBinsTestAccess<B, MIN_SIZE_BITS>`.
43+
* `ArenaBinsTestAccess<B, MIN_SIZE_BITS>`.
4444
*/
4545
template<size_t INTERMEDIATE_BITS, size_t MIN_SIZE_BITS>
46-
class BackendArenaBins
46+
class ArenaBins
4747
{
4848
static_assert(
4949
INTERMEDIATE_BITS >= 1 && INTERMEDIATE_BITS <= 3,
50-
"BackendArenaBins supports B in {1, 2, 3}");
50+
"ArenaBins supports B in {1, 2, 3}");
5151
static_assert(
5252
MIN_SIZE_BITS + INTERMEDIATE_BITS < bits::BITS,
5353
"MIN_SIZE_BITS + INTERMEDIATE_BITS must leave room for at least one "
@@ -73,7 +73,7 @@ namespace snmalloc
7373
};
7474

7575
private:
76-
friend struct BackendArenaBinsTestAccess<INTERMEDIATE_BITS, MIN_SIZE_BITS>;
76+
friend struct ArenaBinsTestAccess<INTERMEDIATE_BITS, MIN_SIZE_BITS>;
7777

7878
static constexpr size_t B = INTERMEDIATE_BITS;
7979

@@ -309,7 +309,7 @@ namespace snmalloc
309309
*/
310310
class Bitmap
311311
{
312-
friend struct BackendArenaBinsTestAccess<
312+
friend struct ArenaBinsTestAccess<
313313
INTERMEDIATE_BITS,
314314
MIN_SIZE_BITS>;
315315

@@ -342,7 +342,7 @@ namespace snmalloc
342342
}
343343

344344
/// Read-only test: is the bit for `bin_id` set?
345-
/// Used by `BackendArena::invariant()`.
345+
/// Used by `Arena::invariant()`.
346346
bool test(size_t bin_id) const
347347
{
348348
SNMALLOC_ASSERT(bin_id < TOTAL_BINS);
@@ -680,7 +680,7 @@ namespace snmalloc
680680
* `carve_info[sc]` is the size/alignment record for each in-range
681681
* sc (consumed by `carve` and by `bin_offset_at`'s `fits`
682682
* predicate during free-side classification).
683-
* `exp_first_sc[e]` is the first raw sc id at BackendArenaBins
683+
* `exp_first_sc[e]` is the first raw sc id at ArenaBins
684684
* exponent e (with `exp_first_sc[bits::BITS] = MAX_SC` as a sentinel
685685
* so `[exp_first_sc[e], exp_first_sc[e + 1])` is a valid raw range
686686
* for every `e < bits::BITS`).

src/snmalloc/backend_helpers/backend_helpers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include "../mem/mem.h"
44
#include "authmap.h"
5-
#include "backend_arena_range.h"
5+
#include "largearenarange.h"
66
#include "commitrange.h"
77
#include "commonconfig.h"
88
#include "defaultpagemapentry.h"

src/snmalloc/backend_helpers/inplacerep.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
#include "../ds_core/bits.h"
44
#include "../ds_core/defines.h"
55
#include "../ds_core/sizeclassconfig.h"
6-
#include "backend_arena.h"
6+
#include "arena.h"
77

88
#include <stdint.h>
99

1010
namespace snmalloc
1111
{
1212
/**
1313
* In-band tree node stored at the head of a free block managed by
14-
* `BackendArena`. Two pointer-sized words per unit; bit-packing of
14+
* `Arena`. Two pointer-sized words per unit; bit-packing of
1515
* red and variant tags lives in `word_one`. Stored as `uintptr_t`
1616
* so we can OR meta bits into the pointer slot without UB on
1717
* non-capability platforms (on CHERI, capabilities to access these
@@ -25,7 +25,7 @@ namespace snmalloc
2525
};
2626

2727
/**
28-
* In-band `Rep` for `BackendArena`. Each free block carries its
28+
* In-band `Rep` for `Arena`. Each free block carries its
2929
* own tree-node and metadata storage in its first few units:
3030
*
3131
* Unit 0 (addr): bin-tree node + variant tag.
@@ -34,7 +34,7 @@ namespace snmalloc
3434
*
3535
* Bit layout in `word_one` of each unit:
3636
* bit 0 : red bit (both trees)
37-
* bits 1..2 : variant tag (`BackendArenaVariant`, unit 0 only)
37+
* bits 1..2 : variant tag (`ArenaVariant`, unit 0 only)
3838
* `word_two` holds the second child pointer with no packed meta.
3939
* Both child pointers are unit-aligned, so their low `MIN_BITS`
4040
* bits are zero — the packed meta occupies bits below
@@ -231,14 +231,14 @@ namespace snmalloc
231231
using BinRep = TreeRep<0, BIN_META_MASK, BIN_REP_NAME>;
232232
using RangeRep = TreeRep<1, RANGE_META_MASK, RANGE_REP_NAME>;
233233

234-
static BackendArenaVariant get_variant(uintptr_t addr)
234+
static ArenaVariant get_variant(uintptr_t addr)
235235
{
236236
auto w = unit_at<0>(addr)->word_one;
237-
return static_cast<BackendArenaVariant>(
237+
return static_cast<ArenaVariant>(
238238
(w & VARIANT_MASK) >> VARIANT_SHIFT);
239239
}
240240

241-
static void set_variant(uintptr_t addr, BackendArenaVariant v)
241+
static void set_variant(uintptr_t addr, ArenaVariant v)
242242
{
243243
auto* w = &unit_at<0>(addr)->word_one;
244244
*w = (*w & ~VARIANT_MASK) | (static_cast<uintptr_t>(v) << VARIANT_SHIFT);
@@ -265,7 +265,7 @@ namespace snmalloc
265265
* Refuse consolidation across `MIN_CHUNK_SIZE` boundaries.
266266
* `SmallArenaRange::add_range_impl` splits incoming ranges at
267267
* chunk boundaries, but does not eagerly merge across them on
268-
* the wrapper side; this check is what stops `BackendArena`
268+
* the wrapper side; this check is what stops `Arena`
269269
* from later merging two adjacent intra-chunk fragments that
270270
* happen to abut the same chunk boundary, which would create a
271271
* free block straddling chunks. Chunk-aligned `higher_addr`

0 commit comments

Comments
 (0)