{
    "content": [
        {
            "type": "text",
            "text": "# cgroups (man)\n\n## NAME\n\ncgroups - Linux control groups\n\n## DESCRIPTION\n\nControl  groups,  usually  referred  to  as  cgroups,  are a Linux kernel feature which allow\nprocesses to be organized into hierarchical groups whose usage of various types of  resources\ncan  then  be  limited  and  monitored.   The kernel's cgroup interface is provided through a\npseudo-filesystem called cgroupfs.  Grouping is implemented in the core cgroup  kernel  code,\nwhile  resource  tracking and limits are implemented in a set of per-resource-type subsystems\n(memory, CPU, and so on).\n\n## TLDR\n\n> Cgroups aka control groups is a Linux kernel feature for limiting, measuring, and controlling resource usage by processes.\n\n- View documentation for `cgclassify`:\n  `tldr cgclassify`\n- View documentation for `cgcreate`:\n  `tldr cgcreate`\n- View documentation for `cgexec`:\n  `tldr cgexec`\n\n*Source: tldr-pages*\n\n## Sections\n\n- **NAME**\n- **DESCRIPTION** (2 subsections)\n- **CGROUPS VERSION 1** (8 subsections)\n- **CGROUPS VERSION 2** (11 subsections)\n- **CGROUPS VERSION 2 THREAD MODE** (7 subsections)\n- **ERRORS**\n- **NOTES** (2 subsections)\n- **SEE ALSO**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "cgroups",
        "section": "",
        "mode": "man",
        "summary": "cgroups - Linux control groups",
        "synopsis": null,
        "tldr_summary": "Cgroups aka control groups is a Linux kernel feature for limiting, measuring, and controlling resource usage by processes.",
        "tldr_examples": [
            {
                "description": "View documentation for `cgclassify`",
                "command": "tldr cgclassify"
            },
            {
                "description": "View documentation for `cgcreate`",
                "command": "tldr cgcreate"
            },
            {
                "description": "View documentation for `cgexec`",
                "command": "tldr cgexec"
            }
        ],
        "tldr_source": "official",
        "flags": [],
        "examples": [],
        "see_also": [
            {
                "name": "prlimit",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/prlimit/1/json"
            },
            {
                "name": "systemd",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/systemd/1/json"
            },
            {
                "name": "systemd-cgls",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/systemd-cgls/1/json"
            },
            {
                "name": "systemd-cgtop",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/systemd-cgtop/1/json"
            },
            {
                "name": "clone",
                "section": "2",
                "url": "https://www.chedong.com/phpMan.php/man/clone/2/json"
            },
            {
                "name": "ioprioset",
                "section": "2",
                "url": "https://www.chedong.com/phpMan.php/man/ioprioset/2/json"
            },
            {
                "name": "perfeventopen",
                "section": "2",
                "url": "https://www.chedong.com/phpMan.php/man/perfeventopen/2/json"
            },
            {
                "name": "setrlimit",
                "section": "2",
                "url": "https://www.chedong.com/phpMan.php/man/setrlimit/2/json"
            },
            {
                "name": "cgroupnamespaces",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/cgroupnamespaces/7/json"
            },
            {
                "name": "cpuset",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/cpuset/7/json"
            },
            {
                "name": "namespaces",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/namespaces/7/json"
            },
            {
                "name": "sched",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/sched/7/json"
            },
            {
                "name": "usernamespaces",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/usernamespaces/7/json"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 7,
                "subsections": [
                    {
                        "name": "Terminology",
                        "lines": 16
                    },
                    {
                        "name": "Cgroups version 1 and version 2",
                        "lines": 25
                    }
                ]
            },
            {
                "name": "CGROUPS VERSION 1",
                "lines": 13,
                "subsections": [
                    {
                        "name": "Tasks (threads) versus processes",
                        "lines": 12
                    },
                    {
                        "name": "Mounting v1 controllers",
                        "lines": 35
                    },
                    {
                        "name": "Unmounting v1 controllers",
                        "lines": 11
                    },
                    {
                        "name": "Cgroups version 1 controllers",
                        "lines": 117
                    },
                    {
                        "name": "Creating cgroups and moving processes",
                        "lines": 32
                    },
                    {
                        "name": "Removing cgroups",
                        "lines": 4
                    },
                    {
                        "name": "Cgroups v1 release notification",
                        "lines": 26
                    },
                    {
                        "name": "Cgroup v1 named hierarchies",
                        "lines": 12
                    }
                ]
            },
            {
                "name": "CGROUPS VERSION 2",
                "lines": 29,
                "subsections": [
                    {
                        "name": "Cgroups v2 unified hierarchy",
                        "lines": 24
                    },
                    {
                        "name": "Cgroups v2 mount options",
                        "lines": 13
                    },
                    {
                        "name": "Cgroups v2 controllers",
                        "lines": 38
                    },
                    {
                        "name": "Cgroups v2 subtree control",
                        "lines": 29
                    },
                    {
                        "name": "Cgroups v2 \"no internal processes\" rule",
                        "lines": 24
                    },
                    {
                        "name": "Cgroups v2 cgroup.events file",
                        "lines": 22
                    },
                    {
                        "name": "Cgroup v2 release notification",
                        "lines": 17
                    },
                    {
                        "name": "Cgroups v2 cgroup.stat file",
                        "lines": 18
                    },
                    {
                        "name": "Limiting the number of descendant cgroups",
                        "lines": 80
                    },
                    {
                        "name": "Cgroups v2 delegation: nsdelegate and cgroup namespaces",
                        "lines": 55
                    },
                    {
                        "name": "Cgroup delegation containment rules",
                        "lines": 28
                    }
                ]
            },
            {
                "name": "CGROUPS VERSION 2 THREAD MODE",
                "lines": 59,
                "subsections": [
                    {
                        "name": "Threaded versus domain controllers",
                        "lines": 12
                    },
                    {
                        "name": "Creating a threaded subtree",
                        "lines": 41
                    },
                    {
                        "name": "Using a threaded subtree",
                        "lines": 41
                    },
                    {
                        "name": "Rules for writing to cgroup.type and creating threaded subtrees",
                        "lines": 30
                    },
                    {
                        "name": "The \"domain threaded\" cgroup type",
                        "lines": 19
                    },
                    {
                        "name": "Exceptions for the root cgroup",
                        "lines": 17
                    },
                    {
                        "name": "The cgroups v2 \"cpu\" controller and realtime threads",
                        "lines": 11
                    }
                ]
            },
            {
                "name": "ERRORS",
                "lines": 5,
                "subsections": []
            },
            {
                "name": "NOTES",
                "lines": 6,
                "subsections": [
                    {
                        "name": "/proc files",
                        "lines": 66
                    },
                    {
                        "name": "/sys/kernel/cgroup files",
                        "lines": 33
                    }
                ]
            },
            {
                "name": "SEE ALSO",
                "lines": 7,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "cgroups - Linux control groups\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "Control  groups,  usually  referred  to  as  cgroups,  are a Linux kernel feature which allow\nprocesses to be organized into hierarchical groups whose usage of various types of  resources\ncan  then  be  limited  and  monitored.   The kernel's cgroup interface is provided through a\npseudo-filesystem called cgroupfs.  Grouping is implemented in the core cgroup  kernel  code,\nwhile  resource  tracking and limits are implemented in a set of per-resource-type subsystems\n(memory, CPU, and so on).\n",
                "subsections": [
                    {
                        "name": "Terminology",
                        "content": "A cgroup is a collection of processes that are bound to a set of limits or parameters defined\nvia the cgroup filesystem.\n\nA subsystem is a kernel component that modifies the behavior of the processes  in  a  cgroup.\nVarious  subsystems  have  been implemented, making it possible to do things such as limiting\nthe amount of CPU time and memory available to a cgroup, accounting for the CPU time used  by\na  cgroup,  and freezing and resuming execution of the processes in a cgroup.  Subsystems are\nsometimes also known as resource controllers (or simply, controllers).\n\nThe cgroups for a controller are arranged in a hierarchy.  This hierarchy is defined by  cre‐\nating,  removing, and renaming subdirectories within the cgroup filesystem.  At each level of\nthe hierarchy, attributes (e.g., limits) can be defined.  The limits, control, and accounting\nprovided by cgroups generally have effect throughout the subhierarchy underneath  the  cgroup\nwhere  the  attributes  are  defined.   Thus, for example, the limits placed on a cgroup at a\nhigher level in the hierarchy cannot be exceeded by descendant cgroups.\n"
                    },
                    {
                        "name": "Cgroups version 1 and version 2",
                        "content": "The initial release of the cgroups implementation was in Linux 2.6.24.   Over  time,  various\ncgroup  controllers  have  been  added to allow the management of various types of resources.\nHowever, the development of these controllers was largely uncoordinated, with the result that\nmany inconsistencies arose between controllers and management of the cgroup  hierarchies  be‐\ncame  rather  complex.   A  longer  description  of these problems can be found in the kernel\nsource file Documentation/admin-guide/cgroup-v2.rst (or Documentation/cgroup-v2.txt in  Linux\n4.17 and earlier).\n\nBecause of the problems with the initial cgroups implementation (cgroups version 1), starting\nin Linux 3.10, work began on a new, orthogonal implementation to remedy these problems.  Ini‐\ntially marked experimental, and hidden behind the -o DEVELsanebehavior mount option, the\nnew  version  (cgroups version 2) was eventually made official with the release of Linux 4.5.\nDifferences  between  the  two  versions  are  described  in  the  text  below.    The   file\ncgroup.sanebehavior,  present  in cgroups v1, is a relic of this mount option.  The file al‐\nways reports \"0\" and is only retained for backward compatibility.\n\nAlthough cgroups v2 is intended as a replacement for cgroups v1, the older  system  continues\nto  exist  (and  for compatibility reasons is unlikely to be removed).  Currently, cgroups v2\nimplements only a subset of the controllers available in cgroups v1.  The two systems are im‐\nplemented so that both v1 controllers and v2 controllers can be mounted on the  same  system.\nThus,  for  example, it is possible to use those controllers that are supported under version\n2, while also using version 1 controllers where version 2 does not  yet  support  those  con‐\ntrollers.  The only restriction here is that a controller can't be simultaneously employed in\nboth a cgroups v1 hierarchy and in the cgroups v2 hierarchy.\n"
                    }
                ]
            },
            "CGROUPS VERSION 1": {
                "content": "Under  cgroups  v1,  each controller may be mounted against a separate cgroup filesystem that\nprovides its own hierarchical organization of the processes on the system.  It is also possi‐\nble to comount multiple (or even all) cgroups v1 controllers against the same cgroup filesys‐\ntem, meaning that the comounted controllers manage  the  same  hierarchical  organization  of\nprocesses.\n\nFor  each  mounted  hierarchy,  the directory tree mirrors the control group hierarchy.  Each\ncontrol group is represented by a directory, with each of its child  control  cgroups  repre‐\nsented  as  a  child  directory.   For instance, /user/joe/1.session represents control group\n1.session, which is a child of cgroup joe, which is a child of /user.  Under each cgroup  di‐\nrectory  is  a set of files which can be read or written to, reflecting resource limits and a\nfew general cgroup properties.\n",
                "subsections": [
                    {
                        "name": "Tasks (threads) versus processes",
                        "content": "In cgroups v1, a distinction is drawn between processes and tasks.  In this view,  a  process\ncan  consist  of multiple tasks (more commonly called threads, from a user-space perspective,\nand called such in the remainder of this man page).  In cgroups v1, it is possible  to  inde‐\npendently manipulate the cgroup memberships of the threads in a process.\n\nThe  cgroups  v1  ability  to  split threads across different cgroups caused problems in some\ncases.  For example, it made no sense for the memory controller, since all of the threads  of\na  process  share a single address space.  Because of these problems, the ability to indepen‐\ndently manipulate the cgroup memberships of the threads in a process was removed in the  ini‐\ntial  cgroups  v2  implementation,  and subsequently restored in a more limited form (see the\ndiscussion of \"thread mode\" below).\n"
                    },
                    {
                        "name": "Mounting v1 controllers",
                        "content": "The use of cgroups requires a kernel built with the CONFIGCGROUP option.  In addition,  each\nof the v1 controllers has an associated configuration option that must be set in order to em‐\nploy that controller.\n\nIn  order  to use a v1 controller, it must be mounted against a cgroup filesystem.  The usual\nplace for such mounts is under a tmpfs(5) filesystem mounted at  /sys/fs/cgroup.   Thus,  one\nmight mount the cpu controller as follows:\n\nmount -t cgroup -o cpu none /sys/fs/cgroup/cpu\n\nIt is possible to comount multiple controllers against the same hierarchy.  For example, here\nthe cpu and cpuacct controllers are comounted against a single hierarchy:\n\nmount -t cgroup -o cpu,cpuacct none /sys/fs/cgroup/cpu,cpuacct\n\nComounting controllers has the effect that a process is in the same cgroup for all of the co‐\nmounted  controllers.  Separately mounting controllers allows a process to be in cgroup /foo1\nfor one controller while being in /foo2/foo3 for another.\n\nIt is possible to comount all v1 controllers against the same hierarchy:\n\nmount -t cgroup -o all cgroup /sys/fs/cgroup\n\n(One can achieve the same result by omitting -o all, since it  is  the  default  if  no  con‐\ntrollers are explicitly specified.)\n\nIt is not possible to mount the same controller against multiple cgroup hierarchies.  For ex‐\nample,  it  is not possible to mount both the cpu and cpuacct controllers against one hierar‐\nchy, and to mount the cpu controller alone against another hierarchy.  It is possible to cre‐\nate multiple mount with exactly the same set of comounted controllers.  However, in this case\nall that results is multiple mount points providing a view of the same hierarchy.\n\nNote that on many systems, the v1 controllers are automatically mounted under /sys/fs/cgroup;\nin particular, systemd(1) automatically creates such mounts.\n"
                    },
                    {
                        "name": "Unmounting v1 controllers",
                        "content": "A mounted cgroup filesystem can be unmounted using the umount(8) command, as in the following\nexample:\n\numount /sys/fs/cgroup/pids\n\nBut note well: a cgroup filesystem is unmounted only if it is not busy, that is,  it  has  no\nchild cgroups.  If this is not the case, then the only effect of the umount(8) is to make the\nmount invisible.  Thus, to ensure that the mount is really removed, one must first remove all\nchild cgroups, which in turn can be done only after all member processes have been moved from\nthose cgroups to the root cgroup.\n"
                    },
                    {
                        "name": "Cgroups version 1 controllers",
                        "content": "Each  of  the  cgroups  version  1  controllers  is governed by a kernel configuration option\n(listed below).  Additionally, the availability of the cgroups feature  is  governed  by  the\nCONFIGCGROUPS kernel configuration option.\n\ncpu (since Linux 2.6.24; CONFIGCGROUPSCHED)\nCgroups  can  be  guaranteed  a  minimum number of \"CPU shares\" when a system is busy.\nThis does not limit a cgroup's CPU usage if the CPUs are not busy.  For further infor‐\nmation,  see  Documentation/scheduler/sched-design-CFS.rst  (or   Documentation/sched‐\nuler/sched-design-CFS.txt in Linux 5.2 and earlier).\n\nIn Linux 3.2, this controller was extended to provide CPU \"bandwidth\" control.  If the\nkernel  is  configured  with  CONFIGCFSBANDWIDTH, then within each scheduling period\n(defined via a file in the cgroup directory), it is possible to define an upper  limit\non the CPU time allocated to the processes in a cgroup.  This upper limit applies even\nif there is no other competition for the CPU.  Further information can be found in the\nkernel  source  file  Documentation/scheduler/sched-bwc.rst  (or  Documentation/sched‐\nuler/sched-bwc.txt in Linux 5.2 and earlier).\n\ncpuacct (since Linux 2.6.24; CONFIGCGROUPCPUACCT)\nThis provides accounting for CPU usage by groups of processes.\n\nFurther  information  can  be  found  in  the  kernel  source  file  Documentation/ad‐\nmin-guide/cgroup-v1/cpuacct.rst  (or  Documentation/cgroup-v1/cpuacct.txt in Linux 5.2\nand earlier).\n\ncpuset (since Linux 2.6.24; CONFIGCPUSETS)\nThis cgroup can be used to bind the processes in a cgroup to a specified set  of  CPUs\nand NUMA nodes.\n\nFurther  information  can  be  found  in  the  kernel  source  file  Documentation/ad‐\nmin-guide/cgroup-v1/cpusets.rst (or Documentation/cgroup-v1/cpusets.txt in  Linux  5.2\nand earlier).\n\nmemory (since Linux 2.6.25; CONFIGMEMCG)\nThe  memory  controller supports reporting and limiting of process memory, kernel mem‐\nory, and swap used by cgroups.\n\nFurther  information  can  be  found  in  the  kernel  source  file  Documentation/ad‐\nmin-guide/cgroup-v1/memory.rst (or Documentation/cgroup-v1/memory.txt in Linux 5.2 and\nearlier).\n\ndevices (since Linux 2.6.26; CONFIGCGROUPDEVICE)\nThis  supports  controlling which processes may create (mknod) devices as well as open\nthem for reading or writing.  The policies may be specified as allow-lists  and  deny-\nlists.   Hierarchy  is  enforced, so new rules must not violate existing rules for the\ntarget or ancestor cgroups.\n\nFurther  information  can  be  found  in  the  kernel  source  file  Documentation/ad‐\nmin-guide/cgroup-v1/devices.rst  (or  Documentation/cgroup-v1/devices.txt in Linux 5.2\nand earlier).\n\nfreezer (since Linux 2.6.28; CONFIGCGROUPFREEZER)\nThe freezer cgroup can suspend and restore (resume) all processes in a cgroup.  Freez‐\ning a cgroup /A also causes its children,  for  example,  processes  in  /A/B,  to  be\nfrozen.\n\nFurther  information  can  be  found  in  the  kernel  source  file  Documentation/ad‐\nmin-guide/cgroup-v1/freezer-subsystem.rst (or  Documentation/cgroup-v1/freezer-subsys‐\ntem.txt in Linux 5.2 and earlier).\n\nnetcls (since Linux 2.6.29; CONFIGCGROUPNETCLASSID)\nThis  places  a  classid,  specified  for  the cgroup, on network packets created by a\ncgroup.  These classids can then be used in firewall rules, as well as used  to  shape\ntraffic  using tc(8).  This applies only to packets leaving the cgroup, not to traffic\narriving at the cgroup.\n\nFurther  information  can  be  found  in  the  kernel  source  file  Documentation/ad‐\nmin-guide/cgroup-v1/netcls.rst  (or  Documentation/cgroup-v1/netcls.txt in Linux 5.2\nand earlier).\n\nblkio (since Linux 2.6.33; CONFIGBLKCGROUP)\nThe blkio cgroup controls and limits access to specified block devices by applying  IO\ncontrol in the form of throttling and upper limits against leaf nodes and intermediate\nnodes in the storage hierarchy.\n\nTwo policies are available.  The first is a proportional-weight time-based division of\ndisk implemented with CFQ.  This is in effect for leaf nodes using CFQ.  The second is\na throttling policy which specifies upper I/O rate limits on a device.\n\nFurther  information  can  be  found  in  the  kernel  source  file  Documentation/ad‐\nmin-guide/cgroup-v1/blkio-controller.rst    (or     Documentation/cgroup-v1/blkio-con‐\ntroller.txt in Linux 5.2 and earlier).\n\nperfevent (since Linux 2.6.39; CONFIGCGROUPPERF)\nThis controller allows perf monitoring of the set of processes grouped in a cgroup.\n\nFurther information can be found in the kernel source files\n\nnetprio (since Linux 3.3; CONFIGCGROUPNETPRIO)\nThis allows priorities to be specified, per network interface, for cgroups.\n\nFurther  information  can  be  found  in  the  kernel  source  file  Documentation/ad‐\nmin-guide/cgroup-v1/netprio.rst (or Documentation/cgroup-v1/netprio.txt in Linux 5.2\nand earlier).\n\nhugetlb (since Linux 3.5; CONFIGCGROUPHUGETLB)\nThis supports limiting the use of huge pages by cgroups.\n\nFurther  information  can  be  found  in  the  kernel  source  file  Documentation/ad‐\nmin-guide/cgroup-v1/hugetlb.rst  (or  Documentation/cgroup-v1/hugetlb.txt in Linux 5.2\nand earlier).\n\npids (since Linux 4.3; CONFIGCGROUPPIDS)\nThis controller permits limiting the number of process that may be created in a cgroup\n(and its descendants).\n\nFurther  information  can  be  found  in  the  kernel  source  file  Documentation/ad‐\nmin-guide/cgroup-v1/pids.rst  (or  Documentation/cgroup-v1/pids.txt  in  Linux 5.2 and\nearlier).\n\nrdma (since Linux 4.11; CONFIGCGROUPRDMA)\nThe RDMA controller permits limiting the use of RDMA/IB-specific resources per cgroup.\n\nFurther  information  can  be  found  in  the  kernel  source  file  Documentation/ad‐\nmin-guide/cgroup-v1/rdma.rst  (or  Documentation/cgroup-v1/rdma.txt  in  Linux 5.2 and\nearlier).\n"
                    },
                    {
                        "name": "Creating cgroups and moving processes",
                        "content": "A cgroup filesystem initially contains a single root cgroup, '/', which all processes  belong\nto.  A new cgroup is created by creating a directory in the cgroup filesystem:\n\nmkdir /sys/fs/cgroup/cpu/cg1\n\nThis creates a new empty cgroup.\n\nA process may be moved to this cgroup by writing its PID into the cgroup's cgroup.procs file:\n\necho $$ > /sys/fs/cgroup/cpu/cg1/cgroup.procs\n\nOnly one PID at a time should be written to this file.\n\nWriting the value 0 to a cgroup.procs file causes the writing process to be moved to the cor‐\nresponding cgroup.\n\nWhen  writing  a PID into the cgroup.procs, all threads in the process are moved into the new\ncgroup at once.\n\nWithin a hierarchy, a process can be a member of exactly one cgroup.  Writing a process's PID\nto a cgroup.procs file automatically removes it from the cgroup of which it was previously  a\nmember.\n\nThe  cgroup.procs  file  can  be read to obtain a list of the processes that are members of a\ncgroup.  The returned list of PIDs is not guaranteed to be in order.  Nor is it guaranteed to\nbe free of duplicates.  (For example, a PID may be recycled while reading from the list.)\n\nIn cgroups v1, an individual thread can be moved to another cgroup by writing its  thread  ID\n(i.e., the kernel thread ID returned by clone(2) and gettid(2)) to the tasks file in a cgroup\ndirectory.   This  file  can  be  read to discover the set of threads that are members of the\ncgroup.\n"
                    },
                    {
                        "name": "Removing cgroups",
                        "content": "To remove a cgroup, it must first have no child cgroups and contain no (nonzombie) processes.\nSo long as that is the case, one can simply  remove  the  corresponding  directory  pathname.\nNote that files in a cgroup directory cannot and need not be removed.\n"
                    },
                    {
                        "name": "Cgroups v1 release notification",
                        "content": "Two  files  can  be used to determine whether the kernel provides notifications when a cgroup\nbecomes empty.  A cgroup is considered to be empty when it contains no child cgroups  and  no\nmember processes.\n\nA  special file in the root directory of each cgroup hierarchy, releaseagent, can be used to\nregister the pathname of a program that may be invoked when a cgroup in the hierarchy becomes\nempty.  The pathname of the newly empty cgroup (relative to the cgroup mount point)  is  pro‐\nvided  as  the sole command-line argument when the releaseagent program is invoked.  The re‐\nleaseagent program might remove the cgroup  directory,  or  perhaps  repopulate  it  with  a\nprocess.\n\nThe  default  value  of the releaseagent file is empty, meaning that no release agent is in‐\nvoked.\n\nThe content of the releaseagent file can also be specified  via  a  mount  option  when  the\ncgroup filesystem is mounted:\n\nmount -o releaseagent=pathname ...\n\nWhether or not the releaseagent program is invoked when a particular cgroup becomes empty is\ndetermined  by the value in the notifyonrelease file in the corresponding cgroup directory.\nIf this file contains the value 0, then the releaseagent program is not invoked.  If it con‐\ntains the value 1, the releaseagent program is invoked.  The default value for this file  in\nthe  root  cgroup  is 0.  At the time when a new cgroup is created, the value in this file is\ninherited from the corresponding file in the parent cgroup.\n"
                    },
                    {
                        "name": "Cgroup v1 named hierarchies",
                        "content": "In cgroups v1, it is possible to mount a cgroup hierarchy that has no attached controllers:\n\nmount -t cgroup -o none,name=somename none /some/mount/point\n\nMultiple instances of such hierarchies can be mounted; each  hierarchy  must  have  a  unique\nname.   The  only  purpose of such hierarchies is to track processes.  (See the discussion of\nrelease notification below.)  An example of this is the name=systemd cgroup hierarchy that is\nused by systemd(1) to track services and user sessions.\n\nSince Linux 5.0, the cgroupnov1 kernel boot option (described below) can be used to disable\ncgroup v1 named hierarchies, by specifying cgroupnov1=named.\n"
                    }
                ]
            },
            "CGROUPS VERSION 2": {
                "content": "In cgroups v2, all mounted controllers reside in a single unified hierarchy.  While  (differ‐\nent)  controllers  may  be  simultaneously mounted under the v1 and v2 hierarchies, it is not\npossible to mount the same controller simultaneously under both the v1  and  the  v2  hierar‐\nchies.\n\nThe new behaviors in cgroups v2 are summarized here, and in some cases elaborated in the fol‐\nlowing subsections.\n\n•  Cgroups v2 provides a unified hierarchy against which all controllers are mounted.\n\n•  \"Internal\"  processes are not permitted.  With the exception of the root cgroup, processes\nmay reside only in leaf nodes (cgroups that do not themselves contain child cgroups).  The\ndetails are somewhat more subtle than this, and are described below.\n\n•  Active cgroups must be specified via the files cgroup.controllers and  cgroup.subtreecon‐\ntrol.\n\n•  The  tasks file has been removed.  In addition, the cgroup.clonechildren file that is em‐\nployed by the cpuset controller has been removed.\n\n•  An improved mechanism for notification of empty cgroups is provided by  the  cgroup.events\nfile.\n\nFor  more  changes, see the Documentation/admin-guide/cgroup-v2.rst file in the kernel source\n(or Documentation/cgroup-v2.txt in Linux 4.17 and earlier).\n\nSome of the new behaviors listed above saw subsequent modification with the addition in Linux\n4.14 of \"thread mode\" (described below).\n",
                "subsections": [
                    {
                        "name": "Cgroups v2 unified hierarchy",
                        "content": "In cgroups v1, the ability to mount different controllers against different  hierarchies  was\nintended  to allow great flexibility for application design.  In practice, though, the flexi‐\nbility turned out to be less useful than  expected,  and  in  many  cases  added  complexity.\nTherefore,  in  cgroups v2, all available controllers are mounted against a single hierarchy.\nThe available controllers are automatically mounted, meaning that it  is  not  necessary  (or\npossible)  to  specify the controllers when mounting the cgroup v2 filesystem using a command\nsuch as the following:\n\nmount -t cgroup2 none /mnt/cgroup2\n\nA cgroup v2 controller is available only if it is not currently in use via a mount against  a\ncgroup  v1  hierarchy.   Or, to put things another way, it is not possible to employ the same\ncontroller against both a v1 hierarchy and the unified v2 hierarchy.  This means that it  may\nbe  necessary first to unmount a v1 controller (as described above) before that controller is\navailable in v2.  Since systemd(1) makes heavy use of some v1 controllers by default, it  can\nin  some  cases  be  simpler to boot the system with selected v1 controllers disabled.  To do\nthis, specify the cgroupnov1=list option on the kernel boot command line; list is a  comma-\nseparated  list of the names of the controllers to disable, or the word all to disable all v1\ncontrollers.  (This situation is correctly handled by systemd(1), which falls back to operat‐\ning without the specified controllers.)\n\nNote that on many modern systems, systemd(1) automatically mounts the cgroup2  filesystem  at\n/sys/fs/cgroup/unified during the boot process.\n"
                    },
                    {
                        "name": "Cgroups v2 mount options",
                        "content": "The following options (mount -o) can be specified when mounting the group v2 filesystem:\n\nnsdelegate (since Linux 4.15)\nTreat cgroup namespaces as delegation boundaries.  For details, see below.\n\nmemorylocalevents (since Linux 5.2)\nThe  memory.events  should show statistics only for the cgroup itself, and not for any\ndescendant cgroups.  This was the behavior before Linux 5.2.  Starting in  Linux  5.2,\nthe default behavior is to include statistics for descendant cgroups in memory.events,\nand  this  mount  option can be used to revert to the legacy behavior.  This option is\nsystem wide and can be set on mount or modified through remount only from the  initial\nmount namespace; it is silently ignored in noninitial namespaces.\n"
                    },
                    {
                        "name": "Cgroups v2 controllers",
                        "content": "The   following   controllers,   documented  in  the  kernel  source  file  Documentation/ad‐\nmin-guide/cgroup-v2.rst (or Documentation/cgroup-v2.txt in Linux 4.17 and earlier), are  sup‐\nported in cgroups version 2:\n\ncpu (since Linux 4.15)\nThis is the successor to the version 1 cpu and cpuacct controllers.\n\ncpuset (since Linux 5.0)\nThis is the successor of the version 1 cpuset controller.\n\nfreezer (since Linux 5.2)\nThis is the successor of the version 1 freezer controller.\n\nhugetlb (since Linux 5.6)\nThis is the successor of the version 1 hugetlb controller.\n\nio (since Linux 4.5)\nThis is the successor of the version 1 blkio controller.\n\nmemory (since Linux 4.5)\nThis is the successor of the version 1 memory controller.\n\nperfevent (since Linux 4.11)\nThis is the same as the version 1 perfevent controller.\n\npids (since Linux 4.5)\nThis is the same as the version 1 pids controller.\n\nrdma (since Linux 4.11)\nThis is the same as the version 1 rdma controller.\n\nThere is no direct equivalent of the netcls and netprio controllers from cgroups version 1.\nInstead,  support  has been added to iptables(8) to allow eBPF filters that hook on cgroup v2\npathnames to make decisions about network traffic on a per-cgroup basis.\n\nThe v2 devices controller provides no interface files; instead, device control  is  gated  by\nattaching an eBPF (BPFCGROUPDEVICE) program to a v2 cgroup.\n"
                    },
                    {
                        "name": "Cgroups v2 subtree control",
                        "content": "Each cgroup in the v2 hierarchy contains the following two files:\n\ncgroup.controllers\nThis  read-only  file  exposes  a  list  of the controllers that are available in this\ncgroup.  The contents of this file match the contents  of  the  cgroup.subtreecontrol\nfile in the parent cgroup.\n\ncgroup.subtreecontrol\nThis  is  a  list  of controllers that are active (enabled) in the cgroup.  The set of\ncontrollers in this file is a subset of the set  in  the  cgroup.controllers  of  this\ncgroup.   The  set  of  active controllers is modified by writing strings to this file\ncontaining space-delimited controller names, each preceded by '+' (to  enable  a  con‐\ntroller) or '-' (to disable a controller), as in the following example:\n\necho '+pids -memory' > x/y/cgroup.subtreecontrol\n\nAn  attempt  to enable a controller that is not present in cgroup.controllers leads to\nan ENOENT error when writing to the cgroup.subtreecontrol file.\n\nBecause the list of controllers in cgroup.subtreecontrol is a subset  of  those  cgroup.con‐\ntrollers, a controller that has been disabled in one cgroup in the hierarchy can never be re-\nenabled in the subtree below that cgroup.\n\nA  cgroup's  cgroup.subtreecontrol file determines the set of controllers that are exercised\nin the child cgroups.  When a controller (e.g., pids) is present in  the  cgroup.subtreecon‐\ntrol  file  of  a  parent  cgroup,  then  the corresponding controller-interface files (e.g.,\npids.max) are automatically created in the children of that cgroup and can be used  to  exert\nresource control in the child cgroups.\n"
                    },
                    {
                        "name": "Cgroups v2 \"no internal processes\" rule",
                        "content": "Cgroups  v2  enforces  a so-called \"no internal processes\" rule.  Roughly speaking, this rule\nmeans that, with the exception of the root cgroup, processes may reside only  in  leaf  nodes\n(cgroups  that  do not themselves contain child cgroups).  This avoids the need to decide how\nto partition resources between processes which are members of cgroup A and processes in child\ncgroups of A.\n\nFor instance, if cgroup /cg1/cg2 exists, then a process may reside in /cg1/cg2,  but  not  in\n/cg1.   This  is  to  avoid  an ambiguity in cgroups v1 with respect to the delegation of re‐\nsources between processes in /cg1 and its child cgroups.  The recommended approach in cgroups\nv2 is to create a subdirectory called leaf  for  any  nonleaf  cgroup  which  should  contain\nprocesses,  but no child cgroups.  Thus, processes which previously would have gone into /cg1\nwould now go into /cg1/leaf.  This has the advantage of making explicit the relationship  be‐\ntween processes in /cg1/leaf and /cg1's other children.\n\nThe  \"no  internal processes\" rule is in fact more subtle than stated above.  More precisely,\nthe rule is that a (nonroot) cgroup can't both (1) have member processes, and (2)  distribute\nresources  into child cgroups—that is, have a nonempty cgroup.subtreecontrol file.  Thus, it\nis possible for a cgroup to have both member processes and child  cgroups,  but  before  con‐\ntrollers can be enabled for that cgroup, the member processes must be moved out of the cgroup\n(e.g., perhaps into the child cgroups).\n\nWith  the Linux 4.14 addition of \"thread mode\" (described below), the \"no internal processes\"\nrule has been relaxed in some cases.\n"
                    },
                    {
                        "name": "Cgroups v2 cgroup.events file",
                        "content": "Each nonroot cgroup in the v2 hierarchy contains a read-only file, cgroup.events, whose  con‐\ntents  are key-value pairs (delimited by newline characters, with the key and value separated\nby spaces) providing state information about the cgroup:\n\n$ cat mygrp/cgroup.events\npopulated 1\nfrozen 0\n\nThe following keys may appear in this file:\n\npopulated\nThe value of this key is either 1, if this cgroup or any of its descendants has member\nprocesses, or otherwise 0.\n\nfrozen (since Linux 5.2)\nThe value of this key is 1 if this cgroup is currently frozen, or 0 if it is not.\n\nThe cgroup.events file can be monitored, in order to receive notification when the  value  of\none  of  its  keys  changes.   Such  monitoring  can be done using inotify(7), which notifies\nchanges as INMODIFY events, or poll(2), which notifies changes by returning the POLLPRI  and\nPOLLERR bits in the revents field.\n"
                    },
                    {
                        "name": "Cgroup v2 release notification",
                        "content": "Cgroups  v2  provides a new mechanism for obtaining notification when a cgroup becomes empty.\nThe cgroups v1 releaseagent and notifyonrelease files are removed,  and  replaced  by  the\npopulated  key  in the cgroup.events file.  This key either has the value 0, meaning that the\ncgroup (and its descendants) contain no (nonzombie) member processes, or 1, meaning that  the\ncgroup (or one of its descendants) contains member processes.\n\nThe  cgroups  v2  release-notification  mechanism  offers  the  following advantages over the\ncgroups v1 releaseagent mechanism:\n\n•  It  allows  for  cheaper  notification,  since  a  single  process  can  monitor  multiple\ncgroup.events files (using the techniques described earlier).  By contrast, the cgroups v1\nmechanism requires the expense of creating a process for each notification.\n\n•  Notification  for different cgroup subhierarchies can be delegated to different processes.\nBy contrast, the cgroups v1 mechanism allows only one release agent for an entire  hierar‐\nchy.\n"
                    },
                    {
                        "name": "Cgroups v2 cgroup.stat file",
                        "content": "Each  cgroup  in  the v2 hierarchy contains a read-only cgroup.stat file (first introduced in\nLinux 4.14) that consists of lines containing key-value pairs.  The following keys  currently\nappear in this file:\n\nnrdescendants\nThis  is the total number of visible (i.e., living) descendant cgroups underneath this\ncgroup.\n\nnrdyingdescendants\nThis is the total number of dying descendant cgroups underneath this cgroup.  A cgroup\nenters the dying state after being deleted.  It remains in that state for an undefined\nperiod (which will depend on system load) while resources are freed before the  cgroup\nis  destroyed.   Note  that the presence of some cgroups in the dying state is normal,\nand is not indicative of any problem.\n\nA process can't be made a member of a dying  cgroup,  and  a  dying  cgroup  can't  be\nbrought back to life.\n"
                    },
                    {
                        "name": "Limiting the number of descendant cgroups",
                        "content": "Each  cgroup  in the v2 hierarchy contains the following files, which can be used to view and\nset limits on the number of descendant cgroups under that cgroup:\n\ncgroup.max.depth (since Linux 4.14)\nThis file defines a limit on the depth of nesting of descendant cgroups.  A value of 0\nin this file means that no descendant cgroups can be created.  An attempt to create  a\ndescendant  whose nesting level exceeds the limit fails (mkdir(2) fails with the error\nEAGAIN).\n\nWriting the string \"max\" to this file means that no limit  is  imposed.   The  default\nvalue in this file is \"max\".\n\ncgroup.max.descendants (since Linux 4.14)\nThis  file  defines  a limit on the number of live descendant cgroups that this cgroup\nmay have.  An attempt to create more descendants  than  allowed  by  the  limit  fails\n(mkdir(2) fails with the error EAGAIN).\n\nWriting  the  string  \"max\"  to this file means that no limit is imposed.  The default\nvalue in this file is \"max\".\n\nCGROUPS DELEGATION: DELEGATING A HIERARCHY TO A LESS PRIVILEGED USER\nIn the context of cgroups, delegation means passing management of some subtree of the  cgroup\nhierarchy  to a nonprivileged user.  Cgroups v1 provides support for delegation based on file\npermissions in the cgroup hierarchy but with less strict containment rules than v2 (as  noted\nbelow).   Cgroups  v2  supports delegation with containment by explicit design.  The focus of\nthe discussion in this section is on delegation in cgroups  v2,  with  some  differences  for\ncgroups v1 noted along the way.\n\nSome  terminology  is  required in order to describe delegation.  A delegater is a privileged\nuser (i.e., root) who owns a parent cgroup.  A delegatee is a nonprivileged user who will  be\ngranted the permissions needed to manage some subhierarchy under that parent cgroup, known as\nthe delegated subtree.\n\nTo perform delegation, the delegater makes certain directories and files writable by the del‐\negatee,  typically  by changing the ownership of the objects to be the user ID of the delega‐\ntee.  Assuming that we want to delegate the hierarchy rooted  at  (say)  /dlgtgrp  and  that\nthere  are  not  yet  any  child cgroups under that cgroup, the ownership of the following is\nchanged to the user ID of the delegatee:\n\n/dlgtgrp\nChanging the ownership of the root of the subtree means that any new  cgroups  created\nunder the subtree (and the files they contain) will also be owned by the delegatee.\n\n/dlgtgrp/cgroup.procs\nChanging  the  ownership of this file means that the delegatee can move processes into\nthe root of the delegated subtree.\n\n/dlgtgrp/cgroup.subtreecontrol (cgroups v2 only)\nChanging the ownership of this file means that the delegatee  can  enable  controllers\n(that  are  present  in /dlgtgrp/cgroup.controllers) in order to further redistribute\nresources at lower levels in the subtree.  (As an alternative to changing  the  owner‐\nship of this file, the delegater might instead add selected controllers to this file.)\n\n/dlgtgrp/cgroup.threads (cgroups v2 only)\nChanging  the ownership of this file is necessary if a threaded subtree is being dele‐\ngated (see the description of \"thread mode\", below).  This permits  the  delegatee  to\nwrite  thread  IDs  to the file.  (The ownership of this file can also be changed when\ndelegating a domain subtree, but currently this serves no purpose, since, as described\nbelow, it is not possible to move a thread  between  domain  cgroups  by  writing  its\nthread ID to the cgroup.threads file.)\n\nIn  cgroups  v1,  the corresponding file that should instead be delegated is the tasks\nfile.\n\nThe delegater should not change the ownership of  any  of  the  controller  interfaces  files\n(e.g.,  pids.max,  memory.high)  in dlgtgrp.  Those files are used from the next level above\nthe delegated subtree in order to distribute resources into the subtree,  and  the  delegatee\nshould  not  have  permission to change the resources that are distributed into the delegated\nsubtree.\n\nSee also the discussion of the /sys/kernel/cgroup/delegate  file  in  NOTES  for  information\nabout further delegatable files in cgroups v2.\n\nAfter  the  aforementioned  steps have been performed, the delegatee can create child cgroups\nwithin the delegated subtree (the cgroup subdirectories and the files they  contain  will  be\nowned  by  the  delegatee)  and  move processes between cgroups in the subtree.  If some con‐\ntrollers are present in dlgtgrp/cgroup.subtreecontrol, or the ownership of  that  file  was\npassed  to  the  delegatee,  the delegatee can also control the further redistribution of the\ncorresponding resources into the delegated subtree.\n"
                    },
                    {
                        "name": "Cgroups v2 delegation: nsdelegate and cgroup namespaces",
                        "content": "Starting with Linux 4.13, there is a second way to perform cgroup delegation in  the  cgroups\nv2  hierarchy.   This is done by mounting or remounting the cgroup v2 filesystem with the ns‐\ndelegate mount option.  For example, if the cgroup v2 filesystem has already been mounted, we\ncan remount it with the nsdelegate option as follows:\n\nmount -t cgroup2 -o remount,nsdelegate \\\nnone /sys/fs/cgroup/unified\n\nThe effect of this mount option is to cause cgroup namespaces to automatically become delega‐\ntion boundaries.  More specifically, the following restrictions apply  for  processes  inside\nthe cgroup namespace:\n\n•  Writes to controller interface files in the root directory of the namespace will fail with\nthe  error  EPERM.   Processes  inside the cgroup namespace can still write to delegatable\nfiles in the root directory of the cgroup namespace such as cgroup.procs  and  cgroup.sub‐\ntreecontrol, and can create subhierarchy underneath the root directory.\n\n•  Attempts  to  migrate  processes  across the namespace boundary are denied (with the error\nENOENT).  Processes inside the cgroup namespace can  still  (subject  to  the  containment\nrules  described  below)  move processes between cgroups within the subhierarchy under the\nnamespace root.\n\nThe ability to define cgroup namespaces as delegation boundaries makes cgroup namespaces more\nuseful.  To understand why, suppose that we already have one cgroup hierarchy that  has  been\ndelegated  to  a  nonprivileged user, cecilia, using the older delegation technique described\nabove.  Suppose further that cecilia wanted to further delegate a subhierarchy under the  ex‐\nisting  delegated  hierarchy.  (For example, the delegated hierarchy might be associated with\nan unprivileged container run by cecilia.)  Even if a cgroup namespace was employed,  because\nboth  hierarchies  are owned by the unprivileged user cecilia, the following illegitimate ac‐\ntions could be performed:\n\n•  A process in the inferior hierarchy could change the resource controller settings  in  the\nroot directory of that hierarchy.  (These resource controller settings are intended to al‐\nlow  control  to  be  exercised  from the parent cgroup; a process inside the child cgroup\nshould not be allowed to modify them.)\n\n•  A process inside the inferior hierarchy could move processes into and out of the  inferior\nhierarchy if the cgroups in the superior hierarchy were somehow visible.\n\nEmploying the nsdelegate mount option prevents both of these possibilities.\n\nThe nsdelegate mount option only has an effect when performed in the initial mount namespace;\nin other mount namespaces, the option is silently ignored.\n\nNote: On some systems, systemd(1) automatically mounts the cgroup v2 filesystem.  In order to\nexperiment  with  the nsdelegate operation, it may be useful to boot the kernel with the fol‐\nlowing command-line options:\n\ncgroupnov1=all systemd.legacysystemdcgroupcontroller\n\nThese options cause the kernel to boot with the cgroups v1 controllers disabled (meaning that\nthe controllers are available in the v2 hierarchy), and tells systemd(1) not to mount and use\nthe cgroup v2 hierarchy, so that the v2 hierarchy can be manually mounted  with  the  desired\noptions after boot-up.\n"
                    },
                    {
                        "name": "Cgroup delegation containment rules",
                        "content": "Some  delegation  containment  rules  ensure  that  the  delegatee can move processes between\ncgroups within the delegated subtree, but can't move processes  from  outside  the  delegated\nsubtree  into  the  subtree or vice versa.  A nonprivileged process (i.e., the delegatee) can\nwrite the PID of a \"target\" process into a cgroup.procs file only if all of the following are\ntrue:\n\n•  The writer has write permission on the cgroup.procs file in the destination cgroup.\n\n•  The writer has write permission on the cgroup.procs file in the nearest common ancestor of\nthe source and destination cgroups.  Note that in some cases, the nearest common  ancestor\nmay  be  the  source  or  destination cgroup itself.  This requirement is not enforced for\ncgroups v1 hierarchies, with the consequence that containment in v1 is less strict than in\nv2.  (For example, in cgroups v1 the user that owns two distinct delegated  subhierarchies\ncan move a process between the hierarchies.)\n\n•  If  the  cgroup  v2  filesystem was mounted with the nsdelegate option, the writer must be\nable to see the source and destination cgroups from its cgroup namespace.\n\n•  In cgroups v1: the effective UID of the writer (i.e., the delegatee) matches the real user\nID or the saved set-user-ID of the target process.  Before Linux  4.11,  this  requirement\nalso  applied  in  cgroups v2 (This was a historical requirement inherited from cgroups v1\nthat was later deemed unnecessary, since  the  other  rules  suffice  for  containment  in\ncgroups v2.)\n\nNote:  one consequence of these delegation containment rules is that the unprivileged delega‐\ntee can't place the first process into the delegated subtree;  instead,  the  delegater  must\nplace the first process (a process owned by the delegatee) into the delegated subtree.\n"
                    }
                ]
            },
            "CGROUPS VERSION 2 THREAD MODE": {
                "content": "Among the restrictions imposed by cgroups v2 that were not present in cgroups v1 are the fol‐\nlowing:\n\n•  No thread-granularity control: all of the threads of a process must be in the same cgroup.\n\n•  No  internal processes: a cgroup can't both have member processes and exercise controllers\non child cgroups.\n\nBoth of these restrictions were added because the lack of these restrictions had caused prob‐\nlems in cgroups v1.  In particular, the cgroups v1 ability to allow thread-level  granularity\nfor  cgroup membership made no sense for some controllers.  (A notable example was the memory\ncontroller: since threads share an address space, it made no sense to  split  threads  across\ndifferent memory cgroups.)\n\nNotwithstanding  the  initial design decision in cgroups v2, there were use cases for certain\ncontrollers, notably the cpu controller, for which thread-level granularity  of  control  was\nmeaningful  and  useful.   To  accommodate  such  use cases, Linux 4.14 added thread mode for\ncgroups v2.\n\nThread mode allows the following:\n\n•  The creation of threaded subtrees in which the threads of a process may be  spread  across\ncgroups  inside  the  tree.   (A  threaded  subtree  may  contain  multiple  multithreaded\nprocesses.)\n\n•  The concept of threaded controllers, which can distribute resources across the cgroups  in\na threaded subtree.\n\n•  A  relaxation  of  the \"no internal processes rule\", so that, within a threaded subtree, a\ncgroup can both contain member threads and exercise resource control over child cgroups.\n\nWith the addition of thread mode, each nonroot cgroup now contains a new  file,  cgroup.type,\nthat  exposes, and in some circumstances can be used to change, the \"type\" of a cgroup.  This\nfile contains one of the following type values:\n\ndomain This is a normal v2 cgroup that provides process-granularity control.  If a process is\na member of this cgroup, then all threads of the process are (by  definition)  in  the\nsame cgroup.  This is the default cgroup type, and provides the same behavior that was\nprovided for cgroups in the initial cgroups v2 implementation.\n\nthreaded\nThis  cgroup  is a member of a threaded subtree.  Threads can be added to this cgroup,\nand controllers can be enabled for the cgroup.\n\ndomain threaded\nThis is a domain cgroup that serves as the root of a threaded  subtree.   This  cgroup\ntype is also known as \"threaded root\".\n\ndomain invalid\nThis  is  a cgroup inside a threaded subtree that is in an \"invalid\" state.  Processes\ncan't be added to the cgroup, and controllers can't be enabled for  the  cgroup.   The\nonly thing that can be done with this cgroup (other than deleting it) is to convert it\nto a threaded cgroup by writing the string \"threaded\" to the cgroup.type file.\n\nThe  rationale  for  the  existence  of  this  \"interim\" type during the creation of a\nthreaded subtree (rather than the kernel simply immediately converting all cgroups un‐\nder the threaded root to the type threaded) is to allow for possible future extensions\nto the thread mode model\n",
                "subsections": [
                    {
                        "name": "Threaded versus domain controllers",
                        "content": "With the addition of threads mode, cgroups v2 now distinguishes two types  of  resource  con‐\ntrollers:\n\n•  Threaded  controllers:  these  controllers support thread-granularity for resource control\nand can be enabled inside threaded subtrees, with the result that the  corresponding  con‐\ntroller-interface  files  appear  inside the cgroups in the threaded subtree.  As at Linux\n4.19, the following controllers are threaded: cpu, perfevent, and pids.\n\n•  Domain controllers: these controllers support only process granularity for  resource  con‐\ntrol.  From the perspective of a domain controller, all threads of a process are always in\nthe same cgroup.  Domain controllers can't be enabled inside a threaded subtree.\n"
                    },
                    {
                        "name": "Creating a threaded subtree",
                        "content": "There  are  two  pathways that lead to the creation of a threaded subtree.  The first pathway\nproceeds as follows:\n\n(1)  We write the string \"threaded\" to the cgroup.type file of a cgroup  y/z  that  currently\nhas the type domain.  This has the following effects:\n\n•  The type of the cgroup y/z becomes threaded.\n\n•  The  type of the parent cgroup, y, becomes domain threaded.  The parent cgroup is the\nroot of a threaded subtree (also known as the \"threaded root\").\n\n•  All other cgroups under y that were not already of type threaded (because  they  were\ninside  already existing threaded subtrees under the new threaded root) are converted\nto type domain invalid.  Any subsequently created cgroups under y will also have  the\ntype domain invalid.\n\n(2)  We  write  the string \"threaded\" to each of the domain invalid cgroups under y, in order\nto convert them to the type threaded.  As a consequence of this step, all threads  under\nthe  threaded  root now have the type threaded and the threaded subtree is now fully us‐\nable.  The requirement to write \"threaded\" to each of these cgroups is somewhat  cumber‐\nsome, but allows for possible future extensions to the thread-mode model.\n\nThe second way of creating a threaded subtree is as follows:\n\n(1)  In  an  existing  cgroup,  z, that currently has the type domain, we (1.1) enable one or\nmore threaded controllers and (1.2) make a process a member of z.  (These two steps  can\nbe done in either order.)  This has the following consequences:\n\n•  The type of z becomes domain threaded.\n\n•  All  of  the  descendant cgroups of z that were not already of type threaded are con‐\nverted to type domain invalid.\n\n(2)  As before, we make the threaded subtree usable by writing the string \"threaded\" to  each\nof the domain invalid cgroups under z, in order to convert them to the type threaded.\n\nOne  of  the  consequences  of  the above pathways to creating a threaded subtree is that the\nthreaded root cgroup can be a parent only to threaded  (and  domain  invalid)  cgroups.   The\nthreaded  root cgroup can't be a parent of a domain cgroups, and a threaded cgroup can't have\na sibling that is a domain cgroup.\n"
                    },
                    {
                        "name": "Using a threaded subtree",
                        "content": "Within a threaded subtree, threaded controllers can be enabled in each  subgroup  whose  type\nhas been changed to threaded; upon doing so, the corresponding controller interface files ap‐\npear in the children of that cgroup.\n\nA process can be moved into a threaded subtree by writing its PID to the cgroup.procs file in\none  of the cgroups inside the tree.  This has the effect of making all of the threads in the\nprocess members of the corresponding cgroup and makes the process a member  of  the  threaded\nsubtree.   The threads of the process can then be spread across the threaded subtree by writ‐\ning their thread IDs (see gettid(2)) to the cgroup.threads files in different cgroups  inside\nthe subtree.  The threads of a process must all reside in the same threaded subtree.\n\nAs  with  writing  to  cgroup.procs,  some  containment  rules  apply  when  writing  to  the\ncgroup.threads file:\n\n•  The writer must have write permission  on  the  cgroup.threads  file  in  the  destination\ncgroup.\n\n•  The  writer  must have write permission on the cgroup.procs file in the common ancestor of\nthe source and destination cgroups.  (In some cases, the common ancestor may be the source\nor destination cgroup itself.)\n\n•  The source and destination cgroups must be in  the  same  threaded  subtree.   (Outside  a\nthreaded  subtree,  an  attempt  to  move  a  thread  by  writing  its  thread  ID  to the\ncgroup.threads file in a different domain cgroup fails with the error EOPNOTSUPP.)\n\nThe cgroup.threads file is present in each cgroup (including domain cgroups) and can be  read\nin order to discover the set of threads that is present in the cgroup.  The set of thread IDs\nobtained when reading this file is not guaranteed to be ordered or free of duplicates.\n\nThe  cgroup.procs  file in the threaded root shows the PIDs of all processes that are members\nof the threaded subtree.  The cgroup.procs files in the other cgroups in the subtree are  not\nreadable.\n\nDomain  controllers can't be enabled in a threaded subtree; no controller-interface files ap‐\npear inside the cgroups underneath the threaded root.  From the point of  view  of  a  domain\ncontroller,  threaded  subtrees are invisible: a multithreaded process inside a threaded sub‐\ntree appears to a domain controller as a process that resides in the threaded root cgroup.\n\nWithin a threaded subtree, the \"no internal processes\" rule does not apply: a cgroup can both\ncontain member processes (or thread) and exercise controllers on child cgroups.\n"
                    },
                    {
                        "name": "Rules for writing to cgroup.type and creating threaded subtrees",
                        "content": "A number of rules apply when writing to the cgroup.type file:\n\n•  Only the string \"threaded\" may be written.  In other words, the only  explicit  transition\nthat is possible is to convert a domain cgroup to type threaded.\n\n•  The effect of writing \"threaded\" depends on the current value in cgroup.type, as follows:\n\n•  domain  or domain threaded: start the creation of a threaded subtree (whose root is the\nparent of this cgroup) via the first of the pathways described above;\n\n•  domain invalid: convert this cgroup (which is inside a threaded subtree)  to  a  usable\n(i.e., threaded) state;\n\n•  threaded: no effect (a \"no-op\").\n\n•  We  can't  write  to  a cgroup.type file if the parent's type is domain invalid.  In other\nwords, the cgroups of a threaded subtree must be converted to the threaded state in a top-\ndown manner.\n\nThere are also some constraints that must be satisfied in order to create a threaded  subtree\nrooted at the cgroup x:\n\n•  There can be no member processes in the descendant cgroups of x.  (The cgroup x can itself\nhave member processes.)\n\n•  No domain controllers may be enabled in x's cgroup.subtreecontrol file.\n\nIf  any  of  the  above  constraints  is  violated,  then an attempt to write \"threaded\" to a\ncgroup.type file fails with the error ENOTSUP.\n"
                    },
                    {
                        "name": "The \"domain threaded\" cgroup type",
                        "content": "According to the pathways described above, the type of a cgroup can change to domain threaded\nin either of the following cases:\n\n•  The string \"threaded\" is written to a child cgroup.\n\n•  A threaded controller is enabled inside the cgroup and a process is made a member  of  the\ncgroup.\n\nA  domain threaded cgroup, x, can revert to the type domain if the above conditions no longer\nhold true—that is, if all threaded child cgroups of x are removed and either x no longer  has\nthreaded controllers enabled or no longer has member processes.\n\nWhen a domain threaded cgroup x reverts to the type domain:\n\n•  All  domain  invalid descendants of x that are not in lower-level threaded subtrees revert\nto the type domain.\n\n•  The root cgroups in any lower-level threaded subtrees revert to the type domain threaded.\n"
                    },
                    {
                        "name": "Exceptions for the root cgroup",
                        "content": "The root cgroup of the v2 hierarchy is treated exceptionally: it can be the  parent  of  both\ndomain  and threaded cgroups.  If the string \"threaded\" is written to the cgroup.type file of\none of the children of the root cgroup, then\n\n•  The type of that cgroup becomes threaded.\n\n•  The type of any descendants of that cgroup that are not part of lower-level threaded  sub‐\ntrees changes to domain invalid.\n\nNote  that in this case, there is no cgroup whose type becomes domain threaded.  (Notionally,\nthe root cgroup can be considered as the threaded root for the cgroup whose type was  changed\nto threaded.)\n\nThe  aim of this exceptional treatment for the root cgroup is to allow a threaded cgroup that\nemploys the cpu controller to be placed as high as possible in the hierarchy, so as to  mini‐\nmize the (small) cost of traversing the cgroup hierarchy.\n"
                    },
                    {
                        "name": "The cgroups v2 \"cpu\" controller and realtime threads",
                        "content": "As  at Linux 4.19, the cgroups v2 cpu controller does not support control of realtime threads\n(specifically threads scheduled under any of the  policies  SCHEDFIFO,  SCHEDRR,  described\nSCHEDDEADLINE;  see  sched(7)).   Therefore,  the  cpu controller can be enabled in the root\ncgroup only if all realtime threads are in the root cgroup.  (If there are  realtime  threads\nin  nonroot  cgroups, then a write(2) of the string \"+cpu\" to the cgroup.subtreecontrol file\nfails with the error EINVAL.)\n\nOn some systems, systemd(1) places certain realtime threads in nonroot cgroups in the v2  hi‐\nerarchy.   On  such  systems, these threads must first be moved to the root cgroup before the\ncpu controller can be enabled.\n"
                    }
                ]
            },
            "ERRORS": {
                "content": "The following errors can occur for mount(2):\n\nEBUSY  An attempt to mount a cgroup version 1 filesystem specified neither the  name=  option\n(to mount a named hierarchy) nor a controller name (or all).\n",
                "subsections": []
            },
            "NOTES": {
                "content": "A  child  process  created via fork(2) inherits its parent's cgroup memberships.  A process's\ncgroup memberships are preserved across execve(2).\n\nThe clone3(2) CLONEINTOCGROUP flag can be used to create a child process  that  begins  its\nlife in a different version 2 cgroup from the parent process.\n",
                "subsections": [
                    {
                        "name": "/proc files",
                        "content": "/proc/cgroups (since Linux 2.6.24)\nThis  file  contains information about the controllers that are compiled into the ker‐\nnel.  An example of the contents of this file (reformatted  for  readability)  is  the\nfollowing:\n\n#subsysname    hierarchy      numcgroups    enabled\ncpuset          4              1              1\ncpu             8              1              1\ncpuacct         8              1              1\nblkio           6              1              1\nmemory          3              1              1\ndevices         10             84             1\nfreezer         7              1              1\nnetcls         9              1              1\nperfevent      5              1              1\nnetprio        9              1              1\nhugetlb         0              1              0\npids            2              1              1\n\nThe fields in this file are, from left to right:\n\n[1]  The name of the controller.\n\n[2]  The  unique  ID  of the cgroup hierarchy on which this controller is mounted.  If\nmultiple cgroups v1 controllers are bound to the same hierarchy, then  each  will\nshow the same hierarchy ID in this field.  The value in this field will be 0 if:\n\n•  the controller is not mounted on a cgroups v1 hierarchy;\n\n•  the controller is bound to the cgroups v2 single unified hierarchy; or\n\n•  the controller is disabled (see below).\n\n[3]  The number of control groups in this hierarchy using this controller.\n\n[4]  This  field  contains  the  value 1 if this controller is enabled, or 0 if it has\nbeen disabled (via the cgroupdisable kernel command-line boot parameter).\n\n/proc/pid/cgroup (since Linux 2.6.24)\nThis file describes control groups to which the process with the corresponding PID be‐\nlongs.  The displayed information differs for cgroups version 1 and version 2  hierar‐\nchies.\n\nFor  each  cgroup  hierarchy of which the process is a member, there is one entry con‐\ntaining three colon-separated fields:\n\nhierarchy-ID:controller-list:cgroup-path\n\nFor example:\n\n5:cpuacct,cpu,cpuset:/daemons\n\nThe colon-separated fields are, from left to right:\n\n[1]  For cgroups version 1 hierarchies, this field contains a unique hierarchy ID num‐\nber that can be matched to a hierarchy ID in /proc/cgroups.  For the cgroups ver‐\nsion 2 hierarchy, this field contains the value 0.\n\n[2]  For cgroups version 1 hierarchies, this field contains a comma-separated list  of\nthe  controllers  bound  to  the hierarchy.  For the cgroups version 2 hierarchy,\nthis field is empty.\n\n[3]  This field contains the pathname of the control group in the hierarchy  to  which\nthe process belongs.  This pathname is relative to the mount point of the hierar‐\nchy.\n"
                    },
                    {
                        "name": "/sys/kernel/cgroup files",
                        "content": "/sys/kernel/cgroup/delegate (since Linux 4.15)\nThis  file  exports a list of the cgroups v2 files (one per line) that are delegatable\n(i.e., whose ownership should be changed to the user ID of the delegatee).  In the fu‐\nture, the set of delegatable files may change or grow, and this file  provides  a  way\nfor the kernel to inform user-space applications of which files must be delegated.  As\nat Linux 4.15, one sees the following when inspecting this file:\n\n$ cat /sys/kernel/cgroup/delegate\ncgroup.procs\ncgroup.subtreecontrol\ncgroup.threads\n\n/sys/kernel/cgroup/features (since Linux 4.15)\nOver  time,  the set of cgroups v2 features that are provided by the kernel may change\nor grow, or some features may not be enabled by default.  This file provides a way for\nuser-space applications to discover what features the running kernel supports and  has\nenabled.  Features are listed one per line:\n\n$ cat /sys/kernel/cgroup/features\nnsdelegate\nmemorylocalevents\n\nThe entries that can appear in this file are:\n\nmemorylocalevents (since Linux 5.2)\nThe kernel supports the memorylocalevents mount option.\n\nnsdelegate (since Linux 4.15)\nThe kernel supports the nsdelegate mount option.\n\nmemoryrecursiveprot (since Linux 5.7)\nThe kernel supports the memoryrecursiveprot mount option.\n"
                    }
                ]
            },
            "SEE ALSO": {
                "content": "prlimit(1),   systemd(1),   systemd-cgls(1),   systemd-cgtop(1),   clone(2),   ioprioset(2),\nperfeventopen(2), setrlimit(2), cgroupnamespaces(7), cpuset(7),  namespaces(7),  sched(7),\nusernamespaces(7)\n\nThe kernel source file Documentation/admin-guide/cgroup-v2.rst.\n\nLinux man-pages 6.7                          2024-03-05                                   cgroups(7)",
                "subsections": []
            }
        }
    }
}