mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Frank Mayhar <fmayhar@google.com>
To: linux-kernel@vger.kernel.org
Subject: [PATCH 2.6.23-rc2] getrusage: return ru_maxrss
Date: Fri, 10 Aug 2007 11:31:51 -0700	[thread overview]
Message-ID: <1186770711.18535.9.camel@peace.smo.corp.google.com> (raw)

Fill in ru_maxrss by, for RUSAGE_BOTH or RUSAGE_CHILDREN, walking the
list of children and summing the hiwater_rss for each.  For RUSAGE_BOTH
or RUSAGE_SELF also include the hiwater_rss for the calling process.

diff --git a/kernel/sys.c b/kernel/sys.c
index 449b81b..71b2850 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -2101,6 +2101,19 @@ static void k_getrusage(struct task_stru
 			r->ru_inblock = p->signal->cinblock;
 			r->ru_oublock = p->signal->coublock;
 
+			read_lock(&tasklist_lock);
+			list_for_each(_p, &p->children) {
+				struct task_struct *mp;
+
+				mp = list_entry(_p, struct task_struct, sibling);
+				mm = get_task_mm(mp);
+				hiwater_rss = get_mm_rss(mm);
+				if (hiwater_rss < mm->hiwater_rss)
+					hiwater_rss = mm->hiwater_rss;
+				r->ru_maxrss += hiwater_rss;
+			}
+			read_unlock(&tasklist_lock);
+
 			if (who == RUSAGE_CHILDREN)
 				break;
 
@@ -2125,6 +2138,11 @@ static void k_getrusage(struct task_stru
 				r->ru_oublock += task_io_get_oublock(t);
 				t = next_thread(t);
 			} while (t != p);
+			mm = get_task_mm(p);
+			hiwater_rss = get_mm_rss(mm);
+			if (hiwater_rss < mm->hiwater_rss)
+				hiwater_rss = mm->hiwater_rss;
+			r->ru_maxrss += hiwater_rss;
 			break;
 
 		default:
---

Like a number of other folks, we recently had a need for a non-/proc way
of getting the RSS of a process and happened on getrusage().  Unlike the
rest, though, we fixed the system call to do what we want.

The code itself was lifted from task_mem() in proc/task_mmu.c.  The only
questionable bit is where it does the read_lock() of the tasklist_lock;
although it seems safe enough, I would appreciate if those more
knowledgeable about that locking vet it (briefly) for safety.

Signed-off-by:  Frank Mayhar <fmayhar@google.com>
-- 
Frank Mayhar <fmayhar@google.com>
Google, Inc.


             reply	other threads:[~2007-08-10 18:32 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-10 18:31 Frank Mayhar [this message]
2007-08-10 18:47 ` [PATCH 2.6.23-rc2] getrusage: return ru_maxrss *WITHDRAWN* Frank Mayhar

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=1186770711.18535.9.camel@peace.smo.corp.google.com \
    --to=fmayhar@google.com \
    --cc=linux-kernel@vger.kernel.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®