WIP: [pr-performance][memory] DARNER_PAGE_DRAIN: the emptiest pool heap of page buffers is emptied and goes back (mode 3, off by default) #332
Loading…
Reference in a new issue
No description provided.
Delete branch "Cyber-Croissant/Darner:page-drain"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Contributor role (optional)
What it changes
With
DARNER_PAGE_DRAIN=1the heap of the pool in the PC's memory with the fewest tiles in use is chosen when the other heaps have room for its tiles and 16 MB more. Its free tiles are given to nobody. The windows written straight in move their tiles of it to other heaps at their next take, in the order of the queue: the bytes are copied by the CPU under the window's write gate, the tiles are mapped at their new place ahead of the take's send, and the old tiles go back once the submissions in the air have finished. The heap goes back when its last tile is free. One heap at a time, 10 s of rest after each, and a heap not empty after 60 looks (one look in 30 frames) is left as it is.Off by default: with the switch unset no heap is chosen and nothing moves. The counters are behind the
diagnosticsfeature.This is a draft on top of #319 (the give-back of tiles under freed title memory); the diff shows both commits until #319 lands, and only the second is this change. Order: #319 first. This one stays a draft (WIP) until #319 is merged; then I take the WIP off and it can be reviewed and merged in turn. The WIP in the title stands for that dependency only: the measurements below are done. Results from more testers and more reviewers would still help a lot: everything below comes from one PC, one route and one card.
How it was tested
Tested revision:
8354d13e(one5abccd9of #319, on mainf3840d73) for the tests, the gates and the build. The drives ran on two other trees, said in the table: an earlier base (57dea7f2) andf3840d73with the same code as8354d13ebut for one comment line and the README. No drive has run on8354d13eitself yet.Commands and results:
cargo test -p darner-gpu --features diagnostics --lib pagebuf::: 7 passed, 5 ignored (the ignored ones need a card). The new one isthe_emptiest_heap_is_emptied_when_the_others_have_room(the choice of the heap).the_emptiest_heap_of_the_pool_is_emptied_and_goes_back_in_mode_three(new, ignored by default, run by name withDARNER_ADAPTER,DARNER_PAGE_BUFFERS=3,DARNER_PAGE_DRAIN=1): passed on the RTX 5070 the drives ran on, and on the PC's integrated AMD adapter. Through the real path of a submission: two windows written straight in fill a heap and start a second; the first window goes, the heap it leaves almost empty is chosen, the other window's tiles in it move at its next send with nothing written, shaders read them at their new place, and the heap goes back once the submissions have run.DARNER_PAGE_DRAIN=1set too, on both adapters.8354d13e(not in this PR), with the game closed.cargo check -p darner(nodiagnosticsfeature): 0 warnings.Changes a default: no
A/B result: the switch is off by default, so this is how it was checked rather than a default's A/B. Autodrive of 12 min on a recorded input tape, the same save, one drive per row, in the order they ran. Numbers are read at the end of the drive (tiles, heaps), over its last tenth (private, commit) or over the window 30 to 720 s after the world's first frame (frame figures). "DRAIN" is
DARNER_PAGE_DRAIN=1, "D60" isDARNER_PAGE_DEAD_S=60of #319, "D10" is 10, "PACK" isDARNER_PAGE_PACK=1. The same table is in #319.f3840d73+ bothf3840d73+ bothf3840d73+ bothf3840d73+ bothf3840d73+ bothf3840d73+ bothf3840d73, main as it isf3840d73+ bothf3840d73+ bothf3840d73+ bothf3840d73+ bothf3840d73+ bothf3840d73+ bothRows 16 to 22 were added later the same day: repeats, and the cases that were missing. Row 16 is main as it is, with none of this code. One drive whose autodrive did not start (the character stayed out of the car) was discarded and run again as row 22. Drives of other trees that ran in between are not listed.
Read from the table:
UpdateTileMappingscalls: 53,494 to 57,742 a drive with D60 and DRAIN (rows 11, 13, 17, 19, 21) against 24,911 to 26,695 without any switch; 27,291 with DRAIN and no D60.DARNER_PAGE_PACK=1. One drive per case is not enough to name a cause, and the light and the weather of the game are not the same from drive to drive. The earlier rows were not looked at for it.Where the process's memory is, from the layer's own
process memory:line (DARNER_PROCESS_MEMORY=1, one a minute; the last one of each drive onf3840d73, MB; column numbers are the rows above):Read from it, nothing more: with both switches the private bytes at host addresses are 19.8 and 19.9 GB against 20.8 and 21.3, the bytes the line does not name 8.9 GB against 10.0 and 10.4, and the working set 16.3 and 16.8 GB against 18.2 and 18.7. With one switch alone the private total is inside the two drives without any (24.7 against 24.6 and 25.0). The title's own private bytes and the write-combined part do not move. The mapped bytes at host addresses are 1.6 to 2.1 GB lower in the two drives with one switch alone: one mapped region of 2,048 MB is in the last reading of the four other drives (it appears at minute 2, 6, 9 or 12 of the drive, with and without the switches) and never in those two. I have not identified it. It is mapped, not private, and the commit charge the system reports for the process (the "Commit" column of the first table) is not lower in those two drives. In an address census on the earlier base (a local diagnostic, not in this PR) the pool's heaps showed as private, not write-combined regions of 64 MiB committed whole.
Gates run on that revision (the three in AGENTS.md; there is no CI): on
8354d13e:cargo clippy --workspace --all-targets --locked -- -D warningspassed; the same with--all-featurespassed;cargo xtask policy: 555 files ok.cargo test --workspace --lockedfailed, as it does on main here (#389): it stopped atdarner-gpuwith 2 failed tests of 1,774 (host::refresh_tests::chunked_nothing_new_with_matches_individual,watch::tests::ask_once_by_res_splits_reservations_without_refusals), neither in the files this touches.cargo test -p darner-gpu --lib --locked20 times: 9 runs failed, against 10 of 20 on mainf3840d73; the tests that fail are those ofwatchandhostthat fail on main, and one more of the same kind (write-watched memory),descriptor::tests::records_copied_as_bytes_are_made_at_the_next_sync, in 2 runs of 26 here and none of 26 on main: I cannot say whether that one is chance. With--test-threads=1: 1,757 passed, 0 failed. The rest of the workspace butdarner-shader: 1,015 passed, 0 failed.darner-shader, on that head: 556 passed, 1 failed (emit::waterfall_tests::sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders, which fails on main too), withoracle64::legacy_mul_forms_are_exactskipped: on main it had not ended after 14 min of CPU time.Gameplay, when relevant: RTX 5070 12 GB, Series S profile, DLSS Quality, no frame generation, no ray tracing. Diagnostics build (
--profile diag --features diagnostics),DARNER_PAGE_BUFFERSat its play default (3).Shader wave sizes tested, when relevant: not relevant.
Hardware dependence: untested elsewhere. Needs tiled resources tier 2 and mode 3; does nothing in the other modes or for heaps on the card.
Coverage gaps:
8354d13eitself.DARNER_PAGE_PACK=1: one drive (row 21).Checklist
main.docs/asset-policy.md.Checked for overlap
shadow.rsfor landed ranges. Closed: #56, #59, #62 (pools and windows; none empties a pool heap). Issues: #111, #290, #60, #19.DARNER_PAGE_PACK,DARNER_PAGE_BUFFERS, "page buffers", "tiles", "pool heaps", "drain", and the file lists of the open pull requests forpagebuf.rs).Code review only (read
8354d13e, this PR's own commit on top of #319'se5abccd9), nothing built or run. It merges cleanly onto main today (git merge-tree). The "not mergeable" flag is the draft state.take_drainmoves only tiles of direct windows (not on the card, not hot). So a heap that also holds a tile that can't move (non-direct takes may use the same CPU-visible heaps) would never empty, and is given up after 60 looks. After the 10 s rest,drain_choicehas no memory of it and likely picks the same heap again (most free tiles). Each round keeps the pool's largest free space unused for about a minute (take_fromskips draining heaps), which can push new tiles into new heaps. The "given up" counter would show it. Remembering given-up heaps for a few minutes, or skipping heaps with tiles that can't move, would avoid it.retire. Lock order is gate/state → pool, and the pool lock never takes a window's state.Reviewed with Claude Code (AI-assisted); findings checked by a human before posting.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.