Allow dcache=0 in runsc to completely disable dentry caching in gofer.

PiperOrigin-RevId: 472621428
This commit is contained in:
Ayush Ranjan
2022-09-06 20:19:57 -07:00
committed by gVisor bot
parent ad7b1121d4
commit 658ee7f7cf
2 changed files with 12 additions and 9 deletions
+11 -8
View File
@@ -113,13 +113,18 @@ type dentryCache struct {
// SetDentryCacheSize sets the size of the global gofer dentry cache.
func SetDentryCacheSize(size int) {
globalDentryCache.mu.Lock()
defer globalDentryCache.mu.Unlock()
globalDentryCache.maxCachedDentries = uint64(size)
if size < 0 {
return
}
if globalDentryCache != nil {
log.Warningf("Global dentry cache has already been initialized. Ignoring subsequent attempt.")
return
}
globalDentryCache = &dentryCache{maxCachedDentries: uint64(size)}
}
// globalDentryCache is a global cache of dentries across all gofers.
var globalDentryCache dentryCache
var globalDentryCache *dentryCache
// Valid values for "trans" mount option.
const transportModeFD = "fd"
@@ -494,13 +499,11 @@ func (fstype FilesystemType) GetFilesystem(ctx context.Context, vfsObj *vfs.Virt
}
// Did the user configure a global dentry cache?
globalDentryCache.mu.Lock()
if globalDentryCache.maxCachedDentries >= 1 {
fs.dentryCache = &globalDentryCache
if globalDentryCache != nil {
fs.dentryCache = globalDentryCache
} else {
fs.dentryCache = &dentryCache{maxCachedDentries: defaultMaxCachedDentries}
}
globalDentryCache.mu.Unlock()
fs.vfsfs.Init(vfsObj, &fstype, fs)
+1 -1
View File
@@ -84,7 +84,7 @@ func RegisterFlags(flagSet *flag.FlagSet) {
flagSet.Bool("cgroupfs", false, "Automatically mount cgroupfs.")
flagSet.Bool("ignore-cgroups", false, "don't configure cgroups.")
flagSet.Int("fdlimit", -1, "Specifies a limit on the number of host file descriptors that can be open. Applies separately to the sentry and gofer. Note: each file in the sandbox holds more than one host FD open.")
flagSet.Int("dcache", 0, "Set the global gofer direct cache size. This acts as a coarse-grained control on the number of host FDs simultaneously open by the sentry. If zero, per-mount caches are used.")
flagSet.Int("dcache", -1, "Set the global dentry cache size. This acts as a coarse-grained control on the number of host FDs simultaneously open by the sentry. If negative, per-mount caches are used.")
// Flags that control sandbox runtime behavior: network related.
flagSet.Var(networkTypePtr(NetworkSandbox), "network", "specifies which network to use: sandbox (default), host, none. Using network inside the sandbox is more secure because it's isolated from the host network.")