Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752291AbdHNSdY (ORCPT ); Mon, 14 Aug 2017 14:33:24 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:60159 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751548AbdHNScz (ORCPT ); Mon, 14 Aug 2017 14:32:55 -0400 From: Roman Gushchin To: CC: Roman Gushchin , Michal Hocko , Vladimir Davydov , Johannes Weiner , Tetsuo Handa , David Rientjes , Tejun Heo , , , , Subject: [v5 1/4] mm, oom: refactor the oom_kill_process() function Date: Mon, 14 Aug 2017 19:32:09 +0100 Message-ID: <20170814183213.12319-1-guro@fb.com> X-Mailer: git-send-email 2.13.5 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [2620:10d:c092:200::1:ff3d] X-ClientProxiedBy: VI1P194CA0014.EURP194.PROD.OUTLOOK.COM (2603:10a6:800:be::24) To BL2PR15MB1076.namprd15.prod.outlook.com (2603:10b6:201:17::10) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: cf96c34a-7140-43dd-77cf-08d4e342d712 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(300000503095)(300135400095)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095);SRVR:BL2PR15MB1076; X-Microsoft-Exchange-Diagnostics: 1;BL2PR15MB1076;3:kvb3tBC4o2hTgbfqS65vdFzwA0STs6yfo6Pj/uhY+fY7PxY5ixLcg5b2H+EmFj34idigWbM33tk037mjVVeh86RVEEEGVUhkafDN1wGQ4/LCSWB6ggXx+zSp9U7VUZllmcCl3m1oH1WZuwmEE8fotl/fsxy/nW6gIhnBQA5TFpOut5sSxmQE9tSIrzGv30w8Rey9ulgByvtRcDaxkqosbg/dK/phuDD01Nifywt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Mx1Rta8KjrU/Li2QgR9Jij2UwGuI4vjdf4kB8ulZ1+aVRPY9tvyDnkYDMyWch+G7VurCh/PsSi9vpSrgMSuRgHzFdGGyq7to8A2XfvZPgYtDh6QXWB8GUKu;4:atk5Whp2d66vrmoe4YKcFhGg4mvVUcou1t83Tgo9PLbtdjc1mePpxJgJZfmPX6Yez1gRXeHVNAIpDVLbZOXeXea2+MUI8tw2EMm6+ccYN++PK9x1LES6xBvDIO/2WVCud+yGniOAyt2BoIapBWFkAT30tvtr92lugha1teangVTILZ4sLyyuRXpqk8OPOD4GL5klIoNxMwMaeXBZmNTyhtTaqqFqvoD9m7NqyAozsdAYapE01W3sl1ojrevBof4lPGJ8w3lZFTK/M6DQ7uaPWSxRZx00KEixtoD+N6TORA6DzziWjFKx8noaD1BolKh65OJMZ0QMOBAJ52rDZebG8TeW7Q0hSYH+dT5T3xzX1N9u9nHr1xLiH/neBtLolYKFL8PcLzOoZS04lO3VgGb1AA== X-Exchange-Antispam-Report-Test: UriScan:(9452136761055)(67672495146484)(211936372134217)(153496737603132); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(5005006)(8121501046)(93006095)(93001095)(100000703101)(100105400095)(10201501046)(3002001)(920507026)(6041248)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123564025)(20161123560025)(20161123558100)(20161123555025)(20161123562025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:BL2PR15MB1076;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:BL2PR15MB1076; X-Forefront-PRVS: 039975700A X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(7370300001)(4630300001)(6009001)(189002)(199003)(54906002)(6506006)(2906002)(50986999)(4326008)(42186005)(8676002)(2361001)(50226002)(33646002)(50466002)(7416002)(53416004)(105586002)(106356001)(6116002)(1076002)(5660300001)(48376002)(2351001)(81166006)(81156014)(6486002)(101416001)(68736007)(34040400001)(478600001)(6666003)(110136004)(7736002)(69596002)(53936002)(97736004)(36756003)(6916009)(5003940100001)(189998001)(86362001)(47776003)(6512007)(305945005)(7350300001)(25786009)(42262002);DIR:OUT;SFP:1102;SCL:1;SRVR:BL2PR15MB1076;H:castle.thefacebook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BL2PR15MB1076;23:VDcTBZNcuEwf2vH97148pTLGqXhuCdCd6z+7LkLok?= =?us-ascii?Q?U6X1KSbL5iHjc2gP9yNIDmLanqEKWdn/2VGGotLKnsQf52/QMd1mPeGrxtqX?= =?us-ascii?Q?1Rld+4Y/2j7ikLU3NSgERyXd7uaKYUbtJQffOxZQ6TuqnRWq/mmW8MnV1flF?= =?us-ascii?Q?e2hIdt8ndHpTahYdp3xvQcOZdPziaVP0t23t/5S7kyzVFyDWLlJH2AOiuEbD?= =?us-ascii?Q?EijzWqZUbqqXGIs4+r2cl9nGV5YjhzMpQ/hvV8Lw/oq0JpoB3V4Rh+f9jWvd?= =?us-ascii?Q?dVkHcXQinicRNPehCOUJV2exYDDxxY8CVW/ZFoth0jI8d0Rput2L/4QQac13?= =?us-ascii?Q?wAzQmLMiz0EYmi7sSq02i+oRNIPH+sjJNTPDuPwFy+UU4N749qytKPK8bHlA?= =?us-ascii?Q?IeFbExh5+sLlK4Xf9RZxM7OEnsGt0W9dTE6rhd5QB85ExEwuhc8p3meznlHB?= =?us-ascii?Q?cJTyWF43KoKQek0LxOOcwuNas9IaEohe1NYSygF9ZPf1+tl45P2xI9my/FKu?= =?us-ascii?Q?l4cSz7Q+NH2Ip/8Q+i2iNthxMTFSwJGt1Hn5eAafVpatIrpjL6wnan9cit9q?= =?us-ascii?Q?G70NOz9bKCvMvByxz76uGMEgSWO7cILcuTJX0tLwKN6dCUnkhHLLjYrsrJUd?= =?us-ascii?Q?QfBnRPxqhgNojOSbhJpUn6lEakF5VqP3IHWvQ87VciSGmnXl8KL43sdsaENE?= =?us-ascii?Q?TadylRuaEDsCrcRvUbPmXeH07r8aOtCHvOj/fgkqpdWqOEu1G3RzRCCcA6YW?= =?us-ascii?Q?xoh7exK2QCN3lw2hVVM9dDkPt3kls7Yrbg+hY54zW3aOpJbXOej3rdDZGWZL?= =?us-ascii?Q?iPdFmJkKyFwTPsca8Vb8WfWMLP4DdbcPahJf9KA2o61K+73Uav3DrgeVm2ko?= =?us-ascii?Q?qbH+HK5hUpijLpBYWnWP8OhRHtyvdOKa/x+WkKRjBlQcT6intoVV+WUjjz7F?= =?us-ascii?Q?hLHHYc2ICzOQY7pLdnhzIGhe0iCSwZpDESLiiqm4rh5sH+cK9HiGIqfvr8Pi?= =?us-ascii?Q?mezjaakU045sObbjzBXW9urW+5ELPWrGdeh5tqg6+nnfcZ36xHY0Gy+YKd9i?= =?us-ascii?Q?0P/jedIID30tKmbZrsa9OGv6yktCGUcUfEyXXazum3AJKNOlWqovI0q9NSiL?= =?us-ascii?Q?Z163jo0haNTrPGkyz+hyJz9ouMrCGeURq1/Kv9iXvmSSWV2OrXh5dRGrIOoc?= =?us-ascii?Q?4gfFE0dvvAN544=3D?= X-Microsoft-Exchange-Diagnostics: 1;BL2PR15MB1076;6:MklOuxcljnsqxFskE/Vs4/SQAY0LlnNHzQRUZiGqmPJvw2/KiPbw0p3bTzZC1f0HO+XuUKgEKbFGJd8MqX9LVNs98i60to044qTT2kvjobty9YLH367dZ6+up92outvijfZauqjk/2E2fECUvr0Jgr9sUJhUrRlOlKulOCEQW+ug2UVTmieD56NcDJ42mBrdJagT4gnH/a03Qokb/ZyQq9Ux8clFC/93WCtK7vSWxf/GQA8RCBSU7k0HUp7NVkeQWH6UkBrkFGUT3h78Bq2HkVe3Ysom3+7f0KAkY9sJyBTIRtRIhAxcQhfOuplCXkLAULwReyJ/Epuh0hnMSftoHw==;5:DladnEEaXhiWr3TKQhx7ExwlTF+2Q+n3oW73EDI0h1JqvqBz07SPmksq1IxzFJ3xp1T9HnC6gshut9ZOjQ4kZpTxv3nGjdUtMkFd3XKCnwyWGGzYEkOirY58h/Z9vrrx/ZdJ4m+Ebp1p2vdbmOv1SwAjJ9cSFn1UOFn2Tq7MPfc=;24:x2qt2+p1Zgw49OwH7ld9NlCHEnCq3bgbAMyCApCNED86ycoNvbXxDRBGpenfG4LcPZ6Ix/GW7jZsLYVR168FMG4R8t8ZJy5GyZjMRIKeDzs=;7:ByNGy6i2s47eEG/6rl80kJTMRRcZNY2/R+alooF+s72v/gpdXoJ2AycyR4kZk/M/BM7GF9Z7Ly9x4GdVz0U7B9X3VErGXybTM2wjQGvw11VXP9JMPCoNiOMsFeaW7mQYZQ9tBbQbmw8AUhZYxXv2UtgLmzVMAs/h7vxzL3/80N4BUkwCclOZbo+B992PjMpo7hKLrki2pL4eRNyM0D7jXo02E+JPJzCOyVsWgYH6qyw= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;BL2PR15MB1076;20:PACAftIu0gJdkrcFXVMH5EMEn5Ndw7R7Zo4lCQtLTMsstHTjGegBPyQXLnq5Hne2Rbh8wMCtNVRVhaXh5hjcjXbkcCYzNs3VOGNbM6zokYdCfmIOhUidu1YdkuSkcK5TXw6akDRW+/SHwuX16fadfL03tJr5PJAZvNB3ApwRKC0= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Aug 2017 18:32:36.2677 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL2PR15MB1076 X-OriginatorOrg: fb.com X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-08-14_16:,, signatures=0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5421 Lines: 181 The oom_kill_process() function consists of two logical parts: the first one is responsible for considering task's children as a potential victim and printing the debug information. The second half is responsible for sending SIGKILL to all tasks sharing the mm struct with the given victim. This commit splits the oom_kill_process() function with an intention to re-use the the second half: __oom_kill_process(). The cgroup-aware OOM killer will kill multiple tasks belonging to the victim cgroup. We don't need to print the debug information for the each task, as well as play with task selection (considering task's children), so we can't use the existing oom_kill_process(). Signed-off-by: Roman Gushchin Cc: Michal Hocko Cc: Vladimir Davydov Cc: Johannes Weiner Cc: Tetsuo Handa Cc: David Rientjes Cc: Tejun Heo Cc: kernel-team@fb.com Cc: cgroups@vger.kernel.org Cc: linux-doc@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org --- mm/oom_kill.c | 123 +++++++++++++++++++++++++++++++--------------------------- 1 file changed, 65 insertions(+), 58 deletions(-) diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 53b44425ef35..5c29a3dd591b 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -817,67 +817,12 @@ static bool task_will_free_mem(struct task_struct *task) return ret; } -static void oom_kill_process(struct oom_control *oc, const char *message) +static void __oom_kill_process(struct task_struct *victim) { - struct task_struct *p = oc->chosen; - unsigned int points = oc->chosen_points; - struct task_struct *victim = p; - struct task_struct *child; - struct task_struct *t; + struct task_struct *p; struct mm_struct *mm; - unsigned int victim_points = 0; - static DEFINE_RATELIMIT_STATE(oom_rs, DEFAULT_RATELIMIT_INTERVAL, - DEFAULT_RATELIMIT_BURST); bool can_oom_reap = true; - /* - * If the task is already exiting, don't alarm the sysadmin or kill - * its children or threads, just set TIF_MEMDIE so it can die quickly - */ - task_lock(p); - if (task_will_free_mem(p)) { - mark_oom_victim(p); - wake_oom_reaper(p); - task_unlock(p); - put_task_struct(p); - return; - } - task_unlock(p); - - if (__ratelimit(&oom_rs)) - dump_header(oc, p); - - pr_err("%s: Kill process %d (%s) score %u or sacrifice child\n", - message, task_pid_nr(p), p->comm, points); - - /* - * If any of p's children has a different mm and is eligible for kill, - * the one with the highest oom_badness() score is sacrificed for its - * parent. This attempts to lose the minimal amount of work done while - * still freeing memory. - */ - read_lock(&tasklist_lock); - for_each_thread(p, t) { - list_for_each_entry(child, &t->children, sibling) { - unsigned int child_points; - - if (process_shares_mm(child, p->mm)) - continue; - /* - * oom_badness() returns 0 if the thread is unkillable - */ - child_points = oom_badness(child, - oc->memcg, oc->nodemask, oc->totalpages); - if (child_points > victim_points) { - put_task_struct(victim); - victim = child; - victim_points = child_points; - get_task_struct(victim); - } - } - } - read_unlock(&tasklist_lock); - p = find_lock_task_mm(victim); if (!p) { put_task_struct(victim); @@ -947,10 +892,72 @@ static void oom_kill_process(struct oom_control *oc, const char *message) wake_oom_reaper(victim); mmdrop(mm); - put_task_struct(victim); } #undef K +static void oom_kill_process(struct oom_control *oc, const char *message) +{ + struct task_struct *p = oc->chosen; + unsigned int points = oc->chosen_points; + struct task_struct *victim = p; + struct task_struct *child; + struct task_struct *t; + unsigned int victim_points = 0; + static DEFINE_RATELIMIT_STATE(oom_rs, DEFAULT_RATELIMIT_INTERVAL, + DEFAULT_RATELIMIT_BURST); + + /* + * If the task is already exiting, don't alarm the sysadmin or kill + * its children or threads, just set TIF_MEMDIE so it can die quickly + */ + task_lock(p); + if (task_will_free_mem(p)) { + mark_oom_victim(p); + wake_oom_reaper(p); + task_unlock(p); + put_task_struct(p); + return; + } + task_unlock(p); + + if (__ratelimit(&oom_rs)) + dump_header(oc, p); + + pr_err("%s: Kill process %d (%s) score %u or sacrifice child\n", + message, task_pid_nr(p), p->comm, points); + + /* + * If any of p's children has a different mm and is eligible for kill, + * the one with the highest oom_badness() score is sacrificed for its + * parent. This attempts to lose the minimal amount of work done while + * still freeing memory. + */ + read_lock(&tasklist_lock); + for_each_thread(p, t) { + list_for_each_entry(child, &t->children, sibling) { + unsigned int child_points; + + if (process_shares_mm(child, p->mm)) + continue; + /* + * oom_badness() returns 0 if the thread is unkillable + */ + child_points = oom_badness(child, + oc->memcg, oc->nodemask, oc->totalpages); + if (child_points > victim_points) { + put_task_struct(victim); + victim = child; + victim_points = child_points; + get_task_struct(victim); + } + } + } + read_unlock(&tasklist_lock); + + __oom_kill_process(victim); + put_task_struct(victim); +} + /* * Determines whether the kernel must panic because of the panic_on_oom sysctl. */ -- 2.13.5