Skip to content

virtiofs: remove unnecessary per-entry lookup from plain readdir#3440

Open
benhillis wants to merge 1 commit intomicrosoft:mainfrom
benhillis:virtiofs-readdir-no-lookup
Open

virtiofs: remove unnecessary per-entry lookup from plain readdir#3440
benhillis wants to merge 1 commit intomicrosoft:mainfrom
benhillis:virtiofs-readdir-no-lookup

Conversation

@benhillis
Copy link
Copy Markdown
Member

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).

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).

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>
@benhillis benhillis requested a review from a team as a code owner May 8, 2026 16:37
Copilot AI review requested due to automatic review settings May 8, 2026 16:37
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() for readdirplus and preserved the existing behavior of skipping entries that fail lookup with EACCES/ENOENT.
  • Updated comments to document why plain readdir no longer does per-entry access checks.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants