diff options
author | Andrea Righi <righi.andrea@gmail.com> | 2008-07-27 11:29:15 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-07-27 12:58:20 -0400 |
commit | 5995477ab7f3522c497c9c4a1c55373e9d655574 (patch) | |
tree | a147fb61642a7ac5441855964eb97a2ff1e37202 /include | |
parent | 605ccb73f6a1c891a16268b3a2923208fc637958 (diff) |
task IO accounting: improve code readability
Put all i/o statistics in struct proc_io_accounting and use inline functions to
initialize and increment statistics, removing a lot of single variable
assignments.
This also reduces the kernel size as following (with CONFIG_TASK_XACCT=y and
CONFIG_TASK_IO_ACCOUNTING=y).
text data bss dec hex filename
11651 0 0 11651 2d83 kernel/exit.o.before
11619 0 0 11619 2d63 kernel/exit.o.after
10886 132 136 11154 2b92 kernel/fork.o.before
10758 132 136 11026 2b12 kernel/fork.o.after
3082029 807968 4818600 8708597 84e1f5 vmlinux.o.before
3081869 807968 4818600 8708437 84e155 vmlinux.o.after
Signed-off-by: Andrea Righi <righi.andrea@gmail.com>
Acked-by: Oleg Nesterov <oleg@tv-sign.ru>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include')
-rw-r--r-- | include/linux/sched.h | 19 | ||||
-rw-r--r-- | include/linux/task_io_accounting.h | 27 | ||||
-rw-r--r-- | include/linux/task_io_accounting_ops.h | 56 |
3 files changed, 76 insertions, 26 deletions
diff --git a/include/linux/sched.h b/include/linux/sched.h index f59318a0099b..034c1ca6b332 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h | |||
@@ -505,10 +505,7 @@ struct signal_struct { | |||
505 | unsigned long nvcsw, nivcsw, cnvcsw, cnivcsw; | 505 | unsigned long nvcsw, nivcsw, cnvcsw, cnivcsw; |
506 | unsigned long min_flt, maj_flt, cmin_flt, cmaj_flt; | 506 | unsigned long min_flt, maj_flt, cmin_flt, cmaj_flt; |
507 | unsigned long inblock, oublock, cinblock, coublock; | 507 | unsigned long inblock, oublock, cinblock, coublock; |
508 | #ifdef CONFIG_TASK_XACCT | 508 | struct proc_io_accounting ioac; |
509 | u64 rchar, wchar, syscr, syscw; | ||
510 | #endif | ||
511 | struct task_io_accounting ioac; | ||
512 | 509 | ||
513 | /* | 510 | /* |
514 | * Cumulative ns of scheduled CPU time for dead threads in the | 511 | * Cumulative ns of scheduled CPU time for dead threads in the |
@@ -1256,11 +1253,7 @@ struct task_struct { | |||
1256 | 1253 | ||
1257 | unsigned long ptrace_message; | 1254 | unsigned long ptrace_message; |
1258 | siginfo_t *last_siginfo; /* For ptrace use. */ | 1255 | siginfo_t *last_siginfo; /* For ptrace use. */ |
1259 | #ifdef CONFIG_TASK_XACCT | 1256 | struct proc_io_accounting ioac; |
1260 | /* i/o counters(bytes read/written, #syscalls */ | ||
1261 | u64 rchar, wchar, syscr, syscw; | ||
1262 | #endif | ||
1263 | struct task_io_accounting ioac; | ||
1264 | #if defined(CONFIG_TASK_XACCT) | 1257 | #if defined(CONFIG_TASK_XACCT) |
1265 | u64 acct_rss_mem1; /* accumulated rss usage */ | 1258 | u64 acct_rss_mem1; /* accumulated rss usage */ |
1266 | u64 acct_vm_mem1; /* accumulated virtual memory usage */ | 1259 | u64 acct_vm_mem1; /* accumulated virtual memory usage */ |
@@ -2190,22 +2183,22 @@ extern long sched_group_rt_period(struct task_group *tg); | |||
2190 | #ifdef CONFIG_TASK_XACCT | 2183 | #ifdef CONFIG_TASK_XACCT |
2191 | static inline void add_rchar(struct task_struct *tsk, ssize_t amt) | 2184 | static inline void add_rchar(struct task_struct *tsk, ssize_t amt) |
2192 | { | 2185 | { |
2193 | tsk->rchar += amt; | 2186 | tsk->ioac.chr.rchar += amt; |
2194 | } | 2187 | } |
2195 | 2188 | ||
2196 | static inline void add_wchar(struct task_struct *tsk, ssize_t amt) | 2189 | static inline void add_wchar(struct task_struct *tsk, ssize_t amt) |
2197 | { | 2190 | { |
2198 | tsk->wchar += amt; | 2191 | tsk->ioac.chr.wchar += amt; |
2199 | } | 2192 | } |
2200 | 2193 | ||
2201 | static inline void inc_syscr(struct task_struct *tsk) | 2194 | static inline void inc_syscr(struct task_struct *tsk) |
2202 | { | 2195 | { |
2203 | tsk->syscr++; | 2196 | tsk->ioac.chr.syscr++; |
2204 | } | 2197 | } |
2205 | 2198 | ||
2206 | static inline void inc_syscw(struct task_struct *tsk) | 2199 | static inline void inc_syscw(struct task_struct *tsk) |
2207 | { | 2200 | { |
2208 | tsk->syscw++; | 2201 | tsk->ioac.chr.syscw++; |
2209 | } | 2202 | } |
2210 | #else | 2203 | #else |
2211 | static inline void add_rchar(struct task_struct *tsk, ssize_t amt) | 2204 | static inline void add_rchar(struct task_struct *tsk, ssize_t amt) |
diff --git a/include/linux/task_io_accounting.h b/include/linux/task_io_accounting.h index 44d00e9cceea..165390f8b936 100644 --- a/include/linux/task_io_accounting.h +++ b/include/linux/task_io_accounting.h | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * task_io_accounting: a structure which is used for recording a single task's | 2 | * proc_io_accounting: a structure which is used for recording a single task's |
3 | * IO statistics. | 3 | * IO statistics. |
4 | * | 4 | * |
5 | * Don't include this header file directly - it is designed to be dragged in via | 5 | * Don't include this header file directly - it is designed to be dragged in via |
@@ -8,6 +8,22 @@ | |||
8 | * Blame akpm@osdl.org for all this. | 8 | * Blame akpm@osdl.org for all this. |
9 | */ | 9 | */ |
10 | 10 | ||
11 | #ifdef CONFIG_TASK_XACCT | ||
12 | struct task_chr_io_accounting { | ||
13 | /* bytes read */ | ||
14 | u64 rchar; | ||
15 | /* bytes written */ | ||
16 | u64 wchar; | ||
17 | /* # of read syscalls */ | ||
18 | u64 syscr; | ||
19 | /* # of write syscalls */ | ||
20 | u64 syscw; | ||
21 | }; | ||
22 | #else /* CONFIG_TASK_XACCT */ | ||
23 | struct task_chr_io_accounting { | ||
24 | }; | ||
25 | #endif /* CONFIG_TASK_XACCT */ | ||
26 | |||
11 | #ifdef CONFIG_TASK_IO_ACCOUNTING | 27 | #ifdef CONFIG_TASK_IO_ACCOUNTING |
12 | struct task_io_accounting { | 28 | struct task_io_accounting { |
13 | /* | 29 | /* |
@@ -31,7 +47,12 @@ struct task_io_accounting { | |||
31 | */ | 47 | */ |
32 | u64 cancelled_write_bytes; | 48 | u64 cancelled_write_bytes; |
33 | }; | 49 | }; |
34 | #else | 50 | #else /* CONFIG_TASK_IO_ACCOUNTING */ |
35 | struct task_io_accounting { | 51 | struct task_io_accounting { |
36 | }; | 52 | }; |
37 | #endif | 53 | #endif /* CONFIG_TASK_IO_ACCOUNTING */ |
54 | |||
55 | struct proc_io_accounting { | ||
56 | struct task_chr_io_accounting chr; | ||
57 | struct task_io_accounting blk; | ||
58 | }; | ||
diff --git a/include/linux/task_io_accounting_ops.h b/include/linux/task_io_accounting_ops.h index ff46c6fad79d..e6f958ebe97f 100644 --- a/include/linux/task_io_accounting_ops.h +++ b/include/linux/task_io_accounting_ops.h | |||
@@ -9,7 +9,7 @@ | |||
9 | #ifdef CONFIG_TASK_IO_ACCOUNTING | 9 | #ifdef CONFIG_TASK_IO_ACCOUNTING |
10 | static inline void task_io_account_read(size_t bytes) | 10 | static inline void task_io_account_read(size_t bytes) |
11 | { | 11 | { |
12 | current->ioac.read_bytes += bytes; | 12 | current->ioac.blk.read_bytes += bytes; |
13 | } | 13 | } |
14 | 14 | ||
15 | /* | 15 | /* |
@@ -18,12 +18,12 @@ static inline void task_io_account_read(size_t bytes) | |||
18 | */ | 18 | */ |
19 | static inline unsigned long task_io_get_inblock(const struct task_struct *p) | 19 | static inline unsigned long task_io_get_inblock(const struct task_struct *p) |
20 | { | 20 | { |
21 | return p->ioac.read_bytes >> 9; | 21 | return p->ioac.blk.read_bytes >> 9; |
22 | } | 22 | } |
23 | 23 | ||
24 | static inline void task_io_account_write(size_t bytes) | 24 | static inline void task_io_account_write(size_t bytes) |
25 | { | 25 | { |
26 | current->ioac.write_bytes += bytes; | 26 | current->ioac.blk.write_bytes += bytes; |
27 | } | 27 | } |
28 | 28 | ||
29 | /* | 29 | /* |
@@ -32,17 +32,25 @@ static inline void task_io_account_write(size_t bytes) | |||
32 | */ | 32 | */ |
33 | static inline unsigned long task_io_get_oublock(const struct task_struct *p) | 33 | static inline unsigned long task_io_get_oublock(const struct task_struct *p) |
34 | { | 34 | { |
35 | return p->ioac.write_bytes >> 9; | 35 | return p->ioac.blk.write_bytes >> 9; |
36 | } | 36 | } |
37 | 37 | ||
38 | static inline void task_io_account_cancelled_write(size_t bytes) | 38 | static inline void task_io_account_cancelled_write(size_t bytes) |
39 | { | 39 | { |
40 | current->ioac.cancelled_write_bytes += bytes; | 40 | current->ioac.blk.cancelled_write_bytes += bytes; |
41 | } | 41 | } |
42 | 42 | ||
43 | static inline void task_io_accounting_init(struct task_struct *tsk) | 43 | static inline void task_io_accounting_init(struct proc_io_accounting *ioac) |
44 | { | 44 | { |
45 | memset(&tsk->ioac, 0, sizeof(tsk->ioac)); | 45 | memset(ioac, 0, sizeof(*ioac)); |
46 | } | ||
47 | |||
48 | static inline void task_blk_io_accounting_add(struct proc_io_accounting *dst, | ||
49 | struct proc_io_accounting *src) | ||
50 | { | ||
51 | dst->blk.read_bytes += src->blk.read_bytes; | ||
52 | dst->blk.write_bytes += src->blk.write_bytes; | ||
53 | dst->blk.cancelled_write_bytes += src->blk.cancelled_write_bytes; | ||
46 | } | 54 | } |
47 | 55 | ||
48 | #else | 56 | #else |
@@ -69,9 +77,37 @@ static inline void task_io_account_cancelled_write(size_t bytes) | |||
69 | { | 77 | { |
70 | } | 78 | } |
71 | 79 | ||
72 | static inline void task_io_accounting_init(struct task_struct *tsk) | 80 | static inline void task_io_accounting_init(struct proc_io_accounting *ioac) |
81 | { | ||
82 | } | ||
83 | |||
84 | static inline void task_blk_io_accounting_add(struct proc_io_accounting *dst, | ||
85 | struct proc_io_accounting *src) | ||
73 | { | 86 | { |
74 | } | 87 | } |
75 | 88 | ||
76 | #endif /* CONFIG_TASK_IO_ACCOUNTING */ | 89 | #endif /* CONFIG_TASK_IO_ACCOUNTING */ |
77 | #endif /* __TASK_IO_ACCOUNTING_OPS_INCLUDED */ | 90 | |
91 | #ifdef CONFIG_TASK_XACCT | ||
92 | static inline void task_chr_io_accounting_add(struct proc_io_accounting *dst, | ||
93 | struct proc_io_accounting *src) | ||
94 | { | ||
95 | dst->chr.rchar += src->chr.rchar; | ||
96 | dst->chr.wchar += src->chr.wchar; | ||
97 | dst->chr.syscr += src->chr.syscr; | ||
98 | dst->chr.syscw += src->chr.syscw; | ||
99 | } | ||
100 | #else | ||
101 | static inline void task_chr_io_accounting_add(struct proc_io_accounting *dst, | ||
102 | struct proc_io_accounting *src) | ||
103 | { | ||
104 | } | ||
105 | #endif /* CONFIG_TASK_XACCT */ | ||
106 | |||
107 | static inline void task_io_accounting_add(struct proc_io_accounting *dst, | ||
108 | struct proc_io_accounting *src) | ||
109 | { | ||
110 | task_chr_io_accounting_add(dst, src); | ||
111 | task_blk_io_accounting_add(dst, src); | ||
112 | } | ||
113 | #endif /* __TASK_IO_ACCOUNTING_OPS_INCLUDED */ | ||