mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 14:19:49 +08:00
fix cgroups
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user