Skip to content

Commit df6a27f

Browse files
committed
removed guard chunks since metadata is OOL
1 parent a705288 commit df6a27f

3 files changed

Lines changed: 13 additions & 31 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
docs/notes.md
2-
docs/plan.md
2+
33

44
# Build directories
55
build/
@@ -14,6 +14,7 @@ bin/
1414
*.dylib
1515
*.dll
1616
*.exe
17+
zialloc
1718

1819
# CMake
1920
CMakeCache.txt

allocators/zialloc/segments.cpp

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,6 @@ class Chunk {
102102
void mark_free() { in_use = 0; }
103103
};
104104

105-
class GuardChunk {
106-
private:
107-
int64_t pattern;
108-
109-
public:
110-
GuardChunk() : pattern(0) {}
111-
explicit GuardChunk(int64_t val) : pattern(val) {}
112-
void set(int64_t val) { pattern = val; }
113-
bool integrity_check(int64_t expected) const {
114-
INTEGRITY_CHECK(pattern == expected, "guard mismatch");
115-
return true;
116-
}
117-
};
118-
119105
typedef struct tc_page_s {
120106
Page* loc;
121107
page_kind_t kind;
@@ -239,8 +225,6 @@ class Page {
239225
uint16_t used;
240226
size_t chunk_sz;
241227
Chunk* page_start;
242-
GuardChunk front_guard;
243-
GuardChunk back_guard;
244228
page_status_t status;
245229
uint64_t prng_state;
246230
PageRuntime runtime;
@@ -250,9 +234,9 @@ class Page {
250234
: owner_tc(nullptr), owner_tid(0), size_class(PAGE_SM), slot_count(0), is_committed(0),
251235
num_committed(0), reserved(0), capacity(0), use_bitmap(true),
252236
freelist(), used(0), chunk_sz(0), page_start(nullptr),
253-
front_guard(), back_guard(), status(EMPTY), prng_state(0), runtime() {}
237+
status(EMPTY), prng_state(0), runtime() {}
254238

255-
bool init(void* base, page_kind_t kind, size_t chunk_size, int64_t canary) {
239+
bool init(void* base, page_kind_t kind, size_t chunk_size) {
256240
if (!base || chunk_size == 0)
257241
return false;
258242

@@ -277,8 +261,6 @@ class Page {
277261
chunk_sz = runtime.chunk_size;
278262
status = EMPTY;
279263
prng_state = generate_canary();
280-
front_guard.set(canary);
281-
back_guard.set(canary);
282264

283265
runtime.chunks.clear();
284266
runtime.freelist.clear();
@@ -485,7 +467,7 @@ class Segment {
485467
return &slots[idx];
486468
}
487469

488-
void* allocate(size_t req, int64_t guard_canary) {
470+
void* allocate(size_t req) {
489471
if (slots.empty())
490472
return nullptr;
491473
size_t start = 0;
@@ -502,7 +484,7 @@ class Segment {
502484
std::lock_guard<std::mutex> page_lk(page_lock_for(&page));
503485
if (!page.is_initialized()) {
504486
void* pbase = static_cast<void*>(static_cast<char*>(runtime.base) + (i * runtime.page_size));
505-
if (!page.init(pbase, size_class, req, guard_canary))
487+
if (!page.init(pbase, size_class, req))
506488
continue;
507489
}
508490
if (!page.can_hold(req))
@@ -580,7 +562,6 @@ class Heap {
580562
memkind_t mem_kind;
581563
uint64_t canary;
582564
size_t reserved_cursor;
583-
int64_t guard_seed;
584565
std::mutex heap_mu;
585566

586567
bool add_segment_nolock(void* segment_base, segment_kind_t kind, page_kind_t page_kind) {
@@ -618,7 +599,7 @@ class Heap {
618599
seg_kind(), seg_bases(), seg_page_kind(), seg_index_by_base(),
619600
xl_allocs(),
620601
mem_kind(MEM_NONE), canary(0),
621-
reserved_cursor(0), guard_seed(0) {}
602+
reserved_cursor(0) {}
622603
~Heap() = default;
623604

624605
public:
@@ -635,7 +616,6 @@ class Heap {
635616
reserved_size = size;
636617
reserved_cursor = 0;
637618
canary = generate_canary();
638-
guard_seed = static_cast<int64_t>(canary);
639619
mem_kind = MEM_OS;
640620
size_t cap = size / SEGMENT_SIZE;
641621
layout.reserve(cap);
@@ -738,7 +718,7 @@ class Heap {
738718
size_t preferred_idx = 0;
739719
if (tc->get_active() && tc->get_preferred_segment(kind, &preferred_idx) &&
740720
preferred_idx < layout.size() && seg_page_kind[preferred_idx] == kind) {
741-
void* ptr = layout[preferred_idx].allocate(need, guard_seed);
721+
void* ptr = layout[preferred_idx].allocate(need);
742722
if (ptr) {
743723
Page* page = layout[preferred_idx].find_page_for(ptr);
744724
if (page) {
@@ -750,7 +730,7 @@ class Heap {
750730
for (size_t i = 0; i < layout.size(); ++i) {
751731
if (seg_page_kind[i] != kind)
752732
continue;
753-
void* ptr = layout[i].allocate(need, guard_seed);
733+
void* ptr = layout[i].allocate(need);
754734
if (ptr) {
755735
if (tc->get_active()) {
756736
tc->set_preferred_segment(kind, i);
@@ -770,7 +750,7 @@ class Heap {
770750
if (tc->get_active()) {
771751
tc->set_preferred_segment(kind, layout.size() - 1);
772752
}
773-
void* ptr = layout.back().allocate(need, guard_seed);
753+
void* ptr = layout.back().allocate(need);
774754
if (ptr) {
775755
Page* page = layout.back().find_page_for(ptr);
776756
if (page) {
@@ -793,7 +773,7 @@ class Heap {
793773
if (tc->get_active()) {
794774
tc->set_preferred_segment(kind, layout.size() - 1);
795775
}
796-
void* ptr = layout.back().allocate(need, guard_seed);
776+
void* ptr = layout.back().allocate(need);
797777
if (ptr) {
798778
Page* page = layout.back().find_page_for(ptr);
799779
if (page) {
@@ -925,7 +905,6 @@ class Heap {
925905
canary = 0;
926906
mem_kind = MEM_NONE;
927907
reserved_cursor = 0;
928-
guard_seed = 0;
929908
}
930909
};
931910

docs/zialloc-design.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ Page
4141

4242
XL allocations bypass the segment/page system and use directly mapped regions that are tracked in `xl_allocs`.
4343

44+
Metadat is stored Out-of-line, zialloc keeps metadata in allocator-owned structures (PageRuntime/Chunk vectors and segment/page structures), and the returned pointer is the raw chunk w/ no inline header. XL allocations are tracked in xl_allocs (which are also out-of-line)
45+
4446
## Allocation Workflow
4547
Allocation starts through allocator API wrappers and then `Heap::allocate(size)`.
4648

0 commit comments

Comments
 (0)