mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 2.6.23-rc2] getrusage: return ru_maxrss
@ 2007-08-10 18:31 Frank Mayhar
  2007-08-10 18:47 ` [PATCH 2.6.23-rc2] getrusage: return ru_maxrss *WITHDRAWN* Frank Mayhar
  0 siblings, 1 reply; 2+ messages in thread
From: Frank Mayhar @ 2007-08-10 18:31 UTC (permalink / raw)
  To: linux-kernel

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.


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

* Re: [PATCH 2.6.23-rc2] getrusage: return ru_maxrss *WITHDRAWN*
  2007-08-10 18:31 [PATCH 2.6.23-rc2] getrusage: return ru_maxrss Frank Mayhar
@ 2007-08-10 18:47 ` Frank Mayhar
  0 siblings, 0 replies; 2+ messages in thread
From: Frank Mayhar @ 2007-08-10 18:47 UTC (permalink / raw)
  To: linux-kernel

For some reason, the first twenty times I read the doc, I missed the
"terminated and waited-for" bit for RUSAGE_CHILDREN.

Patch withdrawn, for the moment anyway.  (And the right fix won't solve
our problem, sigh.)
-- 
Frank Mayhar <fmayhar@google.com>
Google, Inc.


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

end of thread, other threads:[~2007-08-10 18:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-10 18:31 [PATCH 2.6.23-rc2] getrusage: return ru_maxrss Frank Mayhar
2007-08-10 18:47 ` [PATCH 2.6.23-rc2] getrusage: return ru_maxrss *WITHDRAWN* Frank Mayhar

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®