implement distinct block device IO accounting
PATCH 2/4 implement distinct block device IO accounting
I/O statistics are stored in a rbtree (one for each thread or process), using the device number (dev_t) as key.
Note: dev_t block devices are used without registering any usage reference; if a block device is removed the i/o statistics of the running processes remain valid, *but* if a new block device is plugged in and it gets the same dev_t number, then all the previous i/o statistics for the old device will be merged together with i/o statistics of the new device.
Signed-off-by Andrea Righi <[email protected]>
--- include/linux/task_io_accounting.h | 59 ++++++++--- include/linux/task_io_accounting_ops.h | 108 ++++++++++++------- init/Kconfig | 9 ++ kernel/Makefile | 1 + kernel/task-io-accounting.c | 180 ++++++++++++++++++++++++++++++++ 5 files changed, 303 insertions(+), 54 deletions(-) create mode 100644 kernel/task-io-accounting.c
include/linux/task_io_accounting.h +45 -14
@@ -8,31 +8,32 @@* Blame [email protected] for all this. */ -struct task_io_accounting { -#ifdef CONFIG_TASK_XACCT -/* bytes read */ -u64 rchar; -/* bytes written */ -u64 wchar; -/* # of read syscalls */ -u64 syscr; -/* # of write syscalls */ -u64 syscw; -#endif /* CONFIG_TASK_XACCT */ +#include <linux/rbtree.h> +#include <linux/fs.h> -#ifdef CONFIG_TASK_IO_ACCOUNTING +#ifndef _LINUX_TASK_IO_ACCOUNTING_H +#define _LINUX_TASK_IO_ACCOUNTING_H + +enum io_acct_ops { + TASK_IO_ACCT_READ, + TASK_IO_ACCT_WRITE, + TASK_IO_ACCT_CANCELLED_WRITE, +}; + +struct task_io_acct_node { +#ifdef CONFIG_TASK_IO_ACCOUNTING_BDEV + struct rb_node node; + dev_t dev; /* * 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
@@ -41,5 +42,35 @@ struct task_io_accounting {* information loss in doing that. */ u64 cancelled_write_bytes; +#endif /* CONFIG_TASK_IO_ACCOUNTING_BDEV */ +}; + +struct task_io_accounting { +#ifdef CONFIG_TASK_XACCT +/* bytes read */ +u64 rchar; +/* bytes written */ +u64 wchar; +/* # of read syscalls */ +u64 syscr; +/* # of write syscalls */ +u64 syscw; +#endif /* CONFIG_TASK_XACCT */ +#ifdef CONFIG_TASK_IO_ACCOUNTING +u64 read_bytes; +u64 write_bytes; +u64 cancelled_write_bytes;#endif /* CONFIG_TASK_IO_ACCOUNTING */ +#ifdef CONFIG_TASK_IO_ACCOUNTING_BDEV +/* +* Red-Black tree to store each block device accounting informations. +*/ +struct rb_root tree; +/* +* Spinlock to manage red-black tree concurrent accesses. +*/ +spinlock_t lock; +#endif }; + +#endif /* _LINUX_TASK_IO_ACCOUNTING_H */
include/linux/task_io_accounting_ops.h +68 -40
177 lines not on this page · raw message
init/Kconfig +9 -0
@@ -215,6 +215,15 @@ config TASK_IO_ACCOUNTING Say N if unsure. +config TASK_IO_ACCOUNTING_BDEV + bool "Enable distinct block device I/O accounting (EXPERIMENTAL)" + depends on TASK_IO_ACCOUNTING + help + Collect informations on the number of bytes of real storage I/O which + each task has caused for each block device. + + Say N if unsure. + config AUDIT bool "Auditing support" depends on NET
kernel/Makefile +1 -0
@@ -80,6 +80,7 @@ obj-$(CONFIG_RELAY) += relay.o obj-$(CONFIG_SYSCTL) += utsname_sysctl.o obj-$(CONFIG_TASK_DELAY_ACCT) += delayacct.o obj-$(CONFIG_TASKSTATS) += taskstats.o tsacct.o +obj-$(CONFIG_TASK_IO_ACCOUNTING_BDEV) += task-io-accounting.o obj-$(CONFIG_MARKERS) += marker.o obj-$(CONFIG_LATENCYTOP) += latencytop.o obj-$(CONFIG_HAVE_GENERIC_DMA_COHERENT) += dma-coherent.o
kernel/task-io-accounting.c new file +180 -0
180 lines not on this page · raw message
Signature · 1 line
1.5.4.3