nfsproxy: shard NFS handle cache by mount point - #3592
Open
Merlin0220 wants to merge 1 commit into
Open
Conversation
Merlin0220
requested review from
ValentaTomas,
dobrac and
jakubno
as code owners
August 21, 2026 14:09
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.
Fixes #3555.
Problem
The NFS proxy currently uses a single global LRU file-handle cache shared by all sandboxes and mount points on the same orchestrator node.
Because there is no cache ownership boundary between mounts, filesystem activity in one sandbox can affect the cached NFS handles of another sandbox. For example, listing a directory containing many files creates a large number of handles and can evict directory handles that are still being used by an unrelated sandbox.
When the affected sandbox later reuses an evicted directory handle, the NFS proxy can no longer resolve it and returns:
The client surfaces this error as:
The most severe case is eviction of the handle representing a sandbox mount point's root directory, which corresponds to the root of its chroot filesystem. This root handle is the entry point through which the NFS client resolves paths within the mount.
If the root handle is evicted, subsequent operations rooted at that handle fail with
Stale file handle. The existing mount cannot recreate the root handle through normal filesystem operations because those operations already require a valid parent handle. As a result, the entire mount becomes unusable and cannot recover transparently; the client must remount the filesystem to obtain a new root handle.Increasing the global cache size only reduces the likelihood of eviction. It does not prevent one sandbox from evicting handles owned by another sandbox.
Fix
Allocate an independent NFS handle cache for every successful mount.
Each mount is assigned a random UUID. NFS file handles are encoded as:
When resolving or invalidating a handle, the mount UUID selects the correct cache shard, and the remaining bytes are forwarded to that mount's
helpers.CachingHandler.This isolates LRU eviction between mount points. Activity from one sandbox can no longer evict the root handle or other cached handles belonging to another sandbox's mount point, preventing unrelated cache pressure from invalidating the entire mount.
Changes
Testing
Risk: Memory Usage with Larger Cache Limits
The cache limit now applies to each mount point rather than to the entire NFS proxy. As a result, the maximum number of cached handles is approximately:
Increasing the per-mount cache limit can therefore significantly increase the orchestrator's total memory usage.
Capacity planning should reserve memory based on the maximum number of sandboxes hosted by a node and the expected number of mount points per sandbox.
The
nfs.mount_cache.shardsandnfs.mount_cache.ownersgauges can be used to observe the active cache footprint and validate those assumptions before increasing the cache size.