linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] task IO accounting: correctly account threads IO statistics
@ 2008-07-26 15:52 Andrea Righi
  2008-07-26 16:12 ` Oleg Nesterov
  0 siblings, 1 reply; 2+ messages in thread
From: Andrea Righi @ 2008-07-26 15:52 UTC (permalink / raw)
  To: Oleg Nesterov
  Cc: akpm, torvalds, balbir, matt, linux-kernel, Andrea Righi, Oleg Nesterov

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: Andrea Righi <righi.andrea@gmail.com>
Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
---
 fs/proc/base.c |   56 ++++++++++++++++++++++----------------------------------
 1 files changed, 22 insertions(+), 34 deletions(-)

diff --git a/fs/proc/base.c b/fs/proc/base.c
index a891fe4..346500d 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -2381,35 +2381,18 @@ static int do_io_accounting(struct task_struct *task, char *buffer, int whole)
 	u64 rchar, wchar, syscr, syscw;
 	struct task_io_accounting ioac;
 
-	if (!whole) {
-		rchar = task->rchar;
-		wchar = task->wchar;
-		syscr = task->syscr;
-		syscw = task->syscw;
-		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));
+	rchar = task->rchar;
+	wchar = task->wchar;
+	syscr = task->syscr;
+	syscw = task->syscw;
+	memcpy(&ioac, &task->ioac, sizeof(ioac));
 
-		rcu_read_lock();
-		do {
-			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 (whole) {
+		unsigned long flags;
 
 		if (lock_task_sighand(task, &flags)) {
 			struct signal_struct *sig = task->signal;
+			struct task_struct *t = task;
 
 			rchar += sig->rchar;
 			wchar += sig->wchar;
@@ -2420,11 +2403,20 @@ static int do_io_accounting(struct task_struct *task, char *buffer, int whole)
 			ioac.write_bytes += sig->ioac.write_bytes;
 			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);
 		}
 	}
-
 	return sprintf(buffer,
 			"rchar: %llu\n"
 			"wchar: %llu\n"
@@ -2433,13 +2425,9 @@ static int do_io_accounting(struct task_struct *task, char *buffer, int whole)
 			"read_bytes: %llu\n"
 			"write_bytes: %llu\n"
 			"cancelled_write_bytes: %llu\n",
-			(unsigned long long)rchar,
-			(unsigned long long)wchar,
-			(unsigned long long)syscr,
-			(unsigned long long)syscw,
-			(unsigned long long)ioac.read_bytes,
-			(unsigned long long)ioac.write_bytes,
-			(unsigned long long)ioac.cancelled_write_bytes);
+			rchar, wchar, syscr, syscw,
+			ioac.read_bytes, ioac.write_bytes,
+			ioac.cancelled_write_bytes);
 }
 
 static int proc_tid_io_accounting(struct task_struct *task, char *buffer)
-- 
1.5.4.3


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 1/1] task IO accounting: correctly account threads IO statistics
  2008-07-26 15:52 [PATCH 1/1] task IO accounting: correctly account threads IO statistics Andrea Righi
@ 2008-07-26 16:12 ` Oleg Nesterov
  0 siblings, 0 replies; 2+ messages in thread
From: Oleg Nesterov @ 2008-07-26 16:12 UTC (permalink / raw)
  To: Andrea Righi; +Cc: akpm, torvalds, balbir, matt, linux-kernel

On 07/26, Andrea Righi wrote:
>
> --- a/fs/proc/base.c
> +++ b/fs/proc/base.c
> @@ -2381,35 +2381,18 @@ static int do_io_accounting(struct task_struct *task, char *buffer, int whole)
>  	u64 rchar, wchar, syscr, syscw;
>  	struct task_io_accounting ioac;
>  
> -	if (!whole) {
> -		rchar = task->rchar;
> -		wchar = task->wchar;
> -		syscr = task->syscr;
> -		syscw = task->syscw;
> -		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));
> +	rchar = task->rchar;
> +	wchar = task->wchar;
> +	syscr = task->syscr;
> +	syscw = task->syscw;
> +	memcpy(&ioac, &task->ioac, sizeof(ioac));
>  
> -		rcu_read_lock();
> -		do {
> -			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 (whole) {
> +		unsigned long flags;
>  
>  		if (lock_task_sighand(task, &flags)) {
>  			struct signal_struct *sig = task->signal;
> +			struct task_struct *t = task;
>  
>  			rchar += sig->rchar;
>  			wchar += sig->wchar;
> @@ -2420,11 +2403,20 @@ static int do_io_accounting(struct task_struct *task, char *buffer, int whole)
>  			ioac.write_bytes += sig->ioac.write_bytes;
>  			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);
>  		}
>  	}
> -
>  	return sprintf(buffer,
>  			"rchar: %llu\n"
>  			"wchar: %llu\n"
> @@ -2433,13 +2425,9 @@ static int do_io_accounting(struct task_struct *task, char *buffer, int whole)
>  			"read_bytes: %llu\n"
>  			"write_bytes: %llu\n"
>  			"cancelled_write_bytes: %llu\n",
> -			(unsigned long long)rchar,
> -			(unsigned long long)wchar,
> -			(unsigned long long)syscr,
> -			(unsigned long long)syscw,
> -			(unsigned long long)ioac.read_bytes,
> -			(unsigned long long)ioac.write_bytes,
> -			(unsigned long long)ioac.cancelled_write_bytes);
> +			rchar, wchar, syscr, syscw,
> +			ioac.read_bytes, ioac.write_bytes,
> +			ioac.cancelled_write_bytes);
>  }

Looks good!

And thanks for correcting me, of course we should initialize t
before while_each_thread(task, t).

Oleg.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-07-26 16:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-07-26 15:52 [PATCH 1/1] task IO accounting: correctly account threads IO statistics Andrea Righi
2008-07-26 16:12 ` Oleg Nesterov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).