virtiofs: remove unnecessary per-entry lookup from plain readdir#3440
Open
benhillis wants to merge 1 commit intomicrosoft:mainfrom
Open
virtiofs: remove unnecessary per-entry lookup from plain readdir#3440benhillis wants to merge 1 commit intomicrosoft:mainfrom
benhillis wants to merge 1 commit intomicrosoft:mainfrom
Conversation
The plain readdir path was calling lookup_helper() on every directory entry just to check accessibility, then discarding the result. This caused a full stat round-trip per entry even though the lookup results were not returned to the guest kernel (unlike readdirplus, where they pre-populate the dentry cache). Neither virtiofsd nor CrosVM performs per-entry lookups during plain readdir — they return raw getdents64 results directly. Directory read permission is already verified at opendir time, making the per-entry access check redundant. This should improve performance for directory listing workloads where the kernel uses plain readdir (e.g. via READDIRPLUS_AUTO fallback). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves virtio-fs directory listing performance by removing a redundant per-entry lookup_helper() call from the plain readdir path. This avoids an unnecessary stat/lookup round-trip for each directory entry when the results are not returned to the guest (unlike readdirplus, which uses the lookup results to populate the dentry cache).
Changes:
- Removed per-entry
lookup_helper()calls from the non-readdirplus(plus == false) directory enumeration path. - Kept
lookup_helper()forreaddirplusand preserved the existing behavior of skipping entries that fail lookup withEACCES/ENOENT. - Updated comments to document why plain
readdirno longer does per-entry access checks.
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.
The plain readdir path was calling
lookup_helper()on every directoryentry just to check accessibility, then discarding the result. This
caused a full stat round-trip per entry even though the lookup results
were not returned to the guest kernel (unlike readdirplus, where they
pre-populate the dentry cache).
Directory read permission is already verified at opendir time, making
the per-entry access check redundant.
This should improve performance for directory listing workloads where
the kernel uses plain readdir (e.g. via
READDIRPLUS_AUTOfallback).