Skip to content

Support for direct io #8816

Open
Open

Description

@praveen-solanki-oracle

The associated forum post URL from https://forum.rclone.org

What is your current rclone version (output from rclone version)?

v1.70.3

What problem are you are trying to solve?

We are trying to ensure that when rclone is done syncing a file we have a way to also write the dirty pages back. In some cases we need to ensure that all the writes are flushed to disk. It would be nice to be able to control this behavior with a flag that can be provided.

How do you think rclone should be changed to solve that?

We should add a flag that can be provided which ensures that all the writes are done with o_direct flag.

How to use GitHub

  • Please use the 👍 reaction to show that you are affected by the same issue.
  • Please don't comment if you have no relevant information to add. It's just extra noise for everyone subscribed to this issue.
  • Subscribe to receive notifications on status change and new comments.

Activity

  1. praveen-solanki-oracle commented on Sep 11, 2025

    @praveen-solanki-oracle
    ContributorAuthor

    @ncw Let me know what you think of this request. Thank you !!

  2. ncw commented on Sep 12, 2025

    @ncw
    Member

    Thanks for the idea @praveen-solanki-oracle

    Flushing files is quite complicated! There are lots of options and there are cross platform issues also. I asked ChatGPT to come up with a table showing the pros and cons of each method

    Option Durability guarantee Scope Portability Perf impact Complexity Caveats
    Per-file fsync Strong (data+metadata when paired with dir fsync) Each file High High (worst on HDD/latency FS) Low Must also fsync parent dir after create/rename
    Per-file fdatasync Strong (data), metadata later Each file High Med-High Low Still fsync parent dir for durability of names
    Open O_DSYNC Strong (data on each write) Per write Med (Win needs write-through) Med-High Med Many small writes hurt; metadata may lag
    Open O_SYNC Very strong (data+metadata each write) Per write Med Highest Med Big slowdown; overkill for many workloads
    Filesystem syncfs @ end Strong (at end) Per filesystem Low-Med (Linux only) Low Med If crash before end, data may still be dirty
    Global sync() @ end Strong (at end, all FS) System-wide High Low Low Flushes unrelated workloads; impolite
    O_DIRECT Bypass page cache; persistence depends on device cache flush rules Per write Low-Med Med-Low for large aligned IO; poor for small/unaligned High Alignment/size constraints; limited on macOS; still need dir fsync
    Hybrid batched fsync Strong (when batch commits) Batch High Tunable Med Window of vulnerability between batches
    macOS F_FULLFSYNC Stronger than fsync on some stacks Each file macOS only High Low No-op on some devices/FS

    It would help to know what problem you are trying to solve. Do you need the data synced immediately it is written or are you happy to wait until the entire file is written? Or be sure that it is synced every N seconds? Or at the end of the sync?

    The simplest and most portable way to do this would be to use fsync on the file just before we close it. We also need to fsync the parent directory if we are changing it (eg creating a file or renaming a file). This would have the advantage of working on all platforms.

    O_DIRECT is quite tricky as it needs aligned buffers and I can tell you from previous experience that it slows everything down a great deal!

    As a comparison, here is how rsync deals with this It apparently does not fsync the directories though.

       --fsync
              Cause  the receiving side to fsync each finished file.  This may
              slow down the transfer, but can help to provide  peace  of  mind
              when updating critical files.
    
  3. praveen-solanki-oracle commented on Sep 16, 2025

    @praveen-solanki-oracle
    ContributorAuthor

    Hello @ncw , thanks for responding. So for my purpose fsync will work as well. So the goal is that each file that rclone copies to local should be flushed when copy completes. Normally for a C application you would use o_direct hence my initial suggestion, but if we can use a flag that can fsync after the rclone command completes, it will serve my purpose.

    Let me know what you think. If this sounds good to you I am happy to make a code change.

    Proposal

    Introduce a new flag --fsync for copy command which performs a os.fsync(fd) when copy completes.

  4. praveen-solanki-oracle commented on Sep 26, 2025

    @praveen-solanki-oracle
    ContributorAuthor

    Gentle bump :) @ncw

  5. paf0186 commented on Mar 24, 2026

    @paf0186
    Contributor

    This issue conflates two orthogonal concerns, so I've opened
    #9283 to track O_DIRECT separately.

    • O_DIRECT is a performance optimization: bypass the page
      cache to avoid polluting it with single-use streaming data.
      While O_DIRECT does often provide durability in practice,
      it's not guaranteed, and so shouldn't be seen as a
      durability mechanism like fsync. Tracked in local: add O_DIRECT support for local filesystem I/O #9283.
    • fsync is a durability mechanism: ensure data has reached
      persistent storage. Works with or without O_DIRECT.

    The original request here ("ensure all writes are flushed to
    disk") is an fsync use case, and the discussion converged on
    --fsync being the right approach. That still seems right for
    this issue.

  6. praveen-solanki-oracle commented on Mar 24, 2026

    @praveen-solanki-oracle
    ContributorAuthor

    Will try to put out a PR for this.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions