← Documents Documentation/accounting/taskstats-struct.rst GitHub 원문 ↗

Linux 6.18.37 · Accounting

The struct taskstats

Versioned taskstats structure의 common, delay, extended memory/I/O, context-switch, SMT와 reclaim field 의미·단위를 설명합니다.

Source pathDocumentation/accounting/taskstats-struct.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

Versioned layout

taskstats-struct.rst:1-42

Compile-time accounting group과 append-only field extension 규칙을 정의합니다.

Field semantics

taskstats-struct.rst:43-199

Identity·time·fault·delay·memory·I/O·switch·scaled-time·reclaim field와 overflow/update 특성을 정리합니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
1 ====================
2 The struct taskstats
3 ====================
4
5 This document contains an explanation of the struct taskstats fields.
6
7 There are three different groups of fields in the struct taskstats:
8
9 1) Common and basic accounting fields
10 If CONFIG_TASKSTATS is set, the taskstats interface is enabled and
11 the common fields and basic accounting fields are collected for
12 delivery at do_exit() of a task.
13 2) Delay accounting fields
14 These fields are placed between::
15
16 /* Delay accounting fields start */
17
18 and::
19
20 /* Delay accounting fields end */
21
22 Their values are collected if CONFIG_TASK_DELAY_ACCT is set.
23 3) Extended accounting fields
24 These fields are placed between::
25
26 /* Extended accounting fields start */
27
28 and::
29
30 /* Extended accounting fields end */
31
32 Their values are collected if CONFIG_TASK_XACCT is set.
33
34 4) Per-task and per-thread context switch count statistics
35
36 5) Time accounting for SMT machines
37
38 6) Extended delay accounting fields for memory reclaim
39
40 Future extension should add fields to the end of the taskstats struct, and
41 should not change the relative position of each field within the struct.
42
43 ::
44
45 struct taskstats {
46
47 1) Common and basic accounting fields::
48
49 /* The version number of this struct. This field is always set to
50 * TASKSTATS_VERSION, which is defined in <linux/taskstats.h>.
51 * Each time the struct is changed, the value should be incremented.
52 */
53 __u16 version;
54
55 /* The exit code of a task. */
56 __u32 ac_exitcode; /* Exit status */
57
58 /* The accounting flags of a task as defined in <linux/acct.h>
59 * Defined values are AFORK, ASU, ACOMPAT, ACORE, and AXSIG.
60 */
61 __u8 ac_flag; /* Record flags */
62
63 /* The value of task_nice() of a task. */
64 __u8 ac_nice; /* task_nice */
65
66 /* The name of the command that started this task. */
67 char ac_comm[TS_COMM_LEN]; /* Command name */
68
69 /* The scheduling discipline as set in task->policy field. */
70 __u8 ac_sched; /* Scheduling discipline */
71
72 __u8 ac_pad[3];
73 __u32 ac_uid; /* User ID */
74 __u32 ac_gid; /* Group ID */
75 __u32 ac_pid; /* Process ID */
76 __u32 ac_ppid; /* Parent process ID */
77
78 /* The time when a task begins, in [secs] since 1970. */
79 __u32 ac_btime; /* Begin time [sec since 1970] */
80
81 /* The elapsed time of a task, in [usec]. */
82 __u64 ac_etime; /* Elapsed time [usec] */
83
84 /* The user CPU time of a task, in [usec]. */
85 __u64 ac_utime; /* User CPU time [usec] */
86
87 /* The system CPU time of a task, in [usec]. */
88 __u64 ac_stime; /* System CPU time [usec] */
89
90 /* The minor page fault count of a task, as set in task->min_flt. */
91 __u64 ac_minflt; /* Minor Page Fault Count */
92
93 /* The major page fault count of a task, as set in task->maj_flt. */
94 __u64 ac_majflt; /* Major Page Fault Count */
95
96
97 2) Delay accounting fields::
98
99 /* Delay accounting fields start
100 *
101 * All values, until the comment "Delay accounting fields end" are
102 * available only if delay accounting is enabled, even though the last
103 * few fields are not delays
104 *
105 * xxx_count is the number of delay values recorded
106 * xxx_delay_total is the corresponding cumulative delay in nanoseconds
107 *
108 * xxx_delay_total wraps around to zero on overflow
109 * xxx_count incremented regardless of overflow
110 */
111
112 /* Delay waiting for cpu, while runnable
113 * count, delay_total NOT updated atomically
114 */
115 __u64 cpu_count;
116 __u64 cpu_delay_total;
117
118 /* Following four fields atomically updated using task->delays->lock */
119
120 /* Delay waiting for synchronous block I/O to complete
121 * does not account for delays in I/O submission
122 */
123 __u64 blkio_count;
124 __u64 blkio_delay_total;
125
126 /* Delay waiting for page fault I/O (swap in only) */
127 __u64 swapin_count;
128 __u64 swapin_delay_total;
129
130 /* cpu "wall-clock" running time
131 * On some architectures, value will adjust for cpu time stolen
132 * from the kernel in involuntary waits due to virtualization.
133 * Value is cumulative, in nanoseconds, without a corresponding count
134 * and wraps around to zero silently on overflow
135 */
136 __u64 cpu_run_real_total;
137
138 /* cpu "virtual" running time
139 * Uses time intervals seen by the kernel i.e. no adjustment
140 * for kernel's involuntary waits due to virtualization.
141 * Value is cumulative, in nanoseconds, without a corresponding count
142 * and wraps around to zero silently on overflow
143 */
144 __u64 cpu_run_virtual_total;
145 /* Delay accounting fields end */
146 /* version 1 ends here */
147
148
149 3) Extended accounting fields::
150
151 /* Extended accounting fields start */
152
153 /* Accumulated RSS usage in duration of a task, in MBytes-usecs.
154 * The current rss usage is added to this counter every time
155 * a tick is charged to a task's system time. So, at the end we
156 * will have memory usage multiplied by system time. Thus an
157 * average usage per system time unit can be calculated.
158 */
159 __u64 coremem; /* accumulated RSS usage in MB-usec */
160
161 /* Accumulated virtual memory usage in duration of a task.
162 * Same as acct_rss_mem1 above except that we keep track of VM usage.
163 */
164 __u64 virtmem; /* accumulated VM usage in MB-usec */
165
166 /* High watermark of RSS usage in duration of a task, in KBytes. */
167 __u64 hiwater_rss; /* High-watermark of RSS usage */
168
169 /* High watermark of VM usage in duration of a task, in KBytes. */
170 __u64 hiwater_vm; /* High-water virtual memory usage */
171
172 /* The following four fields are I/O statistics of a task. */
173 __u64 read_char; /* bytes read */
174 __u64 write_char; /* bytes written */
175 __u64 read_syscalls; /* read syscalls */
176 __u64 write_syscalls; /* write syscalls */
177
178 /* Extended accounting fields end */
179
180 4) Per-task and per-thread statistics::
181
182 __u64 nvcsw; /* Context voluntary switch counter */
183 __u64 nivcsw; /* Context involuntary switch counter */
184
185 5) Time accounting for SMT machines::
186
187 __u64 ac_utimescaled; /* utime scaled on frequency etc */
188 __u64 ac_stimescaled; /* stime scaled on frequency etc */
189 __u64 cpu_scaled_run_real_total; /* scaled cpu_run_real_total */
190
191 6) Extended delay accounting fields for memory reclaim::
192
193 /* Delay waiting for memory reclaim */
194 __u64 freepages_count;
195 __u64 freepages_delay_total;
196
197 ::
198
199 }
200

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의 상대적 위치를 바꾸면 안 됩니다.

taskstats field groups
GroupCondition/purpose
Common/basic accountingCONFIG_TASKSTATS; delivered at do_exit()
Delay accountingCONFIG_TASK_DELAY_ACCT
Extended accountingCONFIG_TASK_XACCT
Context switch countsPer-task and per-thread
SMT time accountingScaled CPU times
Memory reclaim delayExtended delay accounting

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입니다.

Common taskstats units
FieldMeaning/unit
versionTASKSTATS_VERSION
ac_exitcode / ac_flag / ac_niceExit, accounting flags, nice
ac_uid / ac_gid / ac_pid / ac_ppidIdentity
ac_btimeSeconds since 1970
ac_etime / ac_utime / ac_stimeMicroseconds
ac_minflt / ac_majfltMinor / major page faults

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-148

Delay 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의 끝입니다.

Delay field semantics
FieldsMeasured eventUpdate note
cpu_count / cpu_delay_totalRunnable CPU waitNot atomic
blkio_count / blkio_delay_totalSynchronous block I/O completionUnder task->delays->lock
swapin_count / swapin_delay_totalSwap-in page-fault I/OUnder task->delays->lock
cpu_run_real_totalAdjusted wall-clock CPU runNo count; ns; wraps
cpu_run_virtual_totalKernel-observed CPU runNo count; ns; wraps

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 수입니다.

Extended accounting units
FieldMeaning/unit
corememAccumulated RSS, MB-usec
virtmemAccumulated VM, MB-usec
hiwater_rssRSS high watermark, KBytes
hiwater_vmVM high watermark, KBytes
read_char / write_charBytes read / written
read_syscalls / write_syscallsSyscall counts

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;

::

  }