Repository navigation
Description
What problem are you trying to solve?
When rclone reads from or writes to a local filesystem, all
I/O goes through the kernel page cache. This is usually fine,
but for large streaming transfers — the primary rclone use
case — it can fill the page cache with data rclone will never
re-read, displacing pages that other applications need.
The recent removal of fadvise (#9280) helped by stopping
rclone from actively evicting other apps' cached pages. But
rclone still populates the cache with its own single-use
data. For users where this matters, O_DIRECT would give them
the option to bypass the page cache entirely.
This is a performance option, not a durability mechanism.
While O_DIRECT does often provide durability in practice
(most hardware and filesystems will complete a direct write
to persistent storage), it's not guaranteed, and so shouldn't
be seen as a durability mechanism like fsync. You still need
fsync for that, which is tracked separately in #8816.
Use cases where O_DIRECT is helpful:
- Memory-constrained or multi-tenant systems where page
cache pollution from rclone displaces other workloads'
cached data - Multiple concurrent rclone processes competing for
page cache space - Some storage systems where direct I/O is faster than
buffered I/O for large sequential transfers
This isn't the right choice for every workload — the page
cache exists for good reasons and buffered I/O is often
faster. But it should be available as an option for users
who know their environment benefits from it.
How do you think rclone should be changed?
Add a --local-direct-io flag that opens files with
O_DIRECT for reads and writes in the local backend.
Implementation considerations:
- O_DIRECT requires I/O buffers to be memory-aligned.
We'll align to 4K, which works on all common filesystems.
Go's standard allocator doesn't guarantee this, so aligned
allocation (e.g., via memalign or allocate-and-trim) is
needed. - Not all filesystems or file types support O_DIRECT. The
flag should fall back to buffered I/O with a warning if
O_DIRECT open fails. - Initial implementation targets Linux/Unix. Other platforms
may benefit in the future but are out of scope for now.
Related: #8816 (fsync/durability — orthogonal concern),
#9280 (fadvise removal — complementary), #9281 (I/O block
size), #9282 (soft-start removal).
Activity