Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2970097pxb; Sat, 23 Oct 2021 12:25:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJymSX8djBgXDDT46jP57CRvMjYSNIZ5HZO4G505/OL6ShxMoeWtwK9KsG25Ifm4VxlnWBTb X-Received: by 2002:a17:902:6ac5:b0:13f:ca85:3d97 with SMTP id i5-20020a1709026ac500b0013fca853d97mr7191708plt.73.1635017130166; Sat, 23 Oct 2021 12:25:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635017130; cv=none; d=google.com; s=arc-20160816; b=vZXgTtoa58QBz7Z0PsDzHjf0SrpD1EB+CgK6rYFL7lUkxNzM1jCGnRD0cQxMDeFe3J g/deTHQztmfncgyjU3XykvSA0I6VMYjn4uvx5+7srtsSsnreC/GHUgPmMij6umqVfzcW f8EXqueG+Xvv7ddks2AzT2Zd/qtNGG5SL1CeWt2oOCAkT/ofoqEXDRqnJpC1xvtl7JzI uqsgj9n+e/XJbUlk6K5MsSUejnZrEE4r1NcxNENzPTCepq2ECDLOZJdTY0dpA+BCxBHI swKBvfGAINV8enmBv9e/XoULRbQTZv61xam5Oh/GvTxiVG6EFa+CAsicGFKwbCHof7+A 3kOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=ZuyZvSB+IWaABIIMJw/ofGXgNTuvJPGvRG6ORPX+xCg=; b=UxBzmAN41atJevzp5UKbIFSqLn1NKz2sN/wcRdVwOPg0cxlDfzbrmBvh+vpyAvWNZO H/sGCIGWRIkV16Zt7K0fcH+C7t9Nb+LtFLYIZ0lxKHHP9kzDnwdfE27VRuMmD8lIWfNm v6X/WTFflcCQA5g2Jzi3COsX1ap0dVN1N63P7OsyTV5KYKx78omnxj+FGdJxyFeYjDdw EHe8Spauyh0A5vXrbsP+1I8Of8FVUK8LkUW29iCAwenI1RL+2BQTBBLmGdfil6mPeTqF CTa/+m/JUgdDDJb8Vn2dQgyT1or01c/j3FYWfvuyM5vO8z2Ey0mbgb5bEjFOW3l7aDdN /I2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=b7Oxo3QF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i8si16059141pgl.430.2021.10.23.12.25.15; Sat, 23 Oct 2021 12:25:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=b7Oxo3QF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230519AbhJWTSH (ORCPT + 99 others); Sat, 23 Oct 2021 15:18:07 -0400 Received: from relay.sw.ru ([185.231.240.75]:39782 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229696AbhJWTSH (ORCPT ); Sat, 23 Oct 2021 15:18:07 -0400 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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