[RHEL7,COMMIT] memcg: optimize the "Search everything else" loop in mm_update_next_owner()

Submitted by Konstantin Khorenko on June 14, 2019, 4:29 p.m.

Details

Message ID 201906141629.x5EGTHwd009821@finist-ce7.sw.ru
State New
Series "Series without cover letter"
Headers show

Commit Message

Konstantin Khorenko June 14, 2019, 4:29 p.m.
The commit is pushed to "branch-rh7-3.10.0-957.12.2.vz7.96.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-957.12.2.vz7.96.15
------>
commit 79185c03e4397c1e58aeb026f3bc97a4c5ee6b8d
Author: Oleg Nesterov <oleg@redhat.com>
Date:   Fri Jun 14 19:29:16 2019 +0300

    memcg: optimize the "Search everything else" loop in mm_update_next_owner()
    
    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@redhat.com>
    Reviewed-by: Michal Hocko <mhocko@suse.cz>
    Cc: Balbir Singh <bsingharora@gmail.com>
    Cc: Johannes Weiner <hannes@cmpxchg.org>
    Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
    Cc: Michal Hocko <mhocko@suse.cz>
    Cc: Peter Chiang <pchiang@nvidia.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
    
    https://pmc.acronis.com/browse/VSTOR-23975
    (cherry picked from commit 39af1765f1255b2bbadc3064e16270781abf24a1)
    Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
---
 kernel/exit.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/kernel/exit.c b/kernel/exit.c
index 659f0286096c..af6d9c54119b 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -493,9 +493,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;
+		}
 	}
 
 	qread_unlock(&tasklist_lock);