mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@tv-sign.ru>
To: Andrea Righi <righi.andrea@gmail.com>
Cc: akpm@linux-foundation.org, torvalds@linux-foundation.org,
	balbir@linux.vnet.ibm.com, matt@bluehost.com,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/1] task IO accounting: correctly account threads IO statistics
Date: Sat, 26 Jul 2008 20:12:13 +0400	[thread overview]
Message-ID: <20080726161213.GA594@tv-sign.ru> (raw)
In-Reply-To: <1217087532-22620-1-git-send-email-righi.andrea@gmail.com>

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.


      reply	other threads:[~2008-07-26 16:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-26 15:52 Andrea Righi
2008-07-26 16:12 ` Oleg Nesterov [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080726161213.GA594@tv-sign.ru \
    --to=oleg@tv-sign.ru \
    --cc=akpm@linux-foundation.org \
    --cc=balbir@linux.vnet.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matt@bluehost.com \
    --cc=righi.andrea@gmail.com \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®