Commit 49b5cf34 authored by Jonathan Lim's avatar Jonathan Lim Committed by Linus Torvalds

accounting: account for user time when updating memory integrals

Adapt acct_update_integrals() to include user time when calculating the time
difference.  The units of acct_rss_mem1 and acct_vm_mem1 are also changed from
pages-jiffies to pages-usecs to avoid calling jiffies_to_usecs() in
xacct_add_tsk() which might overflow.
Signed-off-by: default avatarJonathan Lim <jlim@sgi.com>
Cc: Ingo Molnar <mingo@elte.hu>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 7394f0f6
...@@ -1257,7 +1257,7 @@ struct task_struct { ...@@ -1257,7 +1257,7 @@ struct task_struct {
#if defined(CONFIG_TASK_XACCT) #if defined(CONFIG_TASK_XACCT)
u64 acct_rss_mem1; /* accumulated rss usage */ u64 acct_rss_mem1; /* accumulated rss usage */
u64 acct_vm_mem1; /* accumulated virtual memory usage */ u64 acct_vm_mem1; /* accumulated virtual memory usage */
cputime_t acct_stimexpd;/* stime since last update */ cputime_t acct_timexpd; /* stime + utime since last update */
#endif #endif
#ifdef CONFIG_CPUSETS #ifdef CONFIG_CPUSETS
nodemask_t mems_allowed; nodemask_t mems_allowed;
......
...@@ -4046,6 +4046,8 @@ void account_user_time(struct task_struct *p, cputime_t cputime) ...@@ -4046,6 +4046,8 @@ void account_user_time(struct task_struct *p, cputime_t cputime)
cpustat->nice = cputime64_add(cpustat->nice, tmp); cpustat->nice = cputime64_add(cpustat->nice, tmp);
else else
cpustat->user = cputime64_add(cpustat->user, tmp); cpustat->user = cputime64_add(cpustat->user, tmp);
/* Account for user time used */
acct_update_integrals(p);
} }
/* /*
......
...@@ -84,9 +84,9 @@ void xacct_add_tsk(struct taskstats *stats, struct task_struct *p) ...@@ -84,9 +84,9 @@ void xacct_add_tsk(struct taskstats *stats, struct task_struct *p)
{ {
struct mm_struct *mm; struct mm_struct *mm;
/* convert pages-jiffies to Mbyte-usec */ /* convert pages-usec to Mbyte-usec */
stats->coremem = jiffies_to_usecs(p->acct_rss_mem1) * PAGE_SIZE / MB; stats->coremem = p->acct_rss_mem1 * PAGE_SIZE / MB;
stats->virtmem = jiffies_to_usecs(p->acct_vm_mem1) * PAGE_SIZE / MB; stats->virtmem = p->acct_vm_mem1 * PAGE_SIZE / MB;
mm = get_task_mm(p); mm = get_task_mm(p);
if (mm) { if (mm) {
/* adjust to KB unit */ /* adjust to KB unit */
...@@ -118,12 +118,19 @@ void xacct_add_tsk(struct taskstats *stats, struct task_struct *p) ...@@ -118,12 +118,19 @@ void xacct_add_tsk(struct taskstats *stats, struct task_struct *p)
void acct_update_integrals(struct task_struct *tsk) void acct_update_integrals(struct task_struct *tsk)
{ {
if (likely(tsk->mm)) { if (likely(tsk->mm)) {
long delta = cputime_to_jiffies( cputime_t time, dtime;
cputime_sub(tsk->stime, tsk->acct_stimexpd)); struct timeval value;
u64 delta;
time = tsk->stime + tsk->utime;
dtime = cputime_sub(time, tsk->acct_timexpd);
jiffies_to_timeval(cputime_to_jiffies(dtime), &value);
delta = value.tv_sec;
delta = delta * USEC_PER_SEC + value.tv_usec;
if (delta == 0) if (delta == 0)
return; return;
tsk->acct_stimexpd = tsk->stime; tsk->acct_timexpd = time;
tsk->acct_rss_mem1 += delta * get_mm_rss(tsk->mm); tsk->acct_rss_mem1 += delta * get_mm_rss(tsk->mm);
tsk->acct_vm_mem1 += delta * tsk->mm->total_vm; tsk->acct_vm_mem1 += delta * tsk->mm->total_vm;
} }
...@@ -135,7 +142,7 @@ void acct_update_integrals(struct task_struct *tsk) ...@@ -135,7 +142,7 @@ void acct_update_integrals(struct task_struct *tsk)
*/ */
void acct_clear_integrals(struct task_struct *tsk) void acct_clear_integrals(struct task_struct *tsk)
{ {
tsk->acct_stimexpd = 0; tsk->acct_timexpd = 0;
tsk->acct_rss_mem1 = 0; tsk->acct_rss_mem1 = 0;
tsk->acct_vm_mem1 = 0; tsk->acct_vm_mem1 = 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment