diff --git a/cmd/attack/stress.go b/cmd/attack/stress.go index c8ad3341..e0e84db6 100644 --- a/cmd/attack/stress.go +++ b/cmd/attack/stress.go @@ -79,6 +79,7 @@ func NewStressMemCommand(dep fx.Option, options *core.StressCommand) *cobra.Comm cmd.Flags().StringVarP(&options.Size, "size", "s", "", "Size specifies N bytes consumed per vm worker, default is the total available memory. One can specify the size as % of total available memory or in units of B, KB/KiB, MB/MiB, GB/GiB, TB/TiB..") cmd.Flags().StringSliceVarP(&options.Options, "options", "o", []string{}, "extend stress-ng options.") + cmd.Flags().IntVar(&options.OOMScoreAdj, "oom-score-adj", 0, "OOMScoreAdj specifies the oom_score_adj value for the memory stress process. The default is 0.") return cmd } diff --git a/pkg/core/stress.go b/pkg/core/stress.go index d0ea6c3d..31eaebbb 100644 --- a/pkg/core/stress.go +++ b/pkg/core/stress.go @@ -32,6 +32,7 @@ type StressCommand struct { Size string `json:"size,omitempty"` Options []string `json:"options,omitempty"` StressngPid int32 `json:"stress-ng-pid,omitempty"` + OOMScoreAdj int `json:"oom-score-adj,omitempty"` } var _ AttackConfig = &StressCommand{} diff --git a/pkg/server/chaosd/stress.go b/pkg/server/chaosd/stress.go index 6c119773..88377105 100644 --- a/pkg/server/chaosd/stress.go +++ b/pkg/server/chaosd/stress.go @@ -62,8 +62,9 @@ func (stressAttack) Attack(options core.AttackConfig, _ Environment) (err error) Stressor: v1alpha1.Stressor{ Workers: attack.Workers, }, - Size: attack.Size, - Options: attack.Options, + Size: attack.Size, + Options: attack.Options, + OOMScoreAdj: attack.OOMScoreAdj, } } @@ -88,6 +89,7 @@ func (stressAttack) Attack(options core.AttackConfig, _ Environment) (err error) log.Info("stressors normalize", zap.String("arguments", stressorsStr)) cmd := bpm.DefaultProcessBuilder(stressorTool, strings.Fields(stressorsStr)...). + SetOOMScoreAdj(attack.OOMScoreAdj). Build(context.Background()) // Build will set SysProcAttr.Pdeathsig = syscall.SIGTERM, and so stress-ng will exit while chaosd exit