aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/exit.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/exit.c')
-rw-r--r--kernel/exit.c40
1 files changed, 24 insertions, 16 deletions
diff --git a/kernel/exit.c b/kernel/exit.c
index 16395644a98f..059b38cae384 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -112,8 +112,6 @@ static void __exit_signal(struct task_struct *tsk)
112 * We won't ever get here for the group leader, since it 112 * We won't ever get here for the group leader, since it
113 * will have been the last reference on the signal_struct. 113 * will have been the last reference on the signal_struct.
114 */ 114 */
115 sig->utime = cputime_add(sig->utime, task_utime(tsk));
116 sig->stime = cputime_add(sig->stime, task_stime(tsk));
117 sig->gtime = cputime_add(sig->gtime, task_gtime(tsk)); 115 sig->gtime = cputime_add(sig->gtime, task_gtime(tsk));
118 sig->min_flt += tsk->min_flt; 116 sig->min_flt += tsk->min_flt;
119 sig->maj_flt += tsk->maj_flt; 117 sig->maj_flt += tsk->maj_flt;
@@ -122,7 +120,6 @@ static void __exit_signal(struct task_struct *tsk)
122 sig->inblock += task_io_get_inblock(tsk); 120 sig->inblock += task_io_get_inblock(tsk);
123 sig->oublock += task_io_get_oublock(tsk); 121 sig->oublock += task_io_get_oublock(tsk);
124 task_io_accounting_add(&sig->ioac, &tsk->ioac); 122 task_io_accounting_add(&sig->ioac, &tsk->ioac);
125 sig->sum_sched_runtime += tsk->se.sum_exec_runtime;
126 sig = NULL; /* Marker for below. */ 123 sig = NULL; /* Marker for below. */
127 } 124 }
128 125
@@ -583,8 +580,6 @@ mm_need_new_owner(struct mm_struct *mm, struct task_struct *p)
583 * If there are other users of the mm and the owner (us) is exiting 580 * If there are other users of the mm and the owner (us) is exiting
584 * we need to find a new owner to take on the responsibility. 581 * we need to find a new owner to take on the responsibility.
585 */ 582 */
586 if (!mm)
587 return 0;
588 if (atomic_read(&mm->mm_users) <= 1) 583 if (atomic_read(&mm->mm_users) <= 1)
589 return 0; 584 return 0;
590 if (mm->owner != p) 585 if (mm->owner != p)
@@ -627,29 +622,38 @@ retry:
627 } while_each_thread(g, c); 622 } while_each_thread(g, c);
628 623
629 read_unlock(&tasklist_lock); 624 read_unlock(&tasklist_lock);
625 /*
626 * We found no owner yet mm_users > 1: this implies that we are
627 * most likely racing with swapoff (try_to_unuse()) or /proc or
628 * ptrace or page migration (get_task_mm()). Mark owner as NULL,
629 * so that subsystems can understand the callback and take action.
630 */
631 down_write(&mm->mmap_sem);
632 cgroup_mm_owner_callbacks(mm->owner, NULL);
633 mm->owner = NULL;
634 up_write(&mm->mmap_sem);
630 return; 635 return;
631 636
632assign_new_owner: 637assign_new_owner:
633 BUG_ON(c == p); 638 BUG_ON(c == p);
634 get_task_struct(c); 639 get_task_struct(c);
640 read_unlock(&tasklist_lock);
641 down_write(&mm->mmap_sem);
635 /* 642 /*
636 * The task_lock protects c->mm from changing. 643 * The task_lock protects c->mm from changing.
637 * We always want mm->owner->mm == mm 644 * We always want mm->owner->mm == mm
638 */ 645 */
639 task_lock(c); 646 task_lock(c);
640 /*
641 * Delay read_unlock() till we have the task_lock()
642 * to ensure that c does not slip away underneath us
643 */
644 read_unlock(&tasklist_lock);
645 if (c->mm != mm) { 647 if (c->mm != mm) {
646 task_unlock(c); 648 task_unlock(c);
649 up_write(&mm->mmap_sem);
647 put_task_struct(c); 650 put_task_struct(c);
648 goto retry; 651 goto retry;
649 } 652 }
650 cgroup_mm_owner_callbacks(mm->owner, c); 653 cgroup_mm_owner_callbacks(mm->owner, c);
651 mm->owner = c; 654 mm->owner = c;
652 task_unlock(c); 655 task_unlock(c);
656 up_write(&mm->mmap_sem);
653 put_task_struct(c); 657 put_task_struct(c);
654} 658}
655#endif /* CONFIG_MM_OWNER */ 659#endif /* CONFIG_MM_OWNER */
@@ -1294,6 +1298,7 @@ static int wait_task_zombie(struct task_struct *p, int options,
1294 if (likely(!traced)) { 1298 if (likely(!traced)) {
1295 struct signal_struct *psig; 1299 struct signal_struct *psig;
1296 struct signal_struct *sig; 1300 struct signal_struct *sig;
1301 struct task_cputime cputime;
1297 1302
1298 /* 1303 /*
1299 * The resource counters for the group leader are in its 1304 * The resource counters for the group leader are in its
@@ -1309,20 +1314,23 @@ static int wait_task_zombie(struct task_struct *p, int options,
1309 * need to protect the access to p->parent->signal fields, 1314 * need to protect the access to p->parent->signal fields,
1310 * as other threads in the parent group can be right 1315 * as other threads in the parent group can be right
1311 * here reaping other children at the same time. 1316 * here reaping other children at the same time.
1317 *
1318 * We use thread_group_cputime() to get times for the thread
1319 * group, which consolidates times for all threads in the
1320 * group including the group leader.
1312 */ 1321 */
1313 spin_lock_irq(&p->parent->sighand->siglock); 1322 spin_lock_irq(&p->parent->sighand->siglock);
1314 psig = p->parent->signal; 1323 psig = p->parent->signal;
1315 sig = p->signal; 1324 sig = p->signal;
1325 thread_group_cputime(p, &cputime);
1316 psig->cutime = 1326 psig->cutime =
1317 cputime_add(psig->cutime, 1327 cputime_add(psig->cutime,
1318 cputime_add(p->utime, 1328 cputime_add(cputime.utime,
1319 cputime_add(sig->utime, 1329 sig->cutime));
1320 sig->cutime)));
1321 psig->cstime = 1330 psig->cstime =
1322 cputime_add(psig->cstime, 1331 cputime_add(psig->cstime,
1323 cputime_add(p->stime, 1332 cputime_add(cputime.stime,
1324 cputime_add(sig->stime, 1333 sig->cstime));
1325 sig->cstime)));
1326 psig->cgtime = 1334 psig->cgtime =
1327 cputime_add(psig->cgtime, 1335 cputime_add(psig->cgtime,
1328 cputime_add(p->gtime, 1336 cputime_add(p->gtime,