authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-01-30 18:25:01-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-02-06 14:23:23-08:00
logdd2fa4f75d3d2b1214fde22081f0b88850d1b55d
tree272d7d23a6f4bd7627adbbdc6145b3cb8010c89d
parentb23662feeb0ecea67eefbcfe941e609c5a8ca842

std.heap.GeneralPurposeAllocator: runtime-known page size

no longer causes compilation failure. This also addresses the problem of high map count causing OOM by choosing a page size of 2MiB for most targets when the page_size_max is smaller than this number.

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

lib/std/heap/general_purpose_allocator.zig+5-1
......@@ -99,7 +99,11 @@ const math = std.math;
9999const assert = std.debug.assert;
100100const mem = std.mem;
101101const Allocator = std.mem.Allocator;
102const page_size = std.heap.pageSize(); // TODO: allow this to be runtime known
102const page_size: usize = @max(std.heap.page_size_max, switch (builtin.os.tag) {
103 .windows => 64 * 1024, // Makes `std.heap.PageAllocator` take the happy path.
104 .wasi => 64 * 1024, // Max alignment supported by `std.heap.WasmAllocator`.
105 else => 2 * 1024 * 1024, // Avoids too many active mappings when `page_size_max` is low.
106});
103107const StackTrace = std.builtin.StackTrace;
104108
105109/// Integer type for pointing to slots in a small allocation