Skip to content

local: add O_DIRECT support for writes - #9286

Open
paf0186 wants to merge 3 commits into
rclone:masterfrom
paf0186:local-direct-io
Open

paf0186 wants to merge 3 commits into
rclone:masterfrom
paf0186:local-direct-io

Conversation

@paf0186

@paf0186 paf0186 commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

What is the purpose of this change?

Add --local-direct-io flag that opens files with O_DIRECT for
writes, bypassing the kernel page cache. This avoids polluting
the page cache with single-use streaming data on large transfers.

This is a performance option, not a durability guarantee. Use cases:

  • Memory-constrained or multi-tenant systems where page cache
    pollution from rclone displaces other workloads' data
  • Multiple concurrent rclone processes competing for cache space
  • Storage systems where direct I/O is faster for large streaming
    transfers

Implementation details:

  • 4K-aligned buffer allocation for O_DIRECT compatibility
  • Drops O_DIRECT via fcntl for the final partial block of each
    file (O_DIRECT requires sector-aligned write sizes)
  • Falls back to buffered I/O with a warning if O_DIRECT open
    fails
  • Linux only for now; other platforms get a no-op stub
  • Read path O_DIRECT is not yet implemented (requires aligned
    buffers in the accounting/async reader layer)

Fixes #9283

Note: This PR is based on #9285 (configurable I/O block size)
and will need a rebase depending on which lands first. They can
also be reviewed independently — the O_DIRECT commit is separate
from the I/O size commit.

paf0186 added 2 commits March 24, 2026 12:23
The write path was allocating a fresh buffer with make() for
every file written, then relying on GC to clean it up. The
read path already uses a buffer pool (via AsyncReader) for
reuse and memory tracking.

Use pool.Global() for write buffers too, so they are reused
across transfers and tracked by the memory limiter.

Signed-off-by: Patrick Farrell <[email protected]>
Add --local-io-size (default 1M), --local-read-io-size, and
--local-write-io-size flags to control the I/O block size
used by the local backend. Values must be 4K-aligned.

The write path uses pool.GlobalWithSize() to get a properly
sized buffer from a per-size pool, so custom sizes still get
buffer reuse and memory tracking.

The pool gains GlobalWithSize() which returns the default
global pool for the default 1MB size, or creates and caches
a new pool for other sizes.

The AsyncReader gains a NewSize() constructor that uses a
matching pool, so custom read buffer sizes also get proper
pool integration.

Fixes: rclone#9281

Signed-off-by: Patrick Farrell <[email protected]>
Add --local-direct-io flag that opens files with O_DIRECT for
writes, bypassing the kernel page cache.  This avoids polluting
the page cache with single-use streaming data on large
transfers.

O_DIRECT requires aligned I/O buffers and sector-aligned write
sizes.  The implementation uses 4K-aligned buffer allocation
and drops O_DIRECT via fcntl for the final partial block of
each file.

Falls back to buffered I/O with a warning if O_DIRECT open
fails (e.g., filesystem doesn't support it).

Read path O_DIRECT is not yet implemented — it requires
aligned buffers in the accounting/async reader layer.

Linux only for now.

Fixes: rclone#9283

Signed-off-by: Patrick Farrell <[email protected]>
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.

local: add O_DIRECT support for local filesystem I/O

1 participant