Skip to content

Commit 0e609bb

Browse files
ayushr2gvisor-bot
authored andcommitted
Add documentation for exclusive bind mounts and dentry cache.
This change adds sections to the filesystem user guide: - Explaining the `--file-access-mounts=exclusive` option for performance with bind mounts. - Describing the gofer dentry cache and how to configure its size via the `--dcache` flag or `dcache` mount option. PiperOrigin-RevId: 860545363
1 parent 7381ccc commit 0e609bb

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed

g3doc/user_guide/filesystem.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,100 @@ Docker configuration (`/etc/docker/daemon.json`) and restart the Docker daemon:
121121
}
122122
```
123123

124+
## Exclusive bind mounts
125+
126+
By default, all bind mounts are served by the gofer in "shared" mode
127+
(`--file-access-mounts=shared`). In this mode, the gofer continuously
128+
revalidates its dentry tree against the host filesystem. This is necessary
129+
because the sandbox cannot assume exclusive access to the bind mounts, as they
130+
may be observed or mutated by other processes on the host.
131+
132+
If you are confident that **all** bind mounts are exclusive to the sandbox
133+
(i.e., no external process will modify the files), you can set
134+
`--file-access-mounts=exclusive`. This enables aggressive caching in the
135+
sandbox, significantly improving performance by reducing revalidation overhead.
136+
137+
Good candidates for this setting include:
138+
139+
* **Static Data**: Directories containing immutable files (e.g. ML models,
140+
datasets) that are not modified on the host.
141+
* **Dedicated Storage**: Directories created specifically for the container
142+
that are not accessed by any other host process.
143+
144+
Note that this setting applies to **all** bind mounts within the sandbox. It
145+
does not apply to the root filesystem, which is configured via the
146+
`--file-access` flag (see [Shared Root Filesystem](#shared-root-filesystem)).
147+
148+
To enable exclusive access for bind mounts, add the following `runtimeArgs` to
149+
your Docker configuration (`/etc/docker/daemon.json`) and restart the Docker
150+
daemon:
151+
152+
```json
153+
{
154+
"runtimes": {
155+
"runsc": {
156+
"path": "/usr/local/bin/runsc",
157+
"runtimeArgs": [
158+
"--file-access-mounts=exclusive"
159+
]
160+
}
161+
}
162+
}
163+
```
164+
165+
> **Warning**: Enabling exclusive mode on mounts that are modified externally
166+
> can lead to data corruption or undefined behavior, as the sandbox may work
167+
> with stale data.
168+
169+
## Dentry Cache
170+
171+
The gofer client maintains a tree of dentries (directory entries) that mirrors
172+
the filesystem tree to accelerate path resolution. The **dentry cache** is a
173+
subset of this tree that holds dentries with zero references. These correspond
174+
to unreferenced leaf nodes in the filesystem tree (since every dentry holds a
175+
reference to its parent, the internal nodes always have a reference).
176+
177+
The cache is an LRU cache that retains these unused dentries to prevent them
178+
from being destroyed immediately. If a future filesystem request accesses the
179+
same path, we can reuse the existing dentry from the cache instead of recreating
180+
it, which improves performance.
181+
182+
By default, every gofer mount has its own dentry cache with a size of 1000. This
183+
can be configured in two ways:
184+
185+
- **Global Flag**: Passing the `--dcache` flag to `runsc` creates a single,
186+
global dentry cache of the specified size that is shared across all gofer
187+
mounts. You can specify it in `runtimeArgs`:
188+
189+
```json
190+
{
191+
"runtimes": {
192+
"runsc": {
193+
"path": "/usr/local/bin/runsc",
194+
"runtimeArgs": [
195+
"--dcache=5000"
196+
]
197+
}
198+
}
199+
}
200+
```
201+
202+
- **Mount Option**: The `dcache` mount option can be used to set the cache
203+
size on a per-mount basis:
204+
205+
```json
206+
"mounts": [
207+
{
208+
"type": "bind",
209+
"source": "/host/path",
210+
"destination": "/container/path",
211+
"options": [
212+
"dcache=500"
213+
]
214+
}
215+
]
216+
```
217+
124218
## EROFS Support
125219

126220
gVisor supports EROFS (Enhanced Read-Only File System) rootfs and mounts. It is

0 commit comments

Comments
 (0)