Add heap_lazy (off by default): on Windows the game's heap is committed where it is first used.

Windows charges every committed page to the commit limit whether it is used or not, and the game sizes its whole heap up front: in Castle Town after Hyrule Field the heap held 6.8 GiB of commit of which 3.4 GiB had ever been used. With heap_lazy = 1 a change of the heap's size only moves its end, an access to a reserved heap page commits the reserved runs of the 64 KiB around it in the access-fault hook and runs again, and the paths that do not fault commit their range first: mem_thaw (file reads, the host-pointer import), mem_kernel_access (file writes, the frame-rate fix's read) and mem_host_readable (the host's pointer checks). A page another path committed is left as it is, so a frozen, probed or armed page keeps its protection. With trace = perf a line per window gives the faults, the bytes committed and the time they took.

The contributor's runs on a 16 GB PC: 4.67 instead of 6.77 GiB of heap committed and 29.3 instead of 32.9 GiB of process commit in Castle Town, no "system commit low", 12,858 faults in 440 ms over four minutes, the longest 41 ms. With the setting off nothing is hooked and the heap is committed as before.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-10 23:04:40 -05:00
parent 73abd6577f
commit dda12051f5
10 changed files with 133 additions and 15 deletions

View File

@@ -758,6 +758,11 @@
# first one, so their draw pass is not ended and begun again at each of them (about 40 passes fewer a frame in a
# village). 0: each such draw ends its pass and prepares its own count, as before.
# mesh_ahead = 1
# Windows, 1 (experimental): the game's heap is committed a 64 KiB run at a time where it is first used, instead of
# all of it when the game sizes it. Windows counts committed memory against RAM plus the page file whether it is used
# or not, and in Castle Town after Hyrule Field about 3.4 of the heap's 6.8 GiB had never been used. 0: committed up
# front. Linux commits pages on first use anyway.
# heap_lazy = 0
# Linux, shadow storage: 1 clears the write watch's protection of a range in one call before the GPU's bytes are copied
# back into the game's memory, instead of taking a fault at the first store into each page.
# shadow_bulk_write = 0