Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753950AbdIDOXE (ORCPT ); Mon, 4 Sep 2017 10:23:04 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:49140 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753835AbdIDOVx (ORCPT ); Mon, 4 Sep 2017 10:21:53 -0400 From: Roman Gushchin To: CC: Roman Gushchin , Michal Hocko , Vladimir Davydov , Johannes Weiner , Tetsuo Handa , David Rientjes , Andrew Morton , Tejun Heo , , , , Subject: [v7 1/5] mm, oom: refactor the oom_kill_process() function Date: Mon, 4 Sep 2017 15:21:04 +0100 Message-ID: <20170904142108.7165-2-guro@fb.com> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170904142108.7165-1-guro@fb.com> References: <20170904142108.7165-1-guro@fb.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [2620:10d:c092:200::1:6ba5] X-ClientProxiedBy: HE1PR05CA0180.eurprd05.prod.outlook.com (2603:10a6:3:f8::28) To DM3PR15MB1084.namprd15.prod.outlook.com (2603:10b6:0:12::10) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1f9c75f2-c141-41da-deca-08d4f3a0415e X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(300000503095)(300135400095)(2017052603199)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095);SRVR:DM3PR15MB1084; X-Microsoft-Exchange-Diagnostics: 1;DM3PR15MB1084;3:IKMamBXO+iXTUEY+HdGd5y1CusL0j7kkD/5zwXavjWNJR0kS8BXIJKk13RdQKsky0AUnZu2TnC3PPZEW3EfN7ZMKd5atigQzmYAPYd6iAxzny6m2QGHnX8Esl0BK7EORd71beD2dEG3NGF3PZHOzfATwsnrz1glGOxW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yJol0otRffgQS3qpjtT9RmCnyvKSYacCD2e6skuY+KDmSgMfm6lRjfDza6x4qZ1ge4N530t0anUL9cLPgt/WOzAIjUngKJAmA9pnmjOvQ4YsrzXhVqAxyVOePry/2qRFAE7+FvHVy5tbuEJGapvMJSjbyrZwt+8cDUqRHblwJMF2xPBAgU7doGY0;4:92hZcpYcLr4W3XAsX+eL+IgJ19Ot6XX7syPjJlIHt9jr8deU9eAGKxfQEDPrtELK/upr9TYVIqw7qlyTSvl+sJKSUFO85HYxX/tqo8AOAMUktHWTRLMobGhxF0GnUhCommaR/of59ps03/mK+XFJfCzIPsNal9YvK03orkhT0eKjtPTEb93xo1lWG1HFRogd3b3CVBs2ESzFWrGtD0Drb5c9051mf9yZ/a3Hh/BM8JxgBeGskq07GNCShx9bmn2j38/yELBiOqMRm8syhfeDjSuzoySsSBvPqesej8mXDdLiGubRFPg7GSpmtg/tcANgOe4H6VDGHYkfprVV9vqM+j7Y9NQcATkT9qU0vKeDeECCXhXUSvKWdu9exdZHYGHNZ/5KUEr1rx64FdqcpJUrqQ== 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)(2401047)(8121501046)(5005006)(100000703101)(100105400095)(3002001)(93006095)(93001095)(10201501046)(920507026)(6041248)(20161123564025)(20161123555025)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(20161123558100)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:DM3PR15MB1084;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:DM3PR15MB1084; X-Forefront-PRVS: 0420213CCD X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(6009001)(189002)(199003)(86362001)(6666003)(53936002)(1076002)(48376002)(33646002)(50466002)(189998001)(7416002)(69596002)(97736004)(305945005)(6506006)(7736002)(6486002)(5660300001)(6916009)(2950100002)(34040400001)(101416001)(105586002)(6512007)(25786009)(5003940100001)(4326008)(76176999)(50986999)(81156014)(54906002)(36756003)(53416004)(8936002)(2361001)(81166006)(106356001)(2351001)(42186005)(8676002)(110136004)(47776003)(2906002)(39060400002)(50226002)(478600001)(68736007)(6116002)(42262002);DIR:OUT;SFP:1102;SCL:1;SRVR:DM3PR15MB1084;H:castle.thefacebook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;DM3PR15MB1084;23:oXK/9lo+9CZ5t0FT0um0LDTkJ4/Vf1lzxv9U0lQZK?= =?us-ascii?Q?Tm25dfcGjIXcfQ7dmE10enkfEHNOJ3etf1o9DT/6Bw7jBbBKsRPkgcBthPGb?= =?us-ascii?Q?zpDJU6sODQ3HjmHIYk1fJBinZfMDk6J4reXCC/u0WzhOBDlRpDK1rHdjNsH/?= =?us-ascii?Q?gwXSh4i7TWBGpy4ouWTVUKONIix5H+FiW2g6U6NCqJK4kR6iJebg3Jb0ueG/?= =?us-ascii?Q?wirMkjfa/NnE4by+QMjYu69iJbD6uAV6l26aspIT+A8EIVpV5GOGIedU+94b?= =?us-ascii?Q?49id2LpKHk7F33p+uFsFnYgt0Fdw31HMwBHdyacD2bHmdoDOKSvJQbrSnr4t?= =?us-ascii?Q?LuGnTMU+u1oKjIF/aTsZWvEt/09A/Zy5b7xWKM0A7uX3W04xnmNS/Pbg1rby?= =?us-ascii?Q?rgBxaYIPYsq6B7n6iLt1xaZnzfQ9RZCiZwAgL7fgv5tAF10C7d5sn9S+NNTT?= =?us-ascii?Q?RsOir16GO9VJ+UkwuLJTFH/VAKj8QN2iplL8iAvPgQFFLwDNNEPN1YQ24JVp?= =?us-ascii?Q?j+vexmhK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ZdAuTbDjp31/uwpRNiseyAzYJooPtZqFqoWcx8dyh8u7QOr36TCzp4iTXEiMZw6GcS0UpdWR3cD6k7CmDCoPWp1OYar6pLJJCuU6JeJuLqlD9w6fYogI7j0Q316u9EEx78Q==;5:4/voMrqUYz4kNWbPKo8iCNmMdYi9n82lmAwDr2HOPsLmiD7f6NNx/0oDB9tqtEsYrCdpsEG7z/XuqDx0MLIHjJ5JTR8f93ZIy+AI/j3UR3O+qFYGaLD+rb4Y/KYFHXzUG+na2IVvaQXw3/KJVKi8mg==;24:Ky+HxC9S9TJ6Z6qsb87JorXp0/+Lpn5C94P05RfXyfyvRQsx1TV/hyy2SzFU/mQJpxh3fNgD9USfzB04fjWx7PO6eDjhFzauLAXaX371rg8=;7:nBUtU30BTo6ugRv9tH+0sB6iDS8XnuogUTWKivxA8MhYmvGPzcyMG2bez/H21BHcV9P6tlo7K91mRoCHrFiqWGGpfQqF8CfgHeGBpe5HI4GsAQARTx+U3ED8XHSBc3o3+cxeeB6rgTT3uKRTJZeMcmk5I6zAZ7gM65043oYG2Mjy91wxzeSj0lOgc666gTMLTAnceeA2L5JNZd5I1MWeWrH+dgFUz4GYWtkQBC2H9gY= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;DM3PR15MB1084;20:+UGkszDYFFfCxqA+raGvgSxrYo2kSwE2BZd97m+Hq06U3qvMLpbzWCcxawCnYQQrk4bKpDCbeiYACxUEBY7bWHCZkQYu5GLArnnUs6LQOrOFvvJHaFKhiFFJntmEE3xxCbrF3hKNBpdGH8mPc9xNvG5o9nVlfj04mZyiVak+qDU= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Sep 2017 14:21:35.4384 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM3PR15MB1084 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-09-04_09:,, signatures=0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5416 Lines: 179 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: Andrew Morton 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 99736e026712..f061b627092c 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -804,68 +804,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 give it access to memory reserves - * 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); @@ -939,6 +883,69 @@ static void oom_kill_process(struct oom_control *oc, const char *message) } #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 give it access to memory reserves + * 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); +} + /* * Determines whether the kernel must panic because of the panic_on_oom sysctl. */ -- 2.13.5