summaryrefslogtreecommitdiff
path: root/pkg/api/handlers/compat/containers_stats.go
diff options
context:
space:
mode:
authorGiuseppe Scrivano <gscrivan@redhat.com>2022-09-15 00:52:30 +0200
committerGiuseppe Scrivano <gscrivan@redhat.com>2022-09-15 09:00:03 +0200
commit60ef4ad1c873e99825dd08c9300cffb82f3b7aee (patch)
tree21a1849d3a9194098fc0a29f751143e62413d72d /pkg/api/handlers/compat/containers_stats.go
parentcf2118eab3b736feb8018bcc9f4cdb548b7ab70a (diff)
downloadpodman-60ef4ad1c873e99825dd08c9300cffb82f3b7aee.tar.gz
podman-60ef4ad1c873e99825dd08c9300cffb82f3b7aee.tar.bz2
podman-60ef4ad1c873e99825dd08c9300cffb82f3b7aee.zip
stats: cap memory limit to the available memory
Docker compatibility: cap the memory limit reported by the cgroup to the maximum available memory. Closes: https://github.com/containers/podman/issues/15765 Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Diffstat (limited to 'pkg/api/handlers/compat/containers_stats.go')
-rw-r--r--pkg/api/handlers/compat/containers_stats.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/pkg/api/handlers/compat/containers_stats.go b/pkg/api/handlers/compat/containers_stats.go
index 16311ef1e..519661675 100644
--- a/pkg/api/handlers/compat/containers_stats.go
+++ b/pkg/api/handlers/compat/containers_stats.go
@@ -11,6 +11,7 @@ import (
"github.com/containers/podman/v4/libpod/define"
"github.com/containers/podman/v4/pkg/api/handlers/utils"
api "github.com/containers/podman/v4/pkg/api/types"
+ "github.com/containers/storage/pkg/system"
docker "github.com/docker/docker/api/types"
"github.com/gorilla/schema"
runccgroups "github.com/opencontainers/runc/libcontainer/cgroups"
@@ -139,6 +140,16 @@ streamLabel: // A label to flatten the scope
memoryLimit = uint64(*cfg.Spec.Linux.Resources.Memory.Limit)
}
+ memInfo, err := system.ReadMemInfo()
+ if err != nil {
+ logrus.Errorf("Unable to get cgroup stats: %v", err)
+ return
+ }
+ // cap the memory limit to the available memory.
+ if memInfo.MemTotal > 0 && memoryLimit > uint64(memInfo.MemTotal) {
+ memoryLimit = uint64(memInfo.MemTotal)
+ }
+
systemUsage, _ := cgroups.GetSystemCPUUsage()
s := StatsJSON{
Stats: Stats{