From fa56fbf44e440bbbca710ef1b7cc1d54f862c20e Mon Sep 17 00:00:00 2001 From: Fabricio Voznika Date: Mon, 18 Oct 2021 15:06:45 -0700 Subject: Report ramdiskfs usage correctly Updates #1035 PiperOrigin-RevId: 404072231 --- pkg/sentry/fsimpl/tmpfs/regular_file.go | 2 +- pkg/sentry/fsimpl/tmpfs/tmpfs.go | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/pkg/sentry/fsimpl/tmpfs/regular_file.go b/pkg/sentry/fsimpl/tmpfs/regular_file.go index 0f2ac6144..453e1aa61 100644 --- a/pkg/sentry/fsimpl/tmpfs/regular_file.go +++ b/pkg/sentry/fsimpl/tmpfs/regular_file.go @@ -95,7 +95,7 @@ type regularFile struct { func (fs *filesystem) newRegularFile(kuid auth.KUID, kgid auth.KGID, mode linux.FileMode, parentDir *directory) *inode { file := ®ularFile{ memFile: fs.mfp.MemoryFile(), - memoryUsageKind: usage.Tmpfs, + memoryUsageKind: fs.usage, seals: linux.F_SEAL_SEAL, } file.inode.init(file, fs, kuid, kgid, linux.S_IFREG|mode, parentDir) diff --git a/pkg/sentry/fsimpl/tmpfs/tmpfs.go b/pkg/sentry/fsimpl/tmpfs/tmpfs.go index feafb06e4..f84165aba 100644 --- a/pkg/sentry/fsimpl/tmpfs/tmpfs.go +++ b/pkg/sentry/fsimpl/tmpfs/tmpfs.go @@ -41,6 +41,7 @@ import ( "gvisor.dev/gvisor/pkg/sentry/kernel/auth" "gvisor.dev/gvisor/pkg/sentry/kernel/time" "gvisor.dev/gvisor/pkg/sentry/pgalloc" + "gvisor.dev/gvisor/pkg/sentry/usage" "gvisor.dev/gvisor/pkg/sentry/vfs" "gvisor.dev/gvisor/pkg/sentry/vfs/memxattr" "gvisor.dev/gvisor/pkg/sync" @@ -74,6 +75,10 @@ type filesystem struct { // filesystem. Immutable. mopts string + // usage is the memory accounting category under which pages backing + // files in this filesystem are accounted. + usage usage.MemoryKind + // mu serializes changes to the Dentry tree. mu sync.RWMutex `state:"nosave"` @@ -106,6 +111,10 @@ type FilesystemOpts struct { // tmpfs filesystem. This allows tmpfs to "impersonate" other // filesystems, like ramdiskfs and cgroupfs. FilesystemType vfs.FilesystemType + + // Usage is the memory accounting category under which pages backing files in + // the filesystem are accounted. + Usage *usage.MemoryKind } // GetFilesystem implements vfs.FilesystemType.GetFilesystem. @@ -184,11 +193,16 @@ func (fstype FilesystemType) GetFilesystem(ctx context.Context, vfsObj *vfs.Virt return nil, nil, err } clock := time.RealtimeClockFromContext(ctx) + memUsage := usage.Tmpfs + if tmpfsOpts.Usage != nil { + memUsage = *tmpfsOpts.Usage + } fs := filesystem{ mfp: mfp, clock: clock, devMinor: devMinor, mopts: opts.Data, + usage: memUsage, } fs.vfsfs.Init(vfsObj, newFSType, &fs) -- cgit v1.2.3