aboutsummaryrefslogtreecommitdiff
path: root/pkg/api
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2022-09-15 12:12:48 +0200
committerGitHub <noreply@github.com>2022-09-15 12:12:48 +0200
commit2a8df49c2a65831fa2c253afa1ad2b5e1d618b09 (patch)
tree1ed9e8e76d93f4a59cb42c1755e8b2934ea5b509 /pkg/api
parentc8bd81cacacb84aa2b080e7b21991e97d5348b0a (diff)
parent60ef4ad1c873e99825dd08c9300cffb82f3b7aee (diff)
downloadpodman-2a8df49c2a65831fa2c253afa1ad2b5e1d618b09.tar.gz
podman-2a8df49c2a65831fa2c253afa1ad2b5e1d618b09.tar.bz2
podman-2a8df49c2a65831fa2c253afa1ad2b5e1d618b09.zip
Merge pull request #15811 from giuseppe/fix-memory-stats-api
stats: cap memory limit to the available memory
Diffstat (limited to 'pkg/api')
-rw-r--r--pkg/api/handlers/compat/containers_stats.go13
1 files changed, 12 insertions, 1 deletions
diff --git a/pkg/api/handlers/compat/containers_stats.go b/pkg/api/handlers/compat/containers_stats.go
index c115b4181..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{
@@ -177,7 +188,7 @@ streamLabel: // A label to flatten the scope
PreCPUStats: preCPUStats,
MemoryStats: docker.MemoryStats{
Usage: cgroupStat.MemoryStats.Usage.Usage,
- MaxUsage: cgroupStat.MemoryStats.Usage.Limit,
+ MaxUsage: cgroupStat.MemoryStats.Usage.MaxUsage,
Stats: nil,
Failcnt: 0,
Limit: memoryLimit,