Skip to content

Commit

Permalink
fix invalid memory limit
Browse files Browse the repository at this point in the history
Signed-off-by: yeya24 <yb532204897@gmail.com>
  • Loading branch information
yeya24 committed Jun 5, 2019
1 parent c3e6408 commit 854f0e0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions daemon/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ type Config struct {

// EnableBuilder enable builder functionality
EnableBuilder bool `json:"enable-builder,omitempty"`

// MachineMemory is the memory limit for a host.
MachineMemory uint64 `json:"-"`
}

// GetCgroupDriver gets cgroup driver used in runc.
Expand Down
5 changes: 5 additions & 0 deletions daemon/mgr/container_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ func (mgr *ContainerManager) StreamStats(ctx context.Context, name string, confi
wrapContainerStats := func(metricMeta *containerdtypes.Metric, metric *cgroups.Metrics) (*types.ContainerStats, error) {
stats := toContainerStats(c, metricMeta, metric)

// if the container does not set memory limit, use the machineMemory
if stats.MemoryStats.Limit > mgr.Config.MachineMemory && mgr.Config.MachineMemory > 0 {
stats.MemoryStats.Limit = mgr.Config.MachineMemory
}

systemCPUUsage, err := getSystemCPUUsage()
if err != nil {
return nil, err
Expand Down
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/alibaba/pouch/lxcfs"
"github.com/alibaba/pouch/pkg/debug"
"github.com/alibaba/pouch/pkg/kernel"
"github.com/alibaba/pouch/pkg/system"
"github.com/alibaba/pouch/pkg/utils"
"github.com/alibaba/pouch/storage/quota"
"github.com/alibaba/pouch/version"
Expand Down Expand Up @@ -227,6 +228,10 @@ func runDaemon(cmd *cobra.Command) error {
return err
}

if cfg.MachineMemory, err = system.GetTotalMem(); err != nil {
logrus.Warnf("failed to get system mem: %v", err)
}

// initialize signal and handle method.
var (
errCh = make(chan error, 1)
Expand Down

0 comments on commit 854f0e0

Please sign in to comment.