diff options
author | gVisor bot <gvisor-bot@google.com> | 2021-09-09 18:11:10 +0000 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2021-09-09 18:11:10 +0000 |
commit | 905089a76d1c93f8bcf082a1c4a4eb58fafe9ea4 (patch) | |
tree | d6dd82c6e7356e1a2cd385f437ea68494cf2faa6 /pkg/sentry/fsimpl/cgroupfs | |
parent | bd6388c4b8a3863df70ba2f43257ade15d905af0 (diff) | |
parent | 5e9c3a0b934f0dd7513e21372b3fd8593b87525b (diff) |
Merge release-20210830.0-27-g5e9c3a0b9 (automated)
Diffstat (limited to 'pkg/sentry/fsimpl/cgroupfs')
-rw-r--r-- | pkg/sentry/fsimpl/cgroupfs/cgroupfs_state_autogen.go | 6 | ||||
-rw-r--r-- | pkg/sentry/fsimpl/cgroupfs/memory.go | 30 |
2 files changed, 28 insertions, 8 deletions
diff --git a/pkg/sentry/fsimpl/cgroupfs/cgroupfs_state_autogen.go b/pkg/sentry/fsimpl/cgroupfs/cgroupfs_state_autogen.go index aa40bb193..d390050d7 100644 --- a/pkg/sentry/fsimpl/cgroupfs/cgroupfs_state_autogen.go +++ b/pkg/sentry/fsimpl/cgroupfs/cgroupfs_state_autogen.go @@ -627,6 +627,8 @@ func (c *memoryController) StateFields() []string { return []string{ "controllerCommon", "limitBytes", + "softLimitBytes", + "moveChargeAtImmigrate", } } @@ -637,6 +639,8 @@ func (c *memoryController) StateSave(stateSinkObject state.Sink) { c.beforeSave() stateSinkObject.Save(0, &c.controllerCommon) stateSinkObject.Save(1, &c.limitBytes) + stateSinkObject.Save(2, &c.softLimitBytes) + stateSinkObject.Save(3, &c.moveChargeAtImmigrate) } func (c *memoryController) afterLoad() {} @@ -645,6 +649,8 @@ func (c *memoryController) afterLoad() {} func (c *memoryController) StateLoad(stateSourceObject state.Source) { stateSourceObject.Load(0, &c.controllerCommon) stateSourceObject.Load(1, &c.limitBytes) + stateSourceObject.Load(2, &c.softLimitBytes) + stateSourceObject.Load(3, &c.moveChargeAtImmigrate) } func (d *memoryUsageInBytesData) StateTypeName() string { diff --git a/pkg/sentry/fsimpl/cgroupfs/memory.go b/pkg/sentry/fsimpl/cgroupfs/memory.go index 485c98376..d880c9bc4 100644 --- a/pkg/sentry/fsimpl/cgroupfs/memory.go +++ b/pkg/sentry/fsimpl/cgroupfs/memory.go @@ -31,22 +31,34 @@ import ( type memoryController struct { controllerCommon - limitBytes int64 + limitBytes int64 + softLimitBytes int64 + moveChargeAtImmigrate int64 } var _ controller = (*memoryController)(nil) 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, + // Linux sets these limits 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, + softLimitBytes: math.MaxInt64, } - if val, ok := defaults["memory.limit_in_bytes"]; ok { - c.limitBytes = val - delete(defaults, "memory.limit_in_bytes") + + consumeDefault := func(name string, valPtr *int64) { + if val, ok := defaults[name]; ok { + *valPtr = val + delete(defaults, name) + } } + + consumeDefault("memory.limit_in_bytes", &c.limitBytes) + consumeDefault("memory.soft_limit_in_bytes", &c.softLimitBytes) + consumeDefault("memory.move_charge_at_immigrate", &c.moveChargeAtImmigrate) + c.controllerCommon.init(controllerMemory, fs) return c } @@ -55,6 +67,8 @@ func newMemoryController(fs *filesystem, defaults map[string]int64) *memoryContr 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)) + contents["memory.soft_limit_in_bytes"] = c.fs.newStaticControllerFile(ctx, creds, linux.FileMode(0644), fmt.Sprintf("%d\n", c.softLimitBytes)) + contents["memory.move_charge_at_immigrate"] = c.fs.newStaticControllerFile(ctx, creds, linux.FileMode(0644), fmt.Sprintf("%d\n", c.moveChargeAtImmigrate)) } // +stateify savable |