From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753946AbcEZMlp (ORCPT ); Thu, 26 May 2016 08:41:45 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:33578 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753651AbcEZMk0 (ORCPT ); Thu, 26 May 2016 08:40:26 -0400 From: Michal Hocko To: Cc: Tetsuo Handa , David Rientjes , Oleg Nesterov , Vladimir Davydov , Andrew Morton , LKML , Michal Hocko Subject: [PATCH 1/6] mm, oom: do not loop over all tasks if there are no external tasks sharing mm Date: Thu, 26 May 2016 14:40:10 +0200 Message-Id: <1464266415-15558-2-git-send-email-mhocko@kernel.org> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1464266415-15558-1-git-send-email-mhocko@kernel.org> References: <1464266415-15558-1-git-send-email-mhocko@kernel.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Michal Hocko oom_kill_process makes sure to kill all processes outside of the thread group which are sharing the mm. This requires to iterate over all tasks. This is however not a common case so we can optimize it a bit and only do that path only if we know that there are external users of the mm struct outside of the thread group. Signed-off-by: Michal Hocko --- mm/oom_kill.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 5bb2f7698ad7..0e33e912f7e4 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -820,6 +820,13 @@ void oom_kill_process(struct oom_control *oc, struct task_struct *p, task_unlock(victim); /* + * skip expensive iterations over all tasks if we know that there + * are no users outside of threads in the same thread group + */ + if (atomic_read(&mm->mm_users) <= get_nr_threads(victim)) + goto oom_reap; + + /* * Kill all user processes sharing victim->mm in other thread groups, if * any. They don't get access to memory reserves, though, to avoid * depletion of all memory. This prevents mm->mmap_sem livelock when an @@ -848,6 +855,7 @@ void oom_kill_process(struct oom_control *oc, struct task_struct *p, } rcu_read_unlock(); +oom_reap: if (can_oom_reap) wake_oom_reaper(victim); -- 2.8.1