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 lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0FFCFC44500 for ; Mon, 6 Jul 2026 14:19:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.sourceforge.net; s=beta; h=Content-Transfer-Encoding:Content-Type:Cc: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Subject:In-Reply-To:MIME-Version:References:Message-ID:To:From:Date:Sender: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ojbRSxHrLfOwNXIcJKzDEbSExfE1muFDAS1WbsmXgNk=; b=HEXI97ny/9U4J/3DUhcvEZ7ARx ht0vShIVGSBYyxqxScR/0V2qLAfIHLT43bU+8gaPUKtNWmo2rocYP+8KIF6iWLsf31Xz+FdwcBF2V tKsyrowowNgf1P+KanRjSjdnkGPRXfdBS0GDOp0v1Ke8MxrWxPKh8LL7k3o5wNCYWfV0=; Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1wgkAM-0001m1-IT; Mon, 06 Jul 2026 14:19:23 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1wgkA8-0001ln-Qe for linux-f2fs-devel@lists.sourceforge.net; Mon, 06 Jul 2026 14:19:09 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=In-Reply-To:Content-Type:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=xruYhMX6XX22knH4dR2Q9nFX7MPsNbx/yLiH/Ump/1U=; b=kdoXCGwdTgCHfTYFCGCBq8F3LQ mLxnoIXFF7M5+vXSBw1BQK8XE2b2S79ktmFPAngyIRI/z2x1cmayPZlSkiB1HlEeaXTf5z7xL9BER 7/r/bqCwNWQUZTHBQYt01dy+mYa5H44vs8oHbi4kY5Wb9NBlTknJjwAGVHgtosgDEgXY=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To :From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=xruYhMX6XX22knH4dR2Q9nFX7MPsNbx/yLiH/Ump/1U=; b=EEqH/2FXjjIHCZ3iaRcq3GLzac 9Kqtj3zOv3uFsxcwg/N57/wcjzInCYmSZ2XrfkT/4lxmDzcgwZ8CIdomYzbAr6uzei14H9tobYPe/ VGPd3d0HFILUK1U2SYXQG/kLIweijFOmjotQcKp568/HWfwy++seOV33UpAnWTSkJMCM=; Received: from casper.infradead.org ([90.155.50.34]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1wgkA6-0004WD-CZ for linux-f2fs-devel@lists.sourceforge.net; Mon, 06 Jul 2026 14:19:09 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=xruYhMX6XX22knH4dR2Q9nFX7MPsNbx/yLiH/Ump/1U=; b=Y9KfOoib1Cxi1vPI4E9MKAbpaL zUimUmxxxnEFvcRVDHoq2WN6qYt83bSRv25BZnNBYgw9/40exA4r0KvD8DoiCGndI9Ri23a6Tqvgp a3f5LsZBXda+ghWn6mDW/Ib3EDFnV1aHAi6WV6npGGn0NQ+ggTWCDupfipShjNV8txupcq14ArTDI PSLdfa76k00085yPi/DkRuPi5uwGjMsOAzQDqSZbnwdnPYGgVP3GYbs03MBtEfqvUaMHImxzcVhln JwQ3D5o5lGyCIKLqGPagTmvO8Bps2EejvgUzdSAbzQCvX6xtY84uFynv9tz/JxTw5k7v2GNwgh3lw NdLKlDQA==; Received: from willy by casper.infradead.org with local (Exim 4.99.1 #2 (Red Hat Linux)) id 1wgk9v-0000000G1qi-1F2s; Mon, 06 Jul 2026 14:18:55 +0000 Date: Mon, 6 Jul 2026 15:18:55 +0100 From: Matthew Wilcox To: Chao Yu Message-ID: References: <20260706095943.2560208-1-chao@kernel.org> <20260706095943.2560208-2-chao@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20260706095943.2560208-2-chao@kernel.org> X-Headers-End: 1wgkA6-0004WD-CZ Subject: Re: [f2fs-dev] [PATCH 2/2] f2fs: quota: use memalloc_nofs_{save, restore} instead of FGP_NOFS X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jaegeuk@kernel.org, linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net On Mon, Jul 06, 2026 at 05:59:43PM +0800, Chao Yu wrote: > FGP_NOFS could be removed later, let's use memalloc_nofs_{save,restore} > instead, which is recommended to be used to avoid potential deadlock > when memory allocation in f2fs_quota_write() will call into filesystem > interface again, e.g. .writepages, evict_inode, shrinker due to > complicated lock race condition. I think we need to be clear on why we need the memalloc_nofs_save() call here. What problem would it cause if we did call into the filesystem to reclaim memory? I suspect this is the wrong place to insert this call and it should be near the lock that causes the problem. I've attempted a rewrite of the memalloc_nofs_save documentation; let me know what you think: /** * memalloc_nofs_save - Prevent recursion into the filesystem. * * All memory allocations between calling this function and calling * memalloc_nofs_restore() will be prevented from calling into filesystems * to reclaim memory. Clean page cache memory can still be reclaimed, * but (for example) inodes will not be. * * The primary reason to do this is that the caller has taken a lock * which would be needed by FS reclaim. While we could theoretically * call into a different filesystem in this case, it can be a deep call * stack so it is better to avoid all filesystems. * * Filesystems often choose to incorporate a call to this function as part * of starting a journal transaction. While not a lock in the normal * sense, it has much the same effect as nested journal transactions * are either prohibited or expensive. * * Also call this function if you need to allocate memory while holding * a file folio locked. High order allocations (such as those requested * by slab) can trigger compaction which will attempt to lock the folio. * * Context: This function is safe to be used from any context. * Return: The saved flags to be passed to memalloc_nofs_restore. */ _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CC61A376A1F for ; Mon, 6 Jul 2026 14:18:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783347541; cv=none; b=j/SLJvf9c1CPlkv9dizpOK03cJDXIB6zCKpDNe+gMEYArnqpS/BaOn9p4DNIZQxMgL9fIqsXofRxkiTkrJSqfkIX6a1jP5uOLBoQ3/Ely74q80nGyR18AbY+kpxWIIXZtzXbbfYkhDCmbErYytjPMNbFwC4Uglk5niUuxBzUiMU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783347541; c=relaxed/simple; bh=iHo7h2YGmpYKaEHwYvS0xYC3bpLn+lsB99h+9Ucm67U=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=YMxFjvAekgbDeiffvRKXSts5sev7l63sPMUpwev8sVHOoB34jEYLpnbnvodxeV8e30JHXd9AOKuP7FXz4EqNQIvf6XgWNzNGQD4QHxFNHvhuiFARa8TNCizGdF3PMLSjaadZ24T7w5rxz6ermGkn/2RPaN8TTQJx1NDi77YJpcs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=pass smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=Y9KfOoib; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="Y9KfOoib" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=xruYhMX6XX22knH4dR2Q9nFX7MPsNbx/yLiH/Ump/1U=; b=Y9KfOoib1Cxi1vPI4E9MKAbpaL zUimUmxxxnEFvcRVDHoq2WN6qYt83bSRv25BZnNBYgw9/40exA4r0KvD8DoiCGndI9Ri23a6Tqvgp a3f5LsZBXda+ghWn6mDW/Ib3EDFnV1aHAi6WV6npGGn0NQ+ggTWCDupfipShjNV8txupcq14ArTDI PSLdfa76k00085yPi/DkRuPi5uwGjMsOAzQDqSZbnwdnPYGgVP3GYbs03MBtEfqvUaMHImxzcVhln JwQ3D5o5lGyCIKLqGPagTmvO8Bps2EejvgUzdSAbzQCvX6xtY84uFynv9tz/JxTw5k7v2GNwgh3lw NdLKlDQA==; Received: from willy by casper.infradead.org with local (Exim 4.99.1 #2 (Red Hat Linux)) id 1wgk9v-0000000G1qi-1F2s; Mon, 06 Jul 2026 14:18:55 +0000 Date: Mon, 6 Jul 2026 15:18:55 +0100 From: Matthew Wilcox To: Chao Yu Cc: jaegeuk@kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/2] f2fs: quota: use memalloc_nofs_{save,restore} instead of FGP_NOFS Message-ID: References: <20260706095943.2560208-1-chao@kernel.org> <20260706095943.2560208-2-chao@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260706095943.2560208-2-chao@kernel.org> On Mon, Jul 06, 2026 at 05:59:43PM +0800, Chao Yu wrote: > FGP_NOFS could be removed later, let's use memalloc_nofs_{save,restore} > instead, which is recommended to be used to avoid potential deadlock > when memory allocation in f2fs_quota_write() will call into filesystem > interface again, e.g. .writepages, evict_inode, shrinker due to > complicated lock race condition. I think we need to be clear on why we need the memalloc_nofs_save() call here. What problem would it cause if we did call into the filesystem to reclaim memory? I suspect this is the wrong place to insert this call and it should be near the lock that causes the problem. I've attempted a rewrite of the memalloc_nofs_save documentation; let me know what you think: /** * memalloc_nofs_save - Prevent recursion into the filesystem. * * All memory allocations between calling this function and calling * memalloc_nofs_restore() will be prevented from calling into filesystems * to reclaim memory. Clean page cache memory can still be reclaimed, * but (for example) inodes will not be. * * The primary reason to do this is that the caller has taken a lock * which would be needed by FS reclaim. While we could theoretically * call into a different filesystem in this case, it can be a deep call * stack so it is better to avoid all filesystems. * * Filesystems often choose to incorporate a call to this function as part * of starting a journal transaction. While not a lock in the normal * sense, it has much the same effect as nested journal transactions * are either prohibited or expensive. * * Also call this function if you need to allocate memory while holding * a file folio locked. High order allocations (such as those requested * by slab) can trigger compaction which will attempt to lock the folio. * * Context: This function is safe to be used from any context. * Return: The saved flags to be passed to memalloc_nofs_restore. */