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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E4A6C433EF for ; Sat, 23 Oct 2021 19:15:51 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CD32261073 for ; Sat, 23 Oct 2021 19:15:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org CD32261073 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 0F334940007; Sat, 23 Oct 2021 15:15:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0A2DD6B0071; Sat, 23 Oct 2021 15:15:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ED324940007; Sat, 23 Oct 2021 15:15:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0030.hostedemail.com [216.40.44.30]) by kanga.kvack.org (Postfix) with ESMTP id DFD576B006C for ; Sat, 23 Oct 2021 15:15:49 -0400 (EDT) Received: from smtpin35.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 8EE9C8249980 for ; Sat, 23 Oct 2021 19:15:49 +0000 (UTC) X-FDA: 78728656818.35.06717EF Received: from relay.sw.ru (relay.sw.ru [185.231.240.75]) by imf24.hostedemail.com (Postfix) with ESMTP id EC179B0000A4 for ; Sat, 23 Oct 2021 19:15:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=Content-Type:MIME-Version:Date:Message-ID:From: Subject; bh=ZuyZvSB+IWaABIIMJw/ofGXgNTuvJPGvRG6ORPX+xCg=; b=b7Oxo3QFYkhUf1+aI vPwuGhnkZ+uxt4WvbR2ObgwJZxJp6oCuOj7RZTnquMghZb9hiJEd6Azb67tU4KnhnbHCdu13JAlWW V4CxHMXB7c6kmU4Y6+2LRBdsC8J1Dt4hpk+dSis16Zs/lGfAdZFoHZ4NqP8QqfBE8tFluHxwv7UMU =; Received: from [172.29.1.17] by relay.sw.ru with esmtp (Exim 4.94.2) (envelope-from ) id 1meMUX-006wTn-2M; Sat, 23 Oct 2021 22:15:41 +0300 Subject: Re: [PATCH memcg v3 2/3] mm, oom: do not trigger out_of_memory from the #PF To: Tetsuo Handa , Michal Hocko Cc: Roman Gushchin , Uladzislau Rezki , Vlastimil Babka , Shakeel Butt , Mel Gorman , cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel@openvz.org, Johannes Weiner , Vladimir Davydov , Andrew Morton References: From: Vasily Averin Message-ID: <5038ff2f-7358-80df-8167-3449c1a540fe@virtuozzo.com> Date: Sat, 23 Oct 2021 22:15:19 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: EC179B0000A4 X-Stat-Signature: f4cypmmdumboyzjsupbumqsgdb85ajit Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=virtuozzo.com header.s=relay header.b=b7Oxo3QF; spf=pass (imf24.hostedemail.com: domain of vvs@virtuozzo.com designates 185.231.240.75 as permitted sender) smtp.mailfrom=vvs@virtuozzo.com; dmarc=pass (policy=quarantine) header.from=virtuozzo.com X-HE-Tag: 1635016548-530301 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 23.10.2021 18:01, Tetsuo Handa wrote: > On 2021/10/23 22:20, Vasily Averin wrote: >> /* >> - * The pagefault handler calls here because it is out of memory, so kill a >> - * memory-hogging task. If oom_lock is held by somebody else, a parallel oom >> - * killing is already in progress so do nothing. >> + * The pagefault handler calls here because some allocation has failed. We have >> + * to take care of the memcg OOM here because this is the only safe context without >> + * any locks held but let the oom killer triggered from the allocation context care >> + * about the global OOM. >> */ > > Excuse me for a stupid question. I consider > > if (!mutex_trylock(&oom_lock)) > return; > out_of_memory(&oc); > mutex_unlock(&oom_lock); > > here as the last resort (safeguard) when neither __alloc_pages_may_oom() > nor mem_cgroup_out_of_memory() can make progress. This patch says > > let the oom killer triggered from the allocation context care > about the global OOM. > > but what if the OOM killer cannot be invoked from the allocation context? > Is there a guarantee that all memory allocations which might result in > VM_FAULT_OOM can invoke the OOM killer? I don't think this question is stupid, since I asked it myself :) You can find this discussion here: https://lkml.org/lkml/2021/10/21/900 Let me quote it here too :> 1) VM_FAULT_OOM may be triggered w/o execution of out_of_memory() :> for exampel it can be caused by incorrect vm fault operations, :> (a) which can return this error without calling allocator at all. : :I would argue this to be a bug. How can that particular code tell :whether the system is OOM and the oom killer is the a reasonable measure :to take? : :> (b) or which can provide incorrect gfp flags and allocator can fail without execution of out_of_memory. : : I am not sure I can see any sensible scenario where pagefault oom killer : would be an appropriate fix for that. : :> (c) This may happen on stable/LTS kernels when successful allocation was failed by hit into limit of legacy memcg-kmem contoller. :> We'll drop it in upstream kernels, however how to handle it in old kenrels? : :Triggering the global oom killer for legacy kmem charge failure is :clearly wrong. Removing oom killer from #PF would fix that problem. I would note: (c) is not theoretical but real life problem, in this case allocation was failed without execution of OOM, however, it is in this case that execution out_of_memory() from pagefault_out_of_memory() leads to a disaster. Thank you, Vasily Averin