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 15AEBC48260 for ; Thu, 8 Feb 2024 16:02:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 813246B0080; Thu, 8 Feb 2024 11:02:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 79C2F6B0081; Thu, 8 Feb 2024 11:02:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 63D506B0082; Thu, 8 Feb 2024 11:02:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 4D9EC6B0080 for ; Thu, 8 Feb 2024 11:02:33 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 07501A0F78 for ; Thu, 8 Feb 2024 16:02:33 +0000 (UTC) X-FDA: 81769104186.30.05160DB Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf22.hostedemail.com (Postfix) with ESMTP id 1A84CC0058 for ; Thu, 8 Feb 2024 16:02:15 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=obJpFnU3; spf=pass (imf22.hostedemail.com: domain of vbabka@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=vbabka@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707408136; 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=K6yzxiBXb0wFPjacWgz8OttgSJ24QLmHEVfAP2h3kqY=; b=7Rmqy/LbZEFPX7+3tbjJAtP7hSSdGYVHxmsfys0KM8wrdzQHDJNz4CyKZGzBxlB+KVEEaE LeuFL6Fzm5GJQhos5uMyVOFSywsWgMZboz15pkfd9o6+2JeWTDHPol4o2l36Szk5f31vTJ WcfPix6FRNdrV9zQa8NM8k22YodxmZk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707408136; a=rsa-sha256; cv=none; b=ngixOXnMUGR3dOXPXG3pgP3NwqtOZnN5Ne1B+s4LZ4hicb8PEnuZETQUvj4Tc4HlRnK/FJ PSyhEfZys/oWmBsC0nVZtiGempkq1lYXICj81XKxNuLKSggUPzc8H1TC1B2/xsRgsvXjlb 5f8H/5FwgE+JR/LM4mhkSn9oJho5I8w= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=obJpFnU3; spf=pass (imf22.hostedemail.com: domain of vbabka@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=vbabka@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id B4E80CE1D80; Thu, 8 Feb 2024 16:02:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DC76CC433C7; Thu, 8 Feb 2024 16:02:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707408132; bh=uTFe5CG7oWonbpeVbz5UaAiaJEjR9X1sZYLpZSCrroE=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=obJpFnU3wW/7vWnQ2T7KbJTN1o0DhsaGAsrrj2BVE8zioOEqxNl2MiXnaak9whqbt OIDJi1LDw4Ob4TOyMXecgyYlB0ULe8cbKEYD18dH7iv2VOYpw90ipR40HRow6soWvg DkCTi37Z6twlWFr7xB9SDcp4WUYNmxbMlDbECEGxFl+2eUYoaRKZIyH7IwHvpQ9BQu nNUhloOm8p60q6R9WsjvEZT4tnO900WaEIv/prTxnu+YOB1xTOPKTTYP8o7TuhLlr2 Ljl07+/LdqTtHEHadWQ3k0UZK64B9xF+oq5GtFxTc70ZUxMclN84FsAWvnJLmt4GnN Cj4n/P6UyVT+g== Message-ID: <3ba0dffa-beea-478f-bb6e-777b6304fb69@kernel.org> Date: Thu, 8 Feb 2024 17:02:07 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [LSF/MM/BPF TOPIC] Removing GFP_NOFS Content-Language: en-US To: Dave Chinner , Matthew Wilcox Cc: lsf-pc@lists.linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-block@vger.kernel.org, linux-ide@vger.kernel.org, linux-scsi@vger.kernel.org, linux-nvme@lists.infradead.org, Kent Overstreet , Michal Hocko References: From: "Vlastimil Babka (SUSE)" In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 1A84CC0058 X-Rspam-User: X-Stat-Signature: px5exh1ouh8btenwuyxdn3qo4iwwwbz3 X-Rspamd-Server: rspam03 X-HE-Tag: 1707408135-762835 X-HE-Meta: U2FsdGVkX18a+9mfn4giM6pgd8zWd3CjQkD2Jgxf1L5tAzOIiy1ePPk/zj9k9S7JacaMPEBwxPxk+DSyVWsX73+hbzP3UwGCSBJ/GWGO/unWJJux3amj0FMF1EyoZyTA3SupaOBNQFAC3S/KocjRAfNkZOdmg0hQzQsWmHp7/jPWuBrw+GAasgZJ2D7hfEUTw305ryRLN2VlQlVXufuhyQeXu3MmxcOJjLef2UxfPkrX016btfwZs9jXqnkYCKaswoEoTpe5eY6WkKZ6Ei6HXMpYrsWiu+B1KwUrP/ouyTa4BoS4dq9jlt3p1ctbkkl798PGYHMLbpwMCLV67bKcoWBb0+rYN6hn7rUyIoLs7eRIfNdrF0pIT2/autYrH4C83/15Svpo15PztodDEm9zAho6y9Vh7e04IRmPgt0by2j5ZScksIn2P+EUV+/s05dS5IE1OvSJek26kTiBOh4mj/bqQ/Du0JRyoAGLKbv31G/kq3jAyOqInQNvqFlJIyr7qxuK/GFfZJR9/A45V3tThmo+2Yr706kq1wC8//G2NFNBxIn2rjkfkhm7U1XDyqzhLHr+YrR71xzXtegKBsy40rGMdfjR6D8ucUtWoY6fmwXC87oRYR7/OYDklJCzQiJmE79Mw2z8+FOWhaySWuhwmtkm2OLFhIQFUGRLuPqMfpcPfNZuR50ZhEZnEhWBdbCErGesmKuVJshVNhAETCHnhYS2d+cXG0lcfvB6CovH5xw4f029QJHk+GKnO5jf75xI737sQY/PSKjE3vQCOBEkexdB5/Gm9dvMAB22ckjFQP4+YBFsEmq+TKuWeoJV0J/Dzw9GmtJiR+19SkqDizhheSYgysAGpQiNZkvzunjm4FVGM6fqhM+CfObhPexzF0tawDfeuRu+0vqRLp6T/2BheYp6wjBGayKP1KzwDAmF9THJWsedUAPfG2ilT3VjlIP0uzmMTR/8AgMbfveXDap BxHRBdOo VXEO9qoeLANBFWwtkVnLBdZ6zjxvkhpZpnNnNSMqJAnljWZLyHVbHF/ilk/vCVOBsIY8dyZs0LkxEtSY= 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 1/9/24 05:47, Dave Chinner wrote: > On Thu, Jan 04, 2024 at 09:17:16PM +0000, Matthew Wilcox wrote: >> This is primarily a _FILESYSTEM_ track topic. All the work has already >> been done on the MM side; the FS people need to do their part. It could >> be a joint session, but I'm not sure there's much for the MM people >> to say. >> >> There are situations where we need to allocate memory, but cannot call >> into the filesystem to free memory. Generally this is because we're >> holding a lock or we've started a transaction, and attempting to write >> out dirty folios to reclaim memory would result in a deadlock. >> >> The old way to solve this problem is to specify GFP_NOFS when allocating >> memory. This conveys little information about what is being protected >> against, and so it is hard to know when it might be safe to remove. >> It's also a reflex -- many filesystem authors use GFP_NOFS by default >> even when they could use GFP_KERNEL because there's no risk of deadlock. >> >> The new way is to use the scoped APIs -- memalloc_nofs_save() and >> memalloc_nofs_restore(). These should be called when we start a >> transaction or take a lock that would cause a GFP_KERNEL allocation to >> deadlock. Then just use GFP_KERNEL as normal. The memory allocators >> can see the nofs situation is in effect and will not call back into >> the filesystem. > > So in rebasing the XFS kmem.[ch] removal patchset I've been working > on, there is a clear memory allocator function that we need to be > scoped: __GFP_NOFAIL. > > All of the allocations done through the existing XFS kmem.[ch] > interfaces (i.e just about everything) have __GFP_NOFAIL semantics > added except in the explicit cases where we add KM_MAYFAIL to > indicate that the allocation can fail. > > The result of this conversion to remove GFP_NOFS is that I'm also > adding *dozens* of __GFP_NOFAIL annotations because we effectively > scope that behaviour. > > Hence I think this discussion needs to consider that __GFP_NOFAIL is > also widely used within critical filesystem code that cannot > gracefully recover from memory allocation failures, and that this > would also be useful to scope.... > > Yeah, I know, mm developers hate __GFP_NOFAIL. We've been using > these semantics NOFAIL in XFS for over 2 decades and the sky hasn't > fallen. So can we get memalloc_nofail_{save,restore}() so that we > can change the default allocation behaviour in certain contexts > (e.g. the same contexts we need NOFS allocations) to be NOFAIL > unless __GFP_RETRY_MAYFAIL or __GFP_NORETRY are set? Your points and Kent's proposal of scoped GFP_NOWAIT [1] suggests to me this is no longer FS-only topic as this isn't just about converting to the scoped apis, but also how they should be improved. [1] http://lkml.kernel.org/r/Zbu_yyChbCO6b2Lj@tiehlicka > We already have memalloc_noreclaim_{save/restore}() for turning off > direct memory reclaim for a given context (i.e. equivalent of > clearing __GFP_DIRECT_RECLAIM), so if we are going to embrace scoped > allocation contexts, then we should be going all in and providing > all the contexts that filesystems actually need.... > > -Dave.