]> git.ipfire.org Git - thirdparty/man-pages.git/blobdiff - man7/cgroup_namespaces.7
console_codes.4: Document that \e[1;n] and \e[2;n] support 16 colors
[thirdparty/man-pages.git] / man7 / cgroup_namespaces.7
index 4aa6609366de8a79057e8f5720de62743aa0b632..084a92c0860050f99cebf98e082f8cdc772e4c2d 100644 (file)
 .\" %%%LICENSE_END
 .\"
 .\"
-.TH CGROUP_NAMESPACES 7 2016-07-17 "Linux" "Linux Programmer's Manual"
+.TH CGROUP_NAMESPACES 7 2019-03-06 "Linux" "Linux Programmer's Manual"
 .SH NAME
 cgroup_namespaces \- overview of Linux cgroup namespaces
 .SH DESCRIPTION
 For an overview of namespaces, see
 .BR namespaces (7).
-
+.PP
 Cgroup namespaces virtualize the view of a process's cgroups (see
 .BR cgroups (7))
 as seen via
 .IR /proc/[pid]/cgroup
 and
 .IR /proc/[pid]/mountinfo .
-
-Each cgroup namespace has its own set of cgroup root directories,
-which are the base points for the relative locations displayed in
-.IR /proc/[pid]/cgroup .
+.PP
+Each cgroup namespace has its own set of cgroup root directories.
+These root directories are the base points for the relative
+locations displayed in the corresponding records in the
+.IR /proc/[pid]/cgroup
+file.
 When a process creates a new cgroup namespace using
 .BR clone (2)
 or
@@ -51,53 +53,70 @@ cgroups directories become the cgroup root directories
 of the new namespace.
 (This applies both for the cgroups version 1 hierarchies
 and the cgroups version 2 unified hierarchy.)
-
+.PP
 When viewing
 .IR /proc/[pid]/cgroup ,
 the pathname shown in the third field of each record will be
-relative to the reading process's cgroup root directory.
+relative to the reading process's root directory
+for the corresponding cgroup hierarchy.
 If the cgroup directory of the target process lies outside
 the root directory of the reading process's cgroup namespace,
 then the pathname will show
 .I ../
 entries for each ancestor level in the cgroup hierarchy.
-
+.PP
 The following shell session demonstrates the effect of creating
 a new cgroup namespace.
+.PP
 First, (as superuser) we create a child cgroup in the
 .I freezer
-hierarchy, and put the shell into that cgroup:
-
-.nf
+hierarchy, and place a process in that cgroup that we will
+use as part of the demonstration below:
+.PP
+.in +4n
+.EX
+# \fBmkdir \-p /sys/fs/cgroup/freezer/sub2\fP
+# \fBsleep 10000 &\fP     # Create a process that lives for a while
+[1] 20124
+# \fBecho 20124 > /sys/fs/cgroup/freezer/sub2/cgroup.procs\fP
+.EE
+.in
+.PP
+We then create another child cgroup in the
+.I freezer
+hierarchy and put the shell into that cgroup:
+.PP
 .in +4n
+.EX
 # \fBmkdir \-p /sys/fs/cgroup/freezer/sub\fP
 # \fBecho $$\fP                      # Show PID of this shell
 30655
-# \fBsh \-c 'echo 30655 > /sys/fs/cgroup/sub'\fP
+# \fBecho 30655 > /sys/fs/cgroup/freezer/sub/cgroup.procs\fP
 # \fBcat /proc/self/cgroup | grep freezer\fP
 7:freezer:/sub
+.EE
 .in
-.fi
-
+.PP
 Next, we use
 .BR unshare (1)
 to create a process running a new shell in new cgroup and mount namespaces:
-
-.nf
+.PP
+.EX
 .in +4n
 # \fBunshare \-Cm bash\fP
 .in
-.fi
-
+.EE
+.PP
 We then inspect the
 .IR /proc/[pid]/cgroup
 files of, respectively, the new shell process started by the
 .BR unshare (1)
 command, a process that is in the original cgroup namespace
 .RI ( init ,
-with PID 1), and a process in a sibling cgroup:
-
-.nf
+with PID 1), and the process in the sibling cgroup
+.RI ( sub2 ):
+.PP
+.EX
 .in +4n
 $ \fBcat /proc/self/cgroup | grep freezer\fP
 7:freezer:/
@@ -106,20 +125,36 @@ $ \fBcat /proc/1/cgroup | grep freezer\fP
 $ \fBcat /proc/20124/cgroup | grep freezer\fP
 7:freezer:/../sub2
 .in
-.fi
-
+.EE
+.PP
+From the output of the first command,
+we see that the freezer cgroup membership of the new shell
+(which is in the same cgroup as the initial shell)
+is shown defined relative to the freezer cgroup root directory
+that was established when the new cgroup namespace was created.
+(In absolute terms,
+the new shell is in the
+.I /sub
+freezer cgroup,
+and the root directory of the freezer cgroup hierarchy
+in the new cgroup namespace is also
+.IR /sub .
+Thus, the new shell's cgroup membership is displayed as \(aq/\(aq.)
+.PP
 However, when we look in
 .IR /proc/self/mountinfo
 we see the following anomaly:
-
-.nf
+.PP
+.EX
 .in +4n
 # \fBcat /proc/self/mountinfo | grep freezer\fP
 155 145 0:32 /.. /sys/fs/cgroup/freezer ...
 .in
-.fi
-
-The fourth field of this file should show the
+.EE
+.PP
+The fourth field of this line
+.RI ( /.. )
+should show the
 directory in the cgroup filesystem which forms the root of this mount.
 Since by the definition of cgroup namespaces, the process's current
 freezer cgroup directory became its root freezer cgroup directory,
@@ -130,8 +165,8 @@ filesystem corresponding to our initial shell process's cgroup namespace
 .IR sub ).
 We need to remount the freezer cgroup filesystem
 inside this cgroup namespace, after which we see the expected results:
-
-.nf
+.PP
+.EX
 .in +4n
 # \fBmount \-\-make\-rslave /\fP     # Don't propagate mount events
                             # to other namespaces
@@ -140,15 +175,16 @@ inside this cgroup namespace, after which we see the expected results:
 # \fBcat /proc/self/mountinfo | grep freezer\fP
 155 145 0:32 / /sys/fs/cgroup/freezer rw,relatime ...
 .in
-.fi
-
+.EE
+.\"
+.SH CONFORMING TO
+Namespaces are a Linux-specific feature.
+.SH NOTES
 Use of cgroup namespaces requires a kernel that is configured with the
 .B CONFIG_CGROUPS
 option.
-.\"
-.SH NOTES
-Among the purposes served by the
-virtualization provided by cgroup namespaces are the following:
+.PP
+The virtualization provided by cgroup namespaces serves a number of purposes:
 .IP * 2
 It prevents information leaks whereby cgroup directory paths outside of
 a container would otherwise be visible to processes in the container.
@@ -217,8 +253,6 @@ Combined with correct enforcement of hierarchical limits,
 this prevents process
 .I X
 from escaping the limits imposed by ancestor cgroups.
-.SH CONFORMING TO
-Namespaces are a Linux-specific feature.
 .SH SEE ALSO
 .BR unshare (1),
 .BR clone (2),