authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-02-07 02:04:56-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-02-07 14:41:49-08:00
loga9d30056167cbe54c0c144199f01a56f6cdcdafc
treed2df3f7469ca1452768ca3553711a08feedfd89a
parent3246150d4589a25cd1ad762a78d2806ef1da2a95

std.heap.SmpAllocator: fix detection of slab end


1 files changed, 3 insertions(+), 3 deletions(-)

lib/std/heap/SmpAllocator.zig+3-3
......@@ -6,8 +6,6 @@
66//!
77//! ## Basic Design
88//!
9//! Avoid locking the global mutex as much as possible.
10//!
119//! Each thread gets a separate freelist, however, the data must be recoverable
1210//! when the thread exits. We do not directly learn when a thread exits, so
1311//! occasionally, one thread must attempt to reclaim another thread's
......@@ -122,6 +120,7 @@ fn alloc(context: *anyopaque, len: usize, alignment: mem.Alignment, ra: usize) ?
122120 }
123121
124122 const slot_size = slotSize(class);
123 assert(slab_len % slot_size == 0);
125124 const max_search = 1;
126125 var search_count: u8 = 0;
127126
......@@ -148,7 +147,8 @@ fn alloc(context: *anyopaque, len: usize, alignment: mem.Alignment, ra: usize) ?
148147 if (search_count >= max_search) {
149148 @branchHint(.likely);
150149 defer t.unlock();
151 const slab = PageAllocator.map(slab_len, .fromByteUnits(std.heap.pageSize())) orelse return null;
150 // slab alignment here ensures the % slab len earlier catches the end of slots.
151 const slab = PageAllocator.map(slab_len, .fromByteUnits(slab_len)) orelse return null;
152152 t.next_addrs[class] = @intFromPtr(slab) + slot_size;
153153 return slab;
154154 }