Skip to contentSkip to conversation

implement distinct block device IO accounting

PATCH New Andrea Righi 1 participant 1 message Jul 31, 2008

lore
Share & tools
lore
#0 lore raw

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.

---
 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
index 5e88afc..d7eb577 100644
@@ -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
index a451916..4e66bdf 100644
@@ -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
index dd58bdc..ef7cd1b 100644
@@ -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