getrusage: fill ru_maxrss value
Subsystems (5)
PATCH 1/1 getrusage: fill ru_maxrss value
Hi
Oleg, Jiri, this is my getrusage testcase and proposal patch. Could you please review it?
Changes Jiris's last version
- At wait_task_zombie(), parent process doesn't only collect child maxrss, but also cmaxrss.
- ru_maxrss inherit at exec()
- style fixes.
Applied after: introduce-get_mm_hiwater_xxx-fix-taskstats-hiwater_xxx-accounting.patch ==
From: Signed-off-by: Jiri Pirko <[email protected]>
Subject: [PATCH for -mm] getrusage: fill ru_maxrss value
This patch makes ->ru_maxrss value in struct rusage filled accordingly to rss hiwater mark. This struct is filled as a parameter to getrusage syscall. ->ru_maxrss value is set to KBs which is the way it is done in BSD systems. /usr/bin/time (gnu time) application converts ->ru_maxrss to KBs which seems to be incorrect behavior. Maintainer of this util was notified by me with the patch which corrects it and cc'ed.
To make this happen we extend struct signal_struct by two fields. The first one is ->maxrss which we use to store rss hiwater of the task. The second one is ->cmaxrss which we use to store highest rss hiwater of all task childs. These values are used in k_getrusage() to actually fill ->ru_maxrss. k_getrusage() uses current rss hiwater value directly if mm struct exists.
Note:exec() clear mm->hiwater_rss, but doesn't clear sig->maxrss. it is intetionally behavior. *BSD getrusage have exec() inheriting.
Test progmam and test case
===========================
getrusage.c
----
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <signal.h>
static void consume(int mega)
{
size_t sz = mega * 1024 * 1024;
void *ptr;
ptr = malloc(sz);
memset(ptr, 0, sz);
usleep(1); /* BSD rusage statics need to sleep 1 tick */
}static void show_rusage(char *prefix)
{
int err, err2;
struct rusage rusage_self;
struct rusage rusage_children;
printf("%s: ", prefix);
err = getrusage(RUSAGE_SELF, &rusage_self);
if (!err)
printf("self %ld ", rusage_self.ru_maxrss);
err2 = getrusage(RUSAGE_CHILDREN, &rusage_children);
if (!err2)
printf("children %ld ", rusage_children.ru_maxrss);
printf("\n");
}int main(int argc, char** argv)
{
int status;
int c;
int need_sleep_before_wait = 0;
int consume_large_memory_at_first = 0;
int create_child_at_first = 0;
int sigign = 0;
int create_child_before_exec = 0;
int after_fork_test = 0;
while ((c = getopt(argc, argv, "ceflsz")) != -1) {
switch (c) {
case 'c':
create_child_at_first = 1;
break;
case 'e':
create_child_before_exec = 1;
break;
case 'f':
after_fork_test = 1;
break;
case 'l':
consume_large_memory_at_first = 1;
break;
case 's':
sigign = 1;
break;
case 'z':
need_sleep_before_wait = 1;
break;
default:
break;
}
}
if (consume_large_memory_at_first)
consume(100);
if (create_child_at_first)
system("./child -q");
if (sigign)
signal(SIGCHLD, SIG_IGN);
if (fork()) {
usleep(1);
if (need_sleep_before_wait)
sleep(3); /* children become zombie */
show_rusage("pre_wait");
wait(&status);
show_rusage("post_wait");
} else {
usleep(1);
show_rusage("fork");
if (after_fork_test) {
consume(30);
show_rusage("fork2");
}
if (create_child_before_exec) {
system("./child -lq");
usleep(1);
show_rusage("fork3");
}
execl("./child", "child", 0);
exit(0);
}
return 0;
}child.c
----
#include <sys/types.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
static void consume(int mega)
{
size_t sz = mega * 1024 * 1024;
void *ptr;
ptr = malloc(sz);
memset(ptr, 0, sz);
usleep(1); /* BSD rusage statics need to sleep 1 tick */
}static void show_rusage(char *prefix)
{
int err, err2;
struct rusage rusage_self;
struct rusage rusage_children;
printf("%s: ", prefix);
err = getrusage(RUSAGE_SELF, &rusage_self);
if (!err)
printf("self %ld ", rusage_self.ru_maxrss);
err2 = getrusage(RUSAGE_CHILDREN, &rusage_children);
if (!err2)
printf("children %ld ", rusage_children.ru_maxrss);
printf("\n");}
int main(int argc, char** argv)
{
int status;
int c;
int silent = 0;
int light_weight = 0;
while ((c = getopt(argc, argv, "lq")) != -1) {
switch (c) {
case 'l':
light_weight = 1;
break;
case 'q':
silent = 1;
break;
default:
break;
}
}
if (!silent)
show_rusage("exec");
if (fork()) {
if (light_weight)
consume(400);
else
consume(700);
wait(&status);
} else {
if (light_weight)
consume(600);
else
consume(900);
exit(0);
}
return 0;
}testcase
==================
1. inherit fork?
test way:
% ./getrusage -lc
bsd result:
fork line is "fork: self 0 children 0".
-> rusage sholdn't be inherit by fork.
(both RUSAGE_SELF and RUSAGE_CHILDREN)
2. inherit exec?
test way:
% ./getrusage -lce
bsd result:
fork3: self 103204 children 60000
exec: self 103204 children 60000
fork3 and exec line are the same.
-> rusage shold be inherit by exec.
(both RUSAGE_SELF and RUSAGE_CHILDREN)
3. getrusage(RUSAGE_CHILDREN) collect grandchild statics?
test way:
% ./getrusage
bsd result:
post_wait line is about "post_wait: self 0 children 90000".
-> RUSAGE_CHILDREN can collect grandchild.
4. zombie, but not waited children collect or not?
test way:
% ./getrusage -z
bsd result:
pre_wait line is "pre_wait: self 0 children 0".
-> zombie child process (not waited-for child process) isn't accounted.
5. SIG_IGN collect or not
test way:
% ./getrusage -s
bsd result:
post_wait line is "post_wait: self 0 children 0".
-> if SIGCHLD is ignored, children isn't accounted.
6. fork and malloc
test way:
% ./getrusage -lcf
bsd result:
fork line is "fork: self 0 children 0". fork2 line is about "fork: self 130000 children 0".
-> rusage sholdn't be inherit by fork.
(both RUSAGE_SELF and RUSAGE_CHILDREN) but additional memory cunsumption cause right maxrss calculation.
--- fs/exec.c | 5 +++++ include/linux/sched.h | 1 + kernel/exit.c | 6 ++++++ kernel/fork.c | 1 + kernel/sys.c | 15 +++++++++++++++ 5 files changed, 28 insertions(+)
include/linux/sched.h +1 -0
@@ -562,6 +562,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;/*
kernel/exit.c +6 -0
@@ -1053,6 +1053,10 @@ 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 maxrss =get_mm_hiwater_rss (tsk->mm); + tsk->signal->maxrss =max (maxrss, tsk->signal->maxrss); + } }acct_collect (code, group_dead);if (group_dead)
@@ -1349,6 +1353,8 @@ static int wait_task_zombie(struct task_ psig->coublock +=task_io_get_oublock (p) + sig->oublock + sig->coublock; + psig->cmaxrss =max (max (sig->maxrss, sig->cmaxrss), + psig->cmaxrss);task_io_accounting_add (&psig->ioac, &p->ioac);task_io_accounting_add (&psig->ioac, &sig->ioac);spin_unlock_irq (&p->parent->sighand->siglock);
kernel/fork.c +1 -0
@@ -849,6 +849,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);
kernel/sys.c +15 -0
@@ -1569,6 +1569,7 @@ static void k_getrusage(struct task_stru r->ru_majflt = p->signal->cmaj_flt; r->ru_inblock = p->signal->cinblock; r->ru_oublock = p->signal->coublock; + r->ru_maxrss = p->signal->cmaxrss;if (who ==RUSAGE_CHILDREN )break ;
@@ -1583,6 +1584,8 @@ static void k_getrusage(struct task_stru r->ru_majflt += p->signal->maj_flt; r->ru_inblock += p->signal->inblock; r->ru_oublock += p->signal->oublock; +if (r->ru_maxrss < p->signal->maxrss) + r->ru_maxrss = p->signal->maxrss; t = p; do { accumulate_thread_rusage(t, r);
@@ -1598,6 +1601,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 maxrss =get_mm_hiwater_rss (mm); + +if (r->ru_maxrss < maxrss) + r->ru_maxrss = maxrss; +mmput (mm); + } + } + r->ru_maxrss <<=PAGE_SHIFT -10 ; }int getrusage (struct task_struct *p,int who,struct rusage __user *ru)
fs/exec.c +5 -0
@@ -774,6 +774,7 @@ static int de_thread(struct task_structspinlock_t *lock = &oldsighand->siglock;struct task_struct *leader =NULL ;int count; +unsigned long maxrss =0 ;if (thread_group_empty (tsk)) goto no_thread_group;
@@ -870,6 +871,10 @@ static int de_thread(struct task_struct sig->notify_count =0 ; no_thread_group: +if (current->mm) + maxrss =get_mm_hiwater_rss (current->mm); + sig->maxrss =max (sig->maxrss, maxrss); +exit_itimers (sig);flush_itimer_signals ();if (leader)
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 10 lines · On Tue, 30 Dec 2008 20:15:33 +0900 (JST) KOSAKI Motohiro…
Hi
Oleg, Jiri, this is my getrusage testcase and proposal patch. Could you please review it?
Changes Jiris's last version
- Atwait_task_zombie(), parent process doesn't only collect child maxrss, but also cmaxrss.
Yes, this is what we were missing so far.
Quoted 2 lines
-
ru_maxrssinherit atexec()
- style fixes.
New patch seems almost fine to me. Only I do not like usage of max() macro in do_exit() and in de_thread(). It's unnecessary and little wasting (yes only a little :)). This two spots would be maybe better solved with if(<).
Quoted 286 lines
Applied after: introduce-get_mm_hiwater_xxx-fix-taskstats-hiwater_xxx-accounting.patch ==
From: Signed-off-by: Jiri Pirko <[email protected]>
Subject: [PATCH for -mm] getrusage: fillru_maxrssvalueThis patch makes ->ru_maxrss value in struct rusage filled accordingly to rss hiwater mark. This struct is filled as a parameter to getrusage syscall. ->ru_maxrss value is set to KBs which is the way it is done in BSD systems.
/usr/bin/time(gnu time) application converts ->ru_maxrss to KBs which seems to be incorrect behavior. Maintainer of this util was notified by me with the patch which corrects it and cc'ed.To make this happen we extend struct
signal_structby two fields. The first one is ->maxrss which we use to store rss hiwater of the task. The second one is ->cmaxrss which we use to store highest rss hiwater of all task childs. These values are used ink_getrusage()to actually fill ->ru_maxrss.k_getrusage()uses current rss hiwater value directly if mm struct exists.Note:
exec()clearmm->hiwater_rss, but doesn't clearsig->maxrss. it is intetionally behavior. *BSD getrusage haveexec()inheriting.Test progmam and test case
===========================
getrusage.c
----
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <signal.h>static void consume(int mega)
{ size_t sz = mega * 1024 * 1024; void *ptr; ptr = malloc(sz); memset(ptr, 0, sz); usleep(1); /* BSD rusage statics need to sleep 1 tick */ }static void
show_rusage(char *prefix){ int err, err2; struct rusage rusage_self; struct rusage rusage_children; printf("%s: ", prefix); err = getrusage(RUSAGE_SELF, &rusage_self); if (!err) printf("self %ld ", rusage_self.ru_maxrss); err2 = getrusage(RUSAGE_CHILDREN, &rusage_children); if (!err2) printf("children %ld ", rusage_children.ru_maxrss); printf("\n"); }int
main(int argc, char** argv){ int status; int c; int need_sleep_before_wait = 0; int consume_large_memory_at_first = 0; int create_child_at_first = 0; int sigign = 0; int create_child_before_exec = 0; int after_fork_test = 0; while ((c = getopt(argc, argv, "ceflsz")) != -1) { switch (c) { case 'c': create_child_at_first = 1; break; case 'e': create_child_before_exec = 1; break; case 'f': after_fork_test = 1; break; case 'l': consume_large_memory_at_first = 1; break; case 's': sigign = 1; break; case 'z': need_sleep_before_wait = 1; break; default: break; } } if (consume_large_memory_at_first) consume(100); if (create_child_at_first) system("./child -q"); if (sigign) signal(SIGCHLD, SIG_IGN); if (fork()) { usleep(1); if (need_sleep_before_wait) sleep(3); /* children become zombie */ show_rusage("pre_wait"); wait(&status); show_rusage("post_wait"); } else { usleep(1); show_rusage("fork"); if (after_fork_test) { consume(30); show_rusage("fork2"); } if (create_child_before_exec) { system("./child -lq"); usleep(1); show_rusage("fork3"); } execl("./child", "child", 0); exit(0); } return 0; }
child.c
----
#include <sys/types.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>static void consume(int mega)
{ size_t sz = mega * 1024 * 1024; void *ptr; ptr = malloc(sz); memset(ptr, 0, sz); usleep(1); /* BSD rusage statics need to sleep 1 tick */ }static void
show_rusage(char *prefix){ int err, err2; struct rusage rusage_self; struct rusage rusage_children; printf("%s: ", prefix); err = getrusage(RUSAGE_SELF, &rusage_self); if (!err) printf("self %ld ", rusage_self.ru_maxrss); err2 = getrusage(RUSAGE_CHILDREN, &rusage_children); if (!err2) printf("children %ld ", rusage_children.ru_maxrss); printf("\n");}
int
main(int argc, char** argv){ int status; int c; int silent = 0; int light_weight = 0; while ((c = getopt(argc, argv, "lq")) != -1) { switch (c) { case 'l': light_weight = 1; break; case 'q': silent = 1; break; default: break; } } if (!silent) show_rusage("exec"); if (fork()) { if (light_weight) consume(400); else consume(700); wait(&status); } else { if (light_weight) consume(600); else consume(900); exit(0); } return 0; }testcase
==================
1. inherit fork?test way:
% ./getrusage -lcbsd result:
fork line is "fork: self 0 children 0".-> rusage sholdn't be inherit by fork.
(bothRUSAGE_SELFandRUSAGE_CHILDREN)2. inherit exec?
test way:
% ./getrusage -lcebsd result:
fork3: self 103204 children 60000exec: self 103204 children 60000fork3 and exec line are the same.
-> rusage shold be inherit by exec.
(bothRUSAGE_SELFandRUSAGE_CHILDREN)3.
getrusage(RUSAGE_CHILDREN)collect grandchild statics?test way:
% ./getrusagebsd result:
post_waitline is about "post_wait: self 0 children 90000".-> RUSAGE_CHILDREN can collect grandchild.4. zombie, but not waited children collect or not?
test way:
% ./getrusage -zbsd result:
pre_waitline is "pre_wait: self 0 children 0".-> zombie child process (not waited-for child process) isn't accounted.5.
SIG_IGNcollect or nottest way:
% ./getrusage -sbsd result:
post_waitline is "post_wait: self 0 children 0".-> if SIGCHLD is ignored, children isn't accounted.6. fork and malloc
test way:
% ./getrusage -lcf
Quoted 9 lines
bsd result:
fork line is "fork: self 0 children 0". fork2 line is about "fork: self 130000 children 0".-> rusage sholdn't be inherit by fork.
(bothRUSAGE_SELFandRUSAGE_CHILDREN) but additional memory cunsumption cause right maxrss calculation.
Testcases look good. Thanks for doing this.
Quoted 114 lines
Signed-off-by Jiri Pirko <[email protected]>Signed-off-by KOSAKI Motohiro <[email protected]>--- fs/exec.c | 5 +++++ include/linux/sched.h | 1 + kernel/exit.c | 6 ++++++ kernel/fork.c | 1 + kernel/sys.c | 15 +++++++++++++++ 5 files changed, 28 insertions(+)Index:
b/include/linux/sched.h
===================================================================include/linux/sched.h +1
-0@@ -562,6 +562,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;/* Index:
b/kernel/exit.c
===================================================================kernel/exit.c +6
-0@@ -1053,6 +1053,10 @@ 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 maxrss =get_mm_hiwater_rss (tsk->mm); + tsk->signal->maxrss =max (maxrss, tsk->signal->maxrss); + } }acct_collect (code, group_dead);if (group_dead)@@ -1349,6 +1353,8 @@ static int wait_task_zombie(struct task_ psig->coublock +=task_io_get_oublock (p) + sig->oublock + sig->coublock; + psig->cmaxrss =max (max (sig->maxrss, sig->cmaxrss), + psig->cmaxrss);task_io_accounting_add (&psig->ioac, &p->ioac);task_io_accounting_add (&psig->ioac, &sig->ioac);spin_unlock_irq (&p->parent->sighand->siglock);Index:
b/kernel/fork.c
===================================================================kernel/fork.c +1
-0@@ -849,6 +849,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);Index:
b/kernel/sys.c
===================================================================kernel/sys.c +15
-0@@ -1569,6 +1569,7 @@ static void k_getrusage(struct task_stru r->ru_majflt = p->signal->cmaj_flt; r->ru_inblock = p->signal->cinblock; r->ru_oublock = p->signal->coublock; + r->ru_maxrss = p->signal->cmaxrss;if (who ==RUSAGE_CHILDREN )break ;@@ -1583,6 +1584,8 @@ static void k_getrusage(struct task_stru r->ru_majflt += p->signal->maj_flt; r->ru_inblock += p->signal->inblock; r->ru_oublock += p->signal->oublock; +if (r->ru_maxrss < p->signal->maxrss) + r->ru_maxrss = p->signal->maxrss; t = p; do { accumulate_thread_rusage(t, r);@@ -1598,6 +1601,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 maxrss =get_mm_hiwater_rss (mm); + +if (r->ru_maxrss < maxrss) + r->ru_maxrss = maxrss; +mmput (mm); + } + } + r->ru_maxrss <<=PAGE_SHIFT -10 ; }int getrusage (struct task_struct *p,int who,struct rusage __user *ru)Index:
b/fs/exec.c
===================================================================fs/exec.c +1
-0@@ -774,6 +774,7 @@ static int de_thread(struct task_structspinlock_t *lock = &oldsighand->siglock;struct task_struct *leader =NULL ;int count; +unsigned long maxrss =0 ;if (thread_group_empty (tsk)) goto no_thread_group;
fs/exec.c static int de_thread(struct task_struct · line 880
Quoted 10 lines
fs/exec.c +4
-0@@ -870,6 +871,10 @@ static int de_thread(struct task_struct sig->notify_count =0 ; no_thread_group: +if (current->mm) + maxrss =get_mm_hiwater_rss (current->mm); + sig->maxrss =max (sig->maxrss, maxrss); +exit_itimers (sig);flush_itimer_signals ();if (leader)
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Hi!
Quoted 5 lines
Quoted 3 lines
Changes Jiris's last version
- Atwait_task_zombie(), parent process doesn't only collect child maxrss, but also cmaxrss.Yes, this is what we were missing so far.
Quoted 7 lines
Quoted 2 lines
-
ru_maxrssinherit atexec()
- style fixes.New patch seems almost fine to me. Only I do not like usage of
max()macro indo_exit()and inde_thread(). It's unnecessary and little wasting (yes only a little :)). This two spots would be maybe better solved with if(<).
Done!
Changelog
v1 -> v2
- Removed unnecessary max() macro
- To avoid ru_maxrss recalculation in k_getrusage()
- style fixes
Jiri's resend3 -> v1
- At wait_task_zombie(), parent process doesn't only collect child maxrss, but also cmaxrss.
- ru_maxrss inherit at exec()
- style fixes
Applied after: introduce-get_mm_hiwater_xxx-fix-taskstats-hiwater_xxx-accounting.patch ==
From: Signed-off-by: Jiri Pirko <[email protected]>
Subject: [PATCH for -mm] getrusage: fill ru_maxrss value
This patch makes ->ru_maxrss value in struct rusage filled accordingly to rss hiwater mark. This struct is filled as a parameter to getrusage syscall. ->ru_maxrss value is set to KBs which is the way it is done in BSD systems. /usr/bin/time (gnu time) application converts ->ru_maxrss to KBs which seems to be incorrect behavior. Maintainer of this util was notified by me with the patch which corrects it and cc'ed.
To make this happen we extend struct signal_struct by two fields. The first one is ->maxrss which we use to store rss hiwater of the task. The second one is ->cmaxrss which we use to store highest rss hiwater of all task childs. These values are used in k_getrusage() to actually fill ->ru_maxrss. k_getrusage() uses current rss hiwater value directly if mm struct exists.
Note:exec() clear mm->hiwater_rss, but doesn't clear sig->maxrss. it is intetionally behavior. *BSD getrusage have exec() inheriting.
Test progmam and test case
===========================
getrusage.c
----
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <signal.h>
static void consume(int mega)
{
size_t sz = mega * 1024 * 1024;
void *ptr;
ptr = malloc(sz);
memset(ptr, 0, sz);
usleep(1); /* BSD rusage statics need to sleep 1 tick */
}static void show_rusage(char *prefix)
{
int err, err2;
struct rusage rusage_self;
struct rusage rusage_children;
printf("%s: ", prefix);
err = getrusage(RUSAGE_SELF, &rusage_self);
if (!err)
printf("self %ld ", rusage_self.ru_maxrss);
err2 = getrusage(RUSAGE_CHILDREN, &rusage_children);
if (!err2)
printf("children %ld ", rusage_children.ru_maxrss);
printf("\n");
}int main(int argc, char** argv)
{
int status;
int c;
int need_sleep_before_wait = 0;
int consume_large_memory_at_first = 0;
int create_child_at_first = 0;
int sigign = 0;
int create_child_before_exec = 0;
int after_fork_test = 0;
while ((c = getopt(argc, argv, "ceflsz")) != -1) {
switch (c) {
case 'c':
create_child_at_first = 1;
break;
case 'e':
create_child_before_exec = 1;
break;
case 'f':
after_fork_test = 1;
break;
case 'l':
consume_large_memory_at_first = 1;
break;
case 's':
sigign = 1;
break;
case 'z':
need_sleep_before_wait = 1;
break;
default:
break;
}
}
if (consume_large_memory_at_first)
consume(100);
if (create_child_at_first)
system("./child -q");
if (sigign)
signal(SIGCHLD, SIG_IGN);
if (fork()) {
usleep(1);
if (need_sleep_before_wait)
sleep(3); /* children become zombie */
show_rusage("pre_wait");
wait(&status);
show_rusage("post_wait");
} else {
usleep(1);
show_rusage("fork");
if (after_fork_test) {
consume(30);
show_rusage("fork2");
}
if (create_child_before_exec) {
system("./child -lq");
usleep(1);
show_rusage("fork3");
}
execl("./child", "child", 0);
exit(0);
}
return 0;
}child.c
----
#include <sys/types.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
static void consume(int mega)
{
size_t sz = mega * 1024 * 1024;
void *ptr;
ptr = malloc(sz);
memset(ptr, 0, sz);
usleep(1); /* BSD rusage statics need to sleep 1 tick */
}static void show_rusage(char *prefix)
{
int err, err2;
struct rusage rusage_self;
struct rusage rusage_children;
printf("%s: ", prefix);
err = getrusage(RUSAGE_SELF, &rusage_self);
if (!err)
printf("self %ld ", rusage_self.ru_maxrss);
err2 = getrusage(RUSAGE_CHILDREN, &rusage_children);
if (!err2)
printf("children %ld ", rusage_children.ru_maxrss);
printf("\n");}
int main(int argc, char** argv)
{
int status;
int c;
int silent = 0;
int light_weight = 0;
while ((c = getopt(argc, argv, "lq")) != -1) {
switch (c) {
case 'l':
light_weight = 1;
break;
case 'q':
silent = 1;
break;
default:
break;
}
}
if (!silent)
show_rusage("exec");
if (fork()) {
if (light_weight)
consume(400);
else
consume(700);
wait(&status);
} else {
if (light_weight)
consume(600);
else
consume(900);
exit(0);
}
return 0;
}testcase
==================
1. inherit fork?
test way:
% ./getrusage -lc
bsd result:
fork line is "fork: self 0 children 0".
-> rusage sholdn't be inherit by fork.
(both RUSAGE_SELF and RUSAGE_CHILDREN)
2. inherit exec?
test way:
% ./getrusage -lce
bsd result:
fork3: self 103204 children 60000
exec: self 103204 children 60000
fork3 and exec line are the same.
-> rusage shold be inherit by exec.
(both RUSAGE_SELF and RUSAGE_CHILDREN)
3. getrusage(RUSAGE_CHILDREN) collect grandchild statics?
test way:
% ./getrusage
bsd result:
post_wait line is about "post_wait: self 0 children 90000".
-> RUSAGE_CHILDREN can collect grandchild.
4. zombie, but not waited children collect or not?
test way:
% ./getrusage -z
bsd result:
pre_wait line is "pre_wait: self 0 children 0".
-> zombie child process (not waited-for child process) isn't accounted.
5. SIG_IGN collect or not
test way:
% ./getrusage -s
bsd result:
post_wait line is "post_wait: self 0 children 0".
-> if SIGCHLD is ignored, children isn't accounted.
6. fork and malloc
test way:
% ./getrusage -lcf
bsd result:
fork line is "fork: self 0 children 0". fork2 line is about "fork: self 130000 children 0".
-> rusage sholdn't be inherit by fork.
(both RUSAGE_SELF and RUSAGE_CHILDREN) but additional memory cunsumption cause right maxrss calculation.
--- fs/exec.c | 7 +++++++ include/linux/sched.h | 1 + kernel/exit.c | 10 ++++++++++ kernel/fork.c | 1 + kernel/sys.c | 16 ++++++++++++++++ 5 files changed, 35 insertions(+)
include/linux/sched.h +1 -0
@@ -562,6 +562,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;/*
kernel/exit.c +10 -0
@@ -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)
@@ -1298,6 +1304,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
@@ -1349,6 +1356,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);
kernel/fork.c +1 -0
@@ -849,6 +849,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);
kernel/sys.c +16 -0
@@ -1546,6 +1546,7 @@ static void k_getrusage(struct task_struunsigned long flags;cputime_t utime, stime;struct task_cputime cputime; +unsigned long maxrss =0 ;memset ((char *) r,0 ,sizeof *r); utime = stime = cputime_zero;
@@ -1569,6 +1570,7 @@ static void k_getrusage(struct task_stru r->ru_majflt = p->signal->cmaj_flt; r->ru_inblock = p->signal->cinblock; r->ru_oublock = p->signal->coublock; + maxrss = p->signal->cmaxrss;if (who ==RUSAGE_CHILDREN )break ;
@@ -1583,6 +1585,8 @@ static void k_getrusage(struct task_stru r->ru_majflt += p->signal->maj_flt; r->ru_inblock += p->signal->inblock; r->ru_oublock += p->signal->oublock; +if (maxrss < p->signal->maxrss) + maxrss = p->signal->maxrss; t = p; do { accumulate_thread_rusage(t, r);
@@ -1598,6 +1602,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 = maxrss * (PAGE_SIZE /1024 );/* convert pages to KBs */ }int getrusage (struct task_struct *p,int who,struct rusage __user *ru)
fs/exec.c +7 -0
@@ -870,6 +870,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 ();if (leader)
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 10 lines · On Wed, 31 Dec 2008 21:42:36 +0900 (JST) KOSAKI Motohiro…
Hi!
Quoted 8 lines
Quoted 3 lines
Changes Jiris's last version
- Atwait_task_zombie(), parent process doesn't only collect child maxrss, but also cmaxrss.Yes, this is what we were missing so far.
Quoted 2 lines
-
ru_maxrssinherit atexec()
- style fixes.
Quoted 8 lines
Quoted 4 lines
New patch seems almost fine to me. Only I do not like usage of
max()macro indo_exit()and inde_thread(). It's unnecessary and little wasting (yes only a little :)). This two spots would be maybe better solved with if(<).Done!
Okay - now I'm happy with this patch. Let's see with what Oleg will come :)
Quoted 436 lines
Changelog
v1 -> v2
- Removed unnecessarymax()macro
- To avoidru_maxrssrecalculation ink_getrusage()
- style fixesJiri's resend3 -> v1
- Atwait_task_zombie(), parent process doesn't only collect child maxrss, but also cmaxrss.
-ru_maxrssinherit atexec()
- style fixesApplied after: introduce-get_mm_hiwater_xxx-fix-taskstats-hiwater_xxx-accounting.patch ==
From: Signed-off-by: Jiri Pirko <[email protected]>
Subject: [PATCH for -mm] getrusage: fillru_maxrssvalueThis patch makes ->ru_maxrss value in struct rusage filled accordingly to rss hiwater mark. This struct is filled as a parameter to getrusage syscall. ->ru_maxrss value is set to KBs which is the way it is done in BSD systems.
/usr/bin/time(gnu time) application converts ->ru_maxrss to KBs which seems to be incorrect behavior. Maintainer of this util was notified by me with the patch which corrects it and cc'ed.To make this happen we extend struct
signal_structby two fields. The first one is ->maxrss which we use to store rss hiwater of the task. The second one is ->cmaxrss which we use to store highest rss hiwater of all task childs. These values are used ink_getrusage()to actually fill ->ru_maxrss.k_getrusage()uses current rss hiwater value directly if mm struct exists.Note:
exec()clearmm->hiwater_rss, but doesn't clearsig->maxrss. it is intetionally behavior. *BSD getrusage haveexec()inheriting.Test progmam and test case
===========================
getrusage.c
----
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <signal.h>static void consume(int mega)
{ size_t sz = mega * 1024 * 1024; void *ptr; ptr = malloc(sz); memset(ptr, 0, sz); usleep(1); /* BSD rusage statics need to sleep 1 tick */ }static void
show_rusage(char *prefix){ int err, err2; struct rusage rusage_self; struct rusage rusage_children; printf("%s: ", prefix); err = getrusage(RUSAGE_SELF, &rusage_self); if (!err) printf("self %ld ", rusage_self.ru_maxrss); err2 = getrusage(RUSAGE_CHILDREN, &rusage_children); if (!err2) printf("children %ld ", rusage_children.ru_maxrss); printf("\n"); }int
main(int argc, char** argv){ int status; int c; int need_sleep_before_wait = 0; int consume_large_memory_at_first = 0; int create_child_at_first = 0; int sigign = 0; int create_child_before_exec = 0; int after_fork_test = 0; while ((c = getopt(argc, argv, "ceflsz")) != -1) { switch (c) { case 'c': create_child_at_first = 1; break; case 'e': create_child_before_exec = 1; break; case 'f': after_fork_test = 1; break; case 'l': consume_large_memory_at_first = 1; break; case 's': sigign = 1; break; case 'z': need_sleep_before_wait = 1; break; default: break; } } if (consume_large_memory_at_first) consume(100); if (create_child_at_first) system("./child -q"); if (sigign) signal(SIGCHLD, SIG_IGN); if (fork()) { usleep(1); if (need_sleep_before_wait) sleep(3); /* children become zombie */ show_rusage("pre_wait"); wait(&status); show_rusage("post_wait"); } else { usleep(1); show_rusage("fork"); if (after_fork_test) { consume(30); show_rusage("fork2"); } if (create_child_before_exec) { system("./child -lq"); usleep(1); show_rusage("fork3"); } execl("./child", "child", 0); exit(0); } return 0; }
child.c
----
#include <sys/types.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>static void consume(int mega)
{ size_t sz = mega * 1024 * 1024; void *ptr; ptr = malloc(sz); memset(ptr, 0, sz); usleep(1); /* BSD rusage statics need to sleep 1 tick */ }static void
show_rusage(char *prefix){ int err, err2; struct rusage rusage_self; struct rusage rusage_children; printf("%s: ", prefix); err = getrusage(RUSAGE_SELF, &rusage_self); if (!err) printf("self %ld ", rusage_self.ru_maxrss); err2 = getrusage(RUSAGE_CHILDREN, &rusage_children); if (!err2) printf("children %ld ", rusage_children.ru_maxrss); printf("\n");}
int
main(int argc, char** argv){ int status; int c; int silent = 0; int light_weight = 0; while ((c = getopt(argc, argv, "lq")) != -1) { switch (c) { case 'l': light_weight = 1; break; case 'q': silent = 1; break; default: break; } } if (!silent) show_rusage("exec"); if (fork()) { if (light_weight) consume(400); else consume(700); wait(&status); } else { if (light_weight) consume(600); else consume(900); exit(0); } return 0; }testcase
==================
1. inherit fork?test way:
% ./getrusage -lcbsd result:
fork line is "fork: self 0 children 0".-> rusage sholdn't be inherit by fork.
(bothRUSAGE_SELFandRUSAGE_CHILDREN)2. inherit exec?
test way:
% ./getrusage -lcebsd result:
fork3: self 103204 children 60000exec: self 103204 children 60000fork3 and exec line are the same.
-> rusage shold be inherit by exec.
(bothRUSAGE_SELFandRUSAGE_CHILDREN)3.
getrusage(RUSAGE_CHILDREN)collect grandchild statics?test way:
% ./getrusagebsd result:
post_waitline is about "post_wait: self 0 children 90000".-> RUSAGE_CHILDREN can collect grandchild.4. zombie, but not waited children collect or not?
test way:
% ./getrusage -zbsd result:
pre_waitline is "pre_wait: self 0 children 0".-> zombie child process (not waited-for child process) isn't accounted.5.
SIG_IGNcollect or nottest way:
% ./getrusage -sbsd result:
post_waitline is "post_wait: self 0 children 0".-> if SIGCHLD is ignored, children isn't accounted.6. fork and malloc
test way:
% ./getrusage -lcfbsd result:
fork line is "fork: self 0 children 0". fork2 line is about "fork: self 130000 children 0".-> rusage sholdn't be inherit by fork.
(bothRUSAGE_SELFandRUSAGE_CHILDREN) but additional memory cunsumption cause right maxrss calculation.Signed-off-by Jiri Pirko <[email protected]>Signed-off-by KOSAKI Motohiro <[email protected]>--- fs/exec.c | 7 +++++++ include/linux/sched.h | 1 + kernel/exit.c | 10 ++++++++++ kernel/fork.c | 1 + kernel/sys.c | 16 ++++++++++++++++ 5 files changed, 35 insertions(+)Index:
b/include/linux/sched.h
===================================================================include/linux/sched.h +1
-0@@ -562,6 +562,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;/* Index:
b/kernel/exit.c
===================================================================kernel/exit.c +10
-0@@ -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)@@ -1298,6 +1304,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 @@ -1349,6 +1356,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);Index:
b/kernel/fork.c
===================================================================kernel/fork.c +1
-0@@ -849,6 +849,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);Index:
b/kernel/sys.c
===================================================================kernel/sys.c +16
-0@@ -1546,6 +1546,7 @@ static void k_getrusage(struct task_struunsigned long flags;cputime_t utime, stime;struct task_cputime cputime; +unsigned long maxrss =0 ;memset ((char *) r,0 ,sizeof *r); utime = stime = cputime_zero;@@ -1569,6 +1570,7 @@ static void k_getrusage(struct task_stru r->ru_majflt = p->signal->cmaj_flt; r->ru_inblock = p->signal->cinblock; r->ru_oublock = p->signal->coublock; + maxrss = p->signal->cmaxrss;if (who ==RUSAGE_CHILDREN )break ;@@ -1583,6 +1585,8 @@ static void k_getrusage(struct task_stru r->ru_majflt += p->signal->maj_flt; r->ru_inblock += p->signal->inblock; r->ru_oublock += p->signal->oublock; +if (maxrss < p->signal->maxrss) + maxrss = p->signal->maxrss; t = p; do { accumulate_thread_rusage(t, r);@@ -1598,6 +1602,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 = maxrss * (PAGE_SIZE /1024 );/* convert pages to KBs */ }int getrusage (struct task_struct *p,int who,struct rusage __user *ru)Index:
b/fs/exec.c
===================================================================fs/exec.c +0
-0@@ -870,6 +870,13 @@ static int de_thread(struct task_struct sig->notify_count =0 ; no_thread_group:
fs/exec.c static int de_thread(struct task_struct · line 882
Quoted 10 lines
fs/exec.c +7
-0+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 ();if (leader)
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
sorry for delay!
Quoted 4 lines · KOSAKI Motohiro
Jiri's resend3 -> v1
- Atwait_task_zombie(), parent process doesn't only collect child maxrss, but also cmaxrss.
Ah yes, this looks very right to me.
Quoted 1 line
-
ru_maxrssinherit atexec()
I must admit, I hate this ;)
That said, I agree with you point about compatibility. So I have to agree with this change.
Still, I'd like to know what other people think ;)
And I also agree that xacct is linux specific feature, but I still I dislike the fact that xacct and getrusage report different numbers. Perhaps we should change xacct as well?
Quoted 12 lines
kernel/exit.c +6
-0@@ -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; + }
[...snip...]
fs/exec.c static int de_thread(struct task_struct · line 878
Quoted 12 lines
fs/exec.c +6
-0@@ -870,6 +870,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; + }
Perhaps it makes sense to factor out this code and make a helper?
Unfortunately, exit_mm() and exec_mmap() do not have the common path which can update sig->maxrss, mm_release() can't do this...
fs/exec.c static int de_thread(struct task_struct
Quoted 11 lines
fs/exec.c +11
-0+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 = maxrss * (PAGE_SIZE /1024 );/* convert pages to KBs */
Hmm... So, RUSAGE_THREAD always report maxrss == get_mm_hiwater_rss(mm) and ignores signal->maxrss. Doesn't look right to me...
Unless I missed something, Jiris's patch was fine, but given that now we inherit maxrss at exec(), signal->maxrss can have the "inherited" value?
Oleg.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 8 lines
sorry for delay!
Quoted 4 lines
Jiri's resend3 -> v1
- Atwait_task_zombie(), parent process doesn't only collect child maxrss, but also cmaxrss.Ah yes, this looks very right to me.
hehe, therefore I like testcase driven development :)
Quoted 3 lines
Quoted 1 line
-
ru_maxrssinherit atexec()I must admit, I hate this ;)
Your feelings are understood well.
Quoted 4 lines
That said, I agree with you point about compatibility. So I have to agree with this change.
Still, I'd like to know what other people think ;)
Yeah, me too.
Quoted 3 lines
And I also agree that xacct is linux specific feature, but I still I dislike the fact that xacct and getrusage report different numbers. Perhaps we should change xacct as well?
I don't have any strong opinion.
it seems good idea. but I don't know xacct so much.
Quoted 29 lines
Quoted 13 lines
kernel/exit.c 2008-12-31 21:08:08.000000000 +0900 renamed from kernel/exit.c 2008-12-29 23:27:59.000000000 +0900 +6
-0@@ -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; + }[...snip...]
fs/exec.c 2008-12-31 21:11:28.000000000 +0900 static int de_thread(struct task_struct · line 878
Quoted 12 lines
fs/exec.c 2008-12-31 21:11:28.000000000 +0900 renamed from fs/exec.c 2008-12-25 08:26:37.000000000 +0900 +6
-0@@ -870,6 +870,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; + }Perhaps it makes sense to factor out this code and make a helper?
Quoted 2 lines
Unfortunately,
exit_mm()andexec_mmap()do not have the common path which can updatesig->maxrss,mm_release()can't do this...
last problem are, function name and which file have it :)
Quoted 12 lines
fs/exec.c 2008-12-31 21:11:28.000000000 +0900 static int de_thread(struct task_struct
Quoted 11 lines
fs/exec.c 2008-12-31 21:11:28.000000000 +0900 renamed from fs/exec.c 2008-12-25 08:26:37.000000000 +0900 +11
-0+ 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 = maxrss * (PAGE_SIZE / 1024); /* convert pages to KBs */
Quoted 6 lines
Hmm... So,
RUSAGE_THREADalways report maxrss ==get_mm_hiwater_rss(mm)and ignoressignal->maxrss. Doesn't look right to me...Unless I missed something, Jiris's patch was fine, but given that now we inherit maxrss at
exec(),signal->maxrsscan have the "inherited" value?
you are right. thanks.
will fix.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Changelog
v2 -> v3
- in k_getrusage() use (inherited) sig->maxrss value in case of RUSAGE_THREAD
v1 -> v2
- Removed unnecessary max() macro
- To avoid ru_maxrss recalculation in k_getrusage()
- style fixes
Jiri's resend3 -> v1
- At wait_task_zombie(), parent process doesn't only collect child maxrss, but also cmaxrss.
- ru_maxrss inherit at exec()
- style fixes
Applied after: introduce-get_mm_hiwater_xxx-fix-taskstats-hiwater_xxx-accounting.patch ==
From: Signed-off-by: Jiri Pirko <[email protected]>
Subject: [PATCH for -mm] getrusage: fill ru_maxrss value
This patch makes ->ru_maxrss value in struct rusage filled accordingly to rss hiwater mark. This struct is filled as a parameter to getrusage syscall. ->ru_maxrss value is set to KBs which is the way it is done in BSD systems. /usr/bin/time (gnu time) application converts ->ru_maxrss to KBs which seems to be incorrect behavior. Maintainer of this util was notified by me with the patch which corrects it and cc'ed.
To make this happen we extend struct signal_struct by two fields. The first one is ->maxrss which we use to store rss hiwater of the task. The second one is ->cmaxrss which we use to store highest rss hiwater of all task childs. These values are used in k_getrusage() to actually fill ->ru_maxrss. k_getrusage() uses current rss hiwater value directly if mm struct exists.
Note:exec() clear mm->hiwater_rss, but doesn't clear sig->maxrss. it is intetionally behavior. *BSD getrusage have exec() inheriting.
Test progmam and test case
===========================
getrusage.c
----
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <signal.h>
static void consume(int mega)
{
size_t sz = mega * 1024 * 1024;
void *ptr;
ptr = malloc(sz);
memset(ptr, 0, sz);
usleep(1); /* BSD rusage statics need to sleep 1 tick */
}static void show_rusage(char *prefix)
{
int err, err2;
struct rusage rusage_self;
struct rusage rusage_children;
printf("%s: ", prefix);
err = getrusage(RUSAGE_SELF, &rusage_self);
if (!err)
printf("self %ld ", rusage_self.ru_maxrss);
err2 = getrusage(RUSAGE_CHILDREN, &rusage_children);
if (!err2)
printf("children %ld ", rusage_children.ru_maxrss);
printf("\n");
}int main(int argc, char** argv)
{
int status;
int c;
int need_sleep_before_wait = 0;
int consume_large_memory_at_first = 0;
int create_child_at_first = 0;
int sigign = 0;
int create_child_before_exec = 0;
int after_fork_test = 0;
while ((c = getopt(argc, argv, "ceflsz")) != -1) {
switch (c) {
case 'c':
create_child_at_first = 1;
break;
case 'e':
create_child_before_exec = 1;
break;
case 'f':
after_fork_test = 1;
break;
case 'l':
consume_large_memory_at_first = 1;
break;
case 's':
sigign = 1;
break;
case 'z':
need_sleep_before_wait = 1;
break;
default:
break;
}
}
if (consume_large_memory_at_first)
consume(100);
if (create_child_at_first)
system("./child -q");
if (sigign)
signal(SIGCHLD, SIG_IGN);
if (fork()) {
usleep(1);
if (need_sleep_before_wait)
sleep(3); /* children become zombie */
show_rusage("pre_wait");
wait(&status);
show_rusage("post_wait");
} else {
usleep(1);
show_rusage("fork");
if (after_fork_test) {
consume(30);
show_rusage("fork2");
}
if (create_child_before_exec) {
system("./child -lq");
usleep(1);
show_rusage("fork3");
}
execl("./child", "child", 0);
exit(0);
}
return 0;
}child.c
----
#include <sys/types.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
static void consume(int mega)
{
size_t sz = mega * 1024 * 1024;
void *ptr;
ptr = malloc(sz);
memset(ptr, 0, sz);
usleep(1); /* BSD rusage statics need to sleep 1 tick */
}static void show_rusage(char *prefix)
{
int err, err2;
struct rusage rusage_self;
struct rusage rusage_children;
printf("%s: ", prefix);
err = getrusage(RUSAGE_SELF, &rusage_self);
if (!err)
printf("self %ld ", rusage_self.ru_maxrss);
err2 = getrusage(RUSAGE_CHILDREN, &rusage_children);
if (!err2)
printf("children %ld ", rusage_children.ru_maxrss);
printf("\n");}
int main(int argc, char** argv)
{
int status;
int c;
int silent = 0;
int light_weight = 0;
while ((c = getopt(argc, argv, "lq")) != -1) {
switch (c) {
case 'l':
light_weight = 1;
break;
case 'q':
silent = 1;
break;
default:
break;
}
}
if (!silent)
show_rusage("exec");
if (fork()) {
if (light_weight)
consume(400);
else
consume(700);
wait(&status);
} else {
if (light_weight)
consume(600);
else
consume(900);
exit(0);
}
return 0;
}testcase
==================
1. inherit fork?
test way:
% ./getrusage -lc
bsd result:
fork line is "fork: self 0 children 0".
-> rusage sholdn't be inherit by fork.
(both RUSAGE_SELF and RUSAGE_CHILDREN)
2. inherit exec?
test way:
% ./getrusage -lce
bsd result:
fork3: self 103204 children 60000
exec: self 103204 children 60000
fork3 and exec line are the same.
-> rusage shold be inherit by exec.
(both RUSAGE_SELF and RUSAGE_CHILDREN)
3. getrusage(RUSAGE_CHILDREN) collect grandchild statics?
test way:
% ./getrusage
bsd result:
post_wait line is about "post_wait: self 0 children 90000".
-> RUSAGE_CHILDREN can collect grandchild.
4. zombie, but not waited children collect or not?
test way:
% ./getrusage -z
bsd result:
pre_wait line is "pre_wait: self 0 children 0".
-> zombie child process (not waited-for child process) isn't accounted.
5. SIG_IGN collect or not
test way:
% ./getrusage -s
bsd result:
post_wait line is "post_wait: self 0 children 0".
-> if SIGCHLD is ignored, children isn't accounted.
6. fork and malloc
test way:
% ./getrusage -lcf
bsd result:
fork line is "fork: self 0 children 0". fork2 line is about "fork: self 130000 children 0".
-> rusage sholdn't be inherit by fork.
(both RUSAGE_SELF and RUSAGE_CHILDREN) but additional memory cunsumption cause right maxrss calculation.
--- fs/exec.c | 7 +++++++ include/linux/sched.h | 1 + kernel/exit.c | 10 ++++++++++ kernel/fork.c | 1 + kernel/sys.c | 17 +++++++++++++++++ 5 files changed, 36 insertions(+), 0 deletions(-)
fs/exec.c +7 -0
@@ -867,6 +867,13 @@ static int de_thread(struct task_struct *tsk) 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 ();
include/linux/sched.h +1 -0
@@ -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;/*
kernel/exit.c +10 -0
@@ -1060,6 +1060,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)
@@ -1303,6 +1309,7 @@ static int wait_task_zombie(struct task_struct *p, int options,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
@@ -1354,6 +1361,9 @@ static int wait_task_zombie(struct task_struct *p, int options, 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);
kernel/fork.c +1 -0
@@ -846,6 +846,7 @@ static int copy_signal(unsigned long clone_flags, struct task_struct *tsk) 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);
kernel/sys.c +15 -0
@@ -1622,12 +1622,14 @@ static void k_getrusage(struct task_struct *p, int who, struct rusage *r)unsigned long flags;cputime_t utime, stime;struct task_cputime cputime; +unsigned long maxrss =0 ;memset ((char *) r,0 ,sizeof *r); utime = stime = cputime_zero;if (who ==RUSAGE_THREAD ) {accumulate_thread_rusage (p, r); + maxrss = p->signal->maxrss; goto out; }
@@ -1645,6 +1647,7 @@ static void k_getrusage(struct task_struct *p, int who, struct rusage *r) r->ru_majflt = p->signal->cmaj_flt; r->ru_inblock = p->signal->cinblock; r->ru_oublock = p->signal->coublock; + maxrss = p->signal->cmaxrss;if (who ==RUSAGE_CHILDREN )break ;
@@ -1659,6 +1662,8 @@ static void k_getrusage(struct task_struct *p, int who, struct rusage *r) r->ru_majflt += p->signal->maj_flt; r->ru_inblock += p->signal->inblock; r->ru_oublock += p->signal->oublock; +if (maxrss < p->signal->maxrss) + maxrss = p->signal->maxrss; t = p; do { accumulate_thread_rusage(t, r);
@@ -1674,6 +1679,18 @@ static void k_getrusage(struct task_struct *p, int who, struct rusage *r) 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); + }
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Andrew Morton
maintainerQuoted 4 lines · On Mon, 5 Jan 2009 16:32:04 +0100 Jiri Pirko <[email protected]> wrote:
Changelog
v2 -> v3
- ink_getrusage()use (inherited)sig->maxrssvalue in case ofRUSAGE_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.
fs/exec.c renamed from fs/exec.c~getrusage-fill-ru_maxrss-value +7 -0
@@ -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 ();
include/linux/sched.h renamed from include/linux/sched.h~getrusage-fill-ru_maxrss-value +1 -0
@@ -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;/*
kernel/exit.c renamed from kernel/exit.c~getrusage-fill-ru_maxrss-value +10 -0
@@ -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);
kernel/fork.c renamed from kernel/fork.c~getrusage-fill-ru_maxrss-value +1 -0
@@ -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);
kernel/sys.c renamed from kernel/sys.c~getrusage-fill-ru_maxrss-value +12 -0
@@ -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 [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 10 lines · On Mon, 5 Jan 2009 14:13:13 -0800 Andrew Morton <[email protected]>…
Quoted 4 lines · On Mon, 5 Jan 2009 16:32:04 +0100 Jiri Pirko <[email protected]> wrote:
Changelog
v2 -> v3
- ink_getrusage()use (inherited)sig->maxrssvalue in case ofRUSAGE_THREADThe patch which you sent was mysteriously truncated - the
kernel/sys.chunk is partly missing. So I took that bit from the earlier version of the patch.
Sorry for this. I should probably toss this Claws into the garbage can :/
Quoted 2 lines
Please check that the below is still identical to your version 3.
Nope - the tail is different. - Sending the patch again. Please use the changelog text from previous send.
Thanks Andrew and again sorry for problems.
--- fs/exec.c | 7 +++++++ include/linux/sched.h | 1 + kernel/exit.c | 10 ++++++++++ kernel/fork.c | 1 + kernel/sys.c | 17 +++++++++++++++++ 5 files changed, 36 insertions(+), 0 deletions(-)
fs/exec.c +7 -0
@@ -867,6 +867,13 @@ static int de_thread(struct task_struct *tsk) 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 ();
include/linux/sched.h +1 -0
@@ -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;/*
kernel/exit.c +10 -0
@@ -1060,6 +1060,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)
@@ -1303,6 +1309,7 @@ static int wait_task_zombie(struct task_struct *p, int options,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
@@ -1354,6 +1361,9 @@ static int wait_task_zombie(struct task_struct *p, int options, 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);
kernel/fork.c +1 -0
@@ -846,6 +846,7 @@ static int copy_signal(unsigned long clone_flags, struct task_struct *tsk) 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);
kernel/sys.c +17 -0
@@ -1622,12 +1622,14 @@ static void k_getrusage(struct task_struct *p, int who, struct rusage *r)unsigned long flags;cputime_t utime, stime;struct task_cputime cputime; +unsigned long maxrss =0 ;memset ((char *) r,0 ,sizeof *r); utime = stime = cputime_zero;if (who ==RUSAGE_THREAD ) {accumulate_thread_rusage (p, r); + maxrss = p->signal->maxrss; goto out; }
@@ -1645,6 +1647,7 @@ static void k_getrusage(struct task_struct *p, int who, struct rusage *r) r->ru_majflt = p->signal->cmaj_flt; r->ru_inblock = p->signal->cinblock; r->ru_oublock = p->signal->coublock; + maxrss = p->signal->cmaxrss;if (who ==RUSAGE_CHILDREN )break ;
@@ -1659,6 +1662,8 @@ static void k_getrusage(struct task_struct *p, int who, struct rusage *r) r->ru_majflt += p->signal->maj_flt; r->ru_inblock += p->signal->inblock; r->ru_oublock += p->signal->oublock; +if (maxrss < p->signal->maxrss) + maxrss = p->signal->maxrss; t = p; do { accumulate_thread_rusage(t, r);
@@ -1674,6 +1679,18 @@ static void k_getrusage(struct task_struct *p, int who, struct rusage *r) 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 = maxrss * (PAGE_SIZE /1024 );/* convert pages to KBs */ }int getrusage (struct task_struct *p,int who,struct rusage __user *ru)
Signature · 7 lines
1.6.0.3 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Andrew Morton
maintainerQuoted 11 lines · On Tue, 6 Jan 2009 10:48:39 +0100 Jiri Pirko <[email protected]> wrote:
Quoted 8 lines · On Mon, 5 Jan 2009 14:13:13 -0800 Andrew Morton <[email protected]>…
Quoted 4 lines · On Mon, 5 Jan 2009 16:32:04 +0100 Jiri Pirko <[email protected]> wrote:
Changelog
v2 -> v3
- ink_getrusage()use (inherited)sig->maxrssvalue in case ofRUSAGE_THREAD
Quoted 10 lines
Quoted 2 lines
The patch which you sent was mysteriously truncated - the
kernel/sys.chunk is partly missing. So I took that bit from the earlier version of the patch.Sorry for this. I should probably toss this Claws into the garbage can :/
Quoted 2 lines
Please check that the below is still identical to your version 3.
Nope - the tail is different. - Sending the patch again. Please use the changelog text from previous send.
Thanks Andrew and again sorry for problems.
I have a note here that this patch needs acks, but I didn't note who from.
Someone ack it :)
From: Jiri Pirko <[email protected]>
Make ->ru_maxrss value in struct rusage filled accordingly to rss hiwater mark. This struct is filled as a parameter to getrusage syscall. ->ru_maxrss value is set to KBs which is the way it is done in BSD systems. /usr/bin/time (gnu time) application converts ->ru_maxrss to KBs which seems to be incorrect behavior. Maintainer of this util was notified by me with the patch which corrects it and cc'ed.
To make this happen we extend struct signal_struct by two fields. The first one is ->maxrss which we use to store rss hiwater of the task. The second one is ->cmaxrss which we use to store highest rss hiwater of all task childs. These values are used in k_getrusage() to actually fill ->ru_maxrss. k_getrusage() uses current rss hiwater value directly if mm struct exists.
Note:exec() clear mm->hiwater_rss, but doesn't clear sig->maxrss. it is intetionally behavior. *BSD getrusage have exec() inheriting.
Test progmam and test case
===========================
getrusage.c
====
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <signal.h>
static void consume(int mega)
{
size_t sz = mega * 1024 * 1024;
void *ptr;
ptr = malloc(sz);
memset(ptr, 0, sz);
usleep(1); /* BSD rusage statics need to sleep 1 tick */
}static void show_rusage(char *prefix)
{
int err, err2;
struct rusage rusage_self;
struct rusage rusage_children;
printf("%s: ", prefix);
err = getrusage(RUSAGE_SELF, &rusage_self);
if (!err)
printf("self %ld ", rusage_self.ru_maxrss);
err2 = getrusage(RUSAGE_CHILDREN, &rusage_children);
if (!err2)
printf("children %ld ", rusage_children.ru_maxrss);
printf("\n");
}int main(int argc, char** argv)
{
int status;
int c;
int need_sleep_before_wait = 0;
int consume_large_memory_at_first = 0;
int create_child_at_first = 0;
int sigign = 0;
int create_child_before_exec = 0;
int after_fork_test = 0;
while ((c = getopt(argc, argv, "ceflsz")) != -1) {
switch (c) {
case 'c':
create_child_at_first = 1;
break;
case 'e':
create_child_before_exec = 1;
break;
case 'f':
after_fork_test = 1;
break;
case 'l':
consume_large_memory_at_first = 1;
break;
case 's':
sigign = 1;
break;
case 'z':
need_sleep_before_wait = 1;
break;
default:
break;
}
}
if (consume_large_memory_at_first)
consume(100);
if (create_child_at_first)
system("./child -q");
if (sigign)
signal(SIGCHLD, SIG_IGN);
if (fork()) {
usleep(1);
if (need_sleep_before_wait)
sleep(3); /* children become zombie */
show_rusage("pre_wait");
wait(&status);
show_rusage("post_wait");
} else {
usleep(1);
show_rusage("fork");
if (after_fork_test) {
consume(30);
show_rusage("fork2");
}
if (create_child_before_exec) {
system("./child -lq");
usleep(1);
show_rusage("fork3");
}
execl("./child", "child", 0);
exit(0);
}
return 0;
}child.c
====
#include <sys/types.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
static void consume(int mega)
{
size_t sz = mega * 1024 * 1024;
void *ptr;
ptr = malloc(sz);
memset(ptr, 0, sz);
usleep(1); /* BSD rusage statics need to sleep 1 tick */
}static void show_rusage(char *prefix)
{
int err, err2;
struct rusage rusage_self;
struct rusage rusage_children;
printf("%s: ", prefix);
err = getrusage(RUSAGE_SELF, &rusage_self);
if (!err)
printf("self %ld ", rusage_self.ru_maxrss);
err2 = getrusage(RUSAGE_CHILDREN, &rusage_children);
if (!err2)
printf("children %ld ", rusage_children.ru_maxrss);
printf("\n");}
int main(int argc, char** argv)
{
int status;
int c;
int silent = 0;
int light_weight = 0;
while ((c = getopt(argc, argv, "lq")) != -1) {
switch (c) {
case 'l':
light_weight = 1;
break;
case 'q':
silent = 1;
break;
default:
break;
}
}
if (!silent)
show_rusage("exec");
if (fork()) {
if (light_weight)
consume(400);
else
consume(700);
wait(&status);
} else {
if (light_weight)
consume(600);
else
consume(900);
exit(0);
}
return 0;
}testcase
========
1. inherit fork?
test way:
% ./getrusage -lc
bsd result:
fork line is "fork: self 0 children 0".
-> rusage sholdn't be inherit by fork.
(both RUSAGE_SELF and RUSAGE_CHILDREN)
2. inherit exec?
test way:
% ./getrusage -lce
bsd result:
fork3: self 103204 children 60000
exec: self 103204 children 60000
fork3 and exec line are the same.
-> rusage shold be inherit by exec.
(both RUSAGE_SELF and RUSAGE_CHILDREN)
3. getrusage(RUSAGE_CHILDREN) collect grandchild statics?
test way:
% ./getrusage
bsd result:
post_wait line is about "post_wait: self 0 children 90000".
-> RUSAGE_CHILDREN can collect grandchild.
4. zombie, but not waited children collect or not?
test way:
% ./getrusage -z
bsd result:
pre_wait line is "pre_wait: self 0 children 0".
-> zombie child process (not waited-for child process) isn't accounted.
5. SIG_IGN collect or not
test way:
% ./getrusage -s
bsd result:
post_wait line is "post_wait: self 0 children 0".
-> if SIGCHLD is ignored, children isn't accounted.
6. fork and malloc
test way:
% ./getrusage -lcf
bsd result:
fork line is "fork: self 0 children 0". fork2 line is about "fork: self 130000 children 0".
-> rusage sholdn't be inherit by fork.
(both RUSAGE_SELF and RUSAGE_CHILDREN) but additional memory cunsumption cause right maxrss calculation.
---
fs/exec.c | 7 +++++++ include/linux/sched.h | 1 + kernel/exit.c | 10 ++++++++++ kernel/fork.c | 1 + kernel/sys.c | 17 +++++++++++++++++ 5 files changed, 36 insertions(+)
fs/exec.c renamed from fs/exec.c~getrusage-fill-ru_maxrss-value +7 -0
@@ -871,6 +871,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 ();
include/linux/sched.h renamed from include/linux/sched.h~getrusage-fill-ru_maxrss-value +1 -0
@@ -588,6 +588,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;/*
kernel/exit.c renamed from kernel/exit.c~getrusage-fill-ru_maxrss-value +10 -0
@@ -1056,6 +1056,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)
@@ -1301,6 +1307,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
@@ -1352,6 +1359,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);
kernel/fork.c renamed from kernel/fork.c~getrusage-fill-ru_maxrss-value +1 -0
@@ -862,6 +862,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); sig->sum_sched_runtime =0 ;taskstats_tgid_init (sig);
kernel/sys.c renamed from kernel/sys.c~getrusage-fill-ru_maxrss-value +17 -0
@@ -1618,6 +1618,7 @@ static void k_getrusage(struct task_struunsigned long flags;cputime_t utime, stime;struct task_cputime cputime; +unsigned long maxrss =0 ;memset ((char *) r,0 ,sizeof *r); utime = stime = cputime_zero;
@@ -1626,6 +1627,7 @@ static void k_getrusage(struct task_stru utime =task_utime (current); stime =task_stime (current);accumulate_thread_rusage (p, r); + maxrss = p->signal->maxrss; goto out; }
@@ -1643,6 +1645,7 @@ static void k_getrusage(struct task_stru r->ru_majflt = p->signal->cmaj_flt; r->ru_inblock = p->signal->cinblock; r->ru_oublock = p->signal->coublock; + maxrss = p->signal->cmaxrss;if (who ==RUSAGE_CHILDREN )break ;
@@ -1657,6 +1660,8 @@ static void k_getrusage(struct task_stru r->ru_majflt += p->signal->maj_flt; r->ru_inblock += p->signal->inblock; r->ru_oublock += p->signal->oublock; +if (maxrss < p->signal->maxrss) + maxrss = p->signal->maxrss; t = p; do { accumulate_thread_rusage(t, r);
@@ -1672,6 +1677,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 = maxrss * (PAGE_SIZE /1024 );/* convert pages to KBs */ }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 [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 4 lines · Andrew Morton
I have a note here that this patch needs acks, but I didn't note who from.
Someone ack it :)
looks good to me at a quick glance. A stupid technicality. There's repetitive patterns of:
fs/exec.c static int de_thread(struct task_struct · line 879
Quoted 6 lines
fs/exec.c renamed from fs/exec.c~getrusage-fill-ru_maxrss-value +6
-0+if (current->mm) { +unsigned long hiwater_rss =get_mm_hiwater_rss (current->mm); + +if (sig->maxrss < hiwater_rss) + sig->maxrss = hiwater_rss; + }
in about 3 separate places. Wouldnt a helper along the lines of:
sig->maxrss = mm_hiwater_rss(current->mm, sig->maxrss);
be much more readable?
The helper could be something like:
static inline unsigned long
mm_hiwater_rss(struct mm_struct *mm, unsigned long maxrss)
{
return max(maxrss, mm ? get_mm_hiwater_rss(mm) : 0);}
much nicer?
Ingo
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 1/1 getrusage: fill ru_maxrss value
(resend, repetitive patterns put into an inline function - not using max macro
because it's was decided not to use it in previous conversation)
From: Jiri Pirko <[email protected]>
Make ->ru_maxrss value in struct rusage filled accordingly to rss hiwater mark. This struct is filled as a parameter to getrusage syscall. ->ru_maxrss value is set to KBs which is the way it is done in BSD systems. /usr/bin/time (gnu time) application converts ->ru_maxrss to KBs which seems to be incorrect behavior. Maintainer of this util was notified by me with the patch which corrects it and cc'ed.
To make this happen we extend struct signal_struct by two fields. The first one is ->maxrss which we use to store rss hiwater of the task. The second one is ->cmaxrss which we use to store highest rss hiwater of all task childs. These values are used in k_getrusage() to actually fill ->ru_maxrss. k_getrusage() uses current rss hiwater value directly if mm struct exists.
Note:exec() clear mm->hiwater_rss, but doesn't clear sig->maxrss. it is intetionally behavior. *BSD getrusage have exec() inheriting.
Test progmam and test case
===========================
getrusage.c
====
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <signal.h>
static void consume(int mega)
{
size_t sz = mega * 1024 * 1024;
void *ptr;
ptr = malloc(sz);
memset(ptr, 0, sz);
usleep(1); /* BSD rusage statics need to sleep 1 tick */
}static void show_rusage(char *prefix)
{
int err, err2;
struct rusage rusage_self;
struct rusage rusage_children;
printf("%s: ", prefix);
err = getrusage(RUSAGE_SELF, &rusage_self);
if (!err)
printf("self %ld ", rusage_self.ru_maxrss);
err2 = getrusage(RUSAGE_CHILDREN, &rusage_children);
if (!err2)
printf("children %ld ", rusage_children.ru_maxrss);
printf("\n");
}int main(int argc, char** argv)
{
int status;
int c;
int need_sleep_before_wait = 0;
int consume_large_memory_at_first = 0;
int create_child_at_first = 0;
int sigign = 0;
int create_child_before_exec = 0;
int after_fork_test = 0;
while ((c = getopt(argc, argv, "ceflsz")) != -1) {
switch (c) {
case 'c':
create_child_at_first = 1;
break;
case 'e':
create_child_before_exec = 1;
break;
case 'f':
after_fork_test = 1;
break;
case 'l':
consume_large_memory_at_first = 1;
break;
case 's':
sigign = 1;
break;
case 'z':
need_sleep_before_wait = 1;
break;
default:
break;
}
}
if (consume_large_memory_at_first)
consume(100);
if (create_child_at_first)
system("./child -q");
if (sigign)
signal(SIGCHLD, SIG_IGN);
if (fork()) {
usleep(1);
if (need_sleep_before_wait)
sleep(3); /* children become zombie */
show_rusage("pre_wait");
wait(&status);
show_rusage("post_wait");
} else {
usleep(1);
show_rusage("fork");
if (after_fork_test) {
consume(30);
show_rusage("fork2");
}
if (create_child_before_exec) {
system("./child -lq");
usleep(1);
show_rusage("fork3");
}
execl("./child", "child", 0);
exit(0);
}
return 0;
}child.c
====
#include <sys/types.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
static void consume(int mega)
{
size_t sz = mega * 1024 * 1024;
void *ptr;
ptr = malloc(sz);
memset(ptr, 0, sz);
usleep(1); /* BSD rusage statics need to sleep 1 tick */
}static void show_rusage(char *prefix)
{
int err, err2;
struct rusage rusage_self;
struct rusage rusage_children;
printf("%s: ", prefix);
err = getrusage(RUSAGE_SELF, &rusage_self);
if (!err)
printf("self %ld ", rusage_self.ru_maxrss);
err2 = getrusage(RUSAGE_CHILDREN, &rusage_children);
if (!err2)
printf("children %ld ", rusage_children.ru_maxrss);
printf("\n");}
int main(int argc, char** argv)
{
int status;
int c;
int silent = 0;
int light_weight = 0;
while ((c = getopt(argc, argv, "lq")) != -1) {
switch (c) {
case 'l':
light_weight = 1;
break;
case 'q':
silent = 1;
break;
default:
break;
}
}
if (!silent)
show_rusage("exec");
if (fork()) {
if (light_weight)
consume(400);
else
consume(700);
wait(&status);
} else {
if (light_weight)
consume(600);
else
consume(900);
exit(0);
}
return 0;
}testcase
========
1. inherit fork?
test way:
% ./getrusage -lc
bsd result:
fork line is "fork: self 0 children 0".
-> rusage sholdn't be inherit by fork.
(both RUSAGE_SELF and RUSAGE_CHILDREN)
2. inherit exec?
test way:
% ./getrusage -lce
bsd result:
fork3: self 103204 children 60000
exec: self 103204 children 60000
fork3 and exec line are the same.
-> rusage shold be inherit by exec.
(both RUSAGE_SELF and RUSAGE_CHILDREN)
3. getrusage(RUSAGE_CHILDREN) collect grandchild statics?
test way:
% ./getrusage
bsd result:
post_wait line is about "post_wait: self 0 children 90000".
-> RUSAGE_CHILDREN can collect grandchild.
4. zombie, but not waited children collect or not?
test way:
% ./getrusage -z
bsd result:
pre_wait line is "pre_wait: self 0 children 0".
-> zombie child process (not waited-for child process) isn't accounted.
5. SIG_IGN collect or not
test way:
% ./getrusage -s
bsd result:
post_wait line is "post_wait: self 0 children 0".
-> if SIGCHLD is ignored, children isn't accounted.
6. fork and malloc
test way:
% ./getrusage -lcf
bsd result:
fork line is "fork: self 0 children 0". fork2 line is about "fork: self 130000 children 0".
-> rusage sholdn't be inherit by fork.
(both RUSAGE_SELF and RUSAGE_CHILDREN) but additional memory cunsumption cause right maxrss calculation.
---
fs/exec.c | 3 +++ include/linux/sched.h | 10 ++++++++++ kernel/exit.c | 6 ++++++ kernel/fork.c | 1 + kernel/sys.c | 14 ++++++++++++++ 5 files changed, 34 insertions(+), 0 deletions(-)
fs/exec.c +3 -0
@@ -872,6 +872,9 @@ static int de_thread(struct task_struct *tsk) sig->notify_count =0 ; no_thread_group: +if (current->mm) +setmax_mm_hiwater_rss (&sig->maxrss, current->mm); +exit_itimers (sig);flush_itimer_signals ();
include/linux/sched.h +10 -0
@@ -397,6 +397,15 @@ static inline unsigned long get_mm_hiwater_rss(struct mm_struct *mm)return max (mm->hiwater_rss,get_mm_rss (mm)); } +static inline void setmax_mm_hiwater_rss (unsigned long *maxrss, +struct mm_struct *mm) +{ +unsigned long hiwater_rss =get_mm_hiwater_rss (mm); + +if (*maxrss < hiwater_rss) + *maxrss = hiwater_rss; +} +static inline unsigned long get_mm_hiwater_vm (struct mm_struct *mm) {return max (mm->hiwater_vm, mm->total_vm);
@@ -567,6 +576,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;/*
kernel/exit.c +6 -0
@@ -943,6 +943,8 @@ NORET_TYPE void do_exit(long code)if (group_dead) {hrtimer_cancel (&tsk->signal->real_timer);exit_itimers (tsk->signal); +if (tsk->mm) +setmax_mm_hiwater_rss (&tsk->signal->maxrss, tsk->mm); }acct_collect (code, group_dead);if (group_dead)
@@ -1188,6 +1190,7 @@ static int wait_task_zombie(struct task_struct *p, int options,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
@@ -1239,6 +1242,9 @@ static int wait_task_zombie(struct task_struct *p, int options, 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);
kernel/fork.c +1 -0
@@ -848,6 +848,7 @@ static int copy_signal(unsigned long clone_flags, struct task_struct *tsk) 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); sig->sum_sched_runtime =0 ;taskstats_tgid_init (sig);
kernel/sys.c +14 -0
@@ -1626,6 +1626,7 @@ static void k_getrusage(struct task_struct *p, int who, struct rusage *r)unsigned long flags;cputime_t utime, stime;struct task_cputime cputime; +unsigned long maxrss =0 ;memset ((char *) r,0 ,sizeof *r); utime = stime = cputime_zero;
@@ -1634,6 +1635,7 @@ static void k_getrusage(struct task_struct *p, int who, struct rusage *r) utime =task_utime (current); stime =task_stime (current);accumulate_thread_rusage (p, r); + maxrss = p->signal->maxrss; goto out; }
@@ -1651,6 +1653,7 @@ static void k_getrusage(struct task_struct *p, int who, struct rusage *r) r->ru_majflt = p->signal->cmaj_flt; r->ru_inblock = p->signal->cinblock; r->ru_oublock = p->signal->coublock; + maxrss = p->signal->cmaxrss;if (who ==RUSAGE_CHILDREN )break ;
@@ -1665,6 +1668,8 @@ static void k_getrusage(struct task_struct *p, int who, struct rusage *r) r->ru_majflt += p->signal->maj_flt; r->ru_inblock += p->signal->inblock; r->ru_oublock += p->signal->oublock; +if (maxrss < p->signal->maxrss) + maxrss = p->signal->maxrss; t = p; do { accumulate_thread_rusage(t, r);
@@ -1680,6 +1685,15 @@ static void k_getrusage(struct task_struct *p, int who, struct rusage *r) 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) { +setmax_mm_hiwater_rss (&maxrss, mm); +mmput (mm); + } + } + r->ru_maxrss = maxrss * (PAGE_SIZE /1024 );/* convert pages to KBs */ }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 [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 19 lines · Jiri Pirko
(resend, repetitive patterns put into an inline function - not using max macro
because it's was decided not to use it in previous conversation)From: Jiri Pirko <[email protected]>
Make ->ru_maxrss value in struct rusage filled accordingly to rss hiwater mark. This struct is filled as a parameter to getrusage syscall. ->ru_maxrss value is set to KBs which is the way it is done in BSD systems.
/usr/bin/time(gnu time) application converts ->ru_maxrss to KBs which seems to be incorrect behavior. Maintainer of this util was notified by me with the patch which corrects it and cc'ed.To make this happen we extend struct
signal_structby two fields. The first one is ->maxrss which we use to store rss hiwater of the task. The second one is ->cmaxrss which we use to store highest rss hiwater of all task childs. These values are used ink_getrusage()to actually fill ->ru_maxrss.k_getrusage()uses current rss hiwater value directly if mm struct exists.
Quoted 3 lines
Note:
exec()clearmm->hiwater_rss, but doesn't clearsig->maxrss. it is intetionally behavior. *BSD getrusage haveexec()inheriting.
Sorry, I'm finding myself quite unable to Ack this: that may well be a measure of my density, rather than a criticism of your patch.
On the nitpicking level: I wish you'd put the args the other way round in your setmax_mm_hiwater_rss(maxrss, mm): (mm, maxrss) would be more conventional. Though we're gathering so many helpers for these things, hard-to-distinguish without looking up in the header file each time, that I wonder if they could all be refactored better.
But on the more serious level: I find I don't really understand what this ru_maxrss number is supposed to be, so have a hard job telling whether you've implemented it right (as to whether things are updated in the right places, I'd rather rely on Oleg for that).
You convey the impression that it's supposed to be similar to whatever it is in BSD, but little meaning beyond that. We agreed before that it should be derived from hiwater_rss - though now I google for "BSD getrusage" I find ru_maxrss described as "maximum shared memory or current resident set", which leaves me thoroughly confused.
I'm worrying particularly about the fork/exec issue you highlight. You're exemplary in providing your test programs, but there's a big
omission: you don't mention that the first test, "./getrusage -lc", gives a very different result on Linux than you say it does on BSD - you say the BSD fork line is "fork: self 0 children 0", whereas I find my Linux fork line is "fork: self 102636 children 0".
So after that discrepancy, I can't tell what to expect. Not that I can make any sense of BSD's "self 0" there - I don't know how you could present 0 there if this is related to hiwater_rss.
Now I'm seriously wondering if the ru_maxrss reported will generate more bugreports from people puzzled as to how it should behave, than help anyone in studying their process behaviour.
Sorry to be so negative after all this time: I genuinely hope others will spring up to defend your patch and illustrate my stupidity.
Hugh
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Hi
Quoted 6 lines
I'm worrying particularly about the fork/exec issue you highlight. You're exemplary in providing your test programs, but there's a big
omission: you don't mention that the first test, "./getrusage -lc", gives a very different result on Linux than you say it does on BSD - you say the BSD fork line is "fork: self 0 children 0", whereas I find my Linux fork line is "fork: self 102636 children 0".
FreeBSD update rusage at tick updating point. (I think all bsd do that) Then, bsd displaing 0 is bsd's problem :)
Do I must change test program?
Quoted 10 lines
So after that discrepancy, I can't tell what to expect. Not that I can make any sense of BSD's "self 0" there - I don't know how you could present 0 there if this is related to
hiwater_rss.Now I'm seriously wondering if the
ru_maxrssreported will generate more bugreports from people puzzled as to how it should behave, than help anyone in studying their process behaviour.Sorry to be so negative after all this time: I genuinely hope others will spring up to defend your patch and illustrate my stupidity.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 10 lines · KOSAKI Motohiro
Quoted 7 lines
I'm worrying particularly about the fork/exec issue you highlight. You're exemplary in providing your test programs, but there's a big
omission: you don't mention that the first test, "./getrusage -lc", gives a very different result on Linux than you say it does on BSD - you say the BSD fork line is "fork: self 0 children 0", whereas I find my Linux fork line is "fork: self 102636 children 0".FreeBSD update rusage at tick updating point. (I think all bsd do that) Then, bsd displaing 0 is bsd's problem :)
Ah, thank you.
Quoted 2 lines
Do I must change test program?
Apparently somebody needs to, please; though it appears to be already well supplied with usleep(1)s - maybe they needed to be usleep(2)s?
And then change results shown in the changelog, and check conclusions drawn from them (if BSD is behaving as we do, it should still show maxrss not inherited over fork, but less obviously - the number goes down slightly, because the history is lost, but nowhere near to zero).
Hugh
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Andrew Morton
maintainerQuoted 17 lines · On Mon, 6 Apr 2009 08:22:07 +0100 (BST) Hugh Dickins <[email protected]> wrote:
Quoted 10 lines · KOSAKI Motohiro
Quoted 7 lines
I'm worrying particularly about the fork/exec issue you highlight. You're exemplary in providing your test programs, but there's a big
omission: you don't mention that the first test, "./getrusage -lc", gives a very different result on Linux than you say it does on BSD - you say the BSD fork line is "fork: self 0 children 0", whereas I find my Linux fork line is "fork: self 102636 children 0".FreeBSD update rusage at tick updating point. (I think all bsd do that) Then, bsd displaing 0 is bsd's problem :)
Ah, thank you.
Quoted 2 lines
Do I must change test program?
Quoted 8 lines
Apparently somebody needs to, please; though it appears to be already well supplied with usleep(1)s - maybe they needed to be usleep(2)s?
And then change results shown in the changelog, and check conclusions drawn from them (if BSD is behaving as we do, it should still show maxrss not inherited over fork, but less obviously - the number goes down slightly, because the history is lost, but nowhere near to zero).
afaik none of this happened, so I have the patch on hold.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 23 lines
Quoted 20 lines · On Mon, 6 Apr 2009 08:22:07 +0100 (BST) Hugh Dickins <[email protected]> wrote:
Quoted 10 lines · KOSAKI Motohiro
Quoted 7 lines
I'm worrying particularly about the fork/exec issue you highlight. You're exemplary in providing your test programs, but there's a big
omission: you don't mention that the first test, "./getrusage -lc", gives a very different result on Linux than you say it does on BSD - you say the BSD fork line is "fork: self 0 children 0", whereas I find my Linux fork line is "fork: self 102636 children 0".FreeBSD update rusage at tick updating point. (I think all bsd do that) Then, bsd displaing 0 is bsd's problem :)
Ah, thank you.
Quoted 2 lines
Do I must change test program?
Apparently somebody needs to, please; though it appears to be already well supplied with usleep(1)s - maybe they needed to be usleep(2)s?
Quoted 7 lines
Quoted 5 lines
And then change results shown in the changelog, and check conclusions drawn from them (if BSD is behaving as we do, it should still show maxrss not inherited over fork, but less obviously - the number goes down slightly, because the history is lost, but nowhere near to zero).
afaik none of this happened, so I have the patch on hold.
Grr, my fault.
I recognize it. sorry.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 29 lines
Quoted 29 lines
Quoted 25 lines · On Mon, 6 Apr 2009 08:22:07 +0100 (BST) Hugh Dickins <[email protected]> wrote:
Quoted 10 lines · KOSAKI Motohiro
Quoted 7 lines
I'm worrying particularly about the fork/exec issue you highlight. You're exemplary in providing your test programs, but there's a big
omission: you don't mention that the first test, "./getrusage -lc", gives a very different result on Linux than you say it does on BSD - you say the BSD fork line is "fork: self 0 children 0", whereas I find my Linux fork line is "fork: self 102636 children 0".FreeBSD update rusage at tick updating point. (I think all bsd do that) Then, bsd displaing 0 is bsd's problem :)
Ah, thank you.
Quoted 2 lines
Do I must change test program?
Apparently somebody needs to, please; though it appears to be already well supplied with usleep(1)s - maybe they needed to be usleep(2)s?
And then change results shown in the changelog, and check conclusions drawn from them (if BSD is behaving as we do, it should still show maxrss not inherited over fork, but less obviously - the number goes down slightly, because the history is lost, but nowhere near to zero).
Quoted 4 lines
Quoted 1 line
afaik none of this happened, so I have the patch on hold.
Grr, my fault.
I recognize it. sorry.
I've finished my long pending homework ;)
Andrew, can you please replace following patch with getrusage-fill-ru_maxrss-value.patch and getrusage-fill-ru_maxrss-value-update.patch?
ChangeLog
===============================
o Merge getrusage-fill-ru_maxrss-value.patch and getrusage-fill-ru_maxrss-value-update.patch
o rewrote test programs (older version hit FreeBSD bug and it obfuscate testcase intention, thanks Hugh)
========================================================
From: Jiri Pirko <[email protected]>
Subject: [PATCH] getrusage: fill ru_maxrss value
Make ->ru_maxrss value in struct rusage filled accordingly to rss hiwater mark. This struct is filled as a parameter to getrusage syscall. ->ru_maxrss value is set to KBs which is the way it is done in BSD systems. /usr/bin/time (gnu time) application converts ->ru_maxrss to KBs which seems to be incorrect behavior. Maintainer of this util was notified by me with the patch which corrects it and cc'ed.
To make this happen we extend struct signal_struct by two fields. The first one is ->maxrss which we use to store rss hiwater of the task. The second one is ->cmaxrss which we use to store highest rss hiwater of all task childs. These values are used in k_getrusage() to actually fill ->ru_maxrss. k_getrusage() uses current rss hiwater value directly if mm struct exists.
Note:exec() clear mm->hiwater_rss, but doesn't clear sig->maxrss. it is intetionally behavior. *BSD getrusage have exec() inheriting.
test programs
========================================================
getrusage.c
-----------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <signal.h>
#include <sys/mman.h>
#include "common.h"
#define err(str) perror(str), exit(1)
int main(int argc, char** argv)
{
int status;
printf("allocate 100MB\n");
consume(100);
printf("testcase1: fork inherit? \n");
printf(" expect: initial.self ~= child.self\n");
show_rusage("initial");
if (__fork()) {
wait(&status);
} else {
show_rusage("fork child");
_exit(0);
}
printf("\n");
printf("testcase2: fork inherit? (cont.) \n");
printf(" expect: initial.children ~= 100MB, but child.children = 0\n");
show_rusage("initial");
if (__fork()) {
wait(&status);
} else {
show_rusage("child");
_exit(0);
}
printf("\n");
printf("testcase3: fork + malloc \n");
printf(" expect: child.self ~= initial.self + 50MB\n");
show_rusage("initial");
if (__fork()) {
wait(&status);
} else {
printf("allocate +50MB\n");
consume(50);
show_rusage("fork child");
_exit(0);
}
printf("\n");
printf("testcase4: grandchild maxrss\n");
printf(" expect: post_wait.children ~= 300MB\n");
show_rusage("initial");
if (__fork()) {
wait(&status);
show_rusage("post_wait");
} else {
system("./child -n 0 -g 300");
_exit(0);
}
printf("\n");
printf("testcase5: zombie\n");
printf(" expect: pre_wait ~= initial, IOW the zombie process is not accounted.\n");
printf(" post_wait ~= 400MB, IOW wait() collect child's max_rss. \n");
show_rusage("initial");
if (__fork()) {
sleep(1); /* children become zombie */
show_rusage("pre_wait");
wait(&status);
show_rusage("post_wait");
} else {
system("./child -n 400");
_exit(0);
}
printf("\n");
printf("testcase6: SIG_IGN\n");
printf(" expect: initial ~= after_zombie (child's 500MB alloc should be ignored).\n");
show_rusage("initial");
signal(SIGCHLD, SIG_IGN);
if (__fork()) {
sleep(1); /* children become zombie */
show_rusage("after_zombie");
} else {
system("./child -n 500");
_exit(0);
}
printf("\n");
signal(SIGCHLD, SIG_DFL);
printf("testcase7: exec (without fork) \n");
printf(" expect: initial ~= exec \n");
show_rusage("initial");
execl("./child", "child", "-v", NULL);
return 0;
}child.c
------------------------
#include <sys/types.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include "common.h"
int main(int argc, char** argv)
{
int status;
int c;
long consume_size = 0;
long grandchild_consume_size = 0;
int show = 0;
while ((c = getopt(argc, argv, "n:g:v")) != -1) {
switch (c) {
case 'n':
consume_size = atol(optarg);
break;
case 'v':
show = 1;
break;
case 'g':
grandchild_consume_size = atol(optarg);
break;
default:
break;
}
}
if (show)
show_rusage("exec");
if (consume_size) {
printf("child alloc %ldMB\n", consume_size);
consume(consume_size);
}
if (grandchild_consume_size) {
if (fork()) {
wait(&status);
} else {
printf("grandchild alloc %ldMB\n", grandchild_consume_size);
consume(grandchild_consume_size);
exit(0);
}
}
return 0;
}common.c
--------------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <signal.h>
#include <sys/mman.h>
#include "common.h"
#define err(str) perror(str), exit(1)
void show_rusage(char *prefix)
{
int err, err2;
struct rusage rusage_self;
struct rusage rusage_children;
printf("%s: ", prefix);
err = getrusage(RUSAGE_SELF, &rusage_self);
if (!err)
printf("self %ld ", rusage_self.ru_maxrss);
err2 = getrusage(RUSAGE_CHILDREN, &rusage_children);
if (!err2)
printf("children %ld ", rusage_children.ru_maxrss);
printf("\n");
}/* Some buggy OS need this worthless CPU waste. */ void make_pagefault(void)
{
void *addr;
int size = getpagesize();
int i;
for (i=0; i<1000; i++) {
addr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
if (addr == MAP_FAILED)
err("make_pagefault");
memset(addr, 0, size);
munmap(addr, size);
}
}void consume(int mega)
{
size_t sz = mega * 1024 * 1024;
void *ptr;
ptr = malloc(sz);
memset(ptr, 0, sz);
make_pagefault();
}pid_t __fork(void)
{
pid_t pid;
pid = fork();
make_pagefault();
return pid;
}common.h
----------------------
void show_rusage(char *prefix);
void make_pagefault(void);
void consume(int mega);pid_t __fork(void);
FreeBSD result (expected result)
========================================================
allocate 100MB
testcase1: fork inherit?
expect: initial.self ~= child.self
initial: self 103492 children 0
fork child: self 103540 children 0
testcase2: fork inherit? (cont.)
expect: initial.children ~= 100MB, but child.children = 0
initial: self 103540 children 103540
child: self 103564 children 0
testcase3: fork + malloc
expect: child.self ~= initial.self + 50MB
initial: self 103564 children 103564
allocate +50MB
fork child: self 154860 children 0
testcase4: grandchild maxrss
expect: post_wait.children ~= 300MB
initial: self 103564 children 154860
grandchild alloc 300MBpost_wait: self 103564 children 308720
testcase5: zombie
expect: pre_wait ~= initial, IOW the zombie process is not accounted.
post_wait ~= 400MB, IOW wait() collect child's max_rss.
initial: self 103564 children 308720
child alloc 400MBpre_wait: self 103564 children 308720post_wait: self 103564 children 411312
testcase6: SIG_IGN
expect: initial ~= after_zombie (child's 500MB alloc should be ignored).
initial: self 103564 children 411312
child alloc 500MBafter_zombie: self 103624 children 411312
testcase7: exec (without fork)
expect: initial ~= exec
initial: self 103624 children 411312
exec: self 103624 children 411312
Linux result (actual test result)
========================================================
allocate 100MB
testcase1: fork inherit?
expect: initial.self ~= child.self
initial: self 102848 children 0
fork child: self 102572 children 0
testcase2: fork inherit? (cont.)
expect: initial.children ~= 100MB, but child.children = 0
initial: self 102876 children 102644
child: self 102572 children 0
testcase3: fork + malloc
expect: child.self ~= initial.self + 50MB
initial: self 102876 children 102644
allocate +50MB
fork child: self 153804 children 0
testcase4: grandchild maxrss
expect: post_wait.children ~= 300MB
initial: self 102876 children 153864
grandchild alloc 300MBpost_wait: self 102876 children 307536
testcase5: zombie
expect: pre_wait ~= initial, IOW the zombie process is not accounted.
post_wait ~= 400MB, IOW wait() collect child's max_rss.
initial: self 102876 children 307536
child alloc 400MBpre_wait: self 102876 children 307536post_wait: self 102876 children 410076
testcase6: SIG_IGN
expect: initial ~= after_zombie (child's 500MB alloc should be ignored).
initial: self 102876 children 410076
child alloc 500MBafter_zombie: self 102880 children 410076
testcase7: exec (without fork)
expect: initial ~= exec
initial: self 102880 children 410076
exec: self 102880 children 410076
--- fs/exec.c | 3 +++ include/linux/sched.h | 10 ++++++++++ kernel/exit.c | 6 ++++++ kernel/fork.c | 1 + kernel/sys.c | 14 ++++++++++++++ 5 files changed, 34 insertions(+), 0 deletions(-)
fs/exec.c +3 -0
@@ -849,6 +849,9 @@ static int de_thread(struct task_struct *tsk) sig->notify_count =0 ; no_thread_group: +if (current->mm) +setmax_mm_hiwater_rss (&sig->maxrss, current->mm); +exit_itimers (sig);flush_itimer_signals ();
include/linux/sched.h +10 -0
@@ -426,6 +426,15 @@ static inline unsigned long get_mm_hiwater_rss(struct mm_struct *mm)return max (mm->hiwater_rss,get_mm_rss (mm)); } +static inline void setmax_mm_hiwater_rss (unsigned long *maxrss, +struct mm_struct *mm) +{ +unsigned long hiwater_rss =get_mm_hiwater_rss (mm); + +if (*maxrss < hiwater_rss) + *maxrss = hiwater_rss; +} +static inline unsigned long get_mm_hiwater_vm (struct mm_struct *mm) {return max (mm->hiwater_vm, mm->total_vm);
@@ -637,6 +646,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;/*
kernel/exit.c +6 -0
@@ -948,6 +948,8 @@ NORET_TYPE void do_exit(long code)if (group_dead) {hrtimer_cancel (&tsk->signal->real_timer);exit_itimers (tsk->signal); +if (tsk->mm) +setmax_mm_hiwater_rss (&tsk->signal->maxrss, tsk->mm); }acct_collect (code, group_dead);if (group_dead)
@@ -1203,6 +1205,7 @@ static int wait_task_zombie(struct wait_opts *wo, struct task_struct *p)if (likely (!traced) &&likely (!task_detached (p))) {struct signal_struct *psig;struct signal_struct *sig; +unsigned long maxrss;/* * The resource counters for the group leader are in its
@@ -1251,6 +1254,9 @@ static int wait_task_zombie(struct wait_opts *wo, struct task_struct *p) 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->real_parent->sighand->siglock);
kernel/fork.c +1 -0
@@ -889,6 +889,7 @@ static int copy_signal(unsigned long clone_flags, struct task_struct *tsk) 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); sig->sum_sched_runtime =0 ;taskstats_tgid_init (sig);
kernel/sys.c +14 -0
@@ -1338,6 +1338,7 @@ static void k_getrusage(struct task_struct *p, int who, struct rusage *r)unsigned long flags;cputime_t utime, stime;struct task_cputime cputime; +unsigned long maxrss =0 ;memset ((char *) r,0 ,sizeof *r); utime = stime = cputime_zero;
@@ -1346,6 +1347,7 @@ static void k_getrusage(struct task_struct *p, int who, struct rusage *r) utime =task_utime (current); stime =task_stime (current);accumulate_thread_rusage (p, r); + maxrss = p->signal->maxrss; goto out; }
@@ -1363,6 +1365,7 @@ static void k_getrusage(struct task_struct *p, int who, struct rusage *r) r->ru_majflt = p->signal->cmaj_flt; r->ru_inblock = p->signal->cinblock; r->ru_oublock = p->signal->coublock; + maxrss = p->signal->cmaxrss;if (who ==RUSAGE_CHILDREN )break ;
@@ -1377,6 +1380,8 @@ static void k_getrusage(struct task_struct *p, int who, struct rusage *r) r->ru_majflt += p->signal->maj_flt; r->ru_inblock += p->signal->inblock; r->ru_oublock += p->signal->oublock; +if (maxrss < p->signal->maxrss) + maxrss = p->signal->maxrss; t = p; do { accumulate_thread_rusage(t, r);
@@ -1392,6 +1397,15 @@ static void k_getrusage(struct task_struct *p, int who, struct rusage *r) 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) { +setmax_mm_hiwater_rss (&maxrss, mm); +mmput (mm); + } + } + r->ru_maxrss = maxrss * (PAGE_SIZE /1024 );/* convert pages to KBs */ }int getrusage (struct task_struct *p,int who,struct rusage __user *ru)
Signature · 11 lines
1.6.0.6 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Andrew Morton
maintainerQuoted 10 lines · On Mon, 7 Sep 2009 11:58:36 +0900 (JST) KOSAKI Motohiro…
Quoted 2 lines
Grr, my fault.
I recognize it. sorry.I've finished my long pending homework ;)
Andrew, can you please replace following patch with getrusage-fill-ru_maxrss-value.patch and getrusage-fill-ru_maxrss-value-update.patch?
Quoted 4 lines
ChangeLog
===============================
o Merge getrusage-fill-ru_maxrss-value.patch and getrusage-fill-ru_maxrss-value-update.patch
o rewrote test programs (older version hit FreeBSD bug and it obfuscate testcase intention, thanks Hugh)
The code changes are unaltered, so I merely updated the changelog.
The changelog had lots of ^------- lines in it. But those are conventionally the end-of-changelog separator so I rewrote them to ^=======
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 13 lines
Quoted 10 lines · On Mon, 7 Sep 2009 11:58:36 +0900 (JST) KOSAKI Motohiro…
Quoted 2 lines
Grr, my fault.
I recognize it. sorry.I've finished my long pending homework ;)
Andrew, can you please replace following patch with getrusage-fill-ru_maxrss-value.patch and getrusage-fill-ru_maxrss-value-update.patch?
Quoted 6 lines
Quoted 4 lines
ChangeLog
===============================
o Merge getrusage-fill-ru_maxrss-value.patch and getrusage-fill-ru_maxrss-value-update.patch
o rewrote test programs (older version hit FreeBSD bug and it obfuscate testcase intention, thanks Hugh)The code changes are unaltered, so I merely updated the changelog.
I see. thanks.
Quoted 3 lines
The changelog had lots of ^------- lines in it. But those are conventionally the end-of-changelog separator so I rewrote them to ^=======
sorry, I have stupid question.
I thought "--" and "---" have special meaning. but other length "-" are safe. Is this incorrect?
or You mean it's easy confusing bad style?
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Andrew Morton
maintainerQuoted 10 lines · On Thu, 10 Sep 2009 08:17:27 +0900 (JST) KOSAKI Motohiro…
Quoted 4 lines
The changelog had lots of ^------- lines in it. But those are conventionally the end-of-changelog separator so I rewrote them to ^=======
sorry, I have stupid question.
I thought "--" and "---" have special meaning. but other length "-" are safe. Is this incorrect?or You mean it's easy confusing bad style?
Ideally, ^---$ is the only pattern we need to worry about.
In the real world, ^-------- might trigger people's sloppy scripts so it's best to be safe and avoid it altogether.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 12 lines
Quoted 9 lines · On Thu, 10 Sep 2009 08:17:27 +0900 (JST) KOSAKI Motohiro…
Quoted 4 lines
The changelog had lots of ^------- lines in it. But those are conventionally the end-of-changelog separator so I rewrote them to ^=======
sorry, I have stupid question.
I thought "--" and "---" have special meaning. but other length "-" are safe. Is this incorrect?
Quoted 6 lines
Quoted 1 line
or You mean it's easy confusing bad style?
Ideally, ^---$ is the only pattern we need to worry about.
In the real world, ^-------- might trigger people's sloppy scripts so it's best to be safe and avoid it altogether.
Ah I see.
Thank you!
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>