Skip to content

Commit c956850

Browse files
yeya24allencloud
authored andcommitted
fix invalid memory limit
Signed-off-by: yeya24 <[email protected]>
1 parent c3e6408 commit c956850

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

daemon/config/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ type Config struct {
134134

135135
// EnableBuilder enable builder functionality
136136
EnableBuilder bool `json:"enable-builder,omitempty"`
137+
138+
// MachineMemory is the memory limit for a host.
139+
MachineMemory uint64 `json:"-"`
137140
}
138141

139142
// GetCgroupDriver gets cgroup driver used in runc.

daemon/mgr/container_stats.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ func (mgr *ContainerManager) StreamStats(ctx context.Context, name string, confi
3838
wrapContainerStats := func(metricMeta *containerdtypes.Metric, metric *cgroups.Metrics) (*types.ContainerStats, error) {
3939
stats := toContainerStats(c, metricMeta, metric)
4040

41+
// if the container does not set memory limit, use the machineMemory
42+
if stats.MemoryStats.Limit > mgr.Config.MachineMemory && mgr.Config.MachineMemory > 0 {
43+
stats.MemoryStats.Limit = mgr.Config.MachineMemory
44+
}
45+
4146
systemCPUUsage, err := getSystemCPUUsage()
4247
if err != nil {
4348
return nil, err

main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/alibaba/pouch/lxcfs"
1919
"github.com/alibaba/pouch/pkg/debug"
2020
"github.com/alibaba/pouch/pkg/kernel"
21+
"github.com/alibaba/pouch/pkg/system"
2122
"github.com/alibaba/pouch/pkg/utils"
2223
"github.com/alibaba/pouch/storage/quota"
2324
"github.com/alibaba/pouch/version"
@@ -227,6 +228,10 @@ func runDaemon(cmd *cobra.Command) error {
227228
return err
228229
}
229230

231+
if cfg.MachineMemory, err = system.GetTotalMem(); err != nil {
232+
logrus.Warnf("failed to get system mem: %v", err)
233+
}
234+
230235
// initialize signal and handle method.
231236
var (
232237
errCh = make(chan error, 1)

0 commit comments

Comments
 (0)