Skip to content

Commit

Permalink
cluster/check: apply thp fix only if thp found (#1458)
Browse files Browse the repository at this point in the history
  • Loading branch information
9547 authored Jun 29, 2021
1 parent ba53f34 commit f9a06e5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/cluster/manager/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ func fixFailedChecks(host string, res *operator.CheckResult, t *task.Builder) (s
msg = fmt.Sprintf("will try to %s, reboot might be needed", color.HiBlueString("disable SELinux"))
case operator.CheckNameTHP:
t.Shell(host,
"echo never > /sys/kernel/mm/transparent_hugepage/enabled && echo never > /sys/kernel/mm/transparent_hugepage/defrag",
fmt.Sprintf(`if [ -d %[1]s ]; then echo never > %[1]s/defrag && echo never > %[1]s/enabled; fi`, "/sys/kernel/mm/transparent_hugepage"),
"",
true)
msg = fmt.Sprintf("will try to %s, please check again after reboot", color.HiBlueString("disable THP"))
Expand Down
6 changes: 3 additions & 3 deletions pkg/cluster/operation/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -747,8 +747,8 @@ func CheckTHP(ctx context.Context, e ctxt.Executor) *CheckResult {
}

m := module.NewShellModule(module.ShellModuleConfig{
Command: "cat /sys/kernel/mm/transparent_hugepage/{enabled,defrag}",
Sudo: false,
Command: fmt.Sprintf(`if [ -d %[1]s ]; then cat %[1]s/{enabled,defrag}; fi`, "/sys/kernel/mm/transparent_hugepage"),
Sudo: true,
})
stdout, stderr, err := m.Execute(ctx, e)
if err != nil {
Expand All @@ -757,7 +757,7 @@ func CheckTHP(ctx context.Context, e ctxt.Executor) *CheckResult {
}

for _, line := range strings.Split(strings.Trim(string(stdout), "\n"), "\n") {
if !strings.Contains(line, "[never]") {
if len(line) > 0 && !strings.Contains(line, "[never]") {
result.Err = fmt.Errorf("THP is enabled, please disable it for best performance")
return result
}
Expand Down

0 comments on commit f9a06e5

Please sign in to comment.