summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/fsimpl/cgroupfs/memory.go
diff options
context:
space:
mode:
authorRahat Mahmood <rahat@google.com>2021-04-05 16:00:17 -0700
committergVisor bot <gvisor-bot@google.com>2021-04-05 16:06:11 -0700
commit88f198c2a9da1bac9726db18af4e7615aaa65476 (patch)
treeb3be2c4c001ff6899197c6e380178bf4c1dd9726 /pkg/sentry/fsimpl/cgroupfs/memory.go
parent2d9095c7a669ad2632f12de8d0918f8bf48b499e (diff)
Allow default control values to be set for cgroupfs.
PiperOrigin-RevId: 366891806
Diffstat (limited to 'pkg/sentry/fsimpl/cgroupfs/memory.go')
-rw-r--r--pkg/sentry/fsimpl/cgroupfs/memory.go18
1 files changed, 16 insertions, 2 deletions
diff --git a/pkg/sentry/fsimpl/cgroupfs/memory.go b/pkg/sentry/fsimpl/cgroupfs/memory.go
index eaf40a753..485c98376 100644
--- a/pkg/sentry/fsimpl/cgroupfs/memory.go
+++ b/pkg/sentry/fsimpl/cgroupfs/memory.go
@@ -17,7 +17,9 @@ package cgroupfs
import (
"bytes"
"fmt"
+ "math"
+ "gvisor.dev/gvisor/pkg/abi/linux"
"gvisor.dev/gvisor/pkg/context"
"gvisor.dev/gvisor/pkg/sentry/fsimpl/kernfs"
"gvisor.dev/gvisor/pkg/sentry/kernel"
@@ -28,12 +30,23 @@ import (
// +stateify savable
type memoryController struct {
controllerCommon
+
+ limitBytes int64
}
var _ controller = (*memoryController)(nil)
-func newMemoryController(fs *filesystem) *memoryController {
- c := &memoryController{}
+func newMemoryController(fs *filesystem, defaults map[string]int64) *memoryController {
+ c := &memoryController{
+ // Linux sets this to (PAGE_COUNTER_MAX * PAGE_SIZE) by default, which
+ // is ~ 2**63 on a 64-bit system. So essentially, inifinity. The exact
+ // value isn't very important.
+ limitBytes: math.MaxInt64,
+ }
+ if val, ok := defaults["memory.limit_in_bytes"]; ok {
+ c.limitBytes = val
+ delete(defaults, "memory.limit_in_bytes")
+ }
c.controllerCommon.init(controllerMemory, fs)
return c
}
@@ -41,6 +54,7 @@ func newMemoryController(fs *filesystem) *memoryController {
// AddControlFiles implements controller.AddControlFiles.
func (c *memoryController) AddControlFiles(ctx context.Context, creds *auth.Credentials, _ *cgroupInode, contents map[string]kernfs.Inode) {
contents["memory.usage_in_bytes"] = c.fs.newControllerFile(ctx, creds, &memoryUsageInBytesData{})
+ contents["memory.limit_in_bytes"] = c.fs.newStaticControllerFile(ctx, creds, linux.FileMode(0644), fmt.Sprintf("%d\n", c.limitBytes))
}
// +stateify savable