fix(host): the code warm pass finds the game's text on btrfs, by the device /proc/self/maps shows for it #2916
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/mods
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2916
Loading…
Reference in a new issue
No description provided.
Delete branch "HumanBean/Longshot:push-wkpmywslsnwo"
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?
Summary
#2893's code warm keeps nothing on a btrfs
/home. Every run on main logs "code: 0 MB of the game's code kept in memory, of 0 MB in 0 mappings". The cause is thatread_ranges(host/code_warm.c) picks the executable's mappings bystat("/proc/self/exe")'s device and inode. On a btrfs subvolume, stat gives the subvolume's anonymous device (0:59 / 0:60) while/proc/self/mapsshows the file system's (00:1f), with the same inode, so no line matches. The AMD lab PC this was measured for has a btrfs/home, and so does the RTX 3090 PC.This takes the executable's device from its own maps line, found by its inode and its path (
readlink("/proc/self/exe"), " (deleted)" included, as maps writes it). It keeps stat's device when no such line is found, and then matches the mappings by device and inode as before. A different anonymous device with the same inode still doesn't match.How to see it on main: on a btrfs home, the game's log line "code: 0 MB ... in 0 mappings" every minute.
Read first:
read_rangesinhost/code_warm.c, thenhos_maps_exe_deviceinhost/code_warm.handtests/code_warm_btrfs_test.c.See #2893.
Testing
Tested: the AMD lab PC: RX 580 8 GB, RADV Mesa 26.2.6, CachyOS Linux, 16 GB, game on an HDD under a btrfs
/home. I ran a full game build of mainba3f14df+ this branch and one short run: Kakariko, then Hyrule Field, 90 s each. The log's code line went 14 → 387 → 458 → 466 MB "of the game's code kept in memory, of 734 MB in 1 mappings". No crash. On main the same PC logs 0 MB in 0 mappings.Checks:
tests/test_code_warm.pywith gcc and clang. Its newtests/code_warm_btrfs_test.cruns the realread_rangesover a btrfs-style maps, stat and readlink. It fails on main ("0 ranges found") and passes here. Undoing the fix's match makes it fail again.host/code_warm.ccompiles with-fsyntax-only -Wall -Wextraunder gcc and clang.read_rangesrun on each PC's btrfs/home: on this PC (stat dev 0:60) it finds the executable's mapping; on the lab (stat dev 0:59) main finds 0 ranges and this branch 1.mise run teston this PC (queued, build mode): 768 passed, 139 failed, 10 skipped.test_code_warm.pypasses. Of the 139 failures, 101 are "not found: vulkan_headers / spirv_headers (--strict)" in the queue's environment. The other ten or so fail on files this PR leaves alone: the lifter's fmt check, the menu rows, vk_texture.cpp's texture_frame text, the pipeline tour and a present link error. None reads host/code_warm.*. I didn't run main's suite to name them one by one.Still to test:
Measurements
Verdict: the fix works: on a btrfs /home the code warm now keeps 458-466 MB of the game's 734 MB of code where main kept 0. The fps gain is #2893's (in-play frames over 50/100 ms 57/18 → 43/13 on the lab, measured with the earlier path-based match), now reaching btrfs PCs.
ba3f14dffeea6137tests/code_warm_btrfs_test.cOne thing seen: a pass now takes 25-38 ms every 2 s at nice 19, where #2893's earlier path-based version took 4 ms. This is the merged copy-through-the-kernel pass doing real work for the first time on btrfs, not this fix. It costs about 1.5-2 % of one core at the lowest priority.
Risks
Only which mappings are found changes. Where the path isn't found, it falls back to main's rule.
HOS_CODE_WARM=0turns the thread off; a revert is enough. Nothing changes for saves, options or caches.Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named). (the failures are missing headers in the queue's environment and checks of files this PR leaves alone: Testing)main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
mainand passes here.🤖 Generated with Claude Code
https://claude.ai/code/session_016o1k1SdGuww9Q4o1mvYD9c
tests/code_warm_btrfs_test.c runs host/code_warm.c's read_ranges over /proc/self/maps, stat() and readlink() of /proc/self/exe as a btrfs /home gives them: stat's device is the subvolume's anonymous one (0:60), maps' the file system's (00:1f), the inode the same. On main it finds no range, as the lab's and this PC's logs show ("0 MB of the game's code kept in memory, of 0 MB in 0 mappings"). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016o1k1SdGuww9Q4o1mvYD9cOn a btrfs subvolume stat("/proc/self/exe") gives the subvolume's anonymous device (0:60) and /proc/self/maps the file system's (00:1f), the inode the same, so read_ranges matched no mapping and kept nothing (#2893 on every btrfs /home, the lab's among them). The executable's device is now read from its own maps line, found by its inode and its path (readlink of /proc/self/exe); stat's is kept where that line is not found. The mappings are then matched as before. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016o1k1SdGuww9Q4o1mvYD9cTested in game: RX 580 / RADV Mesa 26.2.6 / CachyOS Linux, btrfs /home: main+fix, Kakariko then Hyrule Field; code line 0 MB on main -> 466 MB of 734 MB kept
WIP: fix(host): the code warm pass finds the game's text on btrfs, by the device /proc/self/maps shows for itto fix(host): the code warm pass finds the game's text on btrfs, by the device /proc/self/maps shows for itRecommendation: Approve. The btrfs match works in the reported lab run, but the fix misses valid executable paths containing newlines or long pathnames. Nothing blocking is left: what remains is for the author before merging (below). Recommend approval; not approved on the forge.
The change finds the executable’s device in Linux process maps so the existing code-warming thread can work on btrfs subvolumes. It makes the intended path work on the reported PC, but enables a periodic memory and CPU workload that needs broader measurement.
Should fix (2): not blocking, but worth doing before merging.
host/code_warm.h:54: The pathname comparison does not account for the newline escaping used by /proc/self/maps. (more on the line) Do: Compare against the maps-escaped form of the executable path, and add a synthetic btrfs test containing a newline in a directory name.host/code_warm.c:57: The fixed-size maps line buffer can truncate a valid executable pathname before the device lookup compares it. (more on the line) Do: Read complete maps lines dynamically and handle a truncated readlink result; cover a long synthetic path in the btrfs test.Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)
host/code_warm.c:65: The newly active pass has not been measured against main for its gameplay benefit and costs on the systems it can affect. (more on the line) Do: Run interleaved main-versus-head gameplay comparisons on the affected lab setup and representative Tier 1 btrfs hardware, including Steam Deck, reporting frame-time tails, memory pressure and disk activity. (@fixdoes its part first: Reduce or batch the per-pass work, or restrict the default on configurations where the pass has not been shown to be beneficial.)@fixcan do L1, L2 and L3.Checks: Failing on this head, which is behind its base, where it passes:
CI / Third-party parts and guide screenshots (pull_request).@rebase(or@fix) brings it up to date and runs it again; not held against it. Still running: 7 checks.More: does it help, other systems, switches, what was read
Does it help: Yes for the reported matching failure: the author reports main finding 0 mappings and this head finding one 734 MB mapping, with 458–466 MB kept after 1–2 minutes. The claimed frame-time benefit on this head is unproven: the cited frame counts came from an earlier implementation, not paired runs of these commits.
Other systems: The changed code runs only on Linux; Windows retains the existing stub. On filesystems where the stat and maps devices agree, fallback preserves the old selection. On btrfs, the change enables the existing pass, affecting CPU time, page-cache pressure and potentially disk traffic; the reported RX 580 run does not establish its effect on Tier 1 Linux systems or Steam Deck.
Switches: None added, changed or removed. Existing HOS_CODE_WARM defaults on for Linux and can disable the thread; this change makes that default effective on the affected btrfs installations.
Reviewed:
feea6137a8againstba3f14dff1: Read AGENTS.md, CONTRIBUTING.md, the pull request template, standards, both commits, all four changed files, the existing code-warm tests, compiler selection helper and startup caller. Rechecked the complete diff. No docs/review-checklist.md or adjacent Tooling checkout was present. No generated files or translations changed; other repository files were searched or skimmed for dependencies.; nothing run (a code review).Checked and fine:
Testing: Review only; no code, tests or project scripts were run. The author reports a successful game-free regression test and one in-game btrfs run. CI is still running.
Overlaps and merge order: None found in the supplied pull request context; the network was unavailable for an overlap search.
Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, as HumanBean took it out of WIP. Nothing was run; a maintainer decides.
@ -50,0 +54,4 @@const ssize_t len = readlink("/proc/self/exe", path, sizeof path - 1);if (len > 0) {path[len] = 0;while (fgets(line, sizeof line, f))L2 (should fix): The fixed-size maps line buffer can truncate a valid executable pathname before the device lookup compares it.
When: For a btrfs executable path near Linux’s pathname limit, the address, permissions and other maps fields consume part of the 4095-character line buffer, so the complete pathname is absent and matching falls back to the wrong stat device.
Do: Read complete maps lines dynamically and handle a truncated readlink result; cover a long synthetic path in the btrfs test.
@ -52,3 +63,3 @@while (n < cap && fgets(line, sizeof line, f)) {uint64_t lo, hi;if (!hos_maps_exec_line(line, major(exe.st_dev), minor(exe.st_dev), (uint64_t)exe.st_ino, &lo, &hi) ||if (!hos_maps_exec_line(line, dev_major, dev_minor, (uint64_t)exe.st_ino, &lo, &hi) ||L3 (should fix): The newly active pass has not been measured against main for its gameplay benefit and costs on the systems it can affect.
When: On btrfs the thread now scans and reads hundreds of megabytes of resident code every two seconds; the author reports 25–38 ms per pass, but no paired frame-time, memory-pressure or disk-traffic comparison for this head, and no Tier 1 Linux or Steam Deck run.
Do: Run interleaved main-versus-head gameplay comparisons on the affected lab setup and representative Tier 1 btrfs hardware, including Steam Deck, reporting frame-time tails, memory pressure and disk activity.
@ -40,0 +51,4 @@const char *path = line + at;while (*path == ' ' || *path == '\t') path++;const size_t n = strlen(exe_path);if (strncmp(path, exe_path, n) || (path[n] && path[n] != '\n')) return 0;L1 (should fix): The pathname comparison does not account for the newline escaping used by /proc/self/maps.
When: If a directory in the executable’s btrfs path contains a newline, readlink returns the newline but maps prints it as an octal escape. The comparison fails, the code falls back to stat’s different device, and no game mapping is warmed.
Do: Compare against the maps-escaped form of the executable path, and add a synthetic btrfs test containing a newline in a directory name.