The patch titled getrusage(): fill ru_inblock and ru_oublock fields if possible has been added to the -mm tree. Its filename is getrusage-fill-ru_inblock-and-ru_oublock-fields-if-possible.patch *** Remember to use Documentation/SubmitChecklist when testing your code *** See http://www.zip.com.au/~akpm/linux/patches/stuff/added-to-mm.txt to find out what to do about this ------------------------------------------------------ Subject: getrusage(): fill ru_inblock and ru_oublock fields if possible From: Eric Dumazet <dada1@xxxxxxxxxxxxx> If CONFIG_TASK_IO_ACCOUNTING is defined, we update io accounting counters for each task. This patch permits reporting of values using the well known getrusage() syscall, filling ru_inblock and ru_oublock instead of null values. As TASK_IO_ACCOUNTING currently counts bytes counts, we approximate blocks count doing : nr_blocks = nr_bytes / 512 Example of use : ---------------------- After patch is applied, /usr/bin/time command can now give a good approximation of IO that the process had to do. $ /usr/bin/time grep tototo /usr/include/* Command exited with non-zero status 1 0.00user 0.02system 0:02.11elapsed 1%CPU (0avgtext+0avgdata 0maxresident)k 24288inputs+0outputs (0major+259minor)pagefaults 0swaps $ /usr/bin/time dd if=/dev/zero of=/tmp/testfile count=1000 1000+0 enregistrements lus 1000+0 enregistrements écrits 512000 octets (512 kB) copiés, 0,00326601 seconde, 157 MB/s 0.00user 0.00system 0:00.00elapsed 80%CPU (0avgtext+0avgdata 0maxresident)k 0inputs+3000outputs (0major+299minor)pagefaults 0swaps Signed-off-by: Eric Dumazet <dada1@xxxxxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- include/linux/task_io_accounting_ops.h | 28 +++++++++++++++++++++++ kernel/sys.c | 7 +++++ 2 files changed, 35 insertions(+) diff -puN include/linux/task_io_accounting_ops.h~getrusage-fill-ru_inblock-and-ru_oublock-fields-if-possible include/linux/task_io_accounting_ops.h --- a/include/linux/task_io_accounting_ops.h~getrusage-fill-ru_inblock-and-ru_oublock-fields-if-possible +++ a/include/linux/task_io_accounting_ops.h @@ -10,11 +10,29 @@ static inline void task_io_account_read( current->ioac.read_bytes += bytes; } +/* + * We approximate number of blocks, because we account bytes only. + * A 'block' is 512 bytes + */ +static inline unsigned long task_io_get_inblock(const struct task_struct *p) +{ + return p->ioac.read_bytes >> 9; +} + static inline void task_io_account_write(size_t bytes) { current->ioac.write_bytes += bytes; } +/* + * We approximate number of blocks, because we account bytes only. + * A 'block' is 512 bytes + */ +static inline unsigned long task_io_get_oublock(const struct task_struct *p) +{ + return p->ioac.write_bytes >> 9; +} + static inline void task_io_account_cancelled_write(size_t bytes) { current->ioac.cancelled_write_bytes += bytes; @@ -31,10 +49,20 @@ static inline void task_io_account_read( { } +static inline unsigned long task_io_get_inblock(const struct task_struct *p) +{ + return 0; +} + static inline void task_io_account_write(size_t bytes) { } +static inline unsigned long task_io_get_oublock(const struct task_struct *p) +{ + return 0; +} + static inline void task_io_account_cancelled_write(size_t bytes) { } diff -puN kernel/sys.c~getrusage-fill-ru_inblock-and-ru_oublock-fields-if-possible kernel/sys.c --- a/kernel/sys.c~getrusage-fill-ru_inblock-and-ru_oublock-fields-if-possible +++ a/kernel/sys.c @@ -29,6 +29,7 @@ #include <linux/signal.h> #include <linux/cn_proc.h> #include <linux/getcpu.h> +#include <linux/task_io_accounting_ops.h> #include <linux/compat.h> #include <linux/syscalls.h> @@ -2021,6 +2022,8 @@ static void k_getrusage(struct task_stru r->ru_nivcsw = p->signal->cnivcsw; r->ru_minflt = p->signal->cmin_flt; r->ru_majflt = p->signal->cmaj_flt; + r->ru_inblock = task_io_get_inblock(p); + r->ru_oublock = task_io_get_oublock(p); if (who == RUSAGE_CHILDREN) break; @@ -2032,6 +2035,8 @@ static void k_getrusage(struct task_stru r->ru_nivcsw += p->signal->nivcsw; r->ru_minflt += p->signal->min_flt; r->ru_majflt += p->signal->maj_flt; + r->ru_inblock += task_io_get_inblock(p); + r->ru_oublock += task_io_get_oublock(p); t = p; do { utime = cputime_add(utime, t->utime); @@ -2040,6 +2045,8 @@ static void k_getrusage(struct task_stru r->ru_nivcsw += t->nivcsw; r->ru_minflt += t->min_flt; r->ru_majflt += t->maj_flt; + r->ru_inblock += task_io_get_inblock(t); + r->ru_oublock += task_io_get_oublock(t); t = next_thread(t); } while (t != p); break; _ Patches currently in -mm which might be from dada1@xxxxxxxxxxxxx are optimize-timespec_trunc.patch procfs-reorder-struct-pid_dentry-to-save-space-on-64bit-archs-and-constify-them.patch vfs-delay-the-dentry-name-generation-on-sockets-and.patch getrusage-fill-ru_inblock-and-ru_oublock-fields-if-possible.patch make-static-counters-in-new_inode-and-iunique-be-32-bits.patch speedup-divides-by-cpu_power-in-scheduler.patch - To unsubscribe from this list: send the line "unsubscribe mm-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html