From fa654a5dc952f24e954cbffaa2912dbbefbcb89b Mon Sep 17 00:00:00 2001 From: Victor Fuentes Date: Wed, 15 Jan 2025 14:27:47 -0800 Subject: [PATCH] refactor(tvix/castore/fs): set sane default option flags Sets some sane default caching options and flags for tvix_castore::fs::TvixStoreFs, greatly reducing latency on cache hits. See: https://man7.org/linux/man-pages/man4/fuse.4.html See: https://docs.rs/fuse-backend-rs/latest/fuse_backend_rs/abi/fuse_abi/struct.FsOptions.html Co-Authored-By: Florian Klink Change-Id: Ie105249fc92f56604e7c337d5983e4038b775f42 Reviewed-on: https://cl.tvl.fyi/c/depot/+/13002 Reviewed-by: flokli Tested-by: BuildkiteCI --- tvix/castore/src/fs/mod.rs | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/tvix/castore/src/fs/mod.rs b/tvix/castore/src/fs/mod.rs index 4f50868b8..fdf15cd41 100644 --- a/tvix/castore/src/fs/mod.rs +++ b/tvix/castore/src/fs/mod.rs @@ -322,7 +322,20 @@ where type Inode = u64; fn init(&self, _capable: FsOptions) -> io::Result { - Ok(FsOptions::empty()) + let mut opts = FsOptions::empty(); + + // the filesystem supports readdirplus + opts |= FsOptions::DO_READDIRPLUS; + // issue both readdir and readdirplus depending on the information expected to be required + opts |= FsOptions::READDIRPLUS_AUTO; + // allow more than one pending read request per file-handle at any time + opts |= FsOptions::ASYNC_READ; + // allow concurrent lookup() and readdir() requests for the same directory + opts |= FsOptions::PARALLEL_DIROPS; + // have the kernel cache symlink contents + opts |= FsOptions::CACHE_SYMLINKS; + + Ok(opts) } #[tracing::instrument(skip_all, fields(rq.inode = inode))] @@ -436,13 +449,11 @@ where .write() .insert(dh, (Span::current(), Arc::new(Mutex::new(rx)))); - return Ok(( - Some(dh), - fuse_backend_rs::api::filesystem::OpenOptions::empty(), // TODO: non-seekable - )); + return Ok((Some(dh), OpenOptions::NONSEEKABLE)); } - Ok((None, OpenOptions::empty())) + // allow caching this directory contents, don't invalidate on open + Ok((None, OpenOptions::CACHE_DIR | OpenOptions::KEEP_CACHE)) } #[tracing::instrument(skip_all, fields(rq.inode = inode, rq.handle = handle, rq.offset = offset), parent = self.dir_handles.read().get(&handle).and_then(|x| x.0.id()))] @@ -653,11 +664,7 @@ where inode: Self::Inode, _flags: u32, _fuse_flags: u32, - ) -> io::Result<( - Option, - fuse_backend_rs::api::filesystem::OpenOptions, - Option, - )> { + ) -> io::Result<(Option, OpenOptions, Option)> { if inode == ROOT_ID { return Err(io::Error::from_raw_os_error(libc::ENOSYS)); } @@ -699,7 +706,8 @@ where Ok(( Some(fh), - fuse_backend_rs::api::filesystem::OpenOptions::empty(), + // Don't invalidate the data cache on open. + OpenOptions::KEEP_CACHE, None, )) }