file-operations: throttle page cache during cross-device copies#3726
Open
KonTy wants to merge 1 commit intolinuxmint:masterfrom
Open
file-operations: throttle page cache during cross-device copies#3726KonTy wants to merge 1 commit intolinuxmint:masterfrom
KonTy wants to merge 1 commit intolinuxmint:masterfrom
Conversation
When copying large files to a slow device (e.g. USB), GLib's splice() fills the page cache at RAM speed. Once dirty pages exceed the kernel's dirty_ratio the kernel blocks all writers, making Nemo (and the whole desktop) appear frozen for minutes. Fix this by periodically calling sync_file_range() + posix_fadvise() from the copy progress callback every 32 MiB: - SYNC_FILE_RANGE_WAIT_BEFORE: provides natural back-pressure by waiting for the previous chunk's writeback to finish, pacing the copy to actual device speed. - SYNC_FILE_RANGE_WRITE: starts async writeback for the new chunk. - POSIX_FADV_DONTNEED: drops pages whose writeback already completed, keeping memory usage bounded. This keeps dirty pages at ~32-64 MiB instead of many gigabytes, the progress bar advances at the real device speed, and no single syscall blocks for more than one 32 MiB chunk. Only affects cross-filesystem copies of regular files (the common fast-source → slow-USB case). Same-filesystem moves and copies are unaffected. Fixes: linuxmint#3710
Contributor
|
This "problem" has never occurred for me. |
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.
Fixes #3710
When copying many large files (15-20 ISOs, 3-6 GB each) from a fast source (NAS/SSD) to a slow USB drive, GLib's splice() fills the page cache at RAM speed. Once dirty pages hit the kernel's dirty_ratio, all writes block and the system freezes. I've seen the same behavior in Double Commander on Arch, where I have to enable "verify on copy" to make sure files aren't silently corrupted. The fix adds periodic sync_file_range() + posix_fadvise(DONTNEED) calls every 32 MiB in the copy progress callback, which provides natural back-pressure that paces the copy to actual device speed and keeps dirty pages bounded at ~32-64 MiB instead of many gigabytes.