From d9678912fd1918af7e5f29e60efba6326a0c905c Mon Sep 17 00:00:00 2001 From: Andrew Morton Date: Sun, 10 Dec 2006 02:19:19 -0800 Subject: [PATCH] --- yaml --- r: 43962 b: refs/heads/master c: 7c3ab7381e79dfc7db14a67c6f4f3285664e1ec2 h: refs/heads/master v: v3 --- [refs] | 2 +- trunk/include/linux/sched.h | 2 + trunk/include/linux/task_io_accounting.h | 37 +++++++++++++++ trunk/include/linux/task_io_accounting_ops.h | 47 ++++++++++++++++++++ trunk/init/Kconfig | 9 ++++ trunk/kernel/fork.c | 2 + 6 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 trunk/include/linux/task_io_accounting.h create mode 100644 trunk/include/linux/task_io_accounting_ops.h diff --git a/[refs] b/[refs] index 22e69da923d0..b16bc8c75d74 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 47694bb86af3648d4ec34c7afd46653cefc9b359 +refs/heads/master: 7c3ab7381e79dfc7db14a67c6f4f3285664e1ec2 diff --git a/trunk/include/linux/sched.h b/trunk/include/linux/sched.h index ad9c46071ff8..1208feab46e0 100644 --- a/trunk/include/linux/sched.h +++ b/trunk/include/linux/sched.h @@ -82,6 +82,7 @@ struct sched_param { #include #include #include +#include #include @@ -1013,6 +1014,7 @@ struct task_struct { wait_queue_t *io_wait; /* i/o counters(bytes read/written, #syscalls */ u64 rchar, wchar, syscr, syscw; + struct task_io_accounting ioac; #if defined(CONFIG_TASK_XACCT) u64 acct_rss_mem1; /* accumulated rss usage */ u64 acct_vm_mem1; /* accumulated virtual memory usage */ diff --git a/trunk/include/linux/task_io_accounting.h b/trunk/include/linux/task_io_accounting.h new file mode 100644 index 000000000000..44d00e9cceea --- /dev/null +++ b/trunk/include/linux/task_io_accounting.h @@ -0,0 +1,37 @@ +/* + * task_io_accounting: a structure which is used for recording a single task's + * IO statistics. + * + * Don't include this header file directly - it is designed to be dragged in via + * sched.h. + * + * Blame akpm@osdl.org for all this. + */ + +#ifdef CONFIG_TASK_IO_ACCOUNTING +struct task_io_accounting { + /* + * The number of bytes which this task has caused to be read from + * storage. + */ + u64 read_bytes; + + /* + * The number of bytes which this task has caused, or shall cause to be + * written to disk. + */ + u64 write_bytes; + + /* + * A task can cause "negative" IO too. If this task truncates some + * dirty pagecache, some IO which another task has been accounted for + * (in its write_bytes) will not be happening. We _could_ just + * subtract that from the truncating task's write_bytes, but there is + * information loss in doing that. + */ + u64 cancelled_write_bytes; +}; +#else +struct task_io_accounting { +}; +#endif diff --git a/trunk/include/linux/task_io_accounting_ops.h b/trunk/include/linux/task_io_accounting_ops.h new file mode 100644 index 000000000000..df2a319106b2 --- /dev/null +++ b/trunk/include/linux/task_io_accounting_ops.h @@ -0,0 +1,47 @@ +/* + * Task I/O accounting operations + */ +#ifndef __TASK_IO_ACCOUNTING_OPS_INCLUDED +#define __TASK_IO_ACCOUNTING_OPS_INCLUDED + +#ifdef CONFIG_TASK_IO_ACCOUNTING +static inline void task_io_account_read(size_t bytes) +{ + current->ioac.read_bytes += bytes; +} + +static inline void task_io_account_write(size_t bytes) +{ + current->ioac.write_bytes += bytes; +} + +static inline void task_io_account_cancelled_write(size_t bytes) +{ + current->ioac.cancelled_write_bytes += bytes; +} + +static inline void task_io_accounting_init(struct task_struct *tsk) +{ + memset(&tsk->ioac, 0, sizeof(tsk->ioac)); +} + +#else + +static inline void task_io_account_read(size_t bytes) +{ +} + +static inline void task_io_account_write(size_t bytes) +{ +} + +static inline void task_io_account_cancelled_write(size_t bytes) +{ +} + +static inline void task_io_accounting_init(struct task_struct *tsk) +{ +} + +#endif /* CONFIG_TASK_IO_ACCOUNTING */ +#endif /* __TASK_IO_ACCOUNTING_OPS_INCLUDED */ diff --git a/trunk/init/Kconfig b/trunk/init/Kconfig index 14d484606fab..9edf103b3ec3 100644 --- a/trunk/init/Kconfig +++ b/trunk/init/Kconfig @@ -304,6 +304,15 @@ config TASK_XACCT Say N if unsure. +config TASK_IO_ACCOUNTING + bool "Enable per-task storage I/O accounting (EXPERIMENTAL)" + depends on TASK_XACCT + help + Collect information on the number of bytes of storage I/O which this + task has caused. + + Say N if unsure. + config SYSCTL bool diff --git a/trunk/kernel/fork.c b/trunk/kernel/fork.c index 8c859eef8e6a..086e172d0d3d 100644 --- a/trunk/kernel/fork.c +++ b/trunk/kernel/fork.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -1055,6 +1056,7 @@ static struct task_struct *copy_process(unsigned long clone_flags, p->wchar = 0; /* I/O counter: bytes written */ p->syscr = 0; /* I/O counter: read syscalls */ p->syscw = 0; /* I/O counter: write syscalls */ + task_io_accounting_init(p); acct_clear_integrals(p); p->it_virt_expires = cputime_zero;