use O_DIRECT for file read operations

This commit is contained in:
Ishan Jain
2024-07-09 10:04:04 +05:30
parent 32df171786
commit c171b63ec2
3 changed files with 8 additions and 1 deletions

1
Cargo.lock generated
View File

@@ -954,6 +954,7 @@ dependencies = [
"criterion",
"fallible-iterator 0.3.0",
"io-uring",
"libc",
"log",
"mimalloc",
"ordered-multimap",

View File

@@ -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"

View File

@@ -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<Rc<dyn File>> {
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,