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 C92DBC10F1A for ; Thu, 9 May 2024 03:12:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5CA886B0095; Wed, 8 May 2024 23:12:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 57A106B0096; Wed, 8 May 2024 23:12:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4901F6B0098; Wed, 8 May 2024 23:12:03 -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 2B1256B0095 for ; Wed, 8 May 2024 23:12:03 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id CF838C1271 for ; Thu, 9 May 2024 03:12:02 +0000 (UTC) X-FDA: 82097383284.01.C3825FB Received: from out30-111.freemail.mail.aliyun.com (out30-111.freemail.mail.aliyun.com [115.124.30.111]) by imf23.hostedemail.com (Postfix) with ESMTP id B7DE414001E for ; Thu, 9 May 2024 03:12:00 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=WnOqDtna; spf=pass (imf23.hostedemail.com: domain of hsiangkao@linux.alibaba.com designates 115.124.30.111 as permitted sender) smtp.mailfrom=hsiangkao@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1715224321; 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=27nn0gbmoM0S5j5G2H5A+L8Sx0+wcMP1UH2vqgqnJH0=; b=6Potag4sHp67/xQDtxrDIPDGfgeIVyIznLZyqzUUIuO0h5sVwj82McQRllI+HfBhiKB/jB CHo3xOwLq5sqVWOYTqraUyeNz2z9B9ZgD9gmPKHeX1dzpVCAxICe9vONn07/XZyhJNGTWK xUH/YsbVA1LJVAW+OCDV3JyKtUV68XI= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=WnOqDtna; spf=pass (imf23.hostedemail.com: domain of hsiangkao@linux.alibaba.com designates 115.124.30.111 as permitted sender) smtp.mailfrom=hsiangkao@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715224321; a=rsa-sha256; cv=none; b=jnH/gvyjYzaWlxhko9ZydCrq31lXaQaF7qcYtdWP/uIdl9C1/dWVqTenKOwB8mBaUMz3FS Rb1OA+8n83oxd5HfPT6n9VZY/Da1GSlgJwRaUlh+NTVKl/oFpTwxLBeOtIRUz0tqp4aoTg lA4f4/g8wo0a9pIGE+T/GqZpcWNgl78= DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1715224317; h=Message-ID:Date:MIME-Version:Subject:From:To:Content-Type; bh=27nn0gbmoM0S5j5G2H5A+L8Sx0+wcMP1UH2vqgqnJH0=; b=WnOqDtnaeEEVjw2JcrPJeBrQFyj0ftn0io5w0nbsz9BRkeXBHWQlQv69Ud4zC+JHFSOZJAlYGNl0Sl+3wJYf0U/VO3H7Qd0Rh7/VNmfjem7QAuakbAG1aFXVsFOvww2Tyklqvm0lPGWOlPSfqGOcFgqvFTYOkoBizoOzHz5KlcM= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R881e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033032014031;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=12;SR=0;TI=SMTPD_---0W65FCcV_1715224314; Received: from 30.97.48.191(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0W65FCcV_1715224314) by smtp.aliyun-inc.com; Thu, 09 May 2024 11:11:56 +0800 Message-ID: Date: Thu, 9 May 2024 11:11:54 +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 From: Gao Xiang To: Barry Song <21cnbao@gmail.com>, hailong.liu@oppo.com, Michal Hocko 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> <20d782ad-c059-4029-9c75-0ef278c98d81@linux.alibaba.com> In-Reply-To: <20d782ad-c059-4029-9c75-0ef278c98d81@linux.alibaba.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Stat-Signature: ygyhowd9nndt9p4jkjobid94rdk7opy9 X-Rspamd-Queue-Id: B7DE414001E X-Rspamd-Server: rspam10 X-Rspam-User: X-HE-Tag: 1715224320-631780 X-HE-Meta: U2FsdGVkX1+8GCApenliyydwvdfP+4Ny7zpJDlX7weQ611COPMUxXo+NNqRoThA5vsPS3JUPP5S7cQWsxU7/pgNtOorv70pxuXnBxSpYqsA7Ny3wAgPz46Y6Z9pWCefcylyQQNGAcuolQxna+H2Xl0cKpVwDIDSL63HQQLmLz8/rGS9ZsBML23yowya3haTH5CvieCIWWsr1fPkqeo0tJKYcNk6K7H619cUAuM3RzzG17VUARBbKlzn8IpRUTf87tAmQ0jtM8yQ4cAwjK3Xco1+LoasG6hPMANPdzmYJwnypVrnS+WS9wScBVESWGdI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EBTg9nVPp0axQrNNIcDmINS7mQvB2tSCSD7ZzbywSPl0s5mBXp0T/fPXOYyJcF/2uYB4Q= 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: On 2024/5/9 10:39, Gao Xiang wrote: > 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. add some words... ^ here extreme cases were mostly just generated by syzkaller fuzzing tests, but if real users try to use some configuration to compress more, I still think it needs to be handled (even such kvmalloc may be slow if falling back to order-0 allocations due to memory pressures) > 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. .. kvmalloc with order-0 pages to form a virtual consecutive buffer just like several kmalloc(__GFP_NOFAIL) allocations together in the callers, I don't see any difference of memory pressure here. Thanks, Gao Xiang > > > Thanks, > Gao XIang