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 2315EC04FFE for ; Thu, 9 May 2024 02:39:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7F6396B0089; Wed, 8 May 2024 22:39:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7A6466B008C; Wed, 8 May 2024 22:39:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 694696B0092; Wed, 8 May 2024 22:39:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 4C3366B0089 for ; Wed, 8 May 2024 22:39:41 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id E2A2E1A1050 for ; Thu, 9 May 2024 02:39:40 +0000 (UTC) X-FDA: 82097301720.18.960D000 Received: from out30-110.freemail.mail.aliyun.com (out30-110.freemail.mail.aliyun.com [115.124.30.110]) by imf06.hostedemail.com (Postfix) with ESMTP id D054D180012 for ; Thu, 9 May 2024 02:39:37 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=mY2WpZ80; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf06.hostedemail.com: domain of hsiangkao@linux.alibaba.com designates 115.124.30.110 as permitted sender) smtp.mailfrom=hsiangkao@linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1715222379; 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=GmlupQEObKD3hcpHsT80fX0O66yCosUf38s2RUlYQ0I=; b=LxomUKxCahILsmTeIh79sha2SuiOgp/VSIaWHg9FFpwOJq692Dku+0nXhFw0eN28efg5X3 Pc8ZFepxpNIV+BaqniD1E7W8+rvT+2geqZNLg0fi09sSUOY+5Xww16uqnHSFOOKeiRVRPc /MhVqAu7Y/1hafZRXrwcOduQ3WIHqDc= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=mY2WpZ80; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf06.hostedemail.com: domain of hsiangkao@linux.alibaba.com designates 115.124.30.110 as permitted sender) smtp.mailfrom=hsiangkao@linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715222379; a=rsa-sha256; cv=none; b=XFi/qWAu8H27GugGSy6h9Myjw40QTYIuRkfb1WMhW8SjpQRNbxcScFG3RVlOInlT1GoomY htI665WV5VhEAOTwD2AjxiXEt2lETJyKchKIStSMx4lTpbaBzZEt69Pd7eLykIZEI8eNHY g9PBcqZ8tPwzAyqjSyGbGjPd6IDYd8s= DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1715222375; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=GmlupQEObKD3hcpHsT80fX0O66yCosUf38s2RUlYQ0I=; b=mY2WpZ80evvXSYOIoGRJK739x/M4eyfZHFfq5cM/Gy+gbXomFq/YnULlK+sG+AkFak+SPrXHARcRrhAqwY3dPblQ0w+yv5TdLGqjc5pjVXWTvSTS5R/hkc1UUKR/pL2H/6y2J7gCokokmfmzlXgD9/4ryZU2K0T6RaGeHhyoFWI= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R131e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037067113;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=11;SR=0;TI=SMTPD_---0W65JQwU_1715222372; Received: from 30.97.48.191(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0W65JQwU_1715222372) by smtp.aliyun-inc.com; Thu, 09 May 2024 10:39:33 +0800 Message-ID: <20d782ad-c059-4029-9c75-0ef278c98d81@linux.alibaba.com> Date: Thu, 9 May 2024 10:39:31 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH] mm/vmalloc: fix vmalloc which may return null if called with __GFP_NOFAIL To: Barry Song <21cnbao@gmail.com>, hailong.liu@oppo.com Cc: akpm@linux-foundation.org, urezki@gmail.com, hch@infradead.org, lstoakes@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, xiang@kernel.org, chao@kernel.org, Oven References: <20240508125808.28882-1-hailong.liu@oppo.com> From: Gao Xiang In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: D054D180012 X-Stat-Signature: jqxjzqguiszt4f9c91didgqby8fboaqa X-Rspam-User: X-HE-Tag: 1715222377-494072 X-HE-Meta: U2FsdGVkX1/JubHdgrQtkVH7Ic+7MARt8f1w5NaEh4o/QHjiC8gn1iszTGJtPGGGw/rq6RDHn7AIUex8NjTO9uBo+wh5kdm1izT50IvhM2ShgzZy/rDzh/vOBYcWUcMhnjD7g+m2LbG+FwxAFTAnCB7qfmSyyUSSlcYLJrRgI5+root07/egcJbx9YEy0EdH6SDdECFyTYrfZ6beIOdOTBWYK9JSv0mrAvbpByAOrlwR03p/bBeS6KIf2mKzT6OrPXw5mM/9ZjeBA9ZXO/GJSiLeR7JljU4Vm1QJjUIZEMlIzT/t3zWW/+F52yiW8a6rlu4KLLsTkYqLSpJ2Cp0JdcJjCxLfep3k0nZS88MlCZQpHpE8Q7T27TbI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7YfV+4D0luOrSGXpvVbm7p4M= 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: List-Subscribe: List-Unsubscribe: Hi, On 2024/5/9 10:20, Barry Song wrote: > On Thu, May 9, 2024 at 12:58 AM wrote: >> >> From: "Hailong.Liu" >> >> Commit a421ef303008 ("mm: allow !GFP_KERNEL allocations for kvmalloc") >> includes support for __GFP_NOFAIL, but it presents a conflict with >> commit dd544141b9eb ("vmalloc: back off when the current task is >> OOM-killed"). A possible scenario is as belows: >> >> process-a >> kvcalloc(n, m, GFP_KERNEL | __GFP_NOFAIL) >> __vmalloc_node_range() >> __vmalloc_area_node() >> vm_area_alloc_pages() >> --> oom-killer send SIGKILL to process-a >> if (fatal_signal_pending(current)) break; >> --> return NULL; >> >> to fix this, do not check fatal_signal_pending() in vm_area_alloc_pages() >> if __GFP_NOFAIL set. >> >> Reported-by: Oven >> Signed-off-by: Hailong.Liu >> --- >> mm/vmalloc.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/mm/vmalloc.c b/mm/vmalloc.c >> index 6641be0ca80b..2f359d08bf8d 100644 >> --- a/mm/vmalloc.c >> +++ b/mm/vmalloc.c >> @@ -3560,7 +3560,7 @@ vm_area_alloc_pages(gfp_t gfp, int nid, >> >> /* High-order pages or fallback path if "bulk" fails. */ >> while (nr_allocated < nr_pages) { >> - if (fatal_signal_pending(current)) >> + if (!(gfp & __GFP_NOFAIL) && fatal_signal_pending(current)) >> break; > > why not !nofail ? > > This seems a correct fix, but it undermines the assumption made in > commit dd544141b9eb > ("vmalloc: back off when the current task is OOM-killed") > > " > This may trigger some hidden problems, when caller does not handle > vmalloc failures, or when rollaback after failed vmalloc calls own > vmallocs inside. However all of these scenarios are incorrect: vmalloc > does not guarantee successful allocation, it has never been called with > __GFP_NOFAIL and threfore either should not be used for any rollbacks or > should handle such errors correctly and not lead to critical failures. > " > > If a significant kvmalloc operation is performed with the NOFAIL flag, it risks > reverting the fix intended to address the OOM-killer issue in commit > dd544141b9eb. > Should we indeed permit the NOFAIL flag for large kvmalloc allocations? Just from my perspective, I don't really care about kmalloc, vmalloc or kvmalloc (__GFP_NOFAIL). I even don't care if it returns three order-0 pages or a high-order page. I just would like to need a virtual consecutive buffer (even it works slowly.) with __GFP_NOFAIL. Because in some cases, writing fallback code may be tough and hard to test if such fallback path is correct since it only triggers in extreme workloads, and even such buffers are just used in a very short lifetime. Also see other FS discussion of __GFP_NOFAIL, e.g. https://lore.kernel.org/all/ZcUQfzfQ9R8X0s47@tiehlicka/ In the worst cases, it usually just needs < 5 order-0 pages (for many cases it only needs one page), but with kmalloc it will trigger WARN if it occurs to > order-1 allocation. as I mentioned before. With my limited understanding I don't see why it could any problem with kvmalloc(__GFP_NOFAIL) since it has no difference of kmalloc(GFP_NOFAIL) with order-0 allocation. Thanks, Gao XIang