Skip to content

Commit

Permalink
Support THP in tiup cluster check (#964)
Browse files Browse the repository at this point in the history
* Support THP in tiup cluster check

* fix typo

* update err msg

* Update auto fix prompt message

Co-authored-by: SIGSEGV <[email protected]>
Co-authored-by: Ti Prow Robot <[email protected]>
  • Loading branch information
3 people authored Dec 9, 2020
1 parent a9370cd commit 250c47b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
5 changes: 5 additions & 0 deletions components/cluster/command/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,11 @@ func fixFailedChecks(ctx *task.Context, host string, res *operator.CheckResult,
),
true)
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",
true)
msg = fmt.Sprintf("will try to %s, please check again after reboot", color.HiBlueString("disable THP"))
default:
msg = fmt.Sprintf("%s, auto fixing not supported", res)
}
Expand Down
28 changes: 28 additions & 0 deletions pkg/cluster/operation/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ var (
CheckNameSELinux = "selinux"
CheckNameCommand = "command"
CheckNameFio = "fio"
CheckNameTHP = "thp"
)

// CheckResult is the result of a check
Expand Down Expand Up @@ -651,3 +652,30 @@ func CheckFIOResult(rr, rw, lat []byte) []*CheckResult {

return results
}

// CheckTHP checks THP in /sys/kernel/mm/transparent_hugepage/{enabled,defrag}
func CheckTHP(e executor.Executor) *CheckResult {
result := &CheckResult{
Name: CheckNameTHP,
}

m := module.NewShellModule(module.ShellModuleConfig{
Command: "cat /sys/kernel/mm/transparent_hugepage/{enabled,defrag}",
Sudo: false,
})
stdout, stderr, err := m.Execute(e)
if err != nil {
result.Err = fmt.Errorf("%w %s", err, stderr)
return result
}

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

result.Msg = "THP is disabled"
return result
}
1 change: 1 addition & 0 deletions pkg/cluster/task/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func (c *CheckSys) Execute(ctx *Context) error {
results = append(
results,
operator.CheckSELinux(e),
operator.CheckTHP(e),
)
ctx.SetCheckResults(c.host, results)
case CheckTypePort:
Expand Down
1 change: 1 addition & 0 deletions tests/tiup-cluster/script/cmd_subtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function cmd_subtest() {
echo $check_result | grep "os-version"
echo $check_result | grep "selinux"
echo $check_result | grep "service"
echo $check_result | grep "thp"

# This should fail because there is no such user: tidb
! tiup-cluster $client --yes deploy $name $version $topo -i ~/.ssh/id_rsa --skip-create-user
Expand Down

0 comments on commit 250c47b

Please sign in to comment.