요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
Filesystem interface
cpuacct.rst:22-41Child group 생성, task attach, cpuacct.usage와 cpuacct.stat을 정리합니다.
Counter caveats
cpuacct.rst:42-5032-bit concurrent read와 batch update 때문에 생기는 순간 오차를 다룹니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
=========================
CPU Accounting Controller
=========================
The CPU accounting controller is used to group tasks using cgroups and
account the CPU usage of these groups of tasks.
The CPU accounting controller supports multi-hierarchy groups. An accounting
group accumulates the CPU usage of all of its child groups and the tasks
directly present in its group.
Accounting groups can be created by first mounting the cgroup filesystem::
# mount -t cgroup -ocpuacct none /sys/fs/cgroup
With the above step, the initial or the parent accounting group becomes
visible at /sys/fs/cgroup. At bootup, this group includes all the tasks in
the system. /sys/fs/cgroup/tasks lists the tasks in this cgroup.
/sys/fs/cgroup/cpuacct.usage gives the CPU time (in nanoseconds) obtained
by this group which is essentially the CPU time obtained by all the tasks
in the system.
New accounting groups can be created under the parent group /sys/fs/cgroup::
# cd /sys/fs/cgroup
# mkdir g1
# echo $$ > g1/tasks
The above steps create a new group g1 and move the current shell
process (bash) into it. CPU time consumed by this bash and its children
can be obtained from g1/cpuacct.usage and the same is accumulated in
/sys/fs/cgroup/cpuacct.usage also.
cpuacct.stat file lists a few statistics which further divide the
CPU time obtained by the cgroup into user and system times. Currently
the following statistics are supported:
user: Time spent by tasks of the cgroup in user mode.
system: Time spent by tasks of the cgroup in kernel mode.
user and system are in USER_HZ unit.
cpuacct controller uses percpu_counter interface to collect user and
system times. This has two side effects:
- It is theoretically possible to see wrong values for user and system times.
This is because percpu_counter_read() on 32bit systems isn't safe
against concurrent writes.
- It is possible to see slightly outdated values for user and system times
due to the batch processing nature of percpu_counter.
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
CPU accounting controller와 root group
1-21CPU accounting controller는 cgroup으로 task를 묶고 각 task group의 CPU 사용량을 집계합니다. Multi-hierarchy group을 지원하며, accounting group의 값에는 그 group에 직접 속한 task뿐 아니라 모든 child group의 CPU 사용량도 누적됩니다.
Accounting groups can be created by first mounting the cgroup filesystem::
# mount -t cgroup -ocpuacct none /sys/fs/cgroup
위 명령으로 cgroup filesystem을 mount하면 initial 또는 parent accounting group이 `/sys/fs/cgroup`에 나타납니다. Boot 시 이 group은 system의 모든 task를 포함하고 `/sys/fs/cgroup/tasks`가 그 task 목록을 보여 줍니다.
`/sys/fs/cgroup/cpuacct.usage`는 이 group이 얻은 CPU time을 nanoseconds 단위로 제공합니다. Root group에서는 본질적으로 system 전체 task가 사용한 CPU time입니다.
초기 accounting group에서 확인하는 핵심 파일입니다.
Parent 값은 직접 task와 모든 child group의 사용량을 합산합니다.
Child group 생성과 cpuacct.stat
22-41새 accounting group은 parent `/sys/fs/cgroup` 아래에 directory를 만들어 생성합니다. 다음 명령은 `g1`을 만들고 현재 shell process인 Bash를 그 group으로 이동합니다.
New accounting groups can be created under the parent group /sys/fs/cgroup::
# cd /sys/fs/cgroup
# mkdir g1
# echo $$ > g1/tasks
이후 Bash와 그 child가 소비한 CPU time은 `g1/cpuacct.usage`에서 읽을 수 있고, 같은 값은 ancestor인 `/sys/fs/cgroup/cpuacct.usage`에도 누적됩니다.
Directory 생성, task 이동, descendant accounting 순서입니다.
`cpuacct.stat`은 cgroup의 CPU time을 user mode와 kernel mode로 더 나눕니다. 두 값 모두 `USER_HZ` 단위이므로 `cpuacct.usage`의 nanoseconds와 단위가 다릅니다.
Mode별 CPU 사용 시간을 제공하는 두 statistic입니다.
percpu_counter의 두 가지 관측 오차
42-50cpuacct controller는 user·system time을 모으는 데 `percpu_counter` interface를 사용합니다. 이 구현 방식 때문에 읽은 값에는 다음 두 가지 주의점이 있습니다.
Statistic을 해석할 때 고려해야 하는 정확도와 최신성 제약입니다.
따라서 `cpuacct.stat`은 매우 빠른 변화 구간에서 순간적으로 부정확하거나 지연될 수 있습니다. 이는 controller의 계층 누적 규칙이 아니라 per-CPU counter를 읽고 합치는 방식에서 오는 관측 특성입니다.
Accounting model
cpuacct.rst:1-21Parent가 직접 task와 모든 child group의 CPU time을 누적하는 구조를 설명합니다.