summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/usage
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2020-05-06 17:35:47 +0000
committergVisor bot <gvisor-bot@google.com>2020-05-06 17:35:47 +0000
commit9c0db04fe746df6260e9da0a0cd60a91f6c6887d (patch)
treee71152a5926e32f151e641f2fd4d71504bef7d8f /pkg/sentry/usage
parent568ef4b075849f04e329e964918dbbcaeb675602 (diff)
parent591ff0e424e3b30eb143bce06618cb8656784b90 (diff)
Merge release-20200422.0-34-g591ff0e (automated)
Diffstat (limited to 'pkg/sentry/usage')
-rw-r--r--pkg/sentry/usage/memory.go24
1 files changed, 16 insertions, 8 deletions
diff --git a/pkg/sentry/usage/memory.go b/pkg/sentry/usage/memory.go
index 4320ad17f..ab1d140d2 100644
--- a/pkg/sentry/usage/memory.go
+++ b/pkg/sentry/usage/memory.go
@@ -252,18 +252,23 @@ func (m *MemoryLocked) Copy() (MemoryStats, uint64) {
return ms, m.totalLocked()
}
-// MinimumTotalMemoryBytes is the minimum reported total system memory.
-//
-// This can be configured through options provided to the Sentry at start.
-// This number is purely synthetic. This is only set before the application
-// starts executing, and must not be modified.
-var MinimumTotalMemoryBytes uint64 = 2 << 30 // 2 GB
+// These options control how much total memory the is reported to the application.
+// They may only be set before the application starts executing, and must not
+// be modified.
+var (
+ // MinimumTotalMemoryBytes is the minimum reported total system memory.
+ MinimumTotalMemoryBytes uint64 = 2 << 30 // 2 GB
+
+ // MaximumTotalMemoryBytes is the maximum reported total system memory.
+ // The 0 value indicates no maximum.
+ MaximumTotalMemoryBytes uint64
+)
// TotalMemory returns the "total usable memory" available.
//
// This number doesn't really have a true value so it's based on the following
-// inputs and further bounded to be above some minimum guaranteed value (2GB),
-// additionally ensuring that total memory reported is always less than used.
+// inputs and further bounded to be above the MinumumTotalMemoryBytes and below
+// MaximumTotalMemoryBytes.
//
// memSize should be the platform.Memory size reported by platform.Memory.TotalSize()
// used is the total memory reported by MemoryLocked.Total()
@@ -279,5 +284,8 @@ func TotalMemory(memSize, used uint64) uint64 {
memSize = uint64(1) << (uint(msb) + 1)
}
}
+ if MaximumTotalMemoryBytes > 0 && memSize > MaximumTotalMemoryBytes {
+ memSize = MaximumTotalMemoryBytes
+ }
return memSize
}