Skip to content

Commit f73069c

Browse files
authored
Document that O_DIRECT affects latency only, not durability (#254)
1 parent 0b8edea commit f73069c

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/fs/shim/std/fs/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,19 @@ impl OpenOptions {
11391139
/// When enabled, reads and writes bypass the simulated page cache,
11401140
/// always incurring full I/O latency.
11411141
///
1142+
/// # Durability Note
1143+
///
1144+
/// In this simulation, O_DIRECT only affects **latency**, not **durability**.
1145+
/// Writes still require `sync_all()` to become crash-safe, regardless of
1146+
/// whether O_DIRECT is used. This is actually realistic: on real systems,
1147+
/// O_DIRECT bypasses the OS page cache but data can still sit in the drive's
1148+
/// volatile write cache. Only `fsync()` guarantees data reaches persistent
1149+
/// media.
1150+
///
1151+
/// In practice, O_DIRECT writes are "closer" to disk (smaller device buffer
1152+
/// vs large OS page cache), but this simulation takes the conservative
1153+
/// approach of treating all non-synced writes equally for crash testing.
1154+
///
11421155
/// # Example
11431156
///
11441157
/// ```ignore

src/fs/shim/tokio/fs/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,14 @@ impl OpenOptions {
467467
///
468468
/// When enabled, reads and writes bypass the simulated page cache,
469469
/// always incurring full I/O latency.
470+
///
471+
/// # Durability Note
472+
///
473+
/// O_DIRECT only affects **latency**, not **durability**. Writes still require
474+
/// `sync_all()` to become crash-safe. See [`std::fs::OpenOptions::direct_io`]
475+
/// for details.
476+
///
477+
/// [`std::fs::OpenOptions::direct_io`]: crate::fs::shim::std::fs::OpenOptions::direct_io
470478
pub fn direct_io(&mut self, direct_io: bool) -> &mut Self {
471479
self.inner.direct_io(direct_io);
472480
self

0 commit comments

Comments
 (0)