From c171b63ec2db1caade13c64d8deaad2ec201bc51 Mon Sep 17 00:00:00 2001 From: Ishan Jain Date: Tue, 9 Jul 2024 10:04:04 +0530 Subject: [PATCH] use O_DIRECT for file read operations --- Cargo.lock | 1 + core/Cargo.toml | 1 + core/io/linux.rs | 7 ++++++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 176e381e5..cba209390 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -954,6 +954,7 @@ dependencies = [ "criterion", "fallible-iterator 0.3.0", "io-uring", + "libc", "log", "mimalloc", "ordered-multimap", diff --git a/core/Cargo.toml b/core/Cargo.toml index 7777e2b03..ce6c65140 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -27,6 +27,7 @@ mimalloc = { version = "*", default-features = false } anyhow = "1.0.75" cfg_block = "0.1.1" fallible-iterator = "0.3.0" +libc = "0.2.155" log = "0.4.20" ordered-multimap = "0.7.1" sieve-cache = "0.1.4" diff --git a/core/io/linux.rs b/core/io/linux.rs index 41a5b3242..b1750d565 100644 --- a/core/io/linux.rs +++ b/core/io/linux.rs @@ -2,6 +2,7 @@ use super::{Completion, File, WriteCompletion, IO}; use anyhow::Result; use log::trace; use std::cell::RefCell; +use std::os::unix::fs::OpenOptionsExt; use std::os::unix::io::AsRawFd; use std::rc::Rc; @@ -21,7 +22,11 @@ impl LinuxIO { impl IO for LinuxIO { fn open_file(&self, path: &str) -> Result> { trace!("open_file(path = {})", path); - let file = std::fs::File::options().read(true).write(true).open(path)?; + let file = std::fs::File::options() + .read(true) + .write(true) + .custom_flags(libc::O_DIRECT) + .open(path)?; Ok(Rc::new(LinuxFile { ring: self.ring.clone(), file,