fix cgroups

This commit is contained in:
wanyaoqi
2019-03-14 11:57:56 +08:00
parent 8c9f71ae0d
commit 44f9b4c818
2 changed files with 17 additions and 46 deletions
+5 -28
View File
@@ -995,35 +995,12 @@ func (s *SKVMGuestInstance) setCgroupIo() {
}
func (s *SKVMGuestInstance) setCgroupCpu() {
cpu, _ := s.Desc.Int("cpu")
cgrouputils.CgroupSet(strconv.Itoa(s.cgroupPid), int(cpu))
var (
cpu, _ = s.Desc.Int("cpu")
cpuWeight = 1024
)
// TODO XXX
/*
var (
cpuWeight = 1024
cpuPeriod = 0
cpuQuota = 0
appTags = s.getApptags()
meta, _ = s.Desc.Get("metadata")
)
if meta != nil {
if meta.Contains("__cpu_weight") {
cpuWeight, _ = meta.Int("__cpu_weight")
}
if meta.Contains("__cpu_period") {
cpuPeriod, _ = meta.Int("__cpu_period")
} else {
cpuPeriod = -1
}
if meta.Contains("__cpu_quota") {
cpuQuota, _ = meta.Int("__cpu_quota")
} else {
cpuQuota = -1
}
}
*/
cgrouputils.CgroupSet(strconv.Itoa(s.cgroupPid), int(cpu)*cpuWeight)
}
func (s *SKVMGuestInstance) CreateFromDesc(desc jsonutils.JSONObject) error {
+12 -18
View File
@@ -30,6 +30,7 @@ var (
)
type ICGroupTask interface {
InitTask(hand ICGroupTask, coreNum int, pid string)
SetPid(string)
SetWeight(coreNum int)
SetHand(hand ICGroupTask)
@@ -108,19 +109,9 @@ func GetRootParam(module, name, pid string) string {
}
func SetRootParam(module, name, value, pid string) bool {
if param := GetRootParam(module, name, pid); param != value {
fi, err := os.Open(GetTaskParamPath(module, name, pid))
if err == nil {
_, err = fi.Write([]byte(value))
if err != nil {
err = fi.Close()
} else {
log.Errorln(err)
}
} else {
log.Errorln(err)
}
param := GetRootParam(module, name, pid)
if param != value {
err := ioutil.WriteFile(GetTaskParamPath(module, name, pid), []byte(value), 0644)
if err != nil {
if len(pid) == 0 {
pid = "root"
@@ -168,6 +159,12 @@ func (c *CGroupTask) SetPid(pid string) {
c.pid = pid
}
func (c *CGroupTask) InitTask(hand ICGroupTask, coreNum int, pid string) {
c.SetHand(hand)
c.SetWeight(coreNum)
c.SetPid(pid)
}
func (c *CGroupTask) Module() string {
return ""
}
@@ -536,9 +533,7 @@ func CgroupSet(pid string, coreNum int) bool {
&CGroupMemoryTask{&CGroupTask{}},
}
for _, hand := range tasks {
hand.SetHand(hand)
hand.SetPid(pid)
hand.SetWeight(coreNum)
hand.InitTask(hand, coreNum, pid)
if !hand.SetTask() {
return false
}
@@ -563,8 +558,7 @@ func CgroupDestroy(pid string) bool {
&CGroupIOHardlimitTask{CGroupIOTask: &CGroupIOTask{&CGroupTask{}}},
}
for _, hand := range tasks {
hand.SetHand(hand)
hand.SetPid(pid)
hand.InitTask(hand, 0, pid)
if !hand.RemoveTask() {
return false
}