Show Table of Contents
2.2. 创建层级并附加子系统
警告
以下步骤覆盖从创建新层级到在其中附加子系统到内容,这些步骤假设还没有在您的系统中配置 cgroup。在这种情况下,这些步骤不会影响系统中的操作。更改有任务的 cgroup 中的可调参数可能会马上影响那些任务。本指南提示您它首次演示更改会影响一个或者多个任务的可调 cgroup 参数。
在已经配置了 cgroup 的系统中(可以是手动配置,或者使用
cgconfig 服务配置),这些命令会失败,除非您首先卸载可影响系统操作的现有层级。不要在产品系统中试验这些步骤。
要创建层级并在其中附加子系统,请作为 root 编辑
/etc/cgconfig.conf 文件的 mount 部分。mount 部分的条目有以下格式:
subsystem = /cgroup/hierarchy;
下一次启动
cgconfig 时,它会创建层级并为其附加子系统。
以下示例创建名为
cpu_and_mem 的层级,并附加 cpu、cpuset、cpuacct 和 memory 子系统。
mount {
cpuset = /cgroup/cpu_and_mem;
cpu = /cgroup/cpu_and_mem;
cpuacct = /cgroup/cpu_and_mem;
memory = /cgroup/cpu_and_mem;
}备用方法
您还可以使用 shell 命令和工具创建层级并在其中附加子系统。
作为 root 为该层级创建挂载点。在挂载点中包括 cgroup 名称:
~]# mkdir /cgroup/name
例如:
~]# mkdir /cgroup/cpu_and_mem
下一步,请使用
mount 命令挂载该层级并同时附加一个或者多个系统。例如:
~]# mount -t cgroup -o subsystems name /cgroup/name
其中 subsystems 是使用逗号分开的子系统列表,name 是层级名称。所有可用子系统的简要论述请参考 Red Hat Enterprise Linux 中的可用子系统,第 3 章 子系统和可调参数 中有详细的参考。
例 2.3. 使用 mount 命令附加子系统
在这个示例中,已经有名为
/cgroup/cpu_and_mem 的目录,它可以作为我们所创建层级的挂载点服务。我们将在名为 cpu_and_mem 的层级中附加 cpu、cpuset 和 memory 子系统,并在 /cgroup/cpu_and_mem 中 mount cpu_and_mem 层级:
~]# mount -t cgroup -o cpu,cpuset,memory cpu_and_mem /cgroup/cpu_and_mem
您可以使用
lssubsys [3]命令列出所有可用子系统及其当前挂载点(例如:挂载附加这些子系统的层级的位置)
~]# lssubsys -am
cpu,cpuset,memory /cgroup/cpu_and_mem
net_cls
ns
cpuacct
devices
freezer
blkio
这个输出表示:
- 在挂载到
/cgroup/cpu_and_mem的层级中附加子系统cpu、cpuset和memory,且 - 还没有在任何层级中附加子系统
net_cls、ns、cpuacct、devices、freezer和blkio,因缺少相应的挂载点。
[3]
lssubsys 是 libcgroup 命令提供的工具之一。您必须安装 libcgroup 方可使用这个工具:如果您无法运行 lssubsys,请参考 第 2 章 使用控制组群。

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.