Memory: windows of title memory in place over the page pool, soft writes (12-13 GB at copies' speed under Proton) #51

Closed
github-bot wants to merge 16 commits from gh-pr/51/head into gh-pr/51/base
Owner

@⁠kc01-8 on GitHub · 2026-11-29 17:11 UTC · original
kc01-8:kc/memory-in-place → main · +1235 −48 · 10 files · 16 commits · closed without merging

What this does

Windows of title memory in place over the page pool, through views of our own, instead of copies; and the rest of what makes that fast. Everything is off unless asked for: nothing changes for anyone who does not set these.

Switch Does
VICTORY_INPLACE=1 + VICTORY_INPLACE_VIEWS=1 windows over the page pool are the title's own pages, mapped through views of our own (inplace::OwnViews), not copies the card pins
VICTORY_INPLACE_VIEWS_CHURN=4 a pool cell the title lets go 4 times gets copies (cells remapped all the time cost more as views)
VICTORY_SOFT_VIEWS=1 the title's mapping calls kept in the runtime's books too, not only its page-mapping copies; new here: what shaders wrote goes into such a view's pages through the section (SoftViews::write), instead of making the view real

Also in these commits, active only with the switches above:

  • a pool window in place goes only when the pages read through it change, and the heap slots that showed it are made again;
  • windows in place are indexed by their 64 KiB pages, so a remap looks only at its own pages' windows (was 1.5–3.4 s a frame of the runtime's remap notes);
  • windows are made with no lock on their table (a window takes milliseconds under Wine; readers of the table waited 17–19 ms at a time);
  • the write watch is not asked about views of the title's pages (the system refuses it, and under Wine even the refusal waits on its address-space lock), nor again about a range it refused until its mappings change;
  • a view the runtime made real is opened without waiting for the guards' lock (that wait deadlocked against the runtime's own lock);
  • counts of views mapped and unmapped every 10 s, and of pool cells let go 1, 2, 4 ... 32 times.

Measured

RTX 3080 Ti 12 GB, Ryzen 7 5800X3D, 32 GB, Linux 7.3 with Proton Experimental and vkd3d-proton, Series X profile, 1440p. Each run is in docs/kc-linux-status.md of kc01-8/VIctoryNVIDIALINUX (branch kc/foxhound).

memory that could not be reclaimed fps over 60–240 s
page-pool windows as copies 15.4–16.6 GB (4.4 GB of it the driver's pins of the copies) about 10
in place, before soft views 11.9–13.4 GB 4.9 (the wineserver at 68 % of a core)
in place + VICTORY_SOFT_VIEWS=1 + soft writes 12.1–13.4 GB about 10 (wineserver 3 %), 14–16 in play

So copies' frame rate at about 3 GB less memory. The wineserver part (every map/unmap walks the process's ~90,000 views under Wine) is Proton's; the memory part should hold on Windows too, but I have not measured it on Windows.

Merge notes

Picked onto v0.8.1 (6c67166d). One place met newer code: v0.8's packed HeapRanges in draw.rs; the walk for slots that showed a let-go window reads its dense entries. The timeline span our tree has in merge_page_under_writes is left out (foxhound has v0.8's PageMerge there).

Tests

Under Proton's Wine, diagnostics build: victory-gpu stops after about 455 passed and victory-hle has 164 passed / 3 failed, the same with and without these commits (v0.8.1 alone does the same under Wine: placeholders, ws2_32, NTFS links, and one xmem test). victory.exe builds with no warnings from these commits.

Where this comes from

kc01-8/VIctoryNVIDIALINUX, branch kc/foxhound: foxhound's tree (v0.8.1 ported today, commit 08b28212 on kc/foxhound-v081) run on Linux under Proton on an RTX 3080 Ti, with every run's numbers in docs/kc-linux-status.md and the plan in its README. The same commits went to trustno1-coder/VIctory-NVIDIA as #2776. Also from there: the frame recorder and replay working under vkd3d-proton, a hang watcher that dumps every thread's place without the loader lock, and a fix for a double unlock in vkd3d-proton's memory budget lock.

🤖 Generated with Claude Code

**@⁠kc01-8** on GitHub · 2026-11-29 17:11 UTC · [original](https://github.com/readmet3xt-lab/foxhound/pull/51) `kc01-8:kc/memory-in-place` → `main` · +1235 −48 · 10 files · 16 commits · closed without merging ## What this does Windows of title memory **in place** over the page pool, through views of our own, instead of copies; and the rest of what makes that fast. Everything is **off unless asked for**: nothing changes for anyone who does not set these. | Switch | Does | |---|---| | `VICTORY_INPLACE=1` + `VICTORY_INPLACE_VIEWS=1` | windows over the page pool are the title's own pages, mapped through views of our own (`inplace::OwnViews`), not copies the card pins | | `VICTORY_INPLACE_VIEWS_CHURN=4` | a pool cell the title lets go 4 times gets copies (cells remapped all the time cost more as views) | | `VICTORY_SOFT_VIEWS=1` | the title's mapping calls kept in the runtime's books too, not only its page-mapping copies; **new here:** what shaders wrote goes into such a view's pages through the section (`SoftViews::write`), instead of making the view real | Also in these commits, active only with the switches above: - a pool window in place goes only when the pages read through it change, and the heap slots that showed it are made again; - windows in place are indexed by their 64 KiB pages, so a remap looks only at its own pages' windows (was 1.5–3.4 s a frame of the runtime's remap notes); - windows are made with no lock on their table (a window takes milliseconds under Wine; readers of the table waited 17–19 ms at a time); - the write watch is not asked about views of the title's pages (the system refuses it, and under Wine even the refusal waits on its address-space lock), nor again about a range it refused until its mappings change; - a view the runtime made real is opened without waiting for the guards' lock (that wait deadlocked against the runtime's own lock); - counts of views mapped and unmapped every 10 s, and of pool cells let go 1, 2, 4 ... 32 times. ## Measured RTX 3080 Ti 12 GB, Ryzen 7 5800X3D, 32 GB, Linux 7.3 with Proton Experimental and vkd3d-proton, Series X profile, 1440p. Each run is in [docs/kc-linux-status.md](https://github.com/kc01-8/VIctoryNVIDIALINUX/blob/kc/foxhound/docs/kc-linux-status.md) of [kc01-8/VIctoryNVIDIALINUX](https://github.com/kc01-8/VIctoryNVIDIALINUX) (branch `kc/foxhound`). | | memory that could not be reclaimed | fps over 60–240 s | |---|---|---| | page-pool windows as copies | 15.4–16.6 GB (4.4 GB of it the driver's pins of the copies) | about 10 | | in place, before soft views | 11.9–13.4 GB | 4.9 (the wineserver at 68 % of a core) | | in place + `VICTORY_SOFT_VIEWS=1` + soft writes | **12.1–13.4 GB** | **about 10** (wineserver 3 %), 14–16 in play | So copies' frame rate at about 3 GB less memory. The wineserver part (every map/unmap walks the process's ~90,000 views under Wine) is Proton's; the memory part should hold on Windows too, but **I have not measured it on Windows**. ## Merge notes Picked onto v0.8.1 (6c67166d). One place met newer code: v0.8's packed `HeapRanges` in `draw.rs`; the walk for slots that showed a let-go window reads its `dense` entries. The timeline span our tree has in `merge_page_under_writes` is left out (foxhound has v0.8's `PageMerge` there). ## Tests Under Proton's Wine, diagnostics build: victory-gpu stops after about 455 passed and victory-hle has 164 passed / 3 failed, **the same with and without these commits** (v0.8.1 alone does the same under Wine: placeholders, ws2_32, NTFS links, and one xmem test). `victory.exe` builds with no warnings from these commits. ## Where this comes from [kc01-8/VIctoryNVIDIALINUX](https://github.com/kc01-8/VIctoryNVIDIALINUX), branch `kc/foxhound`: foxhound's tree (v0.8.1 ported today, commit 08b28212 on `kc/foxhound-v081`) run on Linux under Proton on an RTX 3080 Ti, with every run's numbers in `docs/kc-linux-status.md` and the plan in its README. The same commits went to trustno1-coder/VIctory-NVIDIA as #2776. Also from there: the frame recorder and replay working under vkd3d-proton, a hang watcher that dumps every thread's place without the loader lock, and a fix for a double unlock in vkd3d-proton's memory budget lock. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
VICTORY_INPLACE_VIEWS=1 (off by default, with VICTORY_INPLACE): a window
outside buffers over the title's page pool is no longer copied. The pool
pages it covers are mapped again, in order, into a range of our own (a
page of zeros where the title shows none), and that range is opened as
a host heap by its address (OpenExistingHeapFromAddress1). Windows
refuses such a range; vkd3d-proton passes it to the driver
(VK_EXT_external_memory_host). Under Proton these windows are most of
the GPU copies kept in the PC's memory (run 25: 2.4 of 3.9 GB).

The views stay mapped until the buffer and heap are gone (the shadow's
last field). The in-place let-go on a remap now looks as far below a
range as the longest window in place. The probe gains a case that maps
section pages out of order with a hole and checks the GPU reads them in
that order. Not run on the GPU yet.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 44a54dd5959d72c59001c6911c1c32da8bb26d9e)
(cherry picked from commit 3522237aa8e135dbddb1136625f52eb480af3b9a)
Run 27 (VICTORY_INPLACE_VIEWS=1) peaked at 15.0 GB instead of reaching
the 18 GB cap, but every unmap under a window over the page pool let it
go: 2,544 in four minutes, each opened again later. And descriptor slots
that showed a window let go kept showing its old pages: the memory
line's count of slots showing another copy than the one brought up to
date was 68,178, against 6 and 9 in runs 24 and 25.

- A window over the pool records what each of its pages shows. It is no
  longer let go when the title unmaps a page, only when the title maps a
  different section page there (title_memory_view). Both cases are
  counted on the in-place line.
- Copies in place taken out of the tables are marked. When any were,
  the pass over the view heap's buffer views makes again the slots that
  showed one, from the copy their view finds now (remake_later). They
  are counted on the memory line.
- Windows over the pool lock no new memory, so they no longer count
  against VICTORY_INPLACE_MB (run 27 turned 7 private windows down).
- profiles/linux-nvidia.env: VICTORY_NO_WATCHDOG=1.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit a8516281a1303f7ff0b92b026fd28db3c03ed0b0)
(cherry picked from commit f64330a1b3438b917a83c892da09cb7acb817efa)
Run 28 let go 1,529 windows over the page pool in four minutes even when
only a different page let one go, and not one remap mapped the same page
back: a 4 MiB window covers streamed texture pages beside what is read
through it. Each window now notes the part asks read (an ask without a
length reads to its end). A different page mapped into that part lets the
window go at once; elsewhere the page is only marked changed, and the
window goes at the first ask that reaches a changed page. Both counted on
the in-place line.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 25775a3538fe9df782d40bd1987145f8cce2a255)
(cherry picked from commit 22ab3e4b0ffd5c4ae99eb5f2674bc000737ec43f)
The pass over the view heap's buffer views keeps, per slot, the copy it
found, not the one the host slot shows. A slot the title wrote after the
window it showed was let go got the new copy noted while still showing the
old one, so the scan for slots that show a let-go copy missed it (run 29:
17,239 such looks four minutes in). The pass now compares the slot with
the copy it found every time (HostHeap::shows, no longer diagnostics only)
and, while windows over the pool are in place (VICTORY_INPLACE_VIEWS), makes
a mismatched slot again at once.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit e091779008dd93768ea650c1c483ebee6d9695cf)
(cherry picked from commit 63c8c88d10303a80915156cc355974a275eb7481)
Every remap looked through the windows table for each window in place
that could reach the page, as far below as the longest such window: the
runtime's own notes of its remaps took 1.5-3.4 s a frame in runs 28 and
31 against 135-207 ms in run 24, with the lock held that texture
refreshes wait for. Windows in place are now noted on the 64 KiB pages
they cover, and a remap looks only at its own pages' windows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit fdf2f779a4ef2f2934d5850fabac7890c9a9a76a)
(cherry picked from commit 2df8bafedb07dd8a2debf40dd104df549bcd2151)
Under Wine each view mapped or unmapped is a request to the one-thread
wineserver: with every window over the page pool in views of our own
(run 39) it took 81% of a core, about 2,000 views mapped and as many
unmapped a second, and the title's threads queued behind it. With none
(run 41) it fell to 30% and frames ran 8-14 fps instead of 1.3-15, but
the copies' memory, which NVIDIA's Linux driver pins, rose from 0.2 to
4.4 GB. A cell whose views window was let go VICTORY_INPLACE_VIEWS_CHURN
times (2 unless set; 0: never) now gets copies from then on.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 534bf3bc1aa61bc847aef3c42ebd9533db7ed215)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit dcc2ae9866452789c7754b41872e2cf79b85f7a1)
At 2 (run 42), 800-880 page-pool cells had gone to copies by 3-5
minutes and the run reached the 18 GB cap: the churn is spread over most
cells. Off until the cells' counts say where a limit pays.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit d84f1f6ac31a6cce345d3bd764a5f2df9df6af45)
sources() asked about every 64 KiB page in no view (up to 64 a window):
961 queries in run 68's timeline, 2.8 s of waits on Wine's one lock for
the address space. An answer covers a region of one state.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 384c3aa02596103d08317ea4d666127a27b73938)
reads_end made a window (views of the page pool mapped through the
wineserver, buffers made) with LOOSE held for writing, and every reader
waited for it: in run 62's timeline landing jobs waited on it 17-19 ms
at a time, and landings were a fifth of the frames' chains. Now the
window is made with no lock and put in under it; one another thread made
meanwhile is taken instead, and one in place over memory the title
mapped anew meanwhile is made again under the lock. The statistics that
only look at the table take it for reading (they took it for writing
since it was a Mutex). In run 66's timeline landing jobs were off the
frames' chains.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit d12ee4b090e3dd36169f39ebd9f21d2d6e525041)
Under Wine each map and unmap is a request of the wineserver's, and the
server walks the process's whole list of views for each (is_valid_view_addr,
find_mapped_view): perf of the wineserver in run 71 found it 89% busy, 95%
of that in those two walks. The line says the runtime's and the in-place
windows' maps and unmaps over the last 10 s and the views each holds: in
run 72, ~77,000 of the runtime's and ~11,000 of the windows', and the
windows made 3/4 of the requests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit f34ba069a02a6861ea9d59dcca7d48c0d004d676)
write_mapped made every view the runtime keeps in its books alone
(VICTORY_SOFT_VIEWS) real before putting back what shaders wrote: a map
of the host's and later an unmap, each a request of the wineserver's
that walks the process's views (2,135 views in 10 s asked for by the GPU
side, run 85). The runtime now writes those bytes into the view's pages
through the section's own view, as DirectStorage's writes and the GPU
side's reads already go (SoftViews::write); the caller has told of the
write, which counts at every address the page is shown at. Memory in no
such view is written as before.

Run 87 against 85, over 60-240 s: the wineserver from 31 % to 3 % of a
core, maps and unmaps in play from thousands to tens in 10 s, 8.36 fps
to 10.10 (14.6-15.6 from 120 s on), the title drawing about 4,800 draws
a frame where it drew 3,200.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 37b6eba01b634e071b155a6e0ef0eb78aadd690e)
title_memory_made_real waited for the guards' lock with the runtime's
lock on its views held. 76 s into run 91 the whole process stood still,
the title's mapping calls included: a thread that holds the guards and
touches a view kept in the books faults, and the handler has the runtime
make it real (Rust's lock is not taken twice by one thread); or one
holds the guards and asks the runtime to make a view real while another
holds the runtime's lock and waits here. With every mapping call of the
title kept in the books (VICTORY_SOFT_VIEWS=1) views are made real
thousands of times in 10 s while the world loads.

Held elsewhere, the lock is not waited for: the view goes on a list that
the next to take the lock opens first (guards()), as every asking does,
so it counts as written at the next asking as before. The soft-view
guard test now tells of it with the lock held on its own thread.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 2c0b7f09fac742e0cd7533ed0a6e0c0ac0cfb72a)
Under Wine GetWriteWatch still took about 1.3 ms when it refused, and with
the title's views kept in the books (VICTORY_SOFT_VIEWS) every asking was
refused: 258 a frame in run 35, 325 ms of the threads' time a frame. A
refused range goes to the guards, which is right for any memory. Refused
ranges are now remembered, forgotten when a mapping in them changes
(title_memory_changed) and every ten seconds.

The watch tests give the same result as before (43 pass; the same 4 fail
under Wine without this change too).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 15f6ded0a865de068544bae161aee6ea00689f3f)
The system refuses it for a view, and under Wine even the refusal waits
on its one lock for the address space: 216 of 219 askings a frame were
refusals (run 62); the submitting thread's askings were 633 ms in 2
seconds (run 66). The runtime's books say what is a view.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit dc7ad00b6d4f5b65e5b8fc3d199d99c18e318636)
ask_run asks one merged range for a submission's pieces and, when the
kernel refuses it (it crosses into memory that is not write-watched,
or two reservations), splits it. The refusal cache counted every range
inside a refused one as refused, so the pieces were never asked: a
write-watched one went to the guards, or, for memory that is not
view memory, had no answer and its shadow was marked unwatched for
good, every refresh copying it whole. Found in the review of the same
change on trustno1-coder/VIctory-NVIDIA PR 2776 (agentiverse's
suggested fix). a_piece_of_a_refused_run_is_still_asked passes here;
in kc01-8/VIctoryNVIDIALINUX, with the same code, it fails without this.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 02:23:49 +00:00
github-bot closed this pull request 2026-11-30 02:23:49 +00:00
Author
Owner

@⁠kc01-8 on GitHub · 2026-11-30 01:46 UTC · original

Pushed bb556c716, a fix that came out of the review of the same change on trustno1-coder/VIctory-NVIDIA#2776. The write watch's refusal cache counted every range inside a refused one as refused. When ask_run split a merged range the kernel had refused, because it crossed into memory that isn't write-watched, the pieces were never asked: write-watched ones went to the guards, or were marked unwatched for good and copied whole on every refresh. Now only the very range refused counts. The new test a_piece_of_a_refused_run_is_still_asked passes here under Proton.

Full work, run logs and status: https://github.com/kc01-8/VIctoryNVIDIALINUX (branch kc/foxhound).

🤖 Generated with Claude Code

**@⁠kc01-8** on GitHub · 2026-11-30 01:46 UTC · [original](https://github.com/readmet3xt-lab/foxhound/pull/51#issuecomment-7266431708) Pushed bb556c716, a fix that came out of the review of the same change on trustno1-coder/VIctory-NVIDIA#2776. The write watch's refusal cache counted every range inside a refused one as refused. When `ask_run` split a merged range the kernel had refused, because it crossed into memory that isn't write-watched, the pieces were never asked: write-watched ones went to the guards, or were marked unwatched for good and copied whole on every refresh. Now only the very range refused counts. The new test `a_piece_of_a_refused_run_is_still_asked` passes here under Proton. Full work, run logs and status: https://github.com/kc01-8/VIctoryNVIDIALINUX (branch `kc/foxhound`). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Author
Owner

@⁠readmet3xt-lab on GitHub · 2026-11-30 02:01 UTC · original

Not taken: everything here sits behind switches aimed at Proton. On Windows VICTORY_INPLACE=1 gave no gain in our measurements, and about 1,200 lines of off-by-default code in watch, shadow and inplace would have to be kept working with every change there. If it shows a gain on Windows (frame times from two runs, on and off), please reopen with those numbers. Thanks.

**@⁠readmet3xt-lab** on GitHub · 2026-11-30 02:01 UTC · [original](https://github.com/readmet3xt-lab/foxhound/pull/51#issuecomment-7266636513) Not taken: everything here sits behind switches aimed at Proton. On Windows `VICTORY_INPLACE=1` gave no gain in our measurements, and about 1,200 lines of off-by-default code in `watch`, `shadow` and `inplace` would have to be kept working with every change there. If it shows a gain on Windows (frame times from two runs, on and off), please reopen with those numbers. Thanks.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.