[pr-performance][memory] DARNER_PAGE_DEAD_S: page-buffer tiles under freed title memory give their memory back (mode 3, off by default) #319
Loading…
Reference in a new issue
No description provided.
Delete branch "Cyber-Croissant/Darner:page-dead-tiles"
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
In mode 3 a window's tile takes memory from the pool at its first write and keeps it until the window goes. Windows outlive the title's allocations under them, so tiles stay backed by memory nobody reads.
With
DARNER_PAGE_DEAD_S=<seconds>a tile that lies wholly under title memory freed for that long, and that was written nothing but zeros since, is unmapped at its window's next take, in the order of the queue; its pool tile goes back once the submissions in the air have finished (the pathunmapalready uses). It then reads zeros, as a tile that never had memory, and gets memory again at the next write. A look once in 30 frames puts the windows that hold such tiles on the list the next send looks at, since a window nobody writes is not looked at otherwise.Off by default: with the switch unset nothing is unmapped, the look returns at once, and a normal build does not note dead tiles at all. A build with the
diagnosticsfeature notes them (a time stamp per tile) to count them and writes one log line with the page-buffer report; every drive below ran on such a build.This was opened as a work in progress; the repeats below are done and it is now ready for review. Results from more testers and more reviewers would still help a lot: everything below comes from one PC, one route and one card. Other cards (8 GB, AMD, Intel), 16 GB of RAM, long sessions and other places in the game are not covered.
A second change, emptying the emptiest pool heap so that it goes back to the system (
DARNER_PAGE_DRAIN), builds on this one: #332. Order: this one first. #332 sits on this branch and stays a draft (WIP) until this one is merged; then its WIP comes off and it can be reviewed and merged in turn. Most drives below ran with both, since the private-memory gain comes from the two together; they are marked.How it was tested
Tested revision:
e5abccd9on mainf3840d73for the tests, the gates and the build. The drives ran on two other trees, said in the table: an earlier base (57dea7f2) andf3840d73with this change and the drain together (the drain switched off unless marked). No drive has run one5abccd9itself yet.Commands and results:
cargo test -p darner-gpu --features diagnostics --lib pagebuf::: 6 passed, 5 ignored (the ignored ones need a card).tiles_under_freed_title_memory_give_their_memory_back_in_mode_three(new, ignored by default, run by name withDARNER_ADAPTER,DARNER_PAGE_BUFFERS=3,DARNER_PAGE_DEAD_S=1): passed on the RTX 5070 the drives ran on, and on the PC's integrated AMD adapter. It goes through the real path of a submission: the tiles wholly under freed title memory give their memory back at the next send and read zeros; a tile written anything but zeros since the free stays, a tile freed in part stays, nothing leaves before its time, and a tile that left gets memory again when a refresh finds bytes there.a_window_written_straight_into_its_tiles_round_trip_in_mode_three(existing): passed with the switch unset and withDARNER_PAGE_DEAD_S=1, on both adapters.e5abccd9(not in this PR), with the game closed. Before that the tests had only run on the integrated adapter, which shares the PC's memory and so says little about a discrete card.cargo check -p darner(nodiagnosticsfeature): 0 warnings.cargo build --profile diag -p darner --features diagnostics: built.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). "D60" is
DARNER_PAGE_DEAD_S=60, "D10" is 10, "PACK" isDARNER_PAGE_PACK=1, "DRAIN" is the second change.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, for this change alone (rows 2, 5, 12 against the rows without it):
UpdateTileMappingscalls about double (51,356 against 25,169 and 26,695 over a drive).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
e5abccd9: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,773 (gpu_owned::tests::concurrent_faults_on_same_block_serialize_single_readback,watch::tests::ask_once_by_res_splits_reservations_without_refusals), neither in the files this touches.cargo test -p darner-gpu --lib --lockedsix times: 2 runs failed, with tests ofwatchandhost::watch_pipethat fail on main too (mainf3840d73: 10 runs of 20; #332's head, which holds this commit: 9 of 20, and 1,757 passed, 0 failed with--test-threads=1). The rest of the workspace butdarner-shader, on #332's head: 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.
Coverage gaps:
e5abccd9itself; the drives' trees also held the drain code, switched off.DARNER_PAGE_PACK=1: one drive (row 21), with both switches; this change alone without PACK is not measured.windows_direct().Checklist
main.docs/asset-policy.md.Checked for overlap
shadow::paged_freedmarks, and on main that function is reached only when something is in place (inplace::holds_any()). In the drives above the frees did reach it (about 1.2 GB of tiles dead for 60 s and more at the end of a drive without the switch; 48,990 to 53,958 tiles given back with D60); I have not checked whether every free did. With #321 more frees may reach it; not measured. It also touchesshadow.rs; no trial merge done. #310 and #300 touchshadow.rsfor landed ranges, a different subject. #274 is about the host's retirement queues, not the tile pool. Closed: #56, #59, #62 (pools and windows; none gives tiles back). Issues: #111 (memory outside the ledger grows on Proton; this may or may not help there, not tested), #290, #60, #19.DARNER_PAGE_PACK,DARNER_PAGE_BUFFERS, "page buffers", "tiles", "pool heaps", and the file lists of the open pull requests forpagebuf.rs).WIP: [pr-performance][memory] DARNER_PAGE_DEAD_S: page-buffer tiles under freed title memory give their memory back (mode 3, off by default)to [pr-performance][memory] DARNER_PAGE_DEAD_S: page-buffer tiles under freed title memory give their memory back (mode 3, off by default)Code review only (read the diff at
e5abccd9), nothing built or run.try_write, so nothing leaves while a write straight in is under way), skips tiles with a pending mapping, hot tiles and this take'sdirecttiles, and returns memory through the existingunmap/retirepath. I checked whether a tile freed and then written by a shader could keep its dead mark and lose the shader's bytes. It can't: a declared shader write ends the direct way for good (Shadow::end_direct), andtake_deadacts only on direct windows.paged_freedtoday (title_memory_changed, ungated). The title's ownVirtualFreegoes through theholds_any()-gated path, which #321 opens. With #321, tiles over memory the title frees that way may qualify too.UpdateTileMappingscount showed no frame cost on your PC. A second tester with a weaker CPU would help settle that.Reviewed with Claude Code (AI-assisted); findings checked by a human before posting.
@iBooM72 thank you for the review, and for checking the shader-write case.
paged_freed: thank you for naming the two paths, I read the code the same way. With nothing in place, the runtime's unmaps and remaps reach it (title_memory_changed), the title's ownVirtualFreedoes not (holds_any()), until #321. So the dead tiles counted in the drives (about 1.2 GB at the end of a drive without the switch) came from the first path. With #321: not measured here.UpdateTileMappings: agreed, a tester with a weaker CPU is what is missing. I only have this PC.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.