From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753053AbdK3P3P (ORCPT ); Thu, 30 Nov 2017 10:29:15 -0500 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:34442 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750923AbdK3P3L (ORCPT ); Thu, 30 Nov 2017 10:29:11 -0500 From: Roman Gushchin To: CC: Roman Gushchin , Vladimir Davydov , Tetsuo Handa , David Rientjes , Andrew Morton , Tejun Heo , , , , , Subject: [PATCH v13 1/7] mm, oom: refactor the oom_kill_process() function Date: Thu, 30 Nov 2017 15:28:18 +0000 Message-ID: <20171130152824.1591-2-guro@fb.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20171130152824.1591-1-guro@fb.com> References: <20171130152824.1591-1-guro@fb.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [2620:10d:c092:200::1:447a] X-ClientProxiedBy: VI1PR0602CA0002.eurprd06.prod.outlook.com (2603:10a6:800:bc::12) To SN2PR15MB1086.namprd15.prod.outlook.com (2603:10b6:804:22::8) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b4d48922-eaf8-4e33-bbb9-08d538071207 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603286);SRVR:SN2PR15MB1086; X-Microsoft-Exchange-Diagnostics: 1;SN2PR15MB1086;3:+B1ca2KL8cEUeMnLVD0wamzRTfA8MvyBpMgIafcNkceox1Go0SYakuG1vXI5MFxNUQKZoOs1PN53w9g3DoZudqfroHoVtZuGw8qtDgCjRvRSYqLAzFHlEcJuQuhH87g51/mcQsta2ENxO3aSZXhjKptMmx9mtQu7sEw52OkBJWZdj2jhgBoDrgjaR5C7pFuvpxKfX0alBP+lyBBh2zZVtCCPd5A6q7BdSXPtrX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JNHEspgPsNYuMxrCR+9i8jzXvCDrqbpnkb7Fr21A1STAlglmQZdPjctUlB+B5afLq5Imu8nJ86s1RRtBcS8sOJykCIt/bFZH7dsB5cmfdiCqUcJdxT3R00K0nG5N X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(274141268393343)(9452136761055)(67672495146484)(211936372134217)(153496737603132); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(11241501159)(6040450)(2401047)(8121501046)(5005006)(93006095)(93001095)(3002001)(10201501046)(3231022)(920507027)(6041248)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(20161123560025)(20161123555025)(20161123562025)(20161123564025)(6072148)(201708071742011);SRVR:SN2PR15MB1086;BCL:0;PCL:0;RULEID:(100000803101)(100110400095);SRVR:SN2PR15MB1086; X-Microsoft-Exchange-Diagnostics: 1;SN2PR15MB1086;4:wT0Kbg90M5JsgBm6RUiqPAePgd5p+/I7SA5J7EQh2DQC/azvr64iXsfHXfpr2TyrUM9IDrfeK0hJz+ppqjyASX+b/QfvmBxnlBZAeNgqAqAkYdZ4U150Ob63F+pWLP9hrtBXAQ0vSdy7uM1jw0RS4MolxZIdbvfow9onWmbVcLEmubf8EpvBsTjU9nzEs3W2o5996MP7GIfd+fRVoKdUqFIuo72Zf8SqYahvcpIVmTYkBp5xOAf82yRnOhIzu58eyhtnZB3SDoQDMa+xXyVTsaLbGtPzs4p0evEcZnkeEWgGNuRxc122Dhc/6tJ5+zVefXrRjxBAeWTrb+n1rKJd2f4WELLAgXZNJi/VOj5O3L4eSYFOVt73Db1c1WL1vCbafJvK5DsB8c0MEtixhUkhgJ+9HgjUruNa2o1TnVLN2DI3+W7qcGcJEByOyFHI7SDQ X-Forefront-PRVS: 05079D8470 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(6009001)(346002)(376002)(366004)(199003)(189002)(105586002)(33646002)(48376002)(6512007)(1076002)(34040400001)(8676002)(7736002)(81156014)(81166006)(305945005)(36756003)(5660300001)(6916009)(2950100002)(6666003)(97736004)(50466002)(7416002)(52116002)(53416004)(6116002)(68736007)(316002)(69596002)(16586007)(51416003)(2906002)(6486002)(76176010)(101416001)(6506006)(50986010)(54906003)(8936002)(50226002)(39060400002)(4326008)(106356001)(53936002)(25786009)(2351001)(2361001)(189998001)(86362001)(575784001)(47776003)(478600001)(52396003)(42262002);DIR:OUT;SFP:1102;SCL:1;SRVR:SN2PR15MB1086;H:castle.thefacebook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;SN2PR15MB1086;23:vYh4e0YX8FFNYEAyJ65PRA84m7G4yq4aNuDvvjNCE?= =?us-ascii?Q?084mOLPE7dChUWmDGhNbzMYpAnYdG93dLqmL30vHiFdQ2KCPsCCOZHDK/olJ?= =?us-ascii?Q?9lAZ85y6d8rgMgp45pHv/rnwox+e/Onn9qOzcP7PdKnt42M0JCvObo23t4S/?= =?us-ascii?Q?H0P0MwL7PCbGgvXAbbvnad9Fb8BLLxqtp79DBrLMywMU1VmltHhcbiemEoUe?= =?us-ascii?Q?dp5hPk3gaCsEooUFqWSVTt17bFyAW/bRVXuNTIueikDh3NGGVFC3yezQ7sTB?= =?us-ascii?Q?JF5C743BG9QRnGQ4d9iyZiLM5LPEWDZ0+1f5ir1s2G4A5TEqaK2FSRhdOevs?= =?us-ascii?Q?z1fewk3NqNFvhrzuflIJIF/i1fxMOxAvE2uaMgUvAtam0BynkDtXvcIn3MwG?= =?us-ascii?Q?liIf5IOQcJvijZjvsbn1E67Yf6zVenTSGHZV3nOPnaMAOSeBRBVFxo5uYrZ9?= =?us-ascii?Q?PQzCxvXspK24jBODGeeMTtLz6iM8EjIBCtuExnZaZnpsKCy9Ny6tKmSLJFmx?= =?us-ascii?Q?X8E2xDkaB2HYo+pLXNJLuZ2SX/WDfT8wr5uhQ0Hxf8wR4sdyqZYEhsdO8pmM?= =?us-ascii?Q?du6FVvCqH5dshGAsQIEJ5nfFTR7I+oPqffp3cZXNacnZRzP9p60SbkqMDgjk?= =?us-ascii?Q?Is74PKwsgOw990v7yc8dp6OVF4OPIf/pwSDMvpQvfovN5e0x4P4adL9+achV?= =?us-ascii?Q?KvQwMYtZlqqfX+uwmepnkbod5EJDEKtkYMctBJMVyk7vqxs7xViLNo04YLRC?= =?us-ascii?Q?LoRfbmw0Ey1FC2e94QO3keM2oZQOC3SRrUrC1Vav/KSkYh67QUFU8vCOQN4v?= =?us-ascii?Q?SuMQI+F0xmCDIHHdVgk75jtb7V1j9ZNuyxmC2NUnHArc4PDxYiumJvdwdHSm?= =?us-ascii?Q?UM9iaEwy2dfMH/mVBdqTeah9JS4YQXYe59zbyFtlI0f9ceOk8UWoF/Zt0tdX?= =?us-ascii?Q?jSY3GI3nH39IsFyV1xbZTttMZiD5Bv633kiMGevGwKA0NXVuthfX8J7DwwaA?= =?us-ascii?Q?fWywzKDXJCtud/hjZ0vBHkqg9dndTOv4UK78a8Nzu1TfG/bov5As5gCouSf7?= =?us-ascii?Q?UEG5SBiCS8iw//cFyjMb6RQulwiMcZKj0+J4kcDpT+tMFlUDongaCUCyDBSk?= =?us-ascii?Q?6MKICWDki7n9zR3wMRxE3nC5KVEapxG0xXzw06fpiODP0Ei1al8DQNb9OHq2?= =?us-ascii?Q?3J7uCKNqzDjgdVtayWahNplvyjMPekLFIiGj3j3Kq2Qi+Tswp0/7ssvp9YR7?= =?us-ascii?Q?bZeU4wVm1dCo9BCl1cdZR5rawK2b70yl2q03EPQYzrR+rLODbH4G+fOuwlG4?= =?us-ascii?B?Zz09?= X-Microsoft-Exchange-Diagnostics: 1;SN2PR15MB1086;6:exfcFKxsHTnIWPfgc+Tq67p3byTnoBqLLgLRK/gY4aGQ47zw6QRgx2/6Bmy990WS5CJ4KM3yO6g5SCEtUFIIxF1lvn88g3tfRRwarYqMT9IZAdvTUbVw1SqQedUoQu6IGxu/inGtUUE3byDeJzScw9NfrLWJgXWEUQXSlGjI+6vq9CWgxDxirLjPsqBg+GmLKL1Y8zJ20RULY2J5WlcbN+EuVhg6wcFoKJBN9rYjBAQJJoJnLhk5VqdZPiCq5nmu7wFHzrcUqQPHfUsD4UZmySQ9aQ7D9EeJZm4OLFniih5WjClbJ9s0/yGpTqENrunPYDrYRxuIO9vzg1mm+9pSYGePcvOBUHOTuTOpJ1ufNEs=;5:snSlknedq1dhT0OZ57FrvHGmrfv6JUPNDsfyeM6iQ2oSYmkaSR3Pdm60k6zXhdTawYVMbPS/ltNPm6fGdqmKikzdJUJt1XUNQEWxuj6/XPu23BQsvzkClb30dQZwBE4VtvUzb6BAmKB2QkIeTg7i1iqbclkHeS92aC+IJglSm6I=;24:dpbJYbVmO7j6VPWyYRnl9SvDGN5qjBuedeTfuIkkyX+mIIofMqql6knDWSPxeYhEdLAELFCmoduEloKbtVwHvZXCBGxJ8GxjWCKDCNTqj2U=;7:Fhb6dYtoj92EwCLzDNIymkEW5vRHdi6cN2KKXfG1NF1hJIhpDlfdQZWkDa+oOsBiwAR57VlEfoLSpazGo30XyZQFmtyY549DPpN35SDprVl1HJlYLZeefTmVA/Ip/fSSGv+CFaRTDsud+o68mVzSd+GWI5Tf5uJ/Zemzh3/SrM8XBBV+Usw/yra0dOjlqLlLogkT5yHUIVIB+2zlc9oR/6mdI+lQuNKspRPORgOpDMFj1SnEVNHcuJQd6ya43n+X SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;SN2PR15MB1086;20:pyaXBeDf1WgKwaBdbR93KisVITlJqa4kGEJVeYpWEzjyW4MfGSJm0z54JaEJsGmkvrebbfU0xjGQqpndPkyfjCZcQyC/YH9aFHH6ilQ44ZlCnt/SjElQy98kpexJvYpLGoapFIgNDtLb3zjTMw11AErnwXDgrlwL4hNtShE4gE4= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2017 15:28:53.8714 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b4d48922-eaf8-4e33-bbb9-08d538071207 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN2PR15MB1086 X-OriginatorOrg: fb.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-11-30_04:,, signatures=0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Acked-by: Michal Hocko Acked-by: Johannes Weiner Acked-by: David Rientjes Cc: Vladimir Davydov 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 3b0d0fed8480..f041534d77d3 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -814,68 +814,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); @@ -949,6 +893,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.14.3