[lxc-devel] [lxd/master] cgroup: shortcut cgroup2 only layouts

brauner on Github lxc-bot at linuxcontainers.org
Sun Dec 22 12:10:08 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 523 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20191222/d85e08dc/attachment.bin>
-------------- next part --------------
From 31e461f304335b3eef6137a785548cbeee503c21 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sun, 22 Dec 2019 13:07:43 +0100
Subject: [PATCH] cgroup: shortcut cgroup2 only layouts

When we detect that this is a pure cgroup2 layout stop parsing for any
additional mountpoints. Any additional mountpoints are likely a bug.

Closes #6655.
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 lxd/cgroup/init.go | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/lxd/cgroup/init.go b/lxd/cgroup/init.go
index 3cf6dd943d..248c244b52 100644
--- a/lxd/cgroup/init.go
+++ b/lxd/cgroup/init.go
@@ -325,7 +325,7 @@ func init() {
 		// Parse V2 controllers.
 		path := fields[2]
 		hybridPath := filepath.Join(cgPath, "unified", path, "cgroup.controllers")
-		dedicatedPath := filepath.Join(cgPath, path, "cgroup.controllers")
+		dedicatedPath := ""
 
 		controllers, err := os.Open(hybridPath)
 		if err != nil {
@@ -334,6 +334,7 @@ func init() {
 				return
 			}
 
+			dedicatedPath = filepath.Join(cgPath, path, "cgroup.controllers")
 			controllers, err = os.Open(dedicatedPath)
 			if err != nil && !os.IsNotExist(err) {
 				logger.Errorf("Unable to load cgroup.controllers")
@@ -342,15 +343,26 @@ func init() {
 		}
 
 		if err == nil {
+			unifiedControllers := map[string]Backend{}
+
 			// Record the fact that V2 is present at all.
-			cgControllers["unified"] = V2
+			unifiedControllers["unified"] = V2
 
 			scanControllers := bufio.NewScanner(controllers)
 			for scanControllers.Scan() {
 				line := strings.TrimSpace(scanSelfCg.Text())
-				cgControllers[line] = V2
+				unifiedControllers[line] = V2
 			}
 			hasV2 = true
+
+			if dedicatedPath != "" {
+				cgControllers = unifiedControllers
+				break
+			} else {
+				for k, v := range unifiedControllers {
+					cgControllers[k] = v
+				}
+			}
 		}
 	}
 


More information about the lxc-devel mailing list