Make wb_lazy_unlocked = 0 bring back 0.10.1's locking in evictions and releases as well, which the review found it did not.

With the setting at 0, frz_lock was held across every fault's and release's fetch again and mem_thaw released under the
lock, but two parts of the new code stayed. vk_memory.c mirror_evict and hot_check still fetched their victims'
armed ranges before taking pool_lock again, and a release still put up to 16 copies in one submission. Those are the
parts that run only with a device and have no check without one, so a device loss caused by them was the one case the
switch could not take back. Now vk_memory.c reads the setting too (evict_unlocked, once on the replay thread, where
both run): at 0 neither drops pool_lock, and the release under it fetches everything, victim by victim, as before. And
memory.c lazy_take_batch_locked takes one segment at a time at 0, so each is fetched on its own.

What stays at 0 is the table of ranges in flight: a touch of a range being fetched waits for that fetch and runs
again (a write no longer goes on to thaw_fault and releases its region), the hold is set as the range goes out, and
mem_lazy_touches counts the range. memory.c "Ranges in flight", nx2navi.ini.example and docs/building.md say so.

tests/lazy_fetch_check.py gains locked_release, the release scenario at 0: three fetches of one copy each, where the
batched release makes two of up to two copies. It fails with the cap taken out. The eviction's side has a compile
check only. Not reproduced before the change; lazy_fetch_check passed in all its scenarios.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-13 20:03:02 -05:00
parent 0eee849948
commit da60e0d327
6 changed files with 59 additions and 36 deletions

View File

@@ -693,15 +693,17 @@ in flight", `runtime/vk_memory.c` `lazy_fetch`, `mirror_evict`, `hot_check`) pas
which builds memory.c with the Windows fault handler and a fetch that only waits, and runs each scenario as its own
process, so an access violation fails it. A thread that reads a range over and over while it is armed and given back
again never reaches the crash handler, also when the arm's clean test takes 100 ms, and a read of a range being armed
does not either when a range in flight in its region ends during that test. A fetch holds up nothing but the
touches of its range: freezes, thaws, arms, releases and copies of other ranges return at once meanwhile, also while
a thaw fetches the armed ranges of its own regions, two ranges fetch at once, and more touching threads than the
flight table holds all end. The touches of a range in flight wait
for it and run again, a write among them without releasing the region's other ranges; thaws, mapping changes,
releases of its buffer, arms and freezes see it. The same with `wb_lazy_chunk = 1`, and with `wb_lazy_unlocked = 0`
the fetch holds the freeze lock again. The "mem: lazy write-back" lines give the longest fetch, the longest wait of a
fault for the freeze lock and the touches that waited for a range in flight. `vk_memory.c`'s fetch slots and the
order of an eviction against a pool's finalize have no check without a device. Windows only; no game files, no GPU.
does not either when a range in flight in its region ends during that test. A fetch holds up nothing but the touches
of its range: freezes, thaws, arms, releases and copies of other ranges return at once meanwhile, also while a thaw
fetches the armed ranges of its own regions, two ranges fetch at once, and more touching threads than the flight table
holds all end. The touches of a range in flight wait for it and run again, a write among them without releasing the
region's other ranges; thaws, mapping changes, releases of its buffer, arms and freezes see it. The same with
`wb_lazy_chunk = 1`, and with `wb_lazy_unlocked = 0` the fetch holds the freeze lock again, a thaw's too, and a
release fetches one range at a time (the table of ranges in flight stays: a touch of one still waits for it alone).
The "mem: lazy write-back" lines give the longest fetch, the longest wait of a fault for the freeze lock and the
touches that waited for a range in flight. `vk_memory.c`'s fetch slots, and its evictions (`mirror_evict`,
`hot_check`: their fetch before `pool_lock` is taken with `wb_lazy_unlocked = 1`, under it with 0, and their order
against a pool's finalize), have no check without a device. Windows only; no game files, no GPU.
A change to when the freezing of idle guest regions waits (`runtime/freeze_hold.h`, `runtime/vk_memory.c`
`freeze_pass`) passes `python tests\freeze_hold_check.py`, which builds the header alone: the backoff after a slow