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 2FF2FC6FD1D for ; Tue, 14 Mar 2023 13:28:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4B2E08E0001; Tue, 14 Mar 2023 09:28:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 462E56B0074; Tue, 14 Mar 2023 09:28:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 303398E0001; Tue, 14 Mar 2023 09:28:12 -0400 (EDT) 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 1F4996B0072 for ; Tue, 14 Mar 2023 09:28:12 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id E54A580FBF for ; Tue, 14 Mar 2023 13:28:11 +0000 (UTC) X-FDA: 80567582382.14.63B177A Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) by imf07.hostedemail.com (Postfix) with ESMTP id EFFBD4001F for ; Tue, 14 Mar 2023 13:28:09 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=shopee.com header.s=shopee.com header.b="UfZWX/tF"; spf=pass (imf07.hostedemail.com: domain of haifeng.xu@shopee.com designates 209.85.210.177 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=1678800490; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=SqWxNNgiyjRPvW1SVzhFefJbYTcfrMJLvZh3UARCdLs=; b=DDNC0aWGpBrsRNanl9PKrQnCfcddkQS/TKH9likXlnt6/vhFXMg9YnxhIhR1ZqhCLAFmJT GEe652TekkkhgS3I/DQUhJ4GP/cq/TaTbseHUWgry015vnb9XeDAMUEMoptLCQvzLPrPg7 wFsdm/wjsGJD7XpFKV9MNp4mT3Q1AnA= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=shopee.com header.s=shopee.com header.b="UfZWX/tF"; spf=pass (imf07.hostedemail.com: domain of haifeng.xu@shopee.com designates 209.85.210.177 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=1678800490; a=rsa-sha256; cv=none; b=Wa5FteDRhi9e0L1aK/ki4a5EoCEOqsnRLFIevFC+RPgmbKjM3jK11oLCpOcsDCwiqZdbrP ++U/2NVuKZL9AqCM9WYfwX2JWmuKbiCjz8tvGfartrXGkIdN9xbpwkgkX60hEOz//JUXKN wVq9smldJ6DbVM0HcUzR4E5+XYH0CJY= Received: by mail-pf1-f177.google.com with SMTP id ce7so9694045pfb.9 for ; Tue, 14 Mar 2023 06:28:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shopee.com; s=shopee.com; t=1678800489; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=SqWxNNgiyjRPvW1SVzhFefJbYTcfrMJLvZh3UARCdLs=; b=UfZWX/tF8Y5bvfKzueyw8I/F+3lDY6MCLy3PTrPJEnQ9ih7wHAh0JvHvsmBmLoII1h /WqcdSll/fh6vlVszSoAm+wMN0bdSynJY5vrlCKNJkIx1oopwdo2LocLoRPAxihE+kCU WfWj3ABzwy9IyKv34ud7y66RJTtCbFB4VeBQXnaaNA+sH6eQKCrDWbatvL+SHfvDYaxY bDG4aG6mZsG8DSeS/cSsKSWdZZvMKcRoHi7Oz3YzItZSGkAgGoQS1sGE+89mKA//IDBj dNnI+JLzRoVUGr/Pxvesd4BxqFy0iZJboZDjoGWv5GghekIXNG2MnB4gM3i5JWjR73D5 Yz4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678800489; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=SqWxNNgiyjRPvW1SVzhFefJbYTcfrMJLvZh3UARCdLs=; b=KLonM3BShlGq71feFccO+YqiqRkjRUfL+wnYsWcjXlqNCg6voiL8hWshzwsCV53xh5 G71p5kliiCU7jzAIvwzZ/QIqsJsJlhJp5mOcqPvM9cjTPQdJfgBEvs1I/5SaRDu32bji fFUxyJ69cxP1hqL0X/q1Oqv5Aig2he/9Cp1qDnbanT83qPwa+4ENfSi+PRYByGye4B5w bDz8dkBRHjo/d4a2z7t7b/fr1MToKLTx1amtLzEtwJMCasl9d8yxXnwbDPQxqMtUMk60 X/4XaygKYeRBEKFsh5tH0hXb6ODYwkJLrZ8s0dG0AGOgejiP9Ye7AanbUFYpM5LdXDHr B0WQ== X-Gm-Message-State: AO0yUKUvQ7tP6kFjJHqxMg8bBKvRWWJYrt8byaSOohk44I3MVMpNNFr+ j7Y7GcK4TFEP9LJB4zhvYUhKjxdxlkeeCF/aS1a9v5BC X-Google-Smtp-Source: AK7set9QVNa6eB8xyRHYwZh6rcWLH1QYqyeeNvAA/or+hRErflrv3scAopJ25spNQbrIR9iwHLylkw== X-Received: by 2002:a62:3301:0:b0:625:6e00:210d with SMTP id z1-20020a623301000000b006256e00210dmr1451867pfz.21.1678800488713; Tue, 14 Mar 2023 06:28:08 -0700 (PDT) Received: from [10.54.29.37] ([143.92.118.3]) by smtp.gmail.com with ESMTPSA id 14-20020aa7914e000000b00622e01989cbsm1645680pfi.176.2023.03.14.06.28.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 14 Mar 2023 06:28:08 -0700 (PDT) Message-ID: <43717dc3-b8c8-651a-3d61-019c9752a110@shopee.com> Date: Tue, 14 Mar 2023 21:27:56 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Subject: Re: [PATCH RESEND] mm/oom_kill: don't kill exiting tasks in oom_kill_memcg_member To: Michal Hocko Cc: shakeelb@google.com, hannes@cmpxchg.org, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20230314091136.264878-1-haifeng.xu@shopee.com> <3654a73e-6817-4247-73b8-4604efe4a309@shopee.com> From: Haifeng Xu In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Stat-Signature: 4n3iy3bd3cb5a6g8qk8em74wetoarg9a X-Rspam-User: X-Rspamd-Queue-Id: EFFBD4001F X-Rspamd-Server: rspam06 X-HE-Tag: 1678800489-244535 X-HE-Meta: U2FsdGVkX19NQmlPF1WPFqJ/EmjEmzNdZveoJOJWh2/RKxK5I5VOvh0uosAH0gbxIwhN9OONluXvf+jgVxJSKTNgDjJOMKfUTIl+R0CPXs2/4lG7zuAKO86z9+nOlsUSN94iI1rDOR9tI+aX2KSRczoHvt/W0WG9Gt5FzrrXpOh7EMh0s/kEFBEDsI0eY4tIdC52UYMgK7oQKkmn6NyKIPlcQYLVU/dMs4DYW90BzFSFf9oeV2Tl1wWfK7syBAnqaqmoi6OlBadlvG/BKlDlUBICGvpX3SsVfr7tpjdq43U64rHETv8PRhHu8e+7cHUPkL5GN76m4upYk6ZjJ682ejolI+1eALCwxclM3kfpV7/XJ4qimkUdWK4xhdp7Jt4ywfpIoTqRf7zcHX2AbrBAKqy4xnMiHm0tL8qXhAspHnf5zUZzPT7bOQAkwlk+71YsTc3VaMsXUbiPfD6rxxxjjgD+ly+XS4Jhnki7SMQpHjClU5UbTddDw/57O7mb6KqVP8P91RWxjrxZKKkTjuEyv34e+XZwe1KUHQRI1vFFfxst0+XThluldbZjGFFd8VyJvPeSwusTSoO5623pPHvqBbxSDVXv5Ns47V3h0MbCn5YRBJu4uPNhyUHexuTUFXKTOZKCuENTuIOB0mVVJziD9zP4SFg/1/3b9BpTZ7/dhT6pE4Z8CF0jl3HLZGbIvjN0TFx+LIrNVLr4EMrUQSrrnN+dkmp9CSaqAIRiUkxPSZM4eqAPnqzNfK5a23wGQJCgE0Repq0U5BV6GIUVSfQPSVipoN5A2aJVawPBoeSK41vxDY0JNNKTodtw4bPi9UjBac9e4gapNQ16Lv6XXHaFtm9k89aybVzpi1SS/g2qN57bgSRYCo87WBpwAlqZAB075iCmCnmEBRyw+xPys0wbmK/5VHS/Ajg8QZf+Ljgpxi8QpVWRPTHqN75+/BpKLIjT5qxJrPSU2S5KxUar0+1 BqaU/mtR HOk45PX0j3DZNHR5L1Ua+H5SKVXePzBjDBjC+GI9ECTZ/XBaEVkojpO2snqcE2fyz+BONkkzmRO+sst/2SBxwieJKE01RYUJNzzzcIlNFnhMTxQ6lIRdiR1DGNQoD9I9wxULPOQ/CA1H8YqnG7vYtfj/EpPkHreI1WtN/vuCkPJ2NaehmjwojaEpDHwyY08vMfkpMYfqAui7bKS1ykUTw2zcWxRV1aOfdiZMA+HYW9rVtmhtf48QXpC9VLKft12adye4mIa2kNmLurqDwvjjGR1GymH4YfAsVC6YnfY9hQOBRlyd36nZWkiZuAGQAiDPceh09y8qHRuYfIjeGAUChI+QXb0l8WWhjpsPvthDda7irUrRLFcliB6yg/hqdN9vInG2dV4DYcWRAL4b92it8PcsYNv7hhRAj+xJnqhpBxKLcHTQ= 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: On 2023/3/14 20:00, Michal Hocko wrote: > On Tue 14-03-23 19:07:27, Haifeng Xu wrote: >> >> >> On 2023/3/14 18:16, Michal Hocko wrote: >>> On Tue 14-03-23 18:07:42, Haifeng Xu wrote: >>>> >>>> >>>> On 2023/3/14 17:19, Michal Hocko wrote: >>>>> On Tue 14-03-23 09:11:36, Haifeng Xu wrote: >>>>>> 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. >>>>> >>>>> This doesn't state any actual problem. Could you be more specific? Is >>>>> this a bug fix, a behavior change or an optimization? >>>> >>>> >>>> 1) oom_kill_process() has inovked __oom_kill_process() to kill the selected victim, but it will be scanned >>>> in mem_cgroup_scan_tasks(). It's pointless to kill the victim twice. >>> >>> Why does that matter though? The purpose of task_will_free_mem in >>> oom_kill_process is different. It would bail out from a potentially >>> noisy OOM report when the selected oom victim is expected to terminate >>> soon. __oom_kill_process called for the whole memcg doesn't aim at >>> avoiding any oom victims. It merely sends a kill signal too all of them. >>> >> >> except sending kill signals, __oom_kill_process() will do some other work, such as print messeages, traversal all >> all user processes sharing mm which holds RCU section and so on. So if skip the victim, we don't need those work again >> and it won't affect the original mechanism. All oom victims are still get killed. > > mm sharing among processes is a very rare thing but do not forget that > task_will_free_mem needs to do the same thing for the same reason. For the victim, __oom_kill_process() traversals all processes in the system whether there some other tasks sharing mm or not. If skip it, this work can be dropped. > >>>> 2) for those exiting processes, reaping them directly is also a faster way to free memory compare with invoking >>>> __oom_kill_process(). >>> >>> Is it? What if the terminating task is blocked on lock? Async oom >>> reaping might release those resources in that case. >> >> Yes, the reaping process is asynchronous. I mean we don't need the work mentioned above any more. >> "reaping them directly" here is that joining the task in oom reaper queue. > > I do not follow. > > In any case I still do not see any actual justification for the change > other than "we can do it and it might turn out less expensive". This > alone is not sufficient, just be explicit, because oom is hardly a fast > path to optimize every single cpu cycle for. So unless you see an actual > real life problem that would be behaving much better or even fixed then > I am not convinced this is a worthwhile change to have. > we can also see two same messages("Memory cgroup out of memory: Killed process ***")about the victim. This seems a little confusing. If skip the victim, only one message was printed.