Repository navigation
squashfuse_ll: let the kernel cache directory listings - #159
Merged
Merged
Conversation
The image is read-only, so directory listings never change while mounted. - In sqfs_ll_op_opendir, set cache_readdir and keep_cache so the kernel keeps readdir results in the page cache (FOPEN_CACHE_DIR). - If the kernel advertises FUSE_CAP_NO_OPENDIR_SUPPORT, reply ENOSYS to opendir. The kernel then stops sending OPENDIR/RELEASEDIR and caches readdir results as if opendir returned FOPEN_KEEP_CACHE | FOPEN_CACHE_DIR. sqfs_ll_op_readdir looks up the inode itself when there is no handle. A cached traversal then sends no requests to the daemon. fd on a 370k-entry image: 663 ms -> 137 ms (-j1), 244 ms -> 37 ms (-j8). Guarded by FUSE_CAP_NO_OPENDIR_SUPPORT (libfuse >= 3.5, same as cache_readdir), so older libfuse and FUSE 2 builds are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Right now, every directory listing on a
squashfuse_llmount sends four requests to the daemon:OPENDIR,READDIR, a secondREADDIRthat comes back empty, andRELEASEDIR. The kernel caches none of them. Lookups and attributes are already cached forever (SQFS_TIMEOUT = DBL_MAX), so on a repeated tree walk (find,fd, build tools that scan include paths) nearly all remaining requests are these directory ones.The image is read-only and can't change while mounted, so the kernel can safely keep these results. This PR makes it do so:
cache_readdir/keep_cachein opendir.sqfs_ll_op_opendirsetsfi->cache_readdir = 1andfi->keep_cache = 1(FOPEN_CACHE_DIR, Linux ≥ 4.20). Readdir results then stay in the page cache across opens.OPENDIR/RELEASEDIRwhen the kernel supports skipping them.sqfs_ll_op_initrecords whetherconn->capablehasFUSE_CAP_NO_OPENDIR_SUPPORT(Linux ≥ 5.1). If it does, opendir repliesENOSYS. As documented infuse_lowlevel.h, the kernel then handles opendir/releasedir itself and caches readdir "as if opendir returnedFOPEN_KEEP_CACHE | FOPEN_CACHE_DIR".sqfs_ll_op_readdirthen receivesfi->fh == 0, and in that case it looks up the inode into a stacksqfs_ll_i. That's safe because readdir replies before it returns.On a warm cache, a traversal now sends no requests to the daemon at all.
Everything is behind
#ifdef FUSE_CAP_NO_OPENDIR_SUPPORT. That flag andcache_readdirboth arrived in libfuse 3.5, so FUSE 2.x and older libfuse 3 builds don't change. On a kernel without no-opendir support you still get (1).Notes
open_refcountstays balanced: when opendir is skipped, releasedir is never called either. Idle-timeout unmount still works from the last access time.fuse_lowlevel_opsneed to registersqfs_ll_op_init(assquashfuse_llalready does) to get (2). Without it they only get (1).Testing
make checkpasses (7/7) with the multithreaded build, Linux 6.18, libfuse 3./usr/share(370,571 entries, including large directories that need severalREADDIRcalls). I mounted it with three builds: unpatched, patched, and patched with no-opendir forced off (to simulate an older kernel). The fullfindlisting andls -laRoutput give the same md5 for all three.hyperfine -N --warmup 2 'fd -HI -jN does-not-exist <mnt>', warm cache, same image:fd -j1fd -j8On an HPC system (aarch64, kernel 6.4, libfuse 3.10, image with 16k directories),
fd -j1went from 1.50 s to 201 ms. The daemon used no CPU during a cached run.🤖 Generated with Claude Code