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 898F2C47079 for ; Fri, 5 Jan 2024 10:27:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0D0476B0137; Fri, 5 Jan 2024 05:27:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 081356B0138; Fri, 5 Jan 2024 05:27:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E64026B0139; Fri, 5 Jan 2024 05:27:04 -0500 (EST) 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 D340C6B0137 for ; Fri, 5 Jan 2024 05:27:04 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id A5FD9A1EB0 for ; Fri, 5 Jan 2024 10:27:04 +0000 (UTC) X-FDA: 81644879568.08.8FD3CBD Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf28.hostedemail.com (Postfix) with ESMTP id D6F11C000F for ; Fri, 5 Jan 2024 10:26:59 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=OQ2VCqnr; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=PAmRRwDV; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=OQ2VCqnr; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=PAmRRwDV; spf=pass (imf28.hostedemail.com: domain of jack@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=jack@suse.cz; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1704450420; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=LUH6RqocM03TWTBwRHDFCUItap2jx/cmsqp/TXrIYzQ=; b=LOweeWR/J6iAxP+EAa0EsgmeB6xRK9WuRPrT/4hgohTPDrQy5OQq8cbJjFVUdBGHCcCB2z olPIXWEOpZCU1KJHcmGdB2Hx78gH0EUgiIo1SohjJkCicgvn+JvGLE3Y0sF3UHIZmNlphq oda9Rs1tHNARMPlTEzsv6hkTfL38sxQ= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=OQ2VCqnr; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=PAmRRwDV; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=OQ2VCqnr; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=PAmRRwDV; spf=pass (imf28.hostedemail.com: domain of jack@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=jack@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1704450420; a=rsa-sha256; cv=none; b=WiKVc7d6srn5j+O8y7/rS/IJUyRSE8TaTT4jgSg0Rc92NVxevetXHVB/w59i4zxqnwpWe4 +aWLqSVAtWlN1Rn26aWT+nVyekK+cWccRl8Fx66aBmQhDnab9S1d9WxiVXhaYxZIjsERL4 KKnGomIW3bL1dWDs+JrQOvKKyW7EiQY= Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id D1B1121F4F; Fri, 5 Jan 2024 10:26:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1704450417; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=LUH6RqocM03TWTBwRHDFCUItap2jx/cmsqp/TXrIYzQ=; b=OQ2VCqnrrdt13RcjXedA7ZO0msKuuQrIC+Z55rJFbfLY1zONbYYQtozOvnlpQl3gwF5lQd iqLDaYjiRxh6XkXF54c9YBHEPJ/uwvRFgHGGpc2LJxuXidagFk6A0Ks8ff2101conmDabl f0bux88HSIZhWD/o4q5+psJbsTsXNJY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1704450417; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=LUH6RqocM03TWTBwRHDFCUItap2jx/cmsqp/TXrIYzQ=; b=PAmRRwDV40Wd9q/NmvGMfCJwi0HXhnF+Z6DJqLbBZLJa8TPWiWnLiHdXKz07YBAOWNT/NA uommy2Wi1Fev9TBg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1704450417; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=LUH6RqocM03TWTBwRHDFCUItap2jx/cmsqp/TXrIYzQ=; b=OQ2VCqnrrdt13RcjXedA7ZO0msKuuQrIC+Z55rJFbfLY1zONbYYQtozOvnlpQl3gwF5lQd iqLDaYjiRxh6XkXF54c9YBHEPJ/uwvRFgHGGpc2LJxuXidagFk6A0Ks8ff2101conmDabl f0bux88HSIZhWD/o4q5+psJbsTsXNJY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1704450417; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=LUH6RqocM03TWTBwRHDFCUItap2jx/cmsqp/TXrIYzQ=; b=PAmRRwDV40Wd9q/NmvGMfCJwi0HXhnF+Z6DJqLbBZLJa8TPWiWnLiHdXKz07YBAOWNT/NA uommy2Wi1Fev9TBg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id C61B0137E8; Fri, 5 Jan 2024 10:26:57 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id Hb9ZMHHZl2VcXwAAD6G6ig (envelope-from ); Fri, 05 Jan 2024 10:26:57 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 70F33A07EF; Fri, 5 Jan 2024 11:26:57 +0100 (CET) Date: Fri, 5 Jan 2024 11:26:57 +0100 From: Jan Kara To: Viacheslav Dubeyko Cc: Matthew Wilcox , linux-scsi@vger.kernel.org, linux-ide@vger.kernel.org, linux-nvme@lists.infradead.org, linux-block@vger.kernel.org, linux-mm@kvack.org, Linux FS Devel , lsf-pc@lists.linux-foundation.org Subject: Re: [Lsf-pc] [LSF/MM/BPF TOPIC] Removing GFP_NOFS Message-ID: <20240105102657.fwy7uxudqdoyogd5@quack3> References: <2EEB5F76-1D68-4B17-82B6-4A459D91E4BF@dubeyko.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2EEB5F76-1D68-4B17-82B6-4A459D91E4BF@dubeyko.com> X-Rspamd-Queue-Id: D6F11C000F X-Rspam-User: X-Stat-Signature: dbpzfzxhp4gfwmpftorepy6hpm3jpy9j X-Rspamd-Server: rspam01 X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515cJpJ2JlHMDS023pjjDgKIHsMIREW19NqL936WytBr9JieeEouPDEHnkD/A3rBOwEkZj8hQXCJzr6pDWWlVCHqzAmvkQLy3301Af6eRZ7HjTz1jfmc9B+2E6D0R7/YcDu6mdoB3piQ7Foce4zRHAixG+Kvq6aCKrVYqujc4kfw/XjpNh1AJPzhIXY0hwqJnux/bAt4v3CglSkBVgnNoHDaJfgxX0ImlsVZfNme228wM9PTVT9X4Cv+IbO+s+QOST5q4tGbk4TeC6AzirNOrI/0ENRWGcGtXxPTzbQPMCuWw20lOhE9wblSII0aFWKKo12xuEQK1tvJd 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 Fri 05-01-24 13:13:11, Viacheslav Dubeyko wrote: > > > > On Jan 5, 2024, at 12:17 AM, 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. > > > > This results in better code within your filesystem as you don't need to > > pass around gfp flags as much, and can lead to better performance from > > the memory allocators as GFP_NOFS will not be used unnecessarily. > > > > The memalloc_nofs APIs were introduced in May 2017, but we still have > > over 1000 uses of GFP_NOFS in fs/ today (and 200 outside fs/, which is > > really sad). This session is for filesystem developers to talk about > > what they need to do to fix up their own filesystem, or share stories > > about how they made their filesystem better by adopting the new APIs. > > > > Many file systems are still heavily using GFP_NOFS for kmalloc and > kmem_cache_alloc family methods even if memalloc_nofs_save() and > memalloc_nofs_restore() pair is used too. But I can see that GFP_NOFS > is used in radix_tree_preload(), bio_alloc(), posix_acl_clone(), > sb_issue_zeroout, sb_issue_discard(), alloc_inode_sb(), blkdev_issue_zeroout(), > blkdev_issue_secure_erase(), blkdev_zone_mgmt(), etc. Given the nature of the scoped API, the transition has to start in the leaves (i.e. filesystems itself) and only once all users of say radix_tree_preload() are converted to the scoped API, we can remove the GFP_NOFS use from radix_tree_preload() itself. So Matthew is right that we need to start in the filesystems. Honza -- Jan Kara SUSE Labs, CR