Skip to content

Commit

Permalink
Capture transparent hugepages config in health report
Browse files Browse the repository at this point in the history
Add a new node `thp-config` under `sys -> config` and inside it add
values from following config files:

/sys/kernel/mm/transparent_hugepage/enabled
/sys/kernel/mm/transparent_hugepage/defrag
/sys/kernel/mm/transparent_hugepage/khugepaged/max_ptes_none

ref: https://tip.golang.org/doc/gc-guide#Linux_transparent_huge_pages
  • Loading branch information
anjalshireesh committed Jan 2, 2024
1 parent 4c378b0 commit fab6025
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions health.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,17 @@ type XFSErrorConfig struct {
MaxRetries int `json:"max_retries"`
}

// THPConfigs - stores transparent huge pages (THP) related configs
type THPConfigs struct {
// /sys/kernel/mm/transparent_hugepage/enabled
Enabled string `json:"enabled"`
// /sys/kernel/mm/transparent_hugepage/defrag
Defrag string `json:"defrag"`
// /sys/kernel/mm/transparent_hugepage/khugepaged/max_ptes_none
MaxPtesNone int `json:"max_ptes_none"`
Error string `json:"error,omitempty"`
}

// GetOSInfo returns linux only operating system's information.
func GetOSInfo(ctx context.Context, addr string) OSInfo {
if runtime.GOOS != "linux" {
Expand Down Expand Up @@ -467,6 +478,8 @@ func GetSysConfig(_ context.Context, addr string) SysConfig {
sc.Config["xfs-error-config"] = xfsErrorConfigs
}

sc.Config["thp-config"] = getTHPConfigs()

return sc
}

Expand All @@ -487,6 +500,31 @@ func readIntFromFile(filePath string) (num int, err error) {
return strconv.Atoi(strings.TrimSpace(string(data)))
}

func getTHPConfigs() THPConfigs {
data, err := os.ReadFile("/sys/kernel/mm/transparent_hugepage/enabled")
if err != nil {
return THPConfigs{Error: err.Error()}
}
configs := THPConfigs{Enabled: strings.TrimSpace(string(data))}

data, err = os.ReadFile("/sys/kernel/mm/transparent_hugepage/defrag")
if err != nil {
return THPConfigs{Error: err.Error()}
}
configs.Defrag = strings.TrimSpace(string(data))

data, err = os.ReadFile("/sys/kernel/mm/transparent_hugepage/khugepaged/max_ptes_none")
if err != nil {
return THPConfigs{Error: err.Error()}
}

configs.MaxPtesNone, err = strconv.Atoi(strings.TrimSpace(string(data)))
if err != nil {
return THPConfigs{Error: err.Error()}
}
return configs
}

func getXFSErrorMaxRetries() XFSErrorConfigs {
xfsErrCfgPattern := "/sys/fs/xfs/*/error/metadata/*/max_retries"
configFiles, err := filepath.Glob(xfsErrCfgPattern)
Expand Down

0 comments on commit fab6025

Please sign in to comment.