From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1ED87C678D4 for ; Tue, 7 Mar 2023 07:49:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 509356B0071; Tue, 7 Mar 2023 02:49:06 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4B9026B0072; Tue, 7 Mar 2023 02:49:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 380C9280001; Tue, 7 Mar 2023 02:49:06 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 2953D6B0071 for ; Tue, 7 Mar 2023 02:49:06 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id EE8A6A0A72 for ; Tue, 7 Mar 2023 07:49:05 +0000 (UTC) X-FDA: 80541326250.02.D220FC2 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by imf16.hostedemail.com (Postfix) with ESMTP id 24F9C18000C for ; Tue, 7 Mar 2023 07:49:02 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=shopee.com header.s=shopee.com header.b=PBmMz327; spf=pass (imf16.hostedemail.com: domain of haifeng.xu@shopee.com designates 209.85.214.181 as permitted sender) smtp.mailfrom=haifeng.xu@shopee.com; dmarc=pass (policy=reject) header.from=shopee.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678175343; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=5/0dHmlbYMl8JGzVTPk6nV0NKYl8wDENDKsl5texprU=; b=q48EgvWEKob9V+0w2QSJ6utf+/bM+rEf2w/rm4tcKcRhqZim6Nn1dGiChpwvIRqHOsRLih 8L6urbzKk2HrunrK9UWfvM3Pi78KGchq3Hfy4Pp5h2/p9+DG83tJPctEbtf+1FiqfFQvco OHmYqZxClm1gVKUnbNg493v9T5HOcNc= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=shopee.com header.s=shopee.com header.b=PBmMz327; spf=pass (imf16.hostedemail.com: domain of haifeng.xu@shopee.com designates 209.85.214.181 as permitted sender) smtp.mailfrom=haifeng.xu@shopee.com; dmarc=pass (policy=reject) header.from=shopee.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678175343; a=rsa-sha256; cv=none; b=bMAjgTsK1VoT9dOYOusPOUF7yJHo8oBzyJMdF/0JeTc+uqvNcHSO7T+HoGLpYQ7XfiPEVz sRn454s4odIIUkDpE8fxx/gr8xKr0rD1Ytno90vmyHuAIfcQwdk2cy2M4F1mTeLc3rwajG R2+5sgSUwJk2TVtCisM/ghAmCRUgOPc= Received: by mail-pl1-f181.google.com with SMTP id i10so13175821plr.9 for ; Mon, 06 Mar 2023 23:49:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shopee.com; s=shopee.com; t=1678175342; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=5/0dHmlbYMl8JGzVTPk6nV0NKYl8wDENDKsl5texprU=; b=PBmMz327qjFJYp6lc4XsmGReKAbWj/vd1lIcVGm+UXdnrxxZyF08S1xIcNHDHhtRI0 MgPakAbOPqLAJz0IA/OTTy9rnWA4fW3kDPlwYIWpISay8mwkhor+pZ1XSbvJ3PuqXY5S 8zseNOdxhid5xc879kz01okxB0bzz4BOQTPx46uJpTwXyFRIty4ecB0Nf+aJQPLKCqRc W3PCbYEb7hlBVfNCyWu7KLl40nmFXF0WV3C2akZzTVTSbBnTHjaFP6kMhC5HVKpJKZyY 6JvCtuCLV3y0Puqda8KIEH9ovF4zrrJBKd7kQAyC/eJIAfwxmjxed1TR+mtT9/GJ8Hl7 QO+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678175342; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=5/0dHmlbYMl8JGzVTPk6nV0NKYl8wDENDKsl5texprU=; b=DTb1IXqh3F+QxRHQZFc3lZ8ikUnZ2i+wvdyX1dxcGRS3hdL+n/2ts/mJ3CGbNwlvz4 LPpPY7QyQjvYs93NOIboHRIFbGoLp5WF5yg8q0goLulx5oJYbcAa3VYbIZ/cQ1QY4tZo gF07lpNeDwHsGiR4X4UsHnZN3VawetKCPtH42eVxK9QPtexD84GZoAFgwkWfnrkiMH/A BdWNG8FIUUhm2m3F/jxbm7xKvD4q4qLuxP8Ul6pF3UrQ9GGG+kpra0kZ8glFFDHoc3iC qiOX+9KVtstdQx0qwJFaybJMM6Xzg+VFZvDE1TTTB1f0gxOEDzOZP2IQuEGZIMZ4eoiF gtqA== X-Gm-Message-State: AO0yUKUEy/lwhArExnIsjlcLPTbDDJ7SjtqLBAYeaigibHgP4429ZaCV OczEEv71BS1QjrHZj8v5hAHOcw== X-Google-Smtp-Source: AK7set9AX+z+O3GC1BUn+/Ixdi4fNKXrB1mNKK9sgi3krus2z7HASC4eVClH+fDyaMMFaB+CCaWsiQ== X-Received: by 2002:a17:902:c94b:b0:19a:c65d:f93 with SMTP id i11-20020a170902c94b00b0019ac65d0f93mr17706680pla.53.1678175341930; Mon, 06 Mar 2023 23:49:01 -0800 (PST) Received: from ubuntu-haifeng.default.svc.cluster.local ([101.127.248.173]) by smtp.gmail.com with ESMTPSA id ju5-20020a170903428500b0019cad2de863sm7841459plb.176.2023.03.06.23.49.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Mar 2023 23:49:01 -0800 (PST) From: Haifeng Xu To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Haifeng Xu Subject: [PATCH] mm/oom_kill: don't kill exiting tasks in oom_kill_memcg_member Date: Tue, 7 Mar 2023 07:48:08 +0000 Message-Id: <20230307074808.235649-1-haifeng.xu@shopee.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 24F9C18000C X-Stat-Signature: 357ijo3ih3uexc4pd67fudrwdz8g6nn7 X-Rspam-User: X-HE-Tag: 1678175342-679553 X-HE-Meta: U2FsdGVkX18T7CsaK7dr5v3nPUC0nHBrDRWK/cMZRiSL7RaYCmY4AD570WPedMgjjwPjwv3c8k5O9xHvv/RFLtZ68rM3FkfkZLV/lfu1jhfBk53h1grs1vApzvruH3dEv0eBYYWVtIfFqbU2381OsPtrnn7HjR+m/E9MijpLtX7jr3Yi4I1DguTo8BVvVdcJK50q5iDldkDvljixBdfW41fhJzICNtOdSIzExToS9XrzGUx3YN9njlgnPg5CI0iWYI48J9sYKx4ATSaNN+m4wTjWgr+RfJhNE9VTDeQlEQsZ+pMlobzPT4FBJ2xKTmErOzxyBFZ6KAVXx/3XjtQp/fPqATwnXtHKfoBs5rheA9kJcyty/wCOnwdXjGowBtFarAr6tbNFG8gfJh5f4UVjWMCCuphKX+e7QfkkfyQO/3RhDsaFQigaYrEJZ01XKkq1tKN08OvoaMuqCnvte7wZYVj6Uc5wlw8ej2LBhSA0/FuaFxW1j4u1+bW/wFsUEKEyYQ1mgzIyx3+gdSxcY5Yk29lTYEIjqscLYnwVdgeYvbDRUIwoR6Y7ZUE7XRmTD/nyFjf18slZKE80I4VoxD8vqDNdf/djidDeoOFEZlwBTb8f4EvKfYUzX3F7WoD6HiO4o5Z5HKoiJIHjsmURCJS2VDfREE35hjykulr+onWbSQs6OIi1KNd01W9GIH81pf2I8o1AQr9r6zd9F/EJ4h/Prd+z8UZTmyMSmcsao0BFfpdDvN45H8RUd3W7l/EMvjWcajzKWsZfQKGJHIUPt6wvmZ9m85hp7AU69qzsOoMfE9aOqlcCmp1o+QWsOb2aDTW7Lt3WCEPPV4D3sC89zAT9aoyTOjtt04urKcDqrd5aACCGHtmyW5l72OTWqYILdJ6Ld6ORwRveYnRl7HJMBNPSRdt5/gjq0jeAgGTiZxLMzm9yCcMyWzpsRU3mEY6vi0xXsBoagzsBFcDU6KrWQch GnXE53PX d9UiL0Tc9dWCPXckSBvpLMZnepZcqBMbQpusGKqBAO7nlHx8jRHBLvK8SmHSOv8Uz6KSCAqvpLYgj8lpYGewtSjpbA4ccy8JZTIHKYof87chAn0hCbhyRuz93V3sPiRZBRcvLuCIKgIaz++zMJQue5kg70OqSxQqlAIgjG4Xa7qOHW6O85d/KwtFQndUbuubWwfzrm4XENMgxBD8qcNZjrYvBS+y0+nvwsIUl/JZgkQpBR0tzM4pjwT35Hs90REXvzKi0vAHxCCBSSXD9CsoCsWytBHHSDsXV2MJo1wGaRVv5fB9tn/fAwsKwe9QQ8787IGTQbJxu6p4vD3LQZUqGpxJpOPBu3jW6PplFNIeVopGI7rfa+s0SaEY/X2ynGndEGwG3liW0OudBcuGouw6Ud/xVAqL1RREavUT4hXIr8VTbqdRkRzGEuUt8XOGsgkkcv3XJu+/wUmnvlQu6ViSbw/xBrQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: If oom_group is set, oom_kill_process() invokes oom_kill_memcg_member() to kill all processes in the memcg. When scanning tasks in memcg, maybe the provided task is marked as oom victim. Also, some tasks are likely to release their address space. There is no need to kill the exiting tasks. In order to handle these tasks which may free memory in the future, add a function helper reap_task_will_free_mem() to mark it oom victim and queue it in oom reaper. Signed-off-by: Haifeng Xu --- mm/oom_kill.c | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 044e1eed720e..36f5848fbc99 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -996,15 +996,43 @@ static void __oom_kill_process(struct task_struct *victim, const char *message) } #undef K +static bool reap_task_will_free_mem(struct task_struct *victim) +{ + bool ret = false; + + task_lock(victim); + if (task_will_free_mem(victim)) { + mark_oom_victim(victim); + queue_oom_reaper(victim); + ret = true; + } + task_unlock(victim); + + return ret; +} + /* * Kill provided task unless it's secured by setting * oom_score_adj to OOM_SCORE_ADJ_MIN. + * If the task is marked as oom_victim or will free + * memory, there is no need to kill it again. */ static int oom_kill_memcg_member(struct task_struct *task, void *message) { if (task->signal->oom_score_adj != OOM_SCORE_ADJ_MIN && !is_global_init(task)) { get_task_struct(task); + + /* + * 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 + */ + if (tsk_is_oom_victim(task) || reap_task_will_free_mem(task)) { + put_task_struct(task); + return 0; + } + __oom_kill_process(task, message); } return 0; @@ -1022,15 +1050,10 @@ static void oom_kill_process(struct oom_control *oc, const char *message) * its children or threads, just give it access to memory reserves * so it can die quickly */ - task_lock(victim); - if (task_will_free_mem(victim)) { - mark_oom_victim(victim); - queue_oom_reaper(victim); - task_unlock(victim); + if (reap_task_will_free_mem(victim)) { put_task_struct(victim); return; } - task_unlock(victim); if (__ratelimit(&oom_rs)) dump_header(oc, victim); -- 2.25.1