fix(host): check min_free_kbytes size is enough (#23287)

This commit is contained in:
wanyaoqi
2025-09-12 22:56:09 +08:00
committed by GitHub
parent f0a042aff8
commit a3587e800f
2 changed files with 21 additions and 2 deletions
+8 -2
View File
@@ -626,11 +626,10 @@ func (h *SHostInfo) tuneSystem() {
if minMemMb < 100 {
minMemMb = 100
}
minMemKB := fmt.Sprintf("%d", 2*minMemMb*1024)
minMemKB := 2 * minMemMb * 1024
kv := map[string]string{
"/proc/sys/vm/swappiness": "0",
"/proc/sys/vm/vfs_cache_pressure": "350",
"/proc/sys/vm/min_free_kbytes": minMemKB,
"/proc/sys/net/ipv4/tcp_mtu_probing": "2",
"/proc/sys/net/ipv4/neigh/default/gc_thresh1": "1024",
"/proc/sys/net/ipv4/neigh/default/gc_thresh2": "4096",
@@ -640,6 +639,13 @@ func (h *SHostInfo) tuneSystem() {
"/proc/sys/net/netfilter/nf_conntrack_tcp_be_liberal": "1",
}
ret, err := fileutils2.FileGetIntContent("/proc/sys/vm/min_free_kbytes")
if err != nil {
log.Errorf("failed get /proc/sys/vm/min_free_kbytes: %s", err)
} else if ret < minMemKB {
kv["/proc/sys/vm/min_free_kbytes"] = fmt.Sprintf("%d", minMemKB)
}
for k, v := range kv {
sysutils.SetSysConfig(k, v)
}
+13
View File
@@ -22,6 +22,7 @@ import (
"path"
"path/filepath"
"regexp"
"strconv"
"strings"
"yunion.io/x/log"
@@ -219,6 +220,18 @@ func FileGetContents(file string) (string, error) {
return string(content), nil
}
func FileGetIntContent(file string) (int, error) {
content, err := FileGetContents(file)
if err != nil {
return -1, errors.Wrap(err, "FileGetContents")
}
val, err := strconv.Atoi(strings.TrimSpace(content))
if err != nil {
return -1, errors.Wrapf(err, "convert %s to int", content)
}
return val, nil
}
func GetFsFormat(diskPath string) string {
ret, err := procutils.NewCommand("blkid", "-o", "value", "-s", "TYPE", diskPath).Output()
if err != nil {