mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-08-30 17:13:08 +08:00
fix(host): check min_free_kbytes size is enough (#23287)
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user