diff --git a/pkg/cluster/manager/check.go b/pkg/cluster/manager/check.go index 6121d7db3b..fbbc670122 100644 --- a/pkg/cluster/manager/check.go +++ b/pkg/cluster/manager/check.go @@ -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")) diff --git a/pkg/cluster/operation/check.go b/pkg/cluster/operation/check.go index 001c336c32..09e357af63 100644 --- a/pkg/cluster/operation/check.go +++ b/pkg/cluster/operation/check.go @@ -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 { @@ -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 }