以 systemd-cgls 中的层次结构为例:
└─user.slice
├─user-1000.slice
│ ├─[email protected]
│ │ └─init.scope
│ │ ├─3262 /lib/systemd/systemd --user
│ │ └─3263 (sd-pam)
│ └─session-3.scope
│ ├─3260 sshd: user1 [priv]
│ ├─3362 sshd: user1@pts/1
│ ├─3363 -bash
│ └─3378 ssh-agent -s
└─user-0.slice
├─session-1.scope
│ ├─3151 sshd: root@pts/0
│ ├─3252 -bash
│ ├─3625 systemd-cgls
如果我为 user.slice 设置一个限制,例如 5M 内存,则内存行会清楚地报告这一点:
systemctl status user.slice
● user.slice
Loaded: loaded (/etc/systemd/system/user.slice; static; vendor preset: enabled)
Active: active since Mon 2016-08-22 11:32:13 CEST; 52min ago
Tasks: 12
Memory: 3.1M (limit: 5.0M)
CPU: 1.275s
CGroup: /user.slice
...
用户 1000 切片已应用限制,如果我用这个用户对系统施加压力,我可以看到它。但状态不会报告此子切片中的限制:
systemctl status user-1000.slice
● user-1000.slice - User Slice of user1
Loaded: loaded (/run/systemd/transient/user-1000.slice; transient; vendor preset: enabled)
Transient: yes
Active: active since Mon 2016-08-22 11:32:42 CEST; 1h 8min ago
Tasks: 6 (limit: 12288)
Memory: 856.0K
CPU: 521ms
按照 proc 的方式我可以看到 user-1000 进程属于用户切片:
# cat /proc/3260/cgroup
10:memory:/user.slice/user-1000.slice
...
并直接在 /sys/ 内部检查:
root@server1:/sys/fs/cgroup/memory/user.slice# cat memory.limit_in_bytes
5242880
root@server1:/sys/fs/cgroup/memory/user.slice# cd user-1000.slice/
root@server1:/sys/fs/cgroup/memory/user.slice/user-1000.slice# cat memory.limit_in_bytes
9223372036854771712
如何知道子进程/切片是否在父 cgroup 中定义了限制?