Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions fs/src/buffered_writer.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
use std::{
fs,
io::{self, BufWriter},
path::Path,
use {
crate::io_uring::file_writer::IoUringFileWriterBuilder,
std::{
fs,
io::{self, BufWriter},
path::Path,
},
};

/// Default buffer size for writing large files to disks. Since current implementation does not do
/// background writing, this size is set above minimum reasonable SSD write sizes to also reduce
/// number of syscalls.
const DEFAULT_BUFFER_SIZE: usize = 2 * 1024 * 1024;
const DEFAULT_BUFFER_SIZE: usize = 4 * crate::io_uring::file_writer::DEFAULT_WRITE_SIZE as usize;

/// Return a buffered writer for creating a new file at `path`
///
/// The returned writer is using a buffer size tuned for writing large files to disks.
pub fn large_file_buf_writer(path: impl AsRef<Path>) -> io::Result<impl io::Write + io::Seek> {
let file = fs::File::create(path)?;
fs::File::create(&path)?;

Ok(BufWriter::with_capacity(DEFAULT_BUFFER_SIZE, file))
// IoUringFileWriter has poor perf on small writes even when it's just copying to its internal buffer
// putting a bufwriter around it makes it significantly faster for small writes
Ok(BufWriter::new(
IoUringFileWriterBuilder::new().build(path, DEFAULT_BUFFER_SIZE)?,
))
}
3 changes: 2 additions & 1 deletion fs/src/io_uring/file_creator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ const MAX_OPEN_FILES: usize = 512;
// (on open, since in accounts-db most files land in a single dir).
const DEFAULT_MAX_IOWQ_WORKERS: u32 = 4;

const CHECK_PROGRESS_AFTER_SUBMIT_TIMEOUT: Option<Duration> = Some(Duration::from_millis(10));
pub(crate) const CHECK_PROGRESS_AFTER_SUBMIT_TIMEOUT: Option<Duration> =
Some(Duration::from_millis(10));

/// Utility for building [`IoUringFileCreator`] with specified tuning options.
pub struct IoUringFileCreatorBuilder<'sp> {
Expand Down
Loading