summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/zisp/gc/meta_alloc.zig30
1 files changed, 12 insertions, 18 deletions
diff --git a/src/zisp/gc/meta_alloc.zig b/src/zisp/gc/meta_alloc.zig
index f8b9e92..4dec92d 100644
--- a/src/zisp/gc/meta_alloc.zig
+++ b/src/zisp/gc/meta_alloc.zig
@@ -138,29 +138,23 @@ inline fn getSizeClassIndex(size: usize) u8 {
/// Pointer to start of all slabs as a contiguous array.
var slabs: *[SIZES.len]Slab = undefined;
-/// Free-list head pointer with ABA counter.
-const FlHead = packed struct(u64) {
+/// Linked-list head pointer with ABA counter.
+const ListHead = packed struct(u64) {
// Putting aba first leads to slightly better codegen.
aba: UnitIdx,
idx: UnitIdx,
};
-/// Vacancy-list head pointer with ABA counter.
-const VlHead = packed struct(u64) {
- aba: UnitIdx,
- idx: UnitIdx,
-};
-
/// Global shared metadata per slab / size class.
const SlabInfo = struct {
/// Force cache line alignment to prevent false sharing.
_: void align(std.atomic.cache_line) = {},
/// Head of shared free-list for the size class; index value SLAB_LEN is
/// used to mean NULL, since it's an invalid slab index.
- free_list: FlHead = .{ .aba = 0, .idx = SLAB_LEN },
+ free_list: ListHead = .{ .aba = 0, .idx = SLAB_LEN },
/// Head of shared vacancy-list for the size class; index value SLAB_LEN
/// used to mean NULL, since it's an invalid slab index.
- vacancy_list: VlHead = .{ .aba = 0, .idx = SLAB_LEN },
+ vacancy_list: ListHead = .{ .aba = 0, .idx = SLAB_LEN },
/// Global slab watermark: Start address of unused vmem, as 8-byte index.
watermark: UnitIdx = 0,
};
@@ -311,7 +305,7 @@ fn alloc_from_fl(
var ptr: SlotPtr = undefined;
var arr: [*]UnitIdx = undefined;
- var fl_head = @atomicLoad(FlHead, &info.free_list, .acquire);
+ var fl_head = @atomicLoad(ListHead, &info.free_list, .acquire);
while (true) : (std.atomic.spinLoopHint()) {
// Checking for >= SLAB_LEN is optimal; it'll just test the sign bit.
if (fl_head.idx >= SLAB_LEN) return null;
@@ -324,7 +318,7 @@ fn alloc_from_fl(
const next_head = @atomicLoad(UnitIdx, &arr[0], .unordered);
fl_head = @cmpxchgWeak(
- FlHead,
+ ListHead,
&info.free_list,
fl_head,
.{ .aba = fl_head.aba +% 1, .idx = next_head },
@@ -355,7 +349,7 @@ fn alloc_from_vl(
var ptr: SlotPtr = undefined;
var arr: [*]UnitIdx = undefined;
- var vl_head = @atomicLoad(VlHead, &info.vacancy_list, .acquire);
+ var vl_head = @atomicLoad(ListHead, &info.vacancy_list, .acquire);
while (true) : (std.atomic.spinLoopHint()) {
if (vl_head.idx >= SLAB_LEN) return null;
@@ -366,7 +360,7 @@ fn alloc_from_vl(
const next_head = @atomicLoad(UnitIdx, &arr[0], .unordered);
vl_head = @cmpxchgWeak(
- VlHead,
+ ListHead,
&info.vacancy_list,
vl_head,
.{ .aba = vl_head.aba +% 1, .idx = next_head },
@@ -451,12 +445,12 @@ fn free_into_fl(
@memcpy(arr[16 .. 16 + max], tl.fsc[split .. split + max]);
// Now atomically announce the new free-list head to global visibility.
- var fl_head = @atomicLoad(FlHead, &info.free_list, .acquire);
+ var fl_head = @atomicLoad(ListHead, &info.free_list, .acquire);
while (true) : (std.atomic.spinLoopHint()) {
// Still owned exclusively; no need for atomic store.
arr[0] = fl_head.idx;
fl_head = @cmpxchgWeak(
- FlHead,
+ ListHead,
&info.free_list,
fl_head,
.{ .aba = fl_head.aba +% 1, .idx = idx },
@@ -502,11 +496,11 @@ fn flush_to_vl(info: *SlabInfo, tl: *TlSlabInfo, slab: *Slab) void {
arr[1] = tl.wm_hi;
- var vl_head = @atomicLoad(VlHead, &info.vacancy_list, .acquire);
+ var vl_head = @atomicLoad(ListHead, &info.vacancy_list, .acquire);
while (true) : (std.atomic.spinLoopHint()) {
arr[0] = vl_head.idx;
vl_head = @cmpxchgWeak(
- VlHead,
+ ListHead,
&info.vacancy_list,
vl_head,
.{ .aba = vl_head.aba +% 1, .idx = idx },