Commit 49b5cf34727a6c1be1568ab28e89a2d9a6bf51e0
Committed by
Linus Torvalds
1 parent
7394f0f6c0
Exists in
master
and in
7 other branches
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: Jonathan Lim <jlim@sgi.com> Cc: Ingo Molnar <mingo@elte.hu> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 3 changed files with 17 additions and 8 deletions Side-by-side Diff
include/linux/sched.h
... | ... | @@ -1257,7 +1257,7 @@ |
1257 | 1257 | #if defined(CONFIG_TASK_XACCT) |
1258 | 1258 | u64 acct_rss_mem1; /* accumulated rss usage */ |
1259 | 1259 | u64 acct_vm_mem1; /* accumulated virtual memory usage */ |
1260 | - cputime_t acct_stimexpd;/* stime since last update */ | |
1260 | + cputime_t acct_timexpd; /* stime + utime since last update */ | |
1261 | 1261 | #endif |
1262 | 1262 | #ifdef CONFIG_CPUSETS |
1263 | 1263 | nodemask_t mems_allowed; |
kernel/sched.c
kernel/tsacct.c
... | ... | @@ -84,9 +84,9 @@ |
84 | 84 | { |
85 | 85 | struct mm_struct *mm; |
86 | 86 | |
87 | - /* convert pages-jiffies to Mbyte-usec */ | |
88 | - stats->coremem = jiffies_to_usecs(p->acct_rss_mem1) * PAGE_SIZE / MB; | |
89 | - stats->virtmem = jiffies_to_usecs(p->acct_vm_mem1) * PAGE_SIZE / MB; | |
87 | + /* convert pages-usec to Mbyte-usec */ | |
88 | + stats->coremem = p->acct_rss_mem1 * PAGE_SIZE / MB; | |
89 | + stats->virtmem = p->acct_vm_mem1 * PAGE_SIZE / MB; | |
90 | 90 | mm = get_task_mm(p); |
91 | 91 | if (mm) { |
92 | 92 | /* adjust to KB unit */ |
93 | 93 | |
94 | 94 | |
... | ... | @@ -118,12 +118,19 @@ |
118 | 118 | void acct_update_integrals(struct task_struct *tsk) |
119 | 119 | { |
120 | 120 | if (likely(tsk->mm)) { |
121 | - long delta = cputime_to_jiffies( | |
122 | - cputime_sub(tsk->stime, tsk->acct_stimexpd)); | |
121 | + cputime_t time, dtime; | |
122 | + struct timeval value; | |
123 | + u64 delta; | |
123 | 124 | |
125 | + time = tsk->stime + tsk->utime; | |
126 | + dtime = cputime_sub(time, tsk->acct_timexpd); | |
127 | + jiffies_to_timeval(cputime_to_jiffies(dtime), &value); | |
128 | + delta = value.tv_sec; | |
129 | + delta = delta * USEC_PER_SEC + value.tv_usec; | |
130 | + | |
124 | 131 | if (delta == 0) |
125 | 132 | return; |
126 | - tsk->acct_stimexpd = tsk->stime; | |
133 | + tsk->acct_timexpd = time; | |
127 | 134 | tsk->acct_rss_mem1 += delta * get_mm_rss(tsk->mm); |
128 | 135 | tsk->acct_vm_mem1 += delta * tsk->mm->total_vm; |
129 | 136 | } |
... | ... | @@ -135,7 +142,7 @@ |
135 | 142 | */ |
136 | 143 | void acct_clear_integrals(struct task_struct *tsk) |
137 | 144 | { |
138 | - tsk->acct_stimexpd = 0; | |
145 | + tsk->acct_timexpd = 0; | |
139 | 146 | tsk->acct_rss_mem1 = 0; |
140 | 147 | tsk->acct_vm_mem1 = 0; |
141 | 148 | } |