[lxc-devel] [lxd/master] Replace all CGroup{G, S} to use abstractino in container_lxc.go
lucindan on Github
lxc-bot at linuxcontainers.org
Thu Dec 12 08:10:47 UTC 2019
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 395 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20191212/62eb855d/attachment.bin>
-------------- next part --------------
From 56a84185b16375fa78482259dc205a1e46d7e47e Mon Sep 17 00:00:00 2001
From: Aaditya Murthy <amurthy123 at gmail.com>
Date: Wed, 11 Dec 2019 23:43:20 -0600
Subject: [PATCH 1/3] Replaced cgroupget/set calls for memory, pid controllers
Signed-off-by: Lucinda Nguyen <lucinda.onguyen at gmail.com>
---
.idea/.gitignore | 2 +
.idea/lxd.iml | 8 +++
.idea/misc.xml | 6 ++
.idea/modules.xml | 8 +++
.idea/vcs.xml | 6 ++
lxd/cgroup/abstraction.go | 117 ++++++++++++++++++++++++++++++++++++++
lxd/cgroup/init.go | 4 +-
lxd/container_lxc.go | 46 ++++++++-------
8 files changed, 174 insertions(+), 23 deletions(-)
create mode 100644 .idea/.gitignore
create mode 100644 .idea/lxd.iml
create mode 100644 .idea/misc.xml
create mode 100644 .idea/modules.xml
create mode 100644 .idea/vcs.xml
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000000..e7e9d11d4b
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,2 @@
+# Default ignored files
+/workspace.xml
diff --git a/.idea/lxd.iml b/.idea/lxd.iml
new file mode 100644
index 0000000000..c956989b29
--- /dev/null
+++ b/.idea/lxd.iml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="WEB_MODULE" version="4">
+ <component name="NewModuleRootManager">
+ <content url="file://$MODULE_DIR$" />
+ <orderEntry type="inheritedJdk" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ </component>
+</module>
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000000..28a804d893
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="JavaScriptSettings">
+ <option name="languageLevel" value="ES6" />
+ </component>
+</project>
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000000..3e4d197abb
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="ProjectModuleManager">
+ <modules>
+ <module fileurl="file://$PROJECT_DIR$/.idea/lxd.iml" filepath="$PROJECT_DIR$/.idea/lxd.iml" />
+ </modules>
+ </component>
+</project>
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000000..94a25f7f4c
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="VcsDirectoryMappings">
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
+ </component>
+</project>
\ No newline at end of file
diff --git a/lxd/cgroup/abstraction.go b/lxd/cgroup/abstraction.go
index 8144aab6a5..d6ccc0b2c4 100644
--- a/lxd/cgroup/abstraction.go
+++ b/lxd/cgroup/abstraction.go
@@ -29,3 +29,120 @@ func (cg *CGroup) SetMaxProcesses(max int64) error {
return ErrUnknownVersion
}
+
+func (cg *CGroup) GetMaxProcess() (string, error) {
+ version := cgControllers["pids"]
+ if version == Unavailable {
+ return "", ErrControllerMissing
+ }
+ if version == V1 || version == V2 {
+ return cg.rw.Get(version, "pids", "pids.max")
+ }
+ return "",ErrUnknownVersion
+}
+
+func (cg *CGroup) GetMemorySoftLimit() (string, error) {
+ version := cgControllers["memory"]
+ if version == Unavailable {
+ return "", ErrControllerMissing
+ }
+ if version == V1 {
+ return cg.rw.Get(version, "memory", "memory.soft_limit_in_bytes")
+ }
+ if version == V2 {
+ return cg.rw.Get(version, "memory", "memory.low")
+ }
+ return "", ErrUnknownVersion
+}
+
+func (cg *CGroup) SetMemorySoftLimit(softLim string) error {
+ // Confirm we have the controller
+ version := cgControllers["memory"]
+ if version == Unavailable {
+ return ErrControllerMissing
+ }
+ // V1/V2 behavior
+ if version == V1 || version == V2 {
+ if softLim == "-1" {
+ return cg.rw.Set(version, "memory", "memory.soft_limit_in_bytes", "max")
+ }
+ }
+ if version == V1 {
+ return cg.rw.Set(version, "memory", "memory.soft_limit_in_bytes",softLim)
+ }
+ if version == V2 {
+ return cg.rw.Set(version, "memory","memory.low", softLim)
+ }
+
+ return ErrUnknownVersion
+}
+
+
+func (cg *CGroup) GetMaxMemory() (string, error) {
+ version := cgControllers["memory"]
+ if version == Unavailable {
+ return "", ErrControllerMissing
+ }
+ if version == V1 {
+ return cg.rw.Get(version, "memory", "memory.limit_in_bytes")
+ }
+ if version == V2 {
+ return cg.rw.Get(version, "memory", "memory.max")
+ }
+ return "", ErrUnknownVersion
+}
+func (cg *CGroup) SetMemoryMax(max string) error {
+ // Confirm we have the controller
+ version := cgControllers["memory"]
+ if version == Unavailable {
+ return ErrControllerMissing
+ }
+ // V1/V2 behavior
+ if version == V1 {
+ return cg.rw.Set(version, "memory", "memory.limit_in_bytes",max)
+ }
+ if version == V2 {
+ return cg.rw.Set(version, "memory","memory.low", max)
+ }
+ return ErrUnknownVersion
+}
+
+func (cg *CGroup) GetCurrentMemory() (string, error) {
+ version := cgControllers["memory"]
+ if version == Unavailable {
+ return "", ErrControllerMissing
+ }
+ if version == V1 {
+ return cg.rw.Get(version, "memory", "memory.usage_in_bytes")
+ }
+ if version == V2 {
+ return cg.rw.Get(version, "memory", "memory.current")
+ }
+ return "", ErrUnknownVersion
+}
+
+func (cg *CGroup) GetCurrentProcesses() (string, error) {
+ version := cgControllers["pids"]
+ if version == Unavailable {
+ return "", ErrControllerMissing
+ }
+ if version == V1 || version == V2 {
+ return cg.rw.Get(version, "pids", "pids.current")
+ }
+
+ return "", ErrUnknownVersion
+}
+
+
+func (cg *CGroup) GetCpuAcctUsage() (string, error) {
+ version := cgControllers["cpuacct"]
+ //only supported in V1 currently
+ if version == Unavailable || version == V2 {
+ return "", ErrControllerMissing
+ }
+ if version == V1 {
+ return cg.rw.Get(version, "cpuacct", "cpuacct.usage")
+ }
+
+ return "", ErrUnknownVersion
+}
\ No newline at end of file
diff --git a/lxd/cgroup/init.go b/lxd/cgroup/init.go
index ac78c19db9..6b29a0f7c5 100644
--- a/lxd/cgroup/init.go
+++ b/lxd/cgroup/init.go
@@ -72,6 +72,7 @@ func init() {
hasV2 := false
// Go through the file line by line.
scanSelfCg := bufio.NewScanner(selfCg)
+ logger.Warnf(selfCg.Name() +"path being read")
for scanSelfCg.Scan() {
line := strings.TrimSpace(scanSelfCg.Text())
fields := strings.SplitN(line, ":", 3)
@@ -90,8 +91,9 @@ func init() {
// Parse V2 controllers.
path := fields[2]
hybridPath := filepath.Join(cgPath, "unified", path, "cgroup.controllers")
+ logger.Warnf(hybridPath + "hybrid")
dedicatedPath := filepath.Join(cgPath, path, "cgroup.controllers")
-
+ logger.Warnf(dedicatedPath + "dedicated")
controllers, err := os.Open(hybridPath)
if err != nil {
if !os.IsNotExist(err) {
diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index 9de0a935bf..7a859ea00d 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -1120,13 +1120,13 @@ func (c *containerLXC) initLXC(config bool) error {
}
if memoryEnforce == "soft" {
- err = lxcSetConfigItem(cc, "lxc.cgroup.memory.soft_limit_in_bytes", fmt.Sprintf("%d", valueInt))
+ err = cg.SetMemorySoftLimit(fmt.Sprintf("%d", valueInt))
if err != nil {
return err
}
} else {
if c.state.OS.CGroupSwapAccounting && (memorySwap == "" || shared.IsTrue(memorySwap)) {
- err = lxcSetConfigItem(cc, "lxc.cgroup.memory.limit_in_bytes", fmt.Sprintf("%d", valueInt))
+ err = cg.SetMemoryMax(fmt.Sprintf("%d", valueInt))
if err != nil {
return err
}
@@ -1135,13 +1135,13 @@ func (c *containerLXC) initLXC(config bool) error {
return err
}
} else {
- err = lxcSetConfigItem(cc, "lxc.cgroup.memory.limit_in_bytes", fmt.Sprintf("%d", valueInt))
+ err = cg.SetMemoryMax(fmt.Sprintf("%d", valueInt))
if err != nil {
return err
}
}
// Set soft limit to value 10% less than hard limit
- err = lxcSetConfigItem(cc, "lxc.cgroup.memory.soft_limit_in_bytes", fmt.Sprintf("%.0f", float64(valueInt)*0.9))
+ err = cg.SetMemorySoftLimit( fmt.Sprintf("%.0f", float64(valueInt)*0.9))
if err != nil {
return err
}
@@ -4271,24 +4271,22 @@ func (c *containerLXC) Update(args db.InstanceArgs, userRequested bool) error {
oldMemswLimit = ""
}
}
-
- oldLimit, err := c.CGroupGet("memory.limit_in_bytes")
+ oldLimit,err := cg.GetMaxMemory()
if err != nil {
oldLimit = ""
}
-
- oldSoftLimit, err := c.CGroupGet("memory.soft_limit_in_bytes")
+ oldSoftLimit, err := cg.GetMemorySoftLimit()
if err != nil {
oldSoftLimit = ""
}
revertMemory := func() {
if oldSoftLimit != "" {
- c.CGroupSet("memory.soft_limit_in_bytes", oldSoftLimit)
+ cg.SetMemorySoftLimit(oldSoftLimit)
}
if oldLimit != "" {
- c.CGroupSet("memory.limit_in_bytes", oldLimit)
+ cg.SetMemoryMax(oldLimit)
}
if oldMemswLimit != "" {
@@ -4304,14 +4302,12 @@ func (c *containerLXC) Update(args db.InstanceArgs, userRequested bool) error {
return err
}
}
-
- err = c.CGroupSet("memory.limit_in_bytes", "-1")
+ err = cg.SetMemoryMax("-1")
if err != nil {
revertMemory()
return err
}
-
- err = c.CGroupSet("memory.soft_limit_in_bytes", "-1")
+ err = cg.SetMemorySoftLimit("-1")
if err != nil {
revertMemory()
return err
@@ -4320,14 +4316,14 @@ func (c *containerLXC) Update(args db.InstanceArgs, userRequested bool) error {
// Set the new values
if memoryEnforce == "soft" {
// Set new limit
- err = c.CGroupSet("memory.soft_limit_in_bytes", memory)
+ err = cg.SetMemorySoftLimit(memory)
if err != nil {
revertMemory()
return err
}
} else {
if c.state.OS.CGroupSwapAccounting && (memorySwap == "" || shared.IsTrue(memorySwap)) {
- err = c.CGroupSet("memory.limit_in_bytes", memory)
+ err = cg.SetMemoryMax(memory)
if err != nil {
revertMemory()
return err
@@ -4339,7 +4335,7 @@ func (c *containerLXC) Update(args db.InstanceArgs, userRequested bool) error {
return err
}
} else {
- err = c.CGroupSet("memory.limit_in_bytes", memory)
+ err = cg.SetMemoryMax(memory)
if err != nil {
revertMemory()
return err
@@ -4352,8 +4348,7 @@ func (c *containerLXC) Update(args db.InstanceArgs, userRequested bool) error {
revertMemory()
return err
}
-
- err = c.CGroupSet("memory.soft_limit_in_bytes", fmt.Sprintf("%.0f", float64(valueInt)*0.9))
+ err = cg.SetMemorySoftLimit(fmt.Sprintf("%.0f", float64(valueInt)*0.9))
if err != nil {
revertMemory()
return err
@@ -5749,7 +5744,9 @@ func (c *containerLXC) cpuState() api.InstanceStateCPU {
}
// CPU usage in seconds
- value, err := c.CGroupGet("cpuacct.usage")
+ cg , err := c.cgroup(c.c)
+
+ value, err := cg.GetCpuAcctUsage()
if err != nil {
cpu.Usage = -1
return cpu
@@ -5820,7 +5817,8 @@ func (c *containerLXC) memoryState() api.InstanceStateMemory {
}
// Memory in bytes
- value, err := c.CGroupGet("memory.usage_in_bytes")
+ cg, err := c.cgroup(c.c)
+ value, err := cg.GetCurrentMemory()
valueInt, err1 := strconv.ParseInt(value, 10, 64)
if err == nil && err1 == nil {
memory.Usage = valueInt
@@ -5922,7 +5920,11 @@ func (c *containerLXC) processesState() int64 {
}
if c.state.OS.CGroupPidsController {
- value, err := c.CGroupGet("pids.current")
+ cg, err := c.cgroup(nil)
+ if err!= nil {
+ return 0
+ }
+ value, err := cg.GetCurrentProcesses()
if err != nil {
return -1
}
From 6899b33494b3b69a3feee75cf91934591b7ed441 Mon Sep 17 00:00:00 2001
From: Aaditya Murthy <amurthy123 at gmail.com>
Date: Thu, 12 Dec 2019 00:52:11 -0600
Subject: [PATCH 2/3] Controller abstraction for V1 and V2
Signed-off-by: Lucinda Nguyen <lucinda.onguyen at gmail.com>
---
lxd/cgroup/abstraction.go | 175 ++++++++++++++++++++++++++++++++++++--
lxd/container_lxc.go | 66 +++++++-------
2 files changed, 201 insertions(+), 40 deletions(-)
diff --git a/lxd/cgroup/abstraction.go b/lxd/cgroup/abstraction.go
index d6ccc0b2c4..a6e62444fa 100644
--- a/lxd/cgroup/abstraction.go
+++ b/lxd/cgroup/abstraction.go
@@ -38,7 +38,7 @@ func (cg *CGroup) GetMaxProcess() (string, error) {
if version == V1 || version == V2 {
return cg.rw.Get(version, "pids", "pids.max")
}
- return "",ErrUnknownVersion
+ return "", ErrUnknownVersion
}
func (cg *CGroup) GetMemorySoftLimit() (string, error) {
@@ -62,15 +62,16 @@ func (cg *CGroup) SetMemorySoftLimit(softLim string) error {
return ErrControllerMissing
}
// V1/V2 behavior
- if version == V1 || version == V2 {
+ if version == V1 {
if softLim == "-1" {
return cg.rw.Set(version, "memory", "memory.soft_limit_in_bytes", "max")
}
- }
- if version == V1 {
return cg.rw.Set(version, "memory", "memory.soft_limit_in_bytes",softLim)
}
if version == V2 {
+ if softLim == "-1" {
+ return cg.rw.Set(version, "memory", "memory.low", "max")
+ }
return cg.rw.Set(version, "memory","memory.low", softLim)
}
@@ -102,12 +103,12 @@ func (cg *CGroup) SetMemoryMax(max string) error {
return cg.rw.Set(version, "memory", "memory.limit_in_bytes",max)
}
if version == V2 {
- return cg.rw.Set(version, "memory","memory.low", max)
+ return cg.rw.Set(version, "memory","memory.max", max)
}
return ErrUnknownVersion
}
-func (cg *CGroup) GetCurrentMemory() (string, error) {
+func (cg *CGroup) GetMemoryUsage() (string, error) {
version := cgControllers["memory"]
if version == Unavailable {
return "", ErrControllerMissing
@@ -121,7 +122,7 @@ func (cg *CGroup) GetCurrentMemory() (string, error) {
return "", ErrUnknownVersion
}
-func (cg *CGroup) GetCurrentProcesses() (string, error) {
+func (cg *CGroup) GetProcessesUsage() (string, error) {
version := cgControllers["pids"]
if version == Unavailable {
return "", ErrControllerMissing
@@ -133,7 +134,30 @@ func (cg *CGroup) GetCurrentProcesses() (string, error) {
return "", ErrUnknownVersion
}
+func (cg *CGroup) SetMemorySwapMax(max string) error {
+ //Confirm we have the controller
+ version := cgControllers["memory"]
+ if version == Unavailable {
+ return ErrControllerMissing
+ }
+ // V1/V2 behavior
+ if version == V1 {
+ if max == "-1" {
+ return cg.rw.Set(version, "memory","memory.memsw.limit_in_bytes", "max")
+ }
+ return cg.rw.Set(version, "memory","memory.memsw.limit_in_bytes", max)
+ }
+ if version == V2 {
+ if max == "-1" {
+ return cg.rw.Set(version, "memory","memory.swap.max", "max")
+
+ }
+
+ return cg.rw.Set(version, "memory","memory.swap.max", max)
+ }
+ return ErrUnknownVersion
+}
func (cg *CGroup) GetCpuAcctUsage() (string, error) {
version := cgControllers["cpuacct"]
//only supported in V1 currently
@@ -145,4 +169,141 @@ func (cg *CGroup) GetCpuAcctUsage() (string, error) {
}
return "", ErrUnknownVersion
+}
+
+func (cg *CGroup) GetMemoryMaxUsage() (string, error) {
+ version := cgControllers["memory"]
+ //only supported in V1 currently
+ if version == Unavailable || version == V2 {
+ return "", ErrControllerMissing
+ }
+ if version == V1 {
+ return cg.rw.Get(version, "memory", "memory.max_usage_in_bytes")
+ }
+
+ return "", ErrUnknownVersion
+}
+
+func (cg *CGroup) GetMemorySwMaxUsage() (string, error) {
+ version := cgControllers["memory"]
+ //only supported in V1 currently
+ if version == Unavailable || version == V2 {
+ return "", ErrControllerMissing
+ }
+ if version == V1 {
+ return cg.rw.Get(version, "memory", "memory.memsw.max_usage_in_bytes")
+ }
+ return "", ErrUnknownVersion
+}
+
+func (cg *CGroup) SetMemorySwappiness(value string) error {
+ // Confirm we have the controller
+ version := cgControllers["memory"]
+ if version == Unavailable || version == V2{
+ return ErrControllerMissing
+ }
+ // V1 behavior
+ if version == V1 {
+ return cg.rw.Set(version, "memory","memory.swappiness", value)
+ }
+ return ErrUnknownVersion
+}
+
+
+func (cg *CGroup) GetMemorySwapLimit() (string, error) {
+ version := cgControllers["memory"]
+ if version == Unavailable {
+ return "", ErrControllerMissing
+ }
+ if version == V1 {
+ return cg.rw.Get(version, "memory", "memory.memsw.limit_in_bytes")
+ }
+ if version == V2 {
+ return cg.rw.Get(version, "memory", "memory.swap.max")
+ }
+ return "", ErrUnknownVersion
+}
+
+func (cg *CGroup) GetMemorySwapUsage() (string, error) {
+ version := cgControllers["memory"]
+ //only supported in V1 currently
+ if version == Unavailable {
+ return "", ErrControllerMissing
+ }
+ if version == V1 {
+ return cg.rw.Get(version, "memory", "memory.memsw.usage_in_bytes")
+ }
+ if version == V2 {
+ return cg.rw.Get(version, "memory", "memory.swap.current")
+ }
+ return "", ErrUnknownVersion
+}
+
+func (cg *CGroup) GetBlkioWeight() (string, error) {
+ // Confirm we have the controller
+ version := cgControllers["blkio"]
+ if version == Unavailable || version == V2 {
+ return "", ErrControllerMissing
+ }
+ // V1/V2 behavior
+ if version == V1 {
+ return cg.rw.Get(version, "blkio", "blkio.weight")
+ }
+
+ return "", ErrUnknownVersion
+}
+
+func (cg *CGroup) SetCpusShare(value string) error {
+ //Confirm we have the controller
+ version := cgControllers["cpu"]
+ if version == Unavailable {
+ return ErrControllerMissing
+ }
+ // V1/V2 behavior
+ if version == V1 {
+ return cg.rw.Set(version, "cpu","cpu.shares", value)
+ }
+ if version == V2 {
+ return cg.rw.Set(version, "cpu","cpu.weight", value)
+ }
+ return ErrUnknownVersion
+}
+
+func (cg *CGroup) SetCpuCfsPeriod(value string) error {
+ //Confirm we have the controller
+ version := cgControllers["cpu"]
+ if version == Unavailable || version == V2 {
+ return ErrControllerMissing
+ }
+ // V1 behavior
+ if version == V1 {
+ return cg.rw.Set(version, "cpu","cpu.cfs_period_us", value)
+ }
+
+ return ErrUnknownVersion
+}
+
+func (cg *CGroup) SetCpuCfsQuota(value string) error {
+ //Confirm we have the controller
+ version := cgControllers["cpu"]
+ if version == Unavailable || version == V2 {
+ return ErrControllerMissing
+ }
+ // V1/V2 behavior
+ if version == V1 {
+ return cg.rw.Set(version, "cpu","cpu.cfs_quota_us", value)
+ }
+ return ErrUnknownVersion
+}
+
+func (cg *CGroup) SetNetIfPrio(value string) error {
+ version := cgControllers["net_prio"]
+ if version == Unavailable || version == V2 {
+ return ErrControllerMissing
+ }
+ // V1 behavior
+ if version == V1 {
+ return cg.rw.Set(version, "net_prio","net_prio.ifpriomap", value)
+ }
+ return ErrUnknownVersion
}
\ No newline at end of file
diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index 7a859ea00d..ba150368c2 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -1150,7 +1150,7 @@ func (c *containerLXC) initLXC(config bool) error {
// Configure the swappiness
if memorySwap != "" && !shared.IsTrue(memorySwap) {
- err = lxcSetConfigItem(cc, "lxc.cgroup.memory.swappiness", "0")
+ err = cg.SetMemorySwappiness("0")
if err != nil {
return err
}
@@ -1159,8 +1159,7 @@ func (c *containerLXC) initLXC(config bool) error {
if err != nil {
return err
}
-
- err = lxcSetConfigItem(cc, "lxc.cgroup.memory.swappiness", fmt.Sprintf("%d", 60-10+priority))
+ err = cg.SetMemorySwappiness(fmt.Sprintf("%d", 60-10+priority))
if err != nil {
return err
}
@@ -1178,21 +1177,21 @@ func (c *containerLXC) initLXC(config bool) error {
}
if cpuShares != "1024" {
- err = lxcSetConfigItem(cc, "lxc.cgroup.cpu.shares", cpuShares)
+ err = cg.SetCpusShare(cpuShares)
if err != nil {
return err
}
}
if cpuCfsPeriod != "-1" {
- err = lxcSetConfigItem(cc, "lxc.cgroup.cpu.cfs_period_us", cpuCfsPeriod)
+ err = cg.SetCpuCfsPeriod(cpuCfsPeriod)
if err != nil {
return err
}
}
if cpuCfsQuota != "-1" {
- err = lxcSetConfigItem(cc, "lxc.cgroup.cpu.cfs_quota_us", cpuCfsQuota)
+ err = cg.SetCpuCfsQuota(cpuCfsQuota)
if err != nil {
return err
}
@@ -3861,6 +3860,10 @@ func (c *containerLXC) VolatileSet(changes map[string]string) error {
}
func (c *containerLXC) Update(args db.InstanceArgs, userRequested bool) error {
+ cg, err := c.cgroup(c.c)
+ if err != nil {
+ return err
+ }
// Set sane defaults for unset keys
if args.Project == "" {
args.Project = "default"
@@ -3883,7 +3886,7 @@ func (c *containerLXC) Update(args db.InstanceArgs, userRequested bool) error {
}
// Validate the new config
- err := instance.ValidConfig(c.state.OS, args.Config, false, false)
+ err = instance.ValidConfig(c.state.OS, args.Config, false, false)
if err != nil {
return errors.Wrap(err, "Invalid config")
}
@@ -4097,10 +4100,7 @@ func (c *containerLXC) Update(args db.InstanceArgs, userRequested bool) error {
}
// Load cgroup abstraction
- cg, err := c.cgroup(nil)
- if err != nil {
- return err
- }
+
// If apparmor changed, re-validate the apparmor profile
if shared.StringInSlice("raw.apparmor", changedConfig) || shared.StringInSlice("security.nesting", changedConfig) {
@@ -4224,8 +4224,7 @@ func (c *containerLXC) Update(args db.InstanceArgs, userRequested bool) error {
if priority == 0 {
priority = 10
}
-
- err = c.CGroupSet("blkio.weight", fmt.Sprintf("%d", priority))
+ cg.SetBlkioWeight(fmt.Sprintf("%d", priority))
if err != nil {
return err
}
@@ -4266,7 +4265,7 @@ func (c *containerLXC) Update(args db.InstanceArgs, userRequested bool) error {
// Store the old values for revert
oldMemswLimit := ""
if c.state.OS.CGroupSwapAccounting {
- oldMemswLimit, err = c.CGroupGet("memory.memsw.limit_in_bytes")
+ oldMemswLimit, err = cg.GetMemorySwapLimit()
if err != nil {
oldMemswLimit = ""
}
@@ -4290,13 +4289,13 @@ func (c *containerLXC) Update(args db.InstanceArgs, userRequested bool) error {
}
if oldMemswLimit != "" {
- c.CGroupSet("memory.memsw.limit_in_bytes", oldMemswLimit)
+ cg.SetMemorySwapMax(oldMemswLimit)
}
}
// Reset everything
if c.state.OS.CGroupSwapAccounting {
- err = c.CGroupSet("memory.memsw.limit_in_bytes", "-1")
+ err = cg.SetMemorySwapMax("-1")
if err != nil {
revertMemory()
return err
@@ -4328,8 +4327,7 @@ func (c *containerLXC) Update(args db.InstanceArgs, userRequested bool) error {
revertMemory()
return err
}
-
- err = c.CGroupSet("memory.memsw.limit_in_bytes", memory)
+ err = cg.SetMemorySwapMax(memory)
if err != nil {
revertMemory()
return err
@@ -4360,7 +4358,7 @@ func (c *containerLXC) Update(args db.InstanceArgs, userRequested bool) error {
memorySwap := c.expandedConfig["limits.memory.swap"]
memorySwapPriority := c.expandedConfig["limits.memory.swap.priority"]
if memorySwap != "" && !shared.IsTrue(memorySwap) {
- err = c.CGroupSet("memory.swappiness", "0")
+ err = cg.SetMemorySwappiness("0")
if err != nil {
return err
}
@@ -4372,8 +4370,7 @@ func (c *containerLXC) Update(args db.InstanceArgs, userRequested bool) error {
return err
}
}
-
- err = c.CGroupSet("memory.swappiness", fmt.Sprintf("%d", 60-10+priority))
+ err = cg.SetMemorySwappiness(fmt.Sprintf("%d", 60-10+priority))
if err != nil {
return err
}
@@ -4398,18 +4395,16 @@ func (c *containerLXC) Update(args db.InstanceArgs, userRequested bool) error {
if err != nil {
return err
}
-
- err = c.CGroupSet("cpu.shares", cpuShares)
+ err = cg.SetCpusShare(cpuShares)
if err != nil {
return err
}
-
- err = c.CGroupSet("cpu.cfs_period_us", cpuCfsPeriod)
+ err = cg.SetCpuCfsPeriod(cpuCfsPeriod)
if err != nil {
return err
}
- err = c.CGroupSet("cpu.cfs_quota_us", cpuCfsQuota)
+ err = cg.SetCpuCfsQuota(cpuCfsQuota)
if err != nil {
return err
}
@@ -5811,21 +5806,21 @@ func (c *containerLXC) diskState() map[string]api.InstanceStateDisk {
func (c *containerLXC) memoryState() api.InstanceStateMemory {
memory := api.InstanceStateMemory{}
+ cg, err := c.cgroup(c.c)
if !c.state.OS.CGroupMemoryController {
return memory
}
// Memory in bytes
- cg, err := c.cgroup(c.c)
- value, err := cg.GetCurrentMemory()
+ value, err := cg.GetMemoryUsage()
valueInt, err1 := strconv.ParseInt(value, 10, 64)
if err == nil && err1 == nil {
memory.Usage = valueInt
}
// Memory peak in bytes
- value, err = c.CGroupGet("memory.max_usage_in_bytes")
+ value, err = cg.GetMemoryMaxUsage()
valueInt, err1 = strconv.ParseInt(value, 10, 64)
if err == nil && err1 == nil {
memory.UsagePeak = valueInt
@@ -5834,7 +5829,7 @@ func (c *containerLXC) memoryState() api.InstanceStateMemory {
if c.state.OS.CGroupSwapAccounting {
// Swap in bytes
if memory.Usage > 0 {
- value, err := c.CGroupGet("memory.memsw.usage_in_bytes")
+ value, err := cg.GetMemorySwapUsage()
valueInt, err1 := strconv.ParseInt(value, 10, 64)
if err == nil && err1 == nil {
memory.SwapUsage = valueInt - memory.Usage
@@ -5843,7 +5838,7 @@ func (c *containerLXC) memoryState() api.InstanceStateMemory {
// Swap peak in bytes
if memory.UsagePeak > 0 {
- value, err = c.CGroupGet("memory.memsw.max_usage_in_bytes")
+ value, err = cg.GetMemorySwMaxUsage()
valueInt, err1 = strconv.ParseInt(value, 10, 64)
if err == nil && err1 == nil {
memory.SwapUsagePeak = valueInt - memory.UsagePeak
@@ -5924,7 +5919,7 @@ func (c *containerLXC) processesState() int64 {
if err!= nil {
return 0
}
- value, err := cg.GetCurrentProcesses()
+ value, err := cg.GetProcessesUsage()
if err != nil {
return -1
}
@@ -6498,6 +6493,11 @@ func (c *containerLXC) removeDiskDevices() error {
// Network I/O limits
func (c *containerLXC) setNetworkPriority() error {
+ cg, err := c.cgroup(c.c)
+ if err != nil {
+ return err
+ }
+
// Check that the container is running
if !c.IsRunning() {
return fmt.Errorf("Can't set network priority on stopped container")
@@ -6529,7 +6529,7 @@ func (c *containerLXC) setNetworkPriority() error {
success := false
var last_error error
for _, netif := range netifs {
- err = c.CGroupSet("net_prio.ifpriomap", fmt.Sprintf("%s %d", netif.Name, networkInt))
+ err = cg.SetNetIfPrio(fmt.Sprintf("%s %d", netif.Name, networkInt))
if err == nil {
success = true
} else {
From 7269a7fbd3a2ca3f178bfaa1039206d0009bdd9a Mon Sep 17 00:00:00 2001
From: Aaditya Murthy <amurthy123 at gmail.com>
Date: Thu, 12 Dec 2019 00:56:39 -0600
Subject: [PATCH 3/3] removed duplicated directory
Signed-off-by: Lucinda Nguyen <lucinda at tutorial-island.localhost>
---
.idea/.gitignore | 2 --
.idea/lxd.iml | 8 --------
.idea/misc.xml | 6 ------
.idea/modules.xml | 8 --------
.idea/vcs.xml | 6 ------
5 files changed, 30 deletions(-)
delete mode 100644 .idea/.gitignore
delete mode 100644 .idea/lxd.iml
delete mode 100644 .idea/misc.xml
delete mode 100644 .idea/modules.xml
delete mode 100644 .idea/vcs.xml
diff --git a/.idea/.gitignore b/.idea/.gitignore
deleted file mode 100644
index e7e9d11d4b..0000000000
--- a/.idea/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# Default ignored files
-/workspace.xml
diff --git a/.idea/lxd.iml b/.idea/lxd.iml
deleted file mode 100644
index c956989b29..0000000000
--- a/.idea/lxd.iml
+++ /dev/null
@@ -1,8 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<module type="WEB_MODULE" version="4">
- <component name="NewModuleRootManager">
- <content url="file://$MODULE_DIR$" />
- <orderEntry type="inheritedJdk" />
- <orderEntry type="sourceFolder" forTests="false" />
- </component>
-</module>
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
deleted file mode 100644
index 28a804d893..0000000000
--- a/.idea/misc.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project version="4">
- <component name="JavaScriptSettings">
- <option name="languageLevel" value="ES6" />
- </component>
-</project>
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
deleted file mode 100644
index 3e4d197abb..0000000000
--- a/.idea/modules.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project version="4">
- <component name="ProjectModuleManager">
- <modules>
- <module fileurl="file://$PROJECT_DIR$/.idea/lxd.iml" filepath="$PROJECT_DIR$/.idea/lxd.iml" />
- </modules>
- </component>
-</project>
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
deleted file mode 100644
index 94a25f7f4c..0000000000
--- a/.idea/vcs.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project version="4">
- <component name="VcsDirectoryMappings">
- <mapping directory="$PROJECT_DIR$" vcs="Git" />
- </component>
-</project>
\ No newline at end of file
More information about the lxc-devel
mailing list