From: Andrew Morton Add a simple /proc/pid/io to show the IO accounting fields. Maybe this shouldn't be merged in mainline - the preferred reporting channel is taskstats. But given the poor state of our userspace support for taskstats, this is useful for developer-testing, at least. Opinions are sought. The patch also wires up the existing IO-accounting fields. It's a bit racy on 32-bit machines: if process A reads process B's /proc/pid/io while process B is updating one of those 64-bit counters, process A could see an intermediate result. Cc: Jay Lan Cc: Shailabh Nagar Cc: Balbir Singh Cc: Chris Sturtivant Cc: Tony Ernst Cc: Guillaume Thouvenin Cc: David Wright Signed-off-by: Andrew Morton --- fs/proc/base.c | 24 ++++++++++++++++++++++++ 1 files changed, 24 insertions(+) diff -puN fs/proc/base.c~io-accounting-report-in-procfs fs/proc/base.c --- a/fs/proc/base.c~io-accounting-report-in-procfs +++ a/fs/proc/base.c @@ -1745,6 +1745,27 @@ static int proc_base_fill_cache(struct f proc_base_instantiate, task, p); } +#ifdef CONFIG_TASK_IO_ACCOUNTING +static int proc_pid_io_accounting(struct task_struct *task, char *buffer) +{ + return sprintf(buffer, + "rchar: %llu\n" + "wchar: %llu\n" + "syscr: %llu\n" + "syscw: %llu\n" + "read_bytes: %llu\n" + "write_bytes: %llu\n" + "cancelled_write_bytes: %llu\n", + (unsigned long long)task->rchar, + (unsigned long long)task->wchar, + (unsigned long long)task->syscr, + (unsigned long long)task->syscw, + (unsigned long long)task->ioac.read_bytes, + (unsigned long long)task->ioac.write_bytes, + (unsigned long long)task->ioac.cancelled_write_bytes); +} +#endif + /* * Thread groups */ @@ -1793,6 +1814,9 @@ static struct pid_entry tgid_base_stuff[ #ifdef CONFIG_AUDITSYSCALL REG("loginuid", S_IWUSR|S_IRUGO, loginuid), #endif +#ifdef CONFIG_TASK_IO_ACCOUNTING + INF("io", S_IRUGO, pid_io_accounting), +#endif }; static int proc_tgid_base_readdir(struct file * filp, _