Skip to content

Commit

Permalink
bugfix: fix stopping memory load without mode flag
Browse files Browse the repository at this point in the history
Signed-off-by: 穹谷 <changjun.xcj@alibaba-inc.com>
  • Loading branch information
xcaspar committed Sep 17, 2020
1 parent 6260f32 commit 327f6e2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
6 changes: 4 additions & 2 deletions exec/bin/burnmem/burnmem.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ import (
"github.com/chaosblade-io/chaosblade-exec-os/exec/bin"
)

const PAGE_COUNTER_MAX uint64 = 9223372036854770000
const PageCounterMax uint64 = 9223372036854770000


// 128K
type Block [32 * 1024]int32
Expand Down Expand Up @@ -200,6 +201,7 @@ func runBurnMem(ctx context.Context, memPercent, memReserve, memRate int, burnMe

func stopBurnMem() (success bool, errs string) {
ctx := context.WithValue(context.Background(), channel.ProcessKey, "nohup")
ctx = context.WithValue(ctx, channel.ExcludeProcessKey, "stop")
pids, _ := cl.GetPidsByProcessName(burnMemBin, ctx)
var response *spec.Response
if pids != nil && len(pids) != 0 {
Expand Down Expand Up @@ -233,7 +235,7 @@ func calculateMemSize(percent, reserve int) (int64, int64, error) {
if err != nil {
logrus.Infof("get memory stats by cgroup failed, used proc memory, %v", err)
}
if memoryStat == nil || memoryStat.Usage.Limit >= PAGE_COUNTER_MAX {
if memoryStat == nil || memoryStat.Usage.Limit >= PageCounterMax {
//no limit
virtualMemory, err := mem.VirtualMemory()
if err != nil {
Expand Down
13 changes: 8 additions & 5 deletions exec/mem.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ func NewMemCommandModelSpec() spec.ExpModelCommandSpec {
Required: false,
},
&spec.ExpFlag{
Name: "include-buffer-cache",
Desc: "Ram mode mem-percent is include buffer/cache",
NoArgs: true,
Name: "include-buffer-cache",
Desc: "Ram mode mem-percent is include buffer/cache",
NoArgs: true,
},
},
},
Expand Down Expand Up @@ -198,8 +198,11 @@ func (ce *memExecutor) start(ctx context.Context, memPercent, memReserve, memRat

// stop burn mem
func (ce *memExecutor) stop(ctx context.Context, burnMemMode string) *spec.Response {
return ce.channel.Run(ctx, path.Join(ce.channel.GetScriptPath(), burnMemBin),
fmt.Sprintf("--stop --mode %s --debug=%t", burnMemMode, util.Debug))
args := fmt.Sprintf("--stop --debug=%t", util.Debug)
if burnMemMode != "" {
args = fmt.Sprintf("%s --mode %s", args, burnMemMode)
}
return ce.channel.Run(ctx, path.Join(ce.channel.GetScriptPath(), burnMemBin), args)
}

func checkMemoryExpEnv() error {
Expand Down

0 comments on commit 327f6e2

Please sign in to comment.