[pr-fix][memory] RAM trim (soft): a list that gave nothing is not made again at once (the walk of the address space ran back to back, 20 s in 43 s of play) #225

Open
blazecoding2009 wants to merge 1 commit from blazecoding2009/Darner:pr/ramtrim-list-walk into main
First-time contributor

Contributor role (optional)

  • Fluxer ID:

What it changes

  • The problem on main: the log line below, from v2026.12.03.01 (ramtrim.rs is the same file on main f3840d7). With DARNER_RAM_TRIM=soft the trimmer's thread spent 20.6 s of 600 frames (about 43 s of play) and took nothing out:

    RAM trim (DARNER_RAM_TRIM=soft), frame 9001: working set 17215 -> 17415 MB over 600 frames, 1426 MB free; taken out MB: driver-cache 0, mapped-file 0, own 0, title 0, whole-process 0 (0 hand-backs); came back 0 MB; 20589 ms spent; held for pipelines 152 times

soft::slice made its list of ranges again as soon as the last one was gone through. A list with nothing to take (no range, or only ranges whose class is shut or left alone) is gone through in the frame after it was made, so the walk that makes a list ran back to back. That walk asks VirtualQuery about every region of the process (240,000 in play here, about half a second a walk), each question under the address space's lock.

A list is now made again when it is a minute old, as before, and sooner (five seconds after it was made) only when it is gone through and gave something. The rule is a function of its own, list_due, with a unit test. Nothing else changes: the classes, the gates and what is taken are as they were.

How it was tested

  • Tested revision: aefb42b (this one commit on main f3840d7, which is v2026.12.03.02). The "before" lines are from v2026.12.03.01 (bd0de0c), built the same way.

  • Commands and results:

    • cargo build --locked --profile diag -p darner --features diagnostics: built.
    • cargo test --locked -p darner-gpu --lib ramtrim: 10 passed, the new a_list_gone_through_is_not_made_again_at_once among them.
  • Changes a default: no. DARNER_RAM_TRIM is off by default and only its soft mode is touched.

  • A/B result: the trimmer's own line, every 600 frames, from the first period in which it did anything (the world loaded, free memory under its line). One run each, scripts\bench.ps1, the same save, 240 s measured.

    A (before, bd0de0c) B (after, aefb42b)
    ms spent per 600 frames 1074, 0, 666, 20589, 20299, 12482, 9924, 24387 648, 0, 530, 548, 0, 472, 504
    of those frames, held for pipelines 230, 600, 579, 152, 160, 345, 388, 58 237, 309, 365, 57, 24, 121, 302
    MB taken out, all classes 0 0
    median fps (rendered frames) 14.3 14.4

    The two runs are not the same switch set, and I make no fps claim: A also had #59's four switches and DARNER_PARK_COMPACT_WASTE=1, B had DARNER_RAM_TRIM=soft alone. A first version of this change (a walk every 5 s whatever the list gave), on bd0de0c with A's switches, spent 801 to 4791 ms per 600 frames; the commit keeps that figure in the doc comment.

  • Gates run on that revision (the three in AGENTS.md; there is no CI): cargo clippy --workspace --all-targets --locked -- -D warnings: passed. The same with --all-features: passed. cargo xtask policy: 555 files ok. cargo test --workspace --locked --no-fail-fast: every test binary passed but two, and neither failure is in code this touches:

    • darner-shader: 557 passed, 1 failed, 16 ignored. The one is emit::waterfall_tests::sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders, the failure #186 and #163 report on main.
    • darner-gpu: the run stood still, which #224 is about. A run of the gate before it, with fail-fast, ended there with 1773 passed and 1 failed (host::refresh_tests::refresh_front_zero_arc_matches_and_runs_due, which then passed 3 of 3 times by itself). I ran this revision's darner-gpu test binary six more times: once all 1774 passed, five times one to three tests failed, of watch::tests, watch::watch_pipe_epoch_tests, gpu_owned::tests and descriptor::tests. The ten ramtrim tests passed in all six. main without this change does the same: 4 of 6 runs with a failed test and 1 that stood still (the table in #224).
  • Gameplay: RTX 4050 Laptop 6 GB (driver 621.24), Ryzen 7 8845HS, 32 GB, Windows 11 build 26300. Series S profile, DLSS Quality 1080p to 1440p, DLSS frame generation on, ray tracing off.

  • Shader wave sizes tested, when relevant: not relevant.

  • Hardware dependence: likely general. The walk's cost follows the number of regions in the process, not the card.

  • Coverage gaps: the soft trimmer took nothing out in any of my runs (pipelines were still being made for much of each window, DARNER_PAGE_MAP was off and no mirror was idle), so the path where a list gives something and is made again after five seconds ran only in the unit test. One PC.

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only).
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md.
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: none found. I searched the diff of every open pull request (83): none changes ramtrim.rs. Searches of open and closed issues and pull requests for RAM_TRIM, ramtrim and trim found nothing on this. #224 is the test standstill named above, not this change.
  • Replaces or overlaps: none found

This change was made with AI assistance (Claude Code).

🤖 Generated with Claude Code

## Contributor role (optional) - Fluxer ID: ## What it changes - The problem on main: the log line below, from v2026.12.03.01 (`ramtrim.rs` is the same file on `main` f3840d7). With `DARNER_RAM_TRIM=soft` the trimmer's thread spent 20.6 s of 600 frames (about 43 s of play) and took nothing out: `RAM trim (DARNER_RAM_TRIM=soft), frame 9001: working set 17215 -> 17415 MB over 600 frames, 1426 MB free; taken out MB: driver-cache 0, mapped-file 0, own 0, title 0, whole-process 0 (0 hand-backs); came back 0 MB; 20589 ms spent; held for pipelines 152 times` `soft::slice` made its list of ranges again as soon as the last one was gone through. A list with nothing to take (no range, or only ranges whose class is shut or left alone) is gone through in the frame after it was made, so the walk that makes a list ran back to back. That walk asks `VirtualQuery` about every region of the process (240,000 in play here, about half a second a walk), each question under the address space's lock. A list is now made again when it is a minute old, as before, and sooner (five seconds after it was made) only when it is gone through and gave something. The rule is a function of its own, `list_due`, with a unit test. Nothing else changes: the classes, the gates and what is taken are as they were. ## How it was tested - Tested revision: aefb42b (this one commit on `main` f3840d7, which is v2026.12.03.02). The "before" lines are from v2026.12.03.01 (bd0de0c), built the same way. - Commands and results: - `cargo build --locked --profile diag -p darner --features diagnostics`: built. - `cargo test --locked -p darner-gpu --lib ramtrim`: 10 passed, the new `a_list_gone_through_is_not_made_again_at_once` among them. - Changes a default: no. `DARNER_RAM_TRIM` is off by default and only its `soft` mode is touched. - A/B result: the trimmer's own line, every 600 frames, from the first period in which it did anything (the world loaded, free memory under its line). One run each, `scripts\bench.ps1`, the same save, 240 s measured. | | A (before, bd0de0c) | B (after, aefb42b) | |---|---|---| | ms spent per 600 frames | 1074, 0, 666, 20589, 20299, 12482, 9924, 24387 | 648, 0, 530, 548, 0, 472, 504 | | of those frames, held for pipelines | 230, 600, 579, 152, 160, 345, 388, 58 | 237, 309, 365, 57, 24, 121, 302 | | MB taken out, all classes | 0 | 0 | | median fps (rendered frames) | 14.3 | 14.4 | The two runs are not the same switch set, and I make no fps claim: A also had #59's four switches and `DARNER_PARK_COMPACT_WASTE=1`, B had `DARNER_RAM_TRIM=soft` alone. A first version of this change (a walk every 5 s whatever the list gave), on bd0de0c with A's switches, spent 801 to 4791 ms per 600 frames; the commit keeps that figure in the doc comment. - Gates run on that revision (the three in AGENTS.md; there is no CI): `cargo clippy --workspace --all-targets --locked -- -D warnings`: passed. The same with `--all-features`: passed. `cargo xtask policy`: 555 files ok. `cargo test --workspace --locked --no-fail-fast`: every test binary passed but two, and neither failure is in code this touches: - `darner-shader`: 557 passed, 1 failed, 16 ignored. The one is `emit::waterfall_tests::sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders`, the failure #186 and #163 report on `main`. - `darner-gpu`: the run stood still, which #224 is about. A run of the gate before it, with fail-fast, ended there with 1773 passed and 1 failed (`host::refresh_tests::refresh_front_zero_arc_matches_and_runs_due`, which then passed 3 of 3 times by itself). I ran this revision's `darner-gpu` test binary six more times: once all 1774 passed, five times one to three tests failed, of `watch::tests`, `watch::watch_pipe_epoch_tests`, `gpu_owned::tests` and `descriptor::tests`. The ten `ramtrim` tests passed in all six. `main` without this change does the same: 4 of 6 runs with a failed test and 1 that stood still (the table in #224). - Gameplay: RTX 4050 Laptop 6 GB (driver 621.24), Ryzen 7 8845HS, 32 GB, Windows 11 build 26300. Series S profile, DLSS Quality 1080p to 1440p, DLSS frame generation on, ray tracing off. - Shader wave sizes tested, when relevant: not relevant. - Hardware dependence: likely general. The walk's cost follows the number of regions in the process, not the card. - Coverage gaps: the soft trimmer took nothing out in any of my runs (pipelines were still being made for much of each window, `DARNER_PAGE_MAP` was off and no mirror was idle), so the path where a list gives something and is made again after five seconds ran only in the unit test. One PC. ## Checklist - [x] I ran this change in the game, or say below why it can't be (docs, tests only). - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md`. - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: none found. I searched the diff of every open pull request (83): none changes `ramtrim.rs`. Searches of open and closed issues and pull requests for `RAM_TRIM`, `ramtrim` and `trim` found nothing on this. #224 is the test standstill named above, not this change. - Replaces or overlaps: none found This change was made with AI assistance (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
DARNER_RAM_TRIM=soft made its list of ranges again as soon as the last one
was gone through. A list with nothing to take (no range, or only ranges of
classes that are shut or left alone) is gone through in the frame after it
was made, so the walk of the address space that makes a list (VirtualQuery
over some 240,000 regions in play, half a second) ran back to back: 20,589 ms
in 600 frames with 0 MB taken out (v2026.12.03.01, RTX 4050 Laptop 6 GB,
32 GB PC, frame generation on).

A list is now made again when it is a minute old, and sooner (five seconds
after it was made) only when it is gone through and gave something
(list_due). The same scene on f3840d7 with the change: 0 to 648 ms in 600
frames.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
First-time contributor

I exercised the productive-list branch in a real gameplay process on aefb42bf. The local build added one trace immediately before the existing list refresh to record list age, bytes taken, scan position and range count. The trim decisions were unchanged.

After the first world frame there were 24 refreshes before 60 seconds. Each had exhausted its list, had returned bytes, and waited at least 5 seconds. Ages ranged from 5,000 to 18,484 ms. For example, a list that returned 27,975,680 bytes refreshed at 5,016 ms after scanning 2,292/2,292 ranges. Another returned 87,990,272 bytes and refreshed at 7,828 ms after 633/633. The first empty list had 0/0 ranges and refreshed at 71,081 ms.

The candidate logged 53 complete 600-frame reports. Seven reported title pages returned, 407 MB total as reported. Driver-cache, mapped-file, own, whole-process and came-back counters summed to zero. The game reached the world and exited normally after the requested 180 seconds in-world. For context the stock release pilot also returned title pages (418 MB).

Windows 11, i5-13600KF, 32 GB RAM, RTX 4070 Ti SUPER, 1440p, FG/RT off. I explicitly set DARNER_RAM_TRIM=soft, DARNER_RAM_TRIM_FREE_MB=16384, DARNER_RAM_TRIM_SET_MB=8192 and DARNER_PAGE_MAP=1 for the process. This tests refresh behavior under those thresholds. It does not measure default memory pressure or FPS. Tested with Codex assistance.

I exercised the productive-list branch in a real gameplay process on `aefb42bf`. The local build added one trace immediately before the existing list refresh to record list age, bytes taken, scan position and range count. The trim decisions were unchanged. After the first world frame there were 24 refreshes before 60 seconds. Each had exhausted its list, had returned bytes, and waited at least 5 seconds. Ages ranged from 5,000 to 18,484 ms. For example, a list that returned 27,975,680 bytes refreshed at 5,016 ms after scanning 2,292/2,292 ranges. Another returned 87,990,272 bytes and refreshed at 7,828 ms after 633/633. The first empty list had 0/0 ranges and refreshed at 71,081 ms. The candidate logged 53 complete 600-frame reports. Seven reported title pages returned, 407 MB total as reported. Driver-cache, mapped-file, own, whole-process and came-back counters summed to zero. The game reached the world and exited normally after the requested 180 seconds in-world. For context the stock release pilot also returned title pages (418 MB). Windows 11, i5-13600KF, 32 GB RAM, RTX 4070 Ti SUPER, 1440p, FG/RT off. I explicitly set `DARNER_RAM_TRIM=soft`, `DARNER_RAM_TRIM_FREE_MB=16384`, `DARNER_RAM_TRIM_SET_MB=8192` and `DARNER_PAGE_MAP=1` for the process. This tests refresh behavior under those thresholds. It does not measure default memory pressure or FPS. Tested with Codex assistance.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'pr/ramtrim-list-walk:blazecoding2009-pr/ramtrim-list-walk'
git switch 'blazecoding2009-pr/ramtrim-list-walk'

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.

git switch 'main'
git merge --no-ff 'blazecoding2009-pr/ramtrim-list-walk'
git switch 'blazecoding2009-pr/ramtrim-list-walk'
git rebase 'main'
git switch 'main'
git merge --ff-only 'blazecoding2009-pr/ramtrim-list-walk'
git switch 'blazecoding2009-pr/ramtrim-list-walk'
git rebase 'main'
git switch 'main'
git merge --no-ff 'blazecoding2009-pr/ramtrim-list-walk'
git switch 'main'
git merge --squash 'blazecoding2009-pr/ramtrim-list-walk'
git switch 'main'
git merge --ff-only 'blazecoding2009-pr/ramtrim-list-walk'
git switch 'main'
git merge 'blazecoding2009-pr/ramtrim-list-walk'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
TrustNo1/Darner!225
No description provided.