Repository navigation
Description
Context
#286 (for #219) makes Kyty builds on Windows populate each new direct memory mapping, the way the Linux populate backing of #163 does: the readable pages of the new view are read once, so the game's first writes do not take a demand-zero page fault each. That is what lets Hades II (PPSA36082) start on Windows: without it, its CPU texture tiling takes about 19,000 page faults a second, its loader falls behind and its 512 MiB upload pool runs out.
The cost is memory held up front. Hades II maps about 7.8 GiB of direct memory at start (a 1 GiB heap, then 512 MiB, 6 GiB and 128 MiB for its renderer pools), and all of it becomes resident within about 0.9 s:
| Working set after start | |
|---|---|
AnyKyty 7de61e3451 (demand paging) |
1.3 GB, then the crash |
| With #286 (populate) | 9.1 GB |
Upstream main 47139cd910 (its GPU driver imports guest memory into Vulkan) |
7.3 GB |
(Windows 10, Ryzen 5 5600, RTX 4060, 32 GB.)
The problem for most users
Population only runs while a quarter of host memory stays available afterwards, the same rule as on Linux. On a 16 GB host, the 6 GiB mapping needs about 10 GiB available at that moment, so it will most likely stay demand-paged, and Hades II would then crash as before. I have not tested a 16 GB host; this follows from the rule, so a report from someone with 16 GB would help. Many players have 16 GB, so as it stands #286 helps only part of them, and it makes memory that the game reserves but never writes resident on larger hosts.
Ideas, none tried yet
- Large pages on Windows (
MEM_LARGE_PAGES): one fault per 2 MiB, resident only where written, like the Linuxprivatebacking; but it needs the "Lock pages in memory" right, which normal users do not have. - Populate in the background after the mapping returns, instead of blocking the mapping thread: removes the start-up delay, not the memory.
- Populate ahead of the writer: when a guest write faults in fresh direct memory, make the next pages resident too, so memory grows only where the game writes. Windows has nothing like
userfaultfd, so this needs care. - Populate only what needs it (for example only mappings the GPU can read, or with a size cap), and leave the rest on demand.
- A lower threshold than a quarter of host memory for the largest mappings, measured on a 16 GB host.
Whoever tries one: Hades II on Windows is a good test, since without population it crashes before its first frame. The page fault rate and the working set can be read from outside with GetProcessMemoryInfo.
Activity
simnJS commentedon Nov 26, 2026
@talha-devp #286 is now merged (
eb5103d101): Windows direct mappings are populated throughReadProcessMemory. Does that settle this issue for 16 GB hosts, or is there still something to do here?talha-devp commentedon Nov 26, 2026
Not yet. The
ReadProcessMemorychange made the touch safe; it did not change when the populate runs, so 16 GB hosts still skip the 6 GiB pool. I simulated one to check instead of guessing.Setup: my 32 GB host (Windows 10, Ryzen 5 5600, RTX 4060), with a helper process that locks 11.4 GiB with
VirtualLock, so 10.6 GB stays free, like a lightly loaded 16 GB PC. A local build of20f68401d8(same code aseb5103d101) evaluates the quarter-of-RAM rule with a 16 GiB total. A local switch can also force the populate. Hades II (PPSA36082), 60 s per launch with a pad replay.0xc0000005onLoadTaskScheduler, as in #219)The 1 GiB heap and the 512 MiB pool are still populated under the merged rule; the guard fails only at the 6 GiB pool, after those two have eaten into what is free.
So on 16 GB the rule turns the fix off exactly where it is needed. Forcing the populate worked in these short runs, with under 2 GB left free. I did not measure hard faults or longer sessions, so I can't say whether a real 16 GB PC would start paging later. I'd keep this open. My next step would be a lower threshold for the big mapping (the last idea above): populate while a fixed reserve, for example 1–2 GiB, stays free, instead of a quarter of RAM. I'd measure that on this simulated 16 GB host over a longer session, with hard-fault counts. A report from a real 16 GB machine is still welcome.
simnJS commentedon Nov 26, 2026
Thanks for measuring instead of guessing, that table settles it: on 16 GB the quarter-of-RAM rule turns the populate off exactly for the large pool that needs it.
Your next step sounds right to us: for large mappings, populate while a fixed reserve stays free (1-2 GiB), instead of a quarter of RAM. Two things we would like in the PR:
It is yours if you want it: open the PR when ready and we will build and review it. A report from a real 16 GB machine is still welcome from anyone reading this.
talha-devp commentedon Nov 26, 2026
I opened #301 for the 16 GB part. On Windows the populate now keeps a sixteenth of host memory free instead of a quarter. When a mapping doesn't fully fit, it populates as much as fits and leaves only the rest on demand.
The test setup is the same simulated 16 GB host as above. With the current rule, Hades II crashed in 2 of 3 launches. With #301 it ran 7 of 7, including 3 launches where only 5.0 to 5.3 of the 6 GiB pool fit. A lower all-or-nothing threshold alone still crashed 1 of 3. The numbers are in the PR.
The memory the populate holds up front, the other half of this issue, is unchanged.