Repository navigation
Conversation
A commit replaced the whole save folder: it swapped <id>.new and <id> with renameat2(RENAME_EXCHANGE), which gives <id> a new inode. Sync tools such as Syncthing watch the folder with inotify, so their watch stayed on the replaced folder and they missed every save until their next full rescan (hourly by default). plat_rename_swap no longer swaps folders. Every commit now moves the new files into the existing folder one by one, using the crash-safe journal that shared storage already used. The folder stays the same, so sync tools see each new file. A commit cut short by a crash is finished at the next start, so the save is never left half old, half new. Checked: a new test, test_android_saves.py HostSwap, commits a version with a removed file and a new subfolder and checks that the folder keeps its inode, that it ends up with exactly the new files, and that no marker stays. It passes with the fix and fails on the old code. The whole test_android_saves.py passes, including the launcher's JVM tests (JDK 25). plat_android.c and hle_fs.c pass an NDK 28.2.13676358 syntax check with the host's flags (Link's Awakening profile), with no warnings. On an Odin 2 Portal (Snapdragon 8 Gen 2, Android 13), the journal code built with the NDK ran on f2fs (/data/local/tmp, as app-private storage) and on /sdcard, with an inotify watch on the save folder. With RENAME_EXCHANGE the folder got a new inode and the watch saw only IN_MOVE_SELF. With the fix the inode stays and the watch sees each delete, the new subfolder and each file moved in. Not checked: game runs on the phone (system driver, Turnip) with Syncthing, and lint_c.py tidy (no clang-tidy here). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On Android a commit copied the whole work folder into <id>.new, synced every file, renamed every file into the save folder and synced every file again. A mount deleted <id>.work and copied the whole save. On shared storage (FUSE) this is slow for saves with many files: Breath of the Wild (509 files, 469 of them pictures) took 10 s per commit in the game. A changed save file also kept its old modification time (igawa6#571), so Syncthing, which skips files whose size and time did not change, never synced it. On shared storage, Android's media provider puts the old file's time back about two seconds after a file is renamed over it, and the journal's stage 2 renamed each new file over the old one. A commit now puts into <id>.new only the files that differ from the committed save, and a list of every path of the new version (.dm-keep). A file differs when its type, size, mode, attributes or contents differ; times are not trusted. The copied files get the commit's time, and stage 2 deletes the old file before renaming the new one in (SaveStore too), so a changed file keeps its new time; untouched files keep theirs. A stop between the two is finished from .pend2 like any stage 2. The journal keeps its markers and its roll-forward rules: with the list, stage 1 deletes what the list does not name and stage 2 moves in the changed files; without it nothing changes. After stage 2 only the folders are synced (the moved files were synced in <id>.new). SaveStore.recover reads the same list. A mount brings an existing <id>.work up to date instead of copying the save again. Checked: test_android_saves.py (the new delta swap test and three delta recovery states, host and launcher alike) passes; an NDK syntax check of plat_android.c and hle_fs.c. On an Odin 2 Portal, as the app on /storage/emulated/0 with a copy of the BotW save, one slot changed and its old times put back on the changed files: a commit took 1.1 s (21 s the old way) and a mount refresh 0.9 s (5.8 s), each leaving the folders identical; five seconds later the changed files still had the commit's time, the others their own. Not checked in the game with this version (an earlier one that compared times committed a BotW save in 0.27 s; 0.1.8 takes 10.2-10.8 s). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
Fixes #571. Likely fixes #565. Depends on #732 (it builds on its in-place save journal; until that is merged this PR also shows its commit).
On Android, a save commit copied the whole work folder into
<id>.new, synced every file, renamed every file into the save folder and synced every file again; a mount deleted<id>.workand copied the whole save. On shared storage (FUSE: a picked save folder under/storage/emulated/0or on an SD card) every one of those operations is slow, so saves with many files take seconds. Breath of the Wild (509 files, 469 of them pictures) took 10.2-10.8 s per commit on an Odin 2 Portal; #565's log shows 2.7-3.3 s per commit on an SD card, the length of the sound gap after a teleport (BotW saves on arrival). On the Portal the delayed sound after fast travel, and Compendium entries not shown as saved, went away with this change.#571: a changed save file kept its old modification time, so Syncthing (which skips files whose size and time did not change) never synced it. Cause: on shared storage, Android's media provider puts the old file's time back about two seconds after a file is renamed over it, and the journal's stage 2 renamed each new file over the old one.
The change (
plat_android.c,hle_fs.c,SaveStore.java):<id>.newonly the files that differ from the committed save, plus a list of every path of the new version (.dm-keep). A file differs when its type, size, mode, attributes or contents differ; times are not trusted (they can be stale on shared storage).<id>.new)..pend2like any stage 2.SaveStore.recoverreads the same list and moves files the same way.<id>.workup to date (copying only what differs) instead of copying the whole save again.clonefile/RENAME_SWAP).Checked
python3 -m unittest test_android_saves(indm/tools/tests) passes, with a new delta swap test (an unchanged file keeps its inode) and three new stopped-commit states (delta_pend1,delta_pend2_partial,delta_done) that the host'splat_swap_recoverandSaveStore.recoverfinish identically.plat_android.candhle_fs.cwith the host's flags: no errors, no warnings./storage/emulated/0, with a copy of the BotW save, one slot changed and its old times put back on the changed files: a commit took 1.1 s (21 s the old way), a mount refresh 0.9 s (5.8 s); the folders ended identical; five seconds later the changed files still had the commit's time, the others their own.-PnxApp=peanuts -PnxAppId=peanutstest), save folder on/storage/emulated/0: The Legend of Zelda: Breath of the Wild 1.9.0 (01007EF00011E000), loaded and saved twice: 7 commits of 0.63-0.81 s (10.2-10.8 s with 0.1.8 on the same folder), the save identical to.work, the changed files carrying the save's time ten seconds later, no crash.lint_c.py tidy.Docs
docs/reference/<subsystem>.mdentry, andpython3 dm/tools/docs_symptoms.pywas run (the symptom index)dm/third_party/, no change todmsh_chain.lock; the branch starts from the currentmain(on top of Android: a save commit updates the save folder in place (#485) #732)