提交 b2d002db 编写于 作者: A Andrea Righi 提交者: Linus Torvalds

task IO accounting: correctly account threads IO statistics

Oleg Nesterov points out that we should check that the task is still alive
before we iterate over the threads.  This patch includes a fixup for this.

Also simplify do_io_accounting() implementation.
Signed-off-by: NAndrea Righi <righi.andrea@gmail.com>
Signed-off-by: NOleg Nesterov <oleg@tv-sign.ru>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 6a9436d0
...@@ -2406,35 +2406,18 @@ static int do_io_accounting(struct task_struct *task, char *buffer, int whole) ...@@ -2406,35 +2406,18 @@ static int do_io_accounting(struct task_struct *task, char *buffer, int whole)
u64 rchar, wchar, syscr, syscw; u64 rchar, wchar, syscr, syscw;
struct task_io_accounting ioac; struct task_io_accounting ioac;
if (!whole) { rchar = task->rchar;
rchar = task->rchar; wchar = task->wchar;
wchar = task->wchar; syscr = task->syscr;
syscr = task->syscr; syscw = task->syscw;
syscw = task->syscw; memcpy(&ioac, &task->ioac, sizeof(ioac));
memcpy(&ioac, &task->ioac, sizeof(ioac));
} else {
unsigned long flags;
struct task_struct *t = task;
rchar = wchar = syscr = syscw = 0;
memset(&ioac, 0, sizeof(ioac));
rcu_read_lock(); if (whole) {
do { unsigned long flags;
rchar += t->rchar;
wchar += t->wchar;
syscr += t->syscr;
syscw += t->syscw;
ioac.read_bytes += t->ioac.read_bytes;
ioac.write_bytes += t->ioac.write_bytes;
ioac.cancelled_write_bytes +=
t->ioac.cancelled_write_bytes;
t = next_thread(t);
} while (t != task);
rcu_read_unlock();
if (lock_task_sighand(task, &flags)) { if (lock_task_sighand(task, &flags)) {
struct signal_struct *sig = task->signal; struct signal_struct *sig = task->signal;
struct task_struct *t = task;
rchar += sig->rchar; rchar += sig->rchar;
wchar += sig->wchar; wchar += sig->wchar;
...@@ -2445,11 +2428,20 @@ static int do_io_accounting(struct task_struct *task, char *buffer, int whole) ...@@ -2445,11 +2428,20 @@ static int do_io_accounting(struct task_struct *task, char *buffer, int whole)
ioac.write_bytes += sig->ioac.write_bytes; ioac.write_bytes += sig->ioac.write_bytes;
ioac.cancelled_write_bytes += ioac.cancelled_write_bytes +=
sig->ioac.cancelled_write_bytes; sig->ioac.cancelled_write_bytes;
while_each_thread(task, t) {
rchar += t->rchar;
wchar += t->wchar;
syscr += t->syscr;
syscw += t->syscw;
ioac.read_bytes += t->ioac.read_bytes;
ioac.write_bytes += t->ioac.write_bytes;
ioac.cancelled_write_bytes +=
t->ioac.cancelled_write_bytes;
}
unlock_task_sighand(task, &flags); unlock_task_sighand(task, &flags);
} }
} }
return sprintf(buffer, return sprintf(buffer,
"rchar: %llu\n" "rchar: %llu\n"
"wchar: %llu\n" "wchar: %llu\n"
...@@ -2458,13 +2450,9 @@ static int do_io_accounting(struct task_struct *task, char *buffer, int whole) ...@@ -2458,13 +2450,9 @@ static int do_io_accounting(struct task_struct *task, char *buffer, int whole)
"read_bytes: %llu\n" "read_bytes: %llu\n"
"write_bytes: %llu\n" "write_bytes: %llu\n"
"cancelled_write_bytes: %llu\n", "cancelled_write_bytes: %llu\n",
(unsigned long long)rchar, rchar, wchar, syscr, syscw,
(unsigned long long)wchar, ioac.read_bytes, ioac.write_bytes,
(unsigned long long)syscr, ioac.cancelled_write_bytes);
(unsigned long long)syscw,
(unsigned long long)ioac.read_bytes,
(unsigned long long)ioac.write_bytes,
(unsigned long long)ioac.cancelled_write_bytes);
} }
static int proc_tid_io_accounting(struct task_struct *task, char *buffer) static int proc_tid_io_accounting(struct task_struct *task, char *buffer)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册