diff options
Diffstat (limited to 'src/allocators.zig')
| -rw-r--r-- | src/allocators.zig | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/src/allocators.zig b/src/allocators.zig index 7a8433e8..cf024a0b 100644 --- a/src/allocators.zig +++ b/src/allocators.zig @@ -4,16 +4,39 @@ const config = @import("pardes_config"); const Allocator = std.mem.Allocator; const debug_enabled = builtin.mode == .Debug; +/// Three tiers, because the address space differs by four orders of magnitude. +/// `reduced_target` is the browser: a wasm linear memory it grows on demand, so +/// the static reservations are megabytes rather than tens. +/// +/// `p4` is ESP32-P4 firmware, and its tier is deliberately ALL FALLBACK. Every +/// capacity here is a `StackFallbackAllocator`'s buffer, which is a static and +/// therefore lands in `.bss` — and on the P4 `.bss`, `.data` and the stack all +/// share ONE 240 KiB chunk of L2MEM at 0x4FF03000, while the heap the fallback +/// allocator hands out is the separate 384 KiB chunk at 0x4FF40000 - the 128 KiB +/// above that measured as L2 cache rather than memory. A +/// megabyte-shaped reservation here would not fit, and every byte that did fit +/// would be taken from the stack's neighbourhood to duplicate memory the heap +/// already has. So the buffers exist only because the type requires one: 4 KiB +/// absorbs the small churn, and everything else spills to the real heap on the +/// first allocation. +const p4 = config.platform == .p4; const reduced_target = config.platform == .web or builtin.os.tag == .freestanding; const KiB = 1024; const MiB = 1024 * KiB; const capacities = struct { - const pardes = if (reduced_target) 8 * MiB else 32 * MiB; - const frame = if (reduced_target) 4 * MiB else 16 * MiB; - const tree_sitter = if (reduced_target) 4 * MiB else 16 * MiB; - const image = if (reduced_target) 64 * KiB else 32 * MiB; - const pdf = if (reduced_target or !config.mupdf) 64 * KiB else 64 * MiB; + const pardes = if (p4) 4 * KiB else if (reduced_target) 8 * MiB else 32 * MiB; + const frame = if (p4) 4 * KiB else if (reduced_target) 4 * MiB else 16 * MiB; + // Zero is legal and always spills, which is exactly what an arena for a + // compiled-out subsystem should do. `StackFallbackAllocator(0).buffer` is + // `[0]u8`; `get()` inits the FixedBufferAllocator over an empty slice, so + // `FixedBufferAllocator.alloc` fails every nonzero request and `alloc` + // falls through to `self.fallback_allocator.rawAlloc`, while `ownsPtr` over + // an empty range is false for every pointer so `resize`/`remap`/`free` + // route to the fallback too. See lib/std/heap.zig, StackFallbackAllocator. + const tree_sitter = if (p4) 0 else if (reduced_target) 4 * MiB else 16 * MiB; + const image = if (p4) 0 else if (reduced_target) 64 * KiB else 32 * MiB; + const pdf = if (p4) 0 else if (reduced_target or !config.mupdf) 64 * KiB else 64 * MiB; }; pub const Allocators = struct { |
