task IO accounting: move all IO statistics in struct task_io_accounting

Simplify the code of include/linux/task_io_accounting.h.

It is also more reasonable to have all the task i/o-related statistics in a
single struct (task_io_accounting).

Signed-off-by: Andrea Righi <righi.andrea@gmail.com>
Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Andrea Righi and committed by
Linus Torvalds
940389b8 837b41b5

+44 -57
+5 -5
fs/proc/base.c
··· 2403 #ifdef CONFIG_TASK_IO_ACCOUNTING 2404 static int do_io_accounting(struct task_struct *task, char *buffer, int whole) 2405 { 2406 - struct proc_io_accounting acct = task->ioac; 2407 unsigned long flags; 2408 2409 if (whole && lock_task_sighand(task, &flags)) { ··· 2423 "read_bytes: %llu\n" 2424 "write_bytes: %llu\n" 2425 "cancelled_write_bytes: %llu\n", 2426 - acct.chr.rchar, acct.chr.wchar, 2427 - acct.chr.syscr, acct.chr.syscw, 2428 - acct.blk.read_bytes, acct.blk.write_bytes, 2429 - acct.blk.cancelled_write_bytes); 2430 } 2431 2432 static int proc_tid_io_accounting(struct task_struct *task, char *buffer)
··· 2403 #ifdef CONFIG_TASK_IO_ACCOUNTING 2404 static int do_io_accounting(struct task_struct *task, char *buffer, int whole) 2405 { 2406 + struct task_io_accounting acct = task->ioac; 2407 unsigned long flags; 2408 2409 if (whole && lock_task_sighand(task, &flags)) { ··· 2423 "read_bytes: %llu\n" 2424 "write_bytes: %llu\n" 2425 "cancelled_write_bytes: %llu\n", 2426 + acct.rchar, acct.wchar, 2427 + acct.syscr, acct.syscw, 2428 + acct.read_bytes, acct.write_bytes, 2429 + acct.cancelled_write_bytes); 2430 } 2431 2432 static int proc_tid_io_accounting(struct task_struct *task, char *buffer)
+6 -6
include/linux/sched.h
··· 505 unsigned long nvcsw, nivcsw, cnvcsw, cnivcsw; 506 unsigned long min_flt, maj_flt, cmin_flt, cmaj_flt; 507 unsigned long inblock, oublock, cinblock, coublock; 508 - struct proc_io_accounting ioac; 509 510 /* 511 * Cumulative ns of scheduled CPU time for dead threads in the ··· 1253 1254 unsigned long ptrace_message; 1255 siginfo_t *last_siginfo; /* For ptrace use. */ 1256 - struct proc_io_accounting ioac; 1257 #if defined(CONFIG_TASK_XACCT) 1258 u64 acct_rss_mem1; /* accumulated rss usage */ 1259 u64 acct_vm_mem1; /* accumulated virtual memory usage */ ··· 2183 #ifdef CONFIG_TASK_XACCT 2184 static inline void add_rchar(struct task_struct *tsk, ssize_t amt) 2185 { 2186 - tsk->ioac.chr.rchar += amt; 2187 } 2188 2189 static inline void add_wchar(struct task_struct *tsk, ssize_t amt) 2190 { 2191 - tsk->ioac.chr.wchar += amt; 2192 } 2193 2194 static inline void inc_syscr(struct task_struct *tsk) 2195 { 2196 - tsk->ioac.chr.syscr++; 2197 } 2198 2199 static inline void inc_syscw(struct task_struct *tsk) 2200 { 2201 - tsk->ioac.chr.syscw++; 2202 } 2203 #else 2204 static inline void add_rchar(struct task_struct *tsk, ssize_t amt)
··· 505 unsigned long nvcsw, nivcsw, cnvcsw, cnivcsw; 506 unsigned long min_flt, maj_flt, cmin_flt, cmaj_flt; 507 unsigned long inblock, oublock, cinblock, coublock; 508 + struct task_io_accounting ioac; 509 510 /* 511 * Cumulative ns of scheduled CPU time for dead threads in the ··· 1253 1254 unsigned long ptrace_message; 1255 siginfo_t *last_siginfo; /* For ptrace use. */ 1256 + struct task_io_accounting ioac; 1257 #if defined(CONFIG_TASK_XACCT) 1258 u64 acct_rss_mem1; /* accumulated rss usage */ 1259 u64 acct_vm_mem1; /* accumulated virtual memory usage */ ··· 2183 #ifdef CONFIG_TASK_XACCT 2184 static inline void add_rchar(struct task_struct *tsk, ssize_t amt) 2185 { 2186 + tsk->ioac.rchar += amt; 2187 } 2188 2189 static inline void add_wchar(struct task_struct *tsk, ssize_t amt) 2190 { 2191 + tsk->ioac.wchar += amt; 2192 } 2193 2194 static inline void inc_syscr(struct task_struct *tsk) 2195 { 2196 + tsk->ioac.syscr++; 2197 } 2198 2199 static inline void inc_syscw(struct task_struct *tsk) 2200 { 2201 + tsk->ioac.syscw++; 2202 } 2203 #else 2204 static inline void add_rchar(struct task_struct *tsk, ssize_t amt)
+2 -15
include/linux/task_io_accounting.h
··· 1 /* 2 - * proc_io_accounting: a structure which is used for recording a single task's 3 * IO statistics. 4 * 5 * Don't include this header file directly - it is designed to be dragged in via ··· 8 * Blame akpm@osdl.org for all this. 9 */ 10 11 #ifdef CONFIG_TASK_XACCT 12 - struct task_chr_io_accounting { 13 /* bytes read */ 14 u64 rchar; 15 /* bytes written */ ··· 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 27 #ifdef CONFIG_TASK_IO_ACCOUNTING 28 - struct task_io_accounting { 29 /* 30 * The number of bytes which this task has caused to be read from 31 * storage. ··· 41 * information loss in doing that. 42 */ 43 u64 cancelled_write_bytes; 44 - }; 45 - #else /* CONFIG_TASK_IO_ACCOUNTING */ 46 - struct task_io_accounting { 47 - }; 48 #endif /* CONFIG_TASK_IO_ACCOUNTING */ 49 - 50 - struct proc_io_accounting { 51 - struct task_chr_io_accounting chr; 52 - struct task_io_accounting blk; 53 };
··· 1 /* 2 + * task_io_accounting: a structure which is used for recording a single task's 3 * IO statistics. 4 * 5 * Don't include this header file directly - it is designed to be dragged in via ··· 8 * Blame akpm@osdl.org for all this. 9 */ 10 11 + struct task_io_accounting { 12 #ifdef CONFIG_TASK_XACCT 13 /* bytes read */ 14 u64 rchar; 15 /* bytes written */ ··· 18 u64 syscr; 19 /* # of write syscalls */ 20 u64 syscw; 21 #endif /* CONFIG_TASK_XACCT */ 22 23 #ifdef CONFIG_TASK_IO_ACCOUNTING 24 /* 25 * The number of bytes which this task has caused to be read from 26 * storage. ··· 46 * information loss in doing that. 47 */ 48 u64 cancelled_write_bytes; 49 #endif /* CONFIG_TASK_IO_ACCOUNTING */ 50 };
+24 -24
include/linux/task_io_accounting_ops.h
··· 9 #ifdef CONFIG_TASK_IO_ACCOUNTING 10 static inline void task_io_account_read(size_t bytes) 11 { 12 - current->ioac.blk.read_bytes += bytes; 13 } 14 15 /* ··· 18 */ 19 static inline unsigned long task_io_get_inblock(const struct task_struct *p) 20 { 21 - return p->ioac.blk.read_bytes >> 9; 22 } 23 24 static inline void task_io_account_write(size_t bytes) 25 { 26 - current->ioac.blk.write_bytes += bytes; 27 } 28 29 /* ··· 32 */ 33 static inline unsigned long task_io_get_oublock(const struct task_struct *p) 34 { 35 - return p->ioac.blk.write_bytes >> 9; 36 } 37 38 static inline void task_io_account_cancelled_write(size_t bytes) 39 { 40 - current->ioac.blk.cancelled_write_bytes += bytes; 41 } 42 43 - static inline void task_io_accounting_init(struct proc_io_accounting *ioac) 44 { 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; 54 } 55 56 #else ··· 77 { 78 } 79 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) 86 { 87 } 88 89 #endif /* CONFIG_TASK_IO_ACCOUNTING */ 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);
··· 9 #ifdef CONFIG_TASK_IO_ACCOUNTING 10 static inline void task_io_account_read(size_t bytes) 11 { 12 + current->ioac.read_bytes += bytes; 13 } 14 15 /* ··· 18 */ 19 static inline unsigned long task_io_get_inblock(const struct task_struct *p) 20 { 21 + return p->ioac.read_bytes >> 9; 22 } 23 24 static inline void task_io_account_write(size_t bytes) 25 { 26 + current->ioac.write_bytes += bytes; 27 } 28 29 /* ··· 32 */ 33 static inline unsigned long task_io_get_oublock(const struct task_struct *p) 34 { 35 + return p->ioac.write_bytes >> 9; 36 } 37 38 static inline void task_io_account_cancelled_write(size_t bytes) 39 { 40 + current->ioac.cancelled_write_bytes += bytes; 41 } 42 43 + static inline void task_io_accounting_init(struct task_io_accounting *ioac) 44 { 45 memset(ioac, 0, sizeof(*ioac)); 46 } 47 48 + static inline void task_blk_io_accounting_add(struct task_io_accounting *dst, 49 + struct task_io_accounting *src) 50 { 51 + dst->read_bytes += src->read_bytes; 52 + dst->write_bytes += src->write_bytes; 53 + dst->cancelled_write_bytes += src->cancelled_write_bytes; 54 } 55 56 #else ··· 77 { 78 } 79 80 + static inline void task_io_accounting_init(struct task_io_accounting *ioac) 81 { 82 } 83 84 + static inline void task_blk_io_accounting_add(struct task_io_accounting *dst, 85 + struct task_io_accounting *src) 86 { 87 } 88 89 #endif /* CONFIG_TASK_IO_ACCOUNTING */ 90 91 #ifdef CONFIG_TASK_XACCT 92 + static inline void task_chr_io_accounting_add(struct task_io_accounting *dst, 93 + struct task_io_accounting *src) 94 { 95 + dst->rchar += src->rchar; 96 + dst->wchar += src->wchar; 97 + dst->syscr += src->syscr; 98 + dst->syscw += src->syscw; 99 } 100 #else 101 + static inline void task_chr_io_accounting_add(struct task_io_accounting *dst, 102 + struct task_io_accounting *src) 103 { 104 } 105 #endif /* CONFIG_TASK_XACCT */ 106 107 + static inline void task_io_accounting_add(struct task_io_accounting *dst, 108 + struct task_io_accounting *src) 109 { 110 task_chr_io_accounting_add(dst, src); 111 task_blk_io_accounting_add(dst, src);
+7 -7
kernel/tsacct.c
··· 94 stats->hiwater_vm = mm->hiwater_vm * PAGE_SIZE / KB; 95 mmput(mm); 96 } 97 - stats->read_char = p->ioac.chr.rchar; 98 - stats->write_char = p->ioac.chr.wchar; 99 - stats->read_syscalls = p->ioac.chr.syscr; 100 - stats->write_syscalls = p->ioac.chr.syscw; 101 #ifdef CONFIG_TASK_IO_ACCOUNTING 102 - stats->read_bytes = p->ioac.blk.read_bytes; 103 - stats->write_bytes = p->ioac.blk.write_bytes; 104 - stats->cancelled_write_bytes = p->ioac.blk.cancelled_write_bytes; 105 #else 106 stats->read_bytes = 0; 107 stats->write_bytes = 0;
··· 94 stats->hiwater_vm = mm->hiwater_vm * PAGE_SIZE / KB; 95 mmput(mm); 96 } 97 + stats->read_char = p->ioac.rchar; 98 + stats->write_char = p->ioac.wchar; 99 + stats->read_syscalls = p->ioac.syscr; 100 + stats->write_syscalls = p->ioac.syscw; 101 #ifdef CONFIG_TASK_IO_ACCOUNTING 102 + stats->read_bytes = p->ioac.read_bytes; 103 + stats->write_bytes = p->ioac.write_bytes; 104 + stats->cancelled_write_bytes = p->ioac.cancelled_write_bytes; 105 #else 106 stats->read_bytes = 0; 107 stats->write_bytes = 0;