요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
Field semantics
taskstats-struct.rst:43-199Identity·time·fault·delay·memory·I/O·switch·scaled-time·reclaim field와 overflow/update 특성을 정리합니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
====================
The struct taskstats
====================
This document contains an explanation of the struct taskstats fields.
There are three different groups of fields in the struct taskstats:
1) Common and basic accounting fields
If CONFIG_TASKSTATS is set, the taskstats interface is enabled and
the common fields and basic accounting fields are collected for
delivery at do_exit() of a task.
2) Delay accounting fields
These fields are placed between::
/* Delay accounting fields start */
and::
/* Delay accounting fields end */
Their values are collected if CONFIG_TASK_DELAY_ACCT is set.
3) Extended accounting fields
These fields are placed between::
/* Extended accounting fields start */
and::
/* Extended accounting fields end */
Their values are collected if CONFIG_TASK_XACCT is set.
4) Per-task and per-thread context switch count statistics
5) Time accounting for SMT machines
6) Extended delay accounting fields for memory reclaim
Future extension should add fields to the end of the taskstats struct, and
should not change the relative position of each field within the struct.
::
struct taskstats {
1) Common and basic accounting fields::
/* The version number of this struct. This field is always set to
* TASKSTATS_VERSION, which is defined in <linux/taskstats.h>.
* Each time the struct is changed, the value should be incremented.
*/
__u16 version;
/* The exit code of a task. */
__u32 ac_exitcode; /* Exit status */
/* The accounting flags of a task as defined in <linux/acct.h>
* Defined values are AFORK, ASU, ACOMPAT, ACORE, and AXSIG.
*/
__u8 ac_flag; /* Record flags */
/* The value of task_nice() of a task. */
__u8 ac_nice; /* task_nice */
/* The name of the command that started this task. */
char ac_comm[TS_COMM_LEN]; /* Command name */
/* The scheduling discipline as set in task->policy field. */
__u8 ac_sched; /* Scheduling discipline */
__u8 ac_pad[3];
__u32 ac_uid; /* User ID */
__u32 ac_gid; /* Group ID */
__u32 ac_pid; /* Process ID */
__u32 ac_ppid; /* Parent process ID */
/* The time when a task begins, in [secs] since 1970. */
__u32 ac_btime; /* Begin time [sec since 1970] */
/* The elapsed time of a task, in [usec]. */
__u64 ac_etime; /* Elapsed time [usec] */
/* The user CPU time of a task, in [usec]. */
__u64 ac_utime; /* User CPU time [usec] */
/* The system CPU time of a task, in [usec]. */
__u64 ac_stime; /* System CPU time [usec] */
/* The minor page fault count of a task, as set in task->min_flt. */
__u64 ac_minflt; /* Minor Page Fault Count */
/* The major page fault count of a task, as set in task->maj_flt. */
__u64 ac_majflt; /* Major Page Fault Count */
2) Delay accounting fields::
/* Delay accounting fields start
*
* All values, until the comment "Delay accounting fields end" are
* available only if delay accounting is enabled, even though the last
* few fields are not delays
*
* xxx_count is the number of delay values recorded
* xxx_delay_total is the corresponding cumulative delay in nanoseconds
*
* xxx_delay_total wraps around to zero on overflow
* xxx_count incremented regardless of overflow
*/
/* Delay waiting for cpu, while runnable
* count, delay_total NOT updated atomically
*/
__u64 cpu_count;
__u64 cpu_delay_total;
/* Following four fields atomically updated using task->delays->lock */
/* Delay waiting for synchronous block I/O to complete
* does not account for delays in I/O submission
*/
__u64 blkio_count;
__u64 blkio_delay_total;
/* Delay waiting for page fault I/O (swap in only) */
__u64 swapin_count;
__u64 swapin_delay_total;
/* cpu "wall-clock" running time
* On some architectures, value will adjust for cpu time stolen
* from the kernel in involuntary waits due to virtualization.
* Value is cumulative, in nanoseconds, without a corresponding count
* and wraps around to zero silently on overflow
*/
__u64 cpu_run_real_total;
/* cpu "virtual" running time
* Uses time intervals seen by the kernel i.e. no adjustment
* for kernel's involuntary waits due to virtualization.
* Value is cumulative, in nanoseconds, without a corresponding count
* and wraps around to zero silently on overflow
*/
__u64 cpu_run_virtual_total;
/* Delay accounting fields end */
/* version 1 ends here */
3) Extended accounting fields::
/* Extended accounting fields start */
/* Accumulated RSS usage in duration of a task, in MBytes-usecs.
* The current rss usage is added to this counter every time
* a tick is charged to a task's system time. So, at the end we
* will have memory usage multiplied by system time. Thus an
* average usage per system time unit can be calculated.
*/
__u64 coremem; /* accumulated RSS usage in MB-usec */
/* Accumulated virtual memory usage in duration of a task.
* Same as acct_rss_mem1 above except that we keep track of VM usage.
*/
__u64 virtmem; /* accumulated VM usage in MB-usec */
/* High watermark of RSS usage in duration of a task, in KBytes. */
__u64 hiwater_rss; /* High-watermark of RSS usage */
/* High watermark of VM usage in duration of a task, in KBytes. */
__u64 hiwater_vm; /* High-water virtual memory usage */
/* The following four fields are I/O statistics of a task. */
__u64 read_char; /* bytes read */
__u64 write_char; /* bytes written */
__u64 read_syscalls; /* read syscalls */
__u64 write_syscalls; /* write syscalls */
/* Extended accounting fields end */
4) Per-task and per-thread statistics::
__u64 nvcsw; /* Context voluntary switch counter */
__u64 nivcsw; /* Context involuntary switch counter */
5) Time accounting for SMT machines::
__u64 ac_utimescaled; /* utime scaled on frequency etc */
__u64 ac_stimescaled; /* stime scaled on frequency etc */
__u64 cpu_scaled_run_real_total; /* scaled cpu_run_real_total */
6) Extended delay accounting fields for memory reclaim::
/* Delay waiting for memory reclaim */
__u64 freepages_count;
__u64 freepages_delay_total;
::
}
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
struct taskstats field groups와 확장 규칙
1-42이 문서는 `struct taskstats` field를 설명합니다. Common/basic accounting field는 `CONFIG_TASKSTATS`가 설정되면 taskstats interface가 활성화되고 task의 `do_exit()` 때 전달할 값이 수집됩니다.
Delay accounting field는 `/* Delay accounting fields start */`와 `/* Delay accounting fields end */` 사이에 있으며 `CONFIG_TASK_DELAY_ACCT`가 설정될 때 수집합니다. Extended accounting field는 대응하는 start/end marker 사이에 있고 `CONFIG_TASK_XACCT`가 설정될 때 수집합니다.
그 밖에 per-task/per-thread context switch count, SMT machine time accounting, memory reclaim용 extended delay accounting field가 있습니다. 향후 확장은 `taskstats` structure 끝에 field를 추가해야 하며 기존 field의 상대적 위치를 바꾸면 안 됩니다.
Compile-time option과 수집 시점 또는 목적을 연결합니다.
Common/basic accounting fields
43-96`version`은 `<linux/taskstats.h>`의 `TASKSTATS_VERSION`으로 항상 설정하며 structure가 바뀔 때마다 증가해야 합니다. `ac_exitcode`는 task exit status, `ac_flag`는 `<linux/acct.h>`의 `AFORK`, `ASU`, `ACOMPAT`, `ACORE`, `AXSIG`, `ac_nice`는 `task_nice()` 값, `ac_comm`은 task를 시작한 command name, `ac_sched`는 `task->policy` scheduling discipline입니다.
`ac_uid`, `ac_gid`, `ac_pid`, `ac_ppid`는 user, group, process, parent process ID입니다. `ac_btime`은 1970년 이후 task begin seconds, `ac_etime`은 elapsed microseconds, `ac_utime`과 `ac_stime`은 user/system CPU microseconds입니다. `ac_minflt`와 `ac_majflt`는 각각 `task->min_flt`, `task->maj_flt`의 minor/major page fault count입니다.
Identifier, time와 fault fields의 encoding을 정리합니다.
struct taskstats {
1) Common and basic accounting fields::
/* The version number of this struct. This field is always set to
* TASKSTATS_VERSION, which is defined in <linux/taskstats.h>.
* Each time the struct is changed, the value should be incremented.
*/
__u16 version;
/* The exit code of a task. */
__u32 ac_exitcode; /* Exit status */
/* The accounting flags of a task as defined in <linux/acct.h>
* Defined values are AFORK, ASU, ACOMPAT, ACORE, and AXSIG.
*/
__u8 ac_flag; /* Record flags */
/* The value of task_nice() of a task. */
__u8 ac_nice; /* task_nice */
/* The name of the command that started this task. */
char ac_comm[TS_COMM_LEN]; /* Command name */
/* The scheduling discipline as set in task->policy field. */
__u8 ac_sched; /* Scheduling discipline */
__u8 ac_pad[3];
__u32 ac_uid; /* User ID */
__u32 ac_gid; /* Group ID */
__u32 ac_pid; /* Process ID */
__u32 ac_ppid; /* Parent process ID */
/* The time when a task begins, in [secs] since 1970. */
__u32 ac_btime; /* Begin time [sec since 1970] */
/* The elapsed time of a task, in [usec]. */
__u64 ac_etime; /* Elapsed time [usec] */
/* The user CPU time of a task, in [usec]. */
__u64 ac_utime; /* User CPU time [usec] */
/* The system CPU time of a task, in [usec]. */
__u64 ac_stime; /* System CPU time [usec] */
/* The minor page fault count of a task, as set in task->min_flt. */
__u64 ac_minflt; /* Minor Page Fault Count */
/* The major page fault count of a task, as set in task->maj_flt. */
__u64 ac_majflt; /* Major Page Fault Count */
Delay accounting fields
97-148Delay accounting이 enable된 경우 start/end marker 사이의 값을 사용할 수 있습니다. `xxx_count`는 기록한 delay value 수, `xxx_delay_total`은 nanoseconds 단위 cumulative delay입니다. `xxx_delay_total`은 overflow 때 0으로 wrap하지만 `xxx_count`는 overflow와 무관하게 증가합니다.
`cpu_count`, `cpu_delay_total`은 runnable 상태에서 CPU를 기다린 횟수와 delay이며 atomically update되지 않습니다. 이후 네 field는 `task->delays->lock`으로 atomic update됩니다. `blkio_count`, `blkio_delay_total`은 synchronous block I/O completion 대기이며 I/O submission delay는 포함하지 않습니다. `swapin_count`, `swapin_delay_total`은 page-fault I/O 중 swap-in 대기입니다.
`cpu_run_real_total`은 CPU wall-clock running time입니다. 일부 architecture에서는 virtualization 때문에 kernel이 원치 않게 wait하며 빼앗긴 CPU time을 보정합니다. `cpu_run_virtual_total`은 kernel이 본 interval을 사용해 그 보정을 하지 않습니다. 둘 다 nanoseconds cumulative value이고 count가 없으며 overflow 때 조용히 0으로 wrap합니다. 여기까지가 version 1의 끝입니다.
Count와 cumulative nanosecond total 및 update 특성을 비교합니다.
/* Delay accounting fields start
*
* All values, until the comment "Delay accounting fields end" are
* available only if delay accounting is enabled, even though the last
* few fields are not delays
*
* xxx_count is the number of delay values recorded
* xxx_delay_total is the corresponding cumulative delay in nanoseconds
*
* xxx_delay_total wraps around to zero on overflow
* xxx_count incremented regardless of overflow
*/
/* Delay waiting for cpu, while runnable
* count, delay_total NOT updated atomically
*/
__u64 cpu_count;
__u64 cpu_delay_total;
/* Following four fields atomically updated using task->delays->lock */
/* Delay waiting for synchronous block I/O to complete
* does not account for delays in I/O submission
*/
__u64 blkio_count;
__u64 blkio_delay_total;
/* Delay waiting for page fault I/O (swap in only) */
__u64 swapin_count;
__u64 swapin_delay_total;
/* cpu "wall-clock" running time
* On some architectures, value will adjust for cpu time stolen
* from the kernel in involuntary waits due to virtualization.
* Value is cumulative, in nanoseconds, without a corresponding count
* and wraps around to zero silently on overflow
*/
__u64 cpu_run_real_total;
/* cpu "virtual" running time
* Uses time intervals seen by the kernel i.e. no adjustment
* for kernel's involuntary waits due to virtualization.
* Value is cumulative, in nanoseconds, without a corresponding count
* and wraps around to zero silently on overflow
*/
__u64 cpu_run_virtual_total;
/* Delay accounting fields end */
/* version 1 ends here */
Extended accounting fields
149-179`coremem`은 task lifetime의 accumulated RSS usage를 MB-usec 단위로 나타냅니다. Task system time에 tick이 charge될 때마다 current RSS를 더하므로 memory usage와 system time의 곱이 되고 system time unit당 average usage를 계산할 수 있습니다. `virtmem`은 같은 방식으로 virtual memory usage를 추적합니다.
`hiwater_rss`와 `hiwater_vm`은 task lifetime의 RSS와 VM high-watermark를 KBytes로 나타냅니다. `read_char`, `write_char`, `read_syscalls`, `write_syscalls`는 task의 bytes read/written과 read/write syscall 수입니다.
Memory accumulation, watermark와 I/O counts입니다.
/* Extended accounting fields start */
/* Accumulated RSS usage in duration of a task, in MBytes-usecs.
* The current rss usage is added to this counter every time
* a tick is charged to a task's system time. So, at the end we
* will have memory usage multiplied by system time. Thus an
* average usage per system time unit can be calculated.
*/
__u64 coremem; /* accumulated RSS usage in MB-usec */
/* Accumulated virtual memory usage in duration of a task.
* Same as acct_rss_mem1 above except that we keep track of VM usage.
*/
__u64 virtmem; /* accumulated VM usage in MB-usec */
/* High watermark of RSS usage in duration of a task, in KBytes. */
__u64 hiwater_rss; /* High-watermark of RSS usage */
/* High watermark of VM usage in duration of a task, in KBytes. */
__u64 hiwater_vm; /* High-water virtual memory usage */
/* The following four fields are I/O statistics of a task. */
__u64 read_char; /* bytes read */
__u64 write_char; /* bytes written */
__u64 read_syscalls; /* read syscalls */
__u64 write_syscalls; /* write syscalls */
/* Extended accounting fields end */
Context switch, SMT와 reclaim fields
180-199`nvcsw`와 `nivcsw`는 voluntary/involuntary context switch counter입니다. SMT machine용 `ac_utimescaled`, `ac_stimescaled`는 frequency 등을 반영해 scale한 user/system time이고 `cpu_scaled_run_real_total`은 scale한 `cpu_run_real_total`입니다.
Memory reclaim용 extended delay field `freepages_count`, `freepages_delay_total`은 memory reclaim을 기다린 횟수와 cumulative delay를 저장합니다.
__u64 nvcsw; /* Context voluntary switch counter */
__u64 nivcsw; /* Context involuntary switch counter */
5) Time accounting for SMT machines::
__u64 ac_utimescaled; /* utime scaled on frequency etc */
__u64 ac_stimescaled; /* stime scaled on frequency etc */
__u64 cpu_scaled_run_real_total; /* scaled cpu_run_real_total */
6) Extended delay accounting fields for memory reclaim::
/* Delay waiting for memory reclaim */
__u64 freepages_count;
__u64 freepages_delay_total;
::
}
Versioned layout
taskstats-struct.rst:1-42Compile-time accounting group과 append-only field extension 규칙을 정의합니다.