[PATCH 2/2] memcg: optimize the "Search everything else" loop in mm_update_next_owner()

From: Oleg Nesterov
Date: Fri Apr 18 2014 - 13:27:51 EST


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 <oleg@xxxxxxxxxx>
---
kernel/exit.c | 12 +++++++++---
1 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/kernel/exit.c b/kernel/exit.c
index e270d2a..429659c 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -358,9 +358,15 @@ retry:
/*
* 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);
/*
--
1.5.5.1


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/