All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Jiri Pirko <jpirko@redhat.com>
Cc: kosaki.motohiro@jp.fujitsu.com, oleg@redhat.com,
	linux-kernel@vger.kernel.org, hugh@veritas.com,
	linux-mm@kvack.org
Subject: Re: [PATCH for -mm] getrusage: fill ru_maxrss value
Date: Mon, 5 Jan 2009 14:13:13 -0800	[thread overview]
Message-ID: <20090105141313.a4abd475.akpm@linux-foundation.org> (raw)
In-Reply-To: <20090105163204.3ec9ff10@psychotron.englab.brq.redhat.com>

On Mon, 5 Jan 2009 16:32:04 +0100
Jiri Pirko <jpirko@redhat.com> wrote:

> Changelog
> v2 -> v3
>   - in k_getrusage() use (inherited) sig->maxrss value in case of
>     RUSAGE_THREAD

The patch which you sent was mysteriously truncated - the kernel/sys.c hunk
is partly missing.  So I took that bit from the earlier version of the patch.

Please check that the below is still identical to your version 3.


diff -puN fs/exec.c~getrusage-fill-ru_maxrss-value fs/exec.c
--- a/fs/exec.c~getrusage-fill-ru_maxrss-value
+++ a/fs/exec.c
@@ -864,6 +864,13 @@ static int de_thread(struct task_struct 
 	sig->notify_count = 0;
 
 no_thread_group:
+	if (current->mm) {
+		unsigned long hiwater_rss = get_mm_hiwater_rss(current->mm);
+
+		if (sig->maxrss < hiwater_rss)
+			sig->maxrss = hiwater_rss;
+	}
+
 	exit_itimers(sig);
 	flush_itimer_signals();
 
diff -puN include/linux/sched.h~getrusage-fill-ru_maxrss-value include/linux/sched.h
--- a/include/linux/sched.h~getrusage-fill-ru_maxrss-value
+++ a/include/linux/sched.h
@@ -560,6 +560,7 @@ struct signal_struct {
 	unsigned long nvcsw, nivcsw, cnvcsw, cnivcsw;
 	unsigned long min_flt, maj_flt, cmin_flt, cmaj_flt;
 	unsigned long inblock, oublock, cinblock, coublock;
+	unsigned long maxrss, cmaxrss;
 	struct task_io_accounting ioac;
 
 	/*
diff -puN kernel/exit.c~getrusage-fill-ru_maxrss-value kernel/exit.c
--- a/kernel/exit.c~getrusage-fill-ru_maxrss-value
+++ a/kernel/exit.c
@@ -1053,6 +1053,12 @@ NORET_TYPE void do_exit(long code)
 	if (group_dead) {
 		hrtimer_cancel(&tsk->signal->real_timer);
 		exit_itimers(tsk->signal);
+		if (tsk->mm) {
+			unsigned long hiwater_rss = get_mm_hiwater_rss(tsk->mm);
+
+			if (tsk->signal->maxrss < hiwater_rss)
+				tsk->signal->maxrss = hiwater_rss;
+		}
 	}
 	acct_collect(code, group_dead);
 	if (group_dead)
@@ -1296,6 +1302,7 @@ static int wait_task_zombie(struct task_
 		struct signal_struct *psig;
 		struct signal_struct *sig;
 		struct task_cputime cputime;
+		unsigned long maxrss;
 
 		/*
 		 * The resource counters for the group leader are in its
@@ -1347,6 +1354,9 @@ static int wait_task_zombie(struct task_
 		psig->coublock +=
 			task_io_get_oublock(p) +
 			sig->oublock + sig->coublock;
+		maxrss = max(sig->maxrss, sig->cmaxrss);
+		if (psig->cmaxrss < maxrss)
+			psig->cmaxrss = maxrss;
 		task_io_accounting_add(&psig->ioac, &p->ioac);
 		task_io_accounting_add(&psig->ioac, &sig->ioac);
 		spin_unlock_irq(&p->parent->sighand->siglock);
diff -puN kernel/fork.c~getrusage-fill-ru_maxrss-value kernel/fork.c
--- a/kernel/fork.c~getrusage-fill-ru_maxrss-value
+++ a/kernel/fork.c
@@ -851,6 +851,7 @@ static int copy_signal(unsigned long clo
 	sig->nvcsw = sig->nivcsw = sig->cnvcsw = sig->cnivcsw = 0;
 	sig->min_flt = sig->maj_flt = sig->cmin_flt = sig->cmaj_flt = 0;
 	sig->inblock = sig->oublock = sig->cinblock = sig->coublock = 0;
+	sig->maxrss = sig->cmaxrss = 0;
 	task_io_accounting_init(&sig->ioac);
 	taskstats_tgid_init(sig);
 
diff -puN kernel/sys.c~getrusage-fill-ru_maxrss-value kernel/sys.c
--- a/kernel/sys.c~getrusage-fill-ru_maxrss-value
+++ a/kernel/sys.c
@@ -1676,6 +1676,18 @@ static void k_getrusage(struct task_stru
 out:
 	cputime_to_timeval(utime, &r->ru_utime);
 	cputime_to_timeval(stime, &r->ru_stime);
+
+	if (who != RUSAGE_CHILDREN) {
+		struct mm_struct *mm = get_task_mm(p);
+		if (mm) {
+			unsigned long hiwater_rss = get_mm_hiwater_rss(mm);
+
+			if (maxrss < hiwater_rss)
+				maxrss = hiwater_rss;
+			mmput(mm);
+		}
+	}
+	r->ru_maxrss <<= PAGE_SHIFT - 10;
 }
 
 int getrusage(struct task_struct *p, int who, struct rusage __user *ru)
_


WARNING: multiple messages have this Message-ID (diff)
From: Andrew Morton <akpm@linux-foundation.org>
To: Jiri Pirko <jpirko@redhat.com>
Cc: kosaki.motohiro@jp.fujitsu.com, oleg@redhat.com,
	linux-kernel@vger.kernel.org, hugh@veritas.com,
	linux-mm@kvack.org
Subject: Re: [PATCH for -mm] getrusage: fill ru_maxrss value
Date: Mon, 5 Jan 2009 14:13:13 -0800	[thread overview]
Message-ID: <20090105141313.a4abd475.akpm@linux-foundation.org> (raw)
In-Reply-To: <20090105163204.3ec9ff10@psychotron.englab.brq.redhat.com>

On Mon, 5 Jan 2009 16:32:04 +0100
Jiri Pirko <jpirko@redhat.com> wrote:

> Changelog
> v2 -> v3
>   - in k_getrusage() use (inherited) sig->maxrss value in case of
>     RUSAGE_THREAD

The patch which you sent was mysteriously truncated - the kernel/sys.c hunk
is partly missing.  So I took that bit from the earlier version of the patch.

Please check that the below is still identical to your version 3.


diff -puN fs/exec.c~getrusage-fill-ru_maxrss-value fs/exec.c
--- a/fs/exec.c~getrusage-fill-ru_maxrss-value
+++ a/fs/exec.c
@@ -864,6 +864,13 @@ static int de_thread(struct task_struct 
 	sig->notify_count = 0;
 
 no_thread_group:
+	if (current->mm) {
+		unsigned long hiwater_rss = get_mm_hiwater_rss(current->mm);
+
+		if (sig->maxrss < hiwater_rss)
+			sig->maxrss = hiwater_rss;
+	}
+
 	exit_itimers(sig);
 	flush_itimer_signals();
 
diff -puN include/linux/sched.h~getrusage-fill-ru_maxrss-value include/linux/sched.h
--- a/include/linux/sched.h~getrusage-fill-ru_maxrss-value
+++ a/include/linux/sched.h
@@ -560,6 +560,7 @@ struct signal_struct {
 	unsigned long nvcsw, nivcsw, cnvcsw, cnivcsw;
 	unsigned long min_flt, maj_flt, cmin_flt, cmaj_flt;
 	unsigned long inblock, oublock, cinblock, coublock;
+	unsigned long maxrss, cmaxrss;
 	struct task_io_accounting ioac;
 
 	/*
diff -puN kernel/exit.c~getrusage-fill-ru_maxrss-value kernel/exit.c
--- a/kernel/exit.c~getrusage-fill-ru_maxrss-value
+++ a/kernel/exit.c
@@ -1053,6 +1053,12 @@ NORET_TYPE void do_exit(long code)
 	if (group_dead) {
 		hrtimer_cancel(&tsk->signal->real_timer);
 		exit_itimers(tsk->signal);
+		if (tsk->mm) {
+			unsigned long hiwater_rss = get_mm_hiwater_rss(tsk->mm);
+
+			if (tsk->signal->maxrss < hiwater_rss)
+				tsk->signal->maxrss = hiwater_rss;
+		}
 	}
 	acct_collect(code, group_dead);
 	if (group_dead)
@@ -1296,6 +1302,7 @@ static int wait_task_zombie(struct task_
 		struct signal_struct *psig;
 		struct signal_struct *sig;
 		struct task_cputime cputime;
+		unsigned long maxrss;
 
 		/*
 		 * The resource counters for the group leader are in its
@@ -1347,6 +1354,9 @@ static int wait_task_zombie(struct task_
 		psig->coublock +=
 			task_io_get_oublock(p) +
 			sig->oublock + sig->coublock;
+		maxrss = max(sig->maxrss, sig->cmaxrss);
+		if (psig->cmaxrss < maxrss)
+			psig->cmaxrss = maxrss;
 		task_io_accounting_add(&psig->ioac, &p->ioac);
 		task_io_accounting_add(&psig->ioac, &sig->ioac);
 		spin_unlock_irq(&p->parent->sighand->siglock);
diff -puN kernel/fork.c~getrusage-fill-ru_maxrss-value kernel/fork.c
--- a/kernel/fork.c~getrusage-fill-ru_maxrss-value
+++ a/kernel/fork.c
@@ -851,6 +851,7 @@ static int copy_signal(unsigned long clo
 	sig->nvcsw = sig->nivcsw = sig->cnvcsw = sig->cnivcsw = 0;
 	sig->min_flt = sig->maj_flt = sig->cmin_flt = sig->cmaj_flt = 0;
 	sig->inblock = sig->oublock = sig->cinblock = sig->coublock = 0;
+	sig->maxrss = sig->cmaxrss = 0;
 	task_io_accounting_init(&sig->ioac);
 	taskstats_tgid_init(sig);
 
diff -puN kernel/sys.c~getrusage-fill-ru_maxrss-value kernel/sys.c
--- a/kernel/sys.c~getrusage-fill-ru_maxrss-value
+++ a/kernel/sys.c
@@ -1676,6 +1676,18 @@ static void k_getrusage(struct task_stru
 out:
 	cputime_to_timeval(utime, &r->ru_utime);
 	cputime_to_timeval(stime, &r->ru_stime);
+
+	if (who != RUSAGE_CHILDREN) {
+		struct mm_struct *mm = get_task_mm(p);
+		if (mm) {
+			unsigned long hiwater_rss = get_mm_hiwater_rss(mm);
+
+			if (maxrss < hiwater_rss)
+				maxrss = hiwater_rss;
+			mmput(mm);
+		}
+	}
+	r->ru_maxrss <<= PAGE_SHIFT - 10;
 }
 
 int getrusage(struct task_struct *p, int who, struct rusage __user *ru)
_

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2009-01-05 22:13 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-30 11:15 [PATCH for -mm] getrusage: fill ru_maxrss value KOSAKI Motohiro
2008-12-30 11:15 ` KOSAKI Motohiro
2008-12-31 10:08 ` Jiri Pirko
2008-12-31 10:08   ` Jiri Pirko
2008-12-31 12:42   ` KOSAKI Motohiro
2008-12-31 12:42     ` KOSAKI Motohiro
2008-12-31 18:08     ` Jiri Pirko
2008-12-31 18:08       ` Jiri Pirko
2009-01-03 17:59     ` Oleg Nesterov
2009-01-03 17:59       ` Oleg Nesterov
2009-01-03 21:13       ` KOSAKI Motohiro
2009-01-03 21:13         ` KOSAKI Motohiro
2009-01-05 15:32         ` Jiri Pirko
2009-01-05 15:32           ` Jiri Pirko
2009-01-05 22:13           ` Andrew Morton [this message]
2009-01-05 22:13             ` Andrew Morton
2009-01-06  9:48             ` Jiri Pirko
2009-01-06  9:48               ` Jiri Pirko
2009-04-02 20:47               ` Andrew Morton
2009-04-02 20:47                 ` Andrew Morton
2009-04-02 21:13                 ` Ingo Molnar
2009-04-02 21:13                   ` Ingo Molnar
2009-04-05  8:49                   ` Jiri Pirko
2009-04-05  8:49                     ` Jiri Pirko
2009-04-05 17:24                     ` Hugh Dickins
2009-04-05 17:24                       ` Hugh Dickins
2009-04-06  0:21                       ` KOSAKI Motohiro
2009-04-06  0:21                         ` KOSAKI Motohiro
2009-04-06  7:22                         ` Hugh Dickins
2009-04-06  7:22                           ` Hugh Dickins
2009-06-17 20:21                           ` Andrew Morton
2009-06-17 20:21                             ` Andrew Morton
2009-06-18  0:57                             ` KOSAKI Motohiro
2009-06-18  0:57                               ` KOSAKI Motohiro
2009-09-07  2:58                               ` KOSAKI Motohiro
2009-09-07  2:58                                 ` KOSAKI Motohiro
2009-09-09 20:46                                 ` Andrew Morton
2009-09-09 20:46                                   ` Andrew Morton
2009-09-09 23:17                                   ` KOSAKI Motohiro
2009-09-09 23:17                                     ` KOSAKI Motohiro
2009-09-09 23:32                                     ` Andrew Morton
2009-09-09 23:32                                       ` Andrew Morton
2009-09-09 23:37                                       ` KOSAKI Motohiro
2009-09-09 23:37                                         ` KOSAKI Motohiro

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=20090105141313.a4abd475.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=hugh@veritas.com \
    --cc=jpirko@redhat.com \
    --cc=kosaki.motohiro@jp.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=oleg@redhat.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.