Skip to contentSkip to conversation

BSD acct: disk I/O accounting

PATCH New Sergey Kononenko 1 participant 1 message Apr 22, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 BSD acct: disk I/O accounting

Hello,

This patch make acct use I/O statistics gathered when TASK_IO_ACCOUNTING is enabled. getrusage() already uses that statistics, but also will be helpful to get access to disk I/O statistics through traditional BSD accounting interface, because many userspace scripts that process such information not yet adapted to new taskstats API. Patch against 2.6.25.

---

include/linux/task_io_accounting_ops.h +20 -0
diff -uprN a/include/linux/task_io_accounting_ops.h b/include/linux/task_io_accounting_ops.h
@@ -21,6 +21,11 @@ static inline unsigned long task_io_get_
 	return p->ioac.read_bytes >> 9;
 }
 
+static inline unsigned long task_io_get_inbytes(const struct task_struct *p)
+{
+	return p->ioac.read_bytes;
+}
+
 static inline void task_io_account_write(size_t bytes)
 {
 	current->ioac.write_bytes += bytes;
@@ -35,6 +40,11 @@ static inline unsigned long task_io_get_
 	return p->ioac.write_bytes >> 9;
 }
 
+static inline unsigned long task_io_get_oubytes(const struct task_struct *p)
+{
+	return p->ioac.write_bytes;
+}
+
 static inline void task_io_account_cancelled_write(size_t bytes)
 {
 	current->ioac.cancelled_write_bytes += bytes;
@@ -56,6 +66,11 @@ static inline unsigned long task_io_get_
 	return 0;
 }
 
+static inline unsigned long task_io_get_inbytes(const struct task_struct *p)
+{
+	return 0;
+}
+
 static inline void task_io_account_write(size_t bytes)
 {
 }
@@ -65,6 +80,11 @@ static inline unsigned long task_io_get_
 	return 0;
 }
 
+static inline unsigned long task_io_get_oubytes(const struct task_struct *p)
+{
+	return 0;
+}
+
 static inline void task_io_account_cancelled_write(size_t bytes)
 {
 }
kernel/acct.c +3 -2
diff -uprN a/kernel/acct.c b/kernel/acct.c
@@ -55,6 +55,7 @@
 #include <linux/times.h>
 #include <linux/syscalls.h>
 #include <linux/mount.h>
+#include <linux/task_io_accounting_ops.h>
 #include <asm/uaccess.h>
 #include <asm/div64.h>
 #include <linux/blkdev.h> /* sector_div */
@@ -504,8 +505,8 @@ static void do_acct_process(struct pid_n
 	ac.ac_majflt = encode_comp_t(pacct->ac_majflt);
 	ac.ac_exitcode = pacct->ac_exitcode;
 	spin_unlock_irq(&current->sighand->siglock);
-	ac.ac_io = encode_comp_t(0 /* current->io_usage */);	/* %% */
-	ac.ac_rw = encode_comp_t(ac.ac_io / 1024);
+	ac.ac_io = encode_comp_t(task_io_get_inbytes(current) + task_io_get_oubytes(current));
+	ac.ac_rw = encode_comp_t(task_io_get_inblock(current) + task_io_get_oublock(current));
 	ac.ac_swaps = encode_comp_t(0);
 
 	/*