Skip to content

9p: Performance improvements for build workloads

Remi Pommarel linux-fsdevel lkml v9fs 7 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v7 Latest4 patches 2 repliesIn review
  2. v64 patches 0 repliesSuperseded
  3. v54 patches 0 repliesSuperseded
Earlier versions · 4
VersionPostedPatchesRepliesStatus
v44 patches2 repliesSuperseded
v34 patches9 repliesSuperseded
v23 patches14 repliesSuperseded
v1 RFC5 patches3 repliesSuperseded

Changes in v7 from the cover letter

- Don't do strict length check in v9fs_issue_read(), if the file changed on server side truncate the link instead as it is done for files
- Allow page_get_link() to be called during the lockless RCU-walk (with NULL dentry) theoretically improving performaces further

Patches in v7 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/49p: Cache negative dentries for lookup performancefs/9p/fid.c fs/9p/v9fs.c fs/9p/v9fs.h +5 more+128 -240 replies
2/49p: Add mount option for negative dentry cache retentionDocumentation/filesystems/9p.rst fs/9p/v9fs.c fs/9p/v9fs.h+33 -110 replies
3/49p: Set default negative dentry retention time for cache=loosefs/9p/v9fs.c+10 -00 replies
4/49p: Enable symlink caching in page cachefs/9p/vfs_addr.c fs/9p/vfs_inode.c fs/9p/vfs_inode_dotl.c+88 -101 reply

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v7 yet.

Read the v7 thread

Cover letter [PATCH v7 0/4] 9p: Performance improvements for build workloads

This patchset introduces several performance optimizations for the 9p filesystem when used with cache=loose option (exclusive or read only mounts). These improvements particularly target workloads with frequent lookups of non-existent paths and repeated symlink resolutions.

The very state of the art benchmark consisting of cloning a fresh hostap repository and building hostapd and wpa_supplicant for hwsim tests (cd tests/hwsim; time ./build.sh) in a VM running on a 9pfs rootfs (with trans=virtio,cache=loose options) has been used to test those optimizations impact.

For reference, the build takes 0m56.492s on my laptop natively while it completes in 2m18.702sec on the VM. This represents a significant performance penalty considering running the same build on a VM using a virtiofs rootfs (with "--cache always" virtiofsd option) takes around 1m32.141s. This patchset aims to bring the 9pfs build time close to that of virtiofs, rather than the native host time, as a realistic expectation.

This first three patches in this series focus on keeping negative dentries in the cache, ensuring that subsequent lookups for paths known to not exist do not require redundant 9P RPC calls. This optimization reduces the time needed for the compiler to search for header files across known locations. The two first patches introduce a new mount option, ndentrycache, which specifies the number of ms to keep the dentry in the cache. Using ndentrycache without value (i.e. keeping the negative dentry indifinetly) shrunk build time to 1m46.198s. The third patch enable the negative dentry caching for 24 hours by default on cache=loose.

The fourth patch extends page cache usage to symlinks by allowing p9_client_readlink() results to be cached. Resolving symlink is apparently something done quite frequently during the build process and avoiding the cost of a 9P RPC call round trip for already known symlinks helps reduce the build time to 1m26.602s, outperforming the virtiofs setup.

Here is summary of the different hostapd/wpa_supplicant build times:

- Baseline (no patch): 2m18.702s
- negative dentry caching (patches 1-3): 1m46.198s (23% improvement)
- Above + symlink caching (patches 1-4): 1m26.302s (an additional 18% improvement, 37% in total)

With this ~37% performance gain, 9pfs with cache=loose can compete with virtiofs for (at least) this specific scenario. Although this benchmark is not the most typical, I do think that these caching optimizations could benefit a wide range of other workflows as well.

Changes since v6 (address more relevant sashiko.dev remarks):
- Don't do strict length check in v9fs_issue_read(), if the file changed on server side truncate the link instead as it is done for files
- Allow page_get_link() to be called during the lockless RCU-walk (with NULL dentry) theoretically improving performaces further
Changes since v5 (address relevant sashiko.dev remarks):
- Replace forgotten ndentrycache with negtimeout wording in documentation
- Rework v9fs_issue_read() to perform proper offset and length validation, remove PAGE_SIZE truncation, and use the actual copied length rather than the expected one.
- Use d_find_any_alias() instead of d_find_alias() to avoid unhashed dentry race in v9fs_init_request().

Changes since v4:
- Fix potential uninitialized access in v9fs_issue_read() and

    v9fs_vfs_symlink_dotl()

- Fix potential memory leak in v9fs_issue_read()

Changes since v3:
- Go back to s32 ndentry timeout option, rename it to negtimeout so its easier to grep
- Bring back the missing 4 letters for *_TIMEOUT_* macro name
- Fix some alignment/space issues

Changes since v2:
- Rename v9fs_dentry_is_{expired,refresh} to ndentry
- Some grammatical fixes in couple of comments
- Rename the negative cache mount option to ndentrycache. Using ndentrycache without value enable infinite caching while ndentrycache=<time> enable caching for <time> milliseconds. This allows the option to be unsigned.
- Make it more obvious v9fs_issue_read() is only called on dotl symlinks

Changes since v1:
- Rebase on 9p-next (with new mount API conversion)
- Integrated symlink caching with the network filesystem helper library for robustness (a lot of code expects a valid netfs context)
- Instantiate symlink dentry at creation to avoid keeping a negative dentry in cache
- Moved IO waiting time accounting to a separate patch series

Thanks.

Remi Pommarel (4):
9p: Cache negative dentries for lookup performance 9p: Add mount option for negative dentry cache retention 9p: Set default negative dentry retention time for cache=loose 9p: Enable symlink caching in page cache

 Documentation/filesystems/9p.rst |   5 ++
 fs/9p/fid.c                      |  11 ++--
 fs/9p/v9fs.c                     |  27 +++++++-
 fs/9p/v9fs.h                     |  28 ++++++---
 fs/9p/v9fs_vfs.h                 |  15 +++++
 fs/9p/vfs_addr.c                 |  38 ++++++++++-
 fs/9p/vfs_dentry.c               | 105 ++++++++++++++++++++++++++-----
 fs/9p/vfs_inode.c                |  18 +++---
 fs/9p/vfs_inode_dotl.c           |  54 ++++++++++++++--
 fs/9p/vfs_super.c                |   1 +
 include/net/9p/client.h          |   2 +
 11 files changed, 259 insertions(+), 45 deletions(-)
Signature · 1 line
2.52.0