Skip to content

Commit

Permalink
memcg: optimize the "Search everything else" loop in mm_update_next_o…
Browse files Browse the repository at this point in the history
…wner()

for_each_process_thread() is sub-optimal. All threads share the same
->mm, we can swicth to the next process once we found a thread with
->mm != NULL and ->mm != mm.

Signed-off-by: Oleg Nesterov <[email protected]>
Reviewed-by: Michal Hocko <[email protected]>
Cc: Balbir Singh <[email protected]>
Cc: Johannes Weiner <[email protected]>
Cc: KAMEZAWA Hiroyuki <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Peter Chiang <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
oleg-nesterov authored and torvalds committed Jun 4, 2014
1 parent f87fb59 commit 39af176
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions kernel/exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,15 @@ void mm_update_next_owner(struct mm_struct *mm)
/*
* Search through everything else, we should not get here often.
*/
for_each_process_thread(g, c) {
if (!(c->flags & PF_KTHREAD) && c->mm == mm)
goto assign_new_owner;
for_each_process(g) {
if (g->flags & PF_KTHREAD)
continue;
for_each_thread(g, c) {
if (c->mm == mm)
goto assign_new_owner;
if (c->mm)
break;
}
}
read_unlock(&tasklist_lock);
/*
Expand Down

0 comments on commit 39af176

Please sign in to comment.