This commit is contained in:
lobshunter 2024-06-13 19:26:30 +00:00 committed by GitHub
commit aadf79c896
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 2 deletions

View File

@ -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
}

View File

@ -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{}

View File

@ -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