Skip to content

file-operations: throttle page cache during cross-device copies#3726

Open
KonTy wants to merge 1 commit intolinuxmint:masterfrom
KonTy:fix/usb-copy-throttle
Open

file-operations: throttle page cache during cross-device copies#3726
KonTy wants to merge 1 commit intolinuxmint:masterfrom
KonTy:fix/usb-copy-throttle

Conversation

@KonTy
Copy link

@KonTy KonTy commented Mar 6, 2026

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.

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
@Jeremy7701
Copy link
Contributor

This "problem" has never occurred for me.
If you believe it is a kernel problem, then you should contact the kernel maintainers.
User workarounds won't solve any genuine problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Transfer to USB drive locks up with grouped graphical cut/paste

2 participants