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 E7D8BF94CB3 for ; Tue, 21 Apr 2026 21:52:16 +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: Reply-To:From:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Subject:In-Reply-To:MIME-Version:References: Message-ID:To:Date:Sender:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Awa1PQI3NrU+loCs9dkqk/KkB/VFWqW6SdFvOu/MyPE=; b=VhXurow9UbX+ICDV556NckAk1H NWuT50z2P0XS95OcwLFhaOlnid8gLzicXMYYz3GY/bm3oN3+ePScuo7Anz6zVHZPc5ivDRx3EeWgc k5kxjfP7GJLlpUxbHJgwJ55TJp5VbEqFwelgsQcvrsn5/cvEys+/rXD+cVNF91IA+cYM=; 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 1wFJ0y-0004B5-Jc; Tue, 21 Apr 2026 21:52:16 +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 1wFJ0w-0004Ax-Un for linux-f2fs-devel@lists.sourceforge.net; Tue, 21 Apr 2026 21:52:14 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=In-Reply-To:Content-Transfer-Encoding:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: 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=QFKXxx++M0GFqxC4oAREuLnjclL2wT5XauEG+lOALG8=; b=UB7fK2lNRFAZj+xtT6bZH/jZGz u4qrrcDCWPrQxQRZSXqtfTy7R2ZcVC5K+iEzMcOjW0doWqmSe5vEP42honb6aCHB1rW+OfXxY4fTn OrrYXS4eNrJPuphvWWQh9Y1w4UFCczKkpioRJwPjRdtklLUp6EGTyww+kpizLG0BUhOI=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=In-Reply-To:Content-Transfer-Encoding:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: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=QFKXxx++M0GFqxC4oAREuLnjclL2wT5XauEG+lOALG8=; b=bqzL3YnErQjVOqR8I0oQOpVy4l Ou4X8LsXtHqQCUUYn376b8zmVjX8OLn5eQxUOQ1mX5mmCGzrVX7aparhSdEEHIaXi9tZDVmP1a4Dw IQ7XB4aUnTUqNScxr9K+SDjt9JXeNA+Q4eRt50cFa4poEcwlwYq2JyUsdhlIjyfuA7Xc=; Received: from sea.source.kernel.org ([172.234.252.31]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1wFJ0w-0005lg-44 for linux-f2fs-devel@lists.sourceforge.net; Tue, 21 Apr 2026 21:52:14 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id 9126A400E3; Tue, 21 Apr 2026 21:52:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3F858C2BCB0; Tue, 21 Apr 2026 21:52:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776808323; bh=OlWtbmYbOWnAJpeScXahNQiA9AtqdGgQZoXaMjcy5tA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=skK3joQsw1DrbmsPot4bHmwLJukEtMwUCJ72ROrFtW4tv8Dzk+W1Zj+74kvzxq3FG UAKjA21KWp29UOwlnOg4Ypfxjs0LgAJ2Iugee6XhVZAK6/TQqhGUf5cYC9haXrCS0L yq6JeDNCuwlQSN/JOE0BK65HmBjJ+UhaMi87ixYFBKKqlUoZPNiW0+TclJq65LCRNq Hk+BX2Fy5LkhhLVFJZukTfUBbUzYX4bVUV1/f7oxJniS9YT83hZ/ATbYHUXna0bmz7 3wF4f7t/xGZQcUpN2LGnBpbaiXEVznIyQDZ5p5KiqjlqWocEUJGM+jPJ86TjudcDr6 hVWkoWlTi3jwA== Date: Tue, 21 Apr 2026 21:52:01 +0000 To: Chao Yu Message-ID: References: <20260403144015.221811-3-monty_pavel@sina.com> <5c222edf-6888-4007-9240-9e7988b2dc71@sina.com> <252cb446-e313-417b-b780-85dcdcf34a87@sina.com> <9b518ad1-18ad-4eb4-86d4-3a27e40a7635@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <9b518ad1-18ad-4eb4-86d4-3a27e40a7635@kernel.org> X-Headers-End: 1wFJ0w-0005lg-44 Subject: Re: [f2fs-dev] [PATCH] f2fs: fix node_cnt race between extent node destroy and writeback 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: , From: Jaegeuk Kim via Linux-f2fs-devel Reply-To: Jaegeuk Kim Cc: Yongpeng Yang , stable@vger.kernel.org, Yongpeng Yang , linux-f2fs-devel@lists.sourceforge.net Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net On 04/21, Chao Yu wrote: > On 4/21/2026 4:44 PM, Yongpeng Yang wrote: > > = > > On 4/20/26 15:28, Chao Yu via Linux-f2fs-devel wrote: > > > On 4/19/2026 12:29 AM, Yongpeng Yang wrote: > > > > = > > > > On 4/18/26 8:51 AM, Chao Yu via Linux-f2fs-devel wrote: > > > > > On 4/17/26 21:26, Yongpeng Yang wrote: > > > > > > = > > > > > > On 4/17/26 17:00, Chao Yu via Linux-f2fs-devel wrote: > > > > > > > On 4/3/26 22:40, Yongpeng Yang wrote: > > > > > > > > From: Yongpeng Yang > > > > > > > > = > > > > > > > > f2fs_destroy_extent_node() does not set FI_NO_EXTENT before= clearing > > > > > > > > extent nodes. When called from f2fs_drop_inode() with I_SYN= C set, > > > > > > > > concurrent kworker writeback can insert new extent nodes in= to the > > > > > > > > same > > > > > > > > extent tree, racing with the destroy and triggering f2fs_bu= g_on() in > > > > > > > > __destroy_extent_node(). The scenario is as follows: > > > > > > > > = > > > > > > > > drop inode=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 writeback > > > > > > > > =A0=A0=A0 - iput > > > > > > > > =A0=A0=A0=A0 - f2fs_drop_inode=A0 // I_SYNC set > > > > > > > > =A0=A0=A0=A0=A0 - f2fs_destroy_extent_node > > > > > > > > =A0=A0=A0=A0=A0=A0 - __destroy_extent_node > > > > > > > > =A0=A0=A0=A0=A0=A0=A0 - while (node_cnt) { > > > > > > > > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 write_lock(&et->lock) > > > > > > > > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 __free_extent_tree > > > > > > > > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 write_unlock(&et->lock) > > > > > > > > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 - __writ= eback_single_inode > > > > > > > > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 - f2f= s_outplace_write_data > > > > > > > > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 - > > > > > > > > f2fs_update_read_extent_cache > > > > > > > > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= - > > > > > > > > __update_extent_tree_range > > > > > > > > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0 // FI_NO_EXTENT not > > > > > > > > set, > > > > > > > > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0 // insert new extent > > > > > > > > node > > > > > > > > =A0=A0=A0=A0=A0=A0=A0=A0=A0 } // node_cnt =3D=3D 0, exit w= hile > > > > > > > > =A0=A0=A0=A0=A0=A0=A0 - f2fs_bug_on(node_cnt)=A0 // node_c= nt > 0 > > > > > > > > = > > > > > > > > Additionally, __update_extent_tree_range() only checks > > > > > > > > FI_NO_EXTENT for > > > > > > > > EX_READ type, leaving EX_BLOCK_AGE updates completely unpro= tected. > > > > > > > > = > > > > > > > > This patch set FI_NO_EXTENT under et->lock in > > > > > > > > __destroy_extent_node(), > > > > > > > > consistent with other callers (__update_extent_tree_range a= nd > > > > > > > > __drop_extent_tree) and check FI_NO_EXTENT for both EX_READ= and > > > > > > > > EX_BLOCK_AGE tree. > > > > > > > = > > > > > > > I suffered below test failure, then I bisect to this change. > > > > > > > = > > > > > > > =A0=A0=A0=A0=A0 generic/475=A0 84s ... [failed, exit status = 1]- output mismatch > > > > > > > (see / > > > > > > > share/git/fstests/results//generic/475.out.bad) > > > > > > > =A0=A0=A0=A0=A0 --- tests/generic/475.out=A0=A0 2025-01-12 2= 1:57:40.279440664 +0800 > > > > > > > =A0=A0=A0=A0=A0 +++ /share/git/fstests/results//generic/475.= out.bad 2026-04-17 > > > > > > > 12:08:28.000000000 +0800 > > > > > > > =A0=A0=A0=A0=A0 @@ -1,2 +1,6 @@ > > > > > > > =A0=A0=A0=A0=A0=A0 QA output created by 475 > > > > > > > =A0=A0=A0=A0=A0=A0 Silence is golden. > > > > > > > =A0=A0=A0=A0=A0 +mount: /mnt/scratch_f2fs: mount system call= failed: Structure > > > > > > > needs > > > > > > > cleaning. > > > > > > > =A0=A0=A0=A0=A0 +=A0=A0=A0=A0=A0=A0 dmesg(1) may have more i= nformation after failed mount > > > > > > > system > > > > > > > call. > > > > > > > =A0=A0=A0=A0=A0 +mount failed > > > > > > > =A0=A0=A0=A0=A0 +(see /share/git/fstests/results//generic/47= 5.full for details) > > > > > > > =A0=A0=A0=A0=A0 ... > > > > > > > =A0=A0=A0=A0=A0 (Run 'diff -u /share/git/fstests/tests/gener= ic/475.out / > > > > > > > share/git/ > > > > > > > fstests/results//generic/475.out.bad'=A0 to see the entire di= ff) > > > > > > > = > > > > > > > = > > > > > > > =A0=A0=A0=A0=A0 generic/388=A0 73s ... [failed, exit status = 1]- output mismatch > > > > > > > (see / > > > > > > > share/git/fstests/results//generic/388.out.bad) > > > > > > > =A0=A0=A0=A0=A0 --- tests/generic/388.out=A0=A0 2025-01-12 2= 1:57:40.275440602 +0800 > > > > > > > =A0=A0=A0=A0=A0 +++ /share/git/fstests/results//generic/388.= out.bad 2026-04-17 > > > > > > > 11:58:05.000000000 +0800 > > > > > > > =A0=A0=A0=A0=A0 @@ -1,2 +1,6 @@ > > > > > > > =A0=A0=A0=A0=A0=A0 QA output created by 388 > > > > > > > =A0=A0=A0=A0=A0=A0 Silence is golden. > > > > > > > =A0=A0=A0=A0=A0 +mount: /mnt/scratch_f2fs: mount system call= failed: Structure > > > > > > > needs > > > > > > > cleaning. > > > > > > > =A0=A0=A0=A0=A0 +=A0=A0=A0=A0=A0=A0 dmesg(1) may have more i= nformation after failed mount > > > > > > > system > > > > > > > call. > > > > > > > =A0=A0=A0=A0=A0 +cycle mount failed > > > > > > > =A0=A0=A0=A0=A0 +(see /share/git/fstests/results//generic/38= 8.full for details) > > > > > > > =A0=A0=A0=A0=A0 ... > > > > > > > =A0=A0=A0=A0=A0 (Run 'diff -u /share/git/fstests/tests/gener= ic/388.out / > > > > > > > share/git/ > > > > > > > fstests/results//generic/388.out.bad'=A0 to see the entire di= ff) > > > > > > > = > > > > > > > = > > > > > > > =A0=A0=A0=A0=A0 F2FS-fs (dm-0): sanity_check_extent_cache: i= node (ino=3D1761) > > > > > > > extent > > > > > > > info [220057, 57, 6] is incorrect, run fsck to fix > > > > > > > = > > > > > > > I suspect we may miss any extent updates after we set FI_NO_E= XTENT in > > > > > > > __destroy_extent_node(), result in failing in > > > > > > > sanity_check_extent_cache(). > > > > > > > = > > > > > > > Can we just relocate f2fs_bug_on(node_cnt) rather than compli= cated > > > > > > > change? > > > > > > > Thoughts? > > > > > > = > > > > > > Oh, I overlooked largest extent. How about relocate > > > > > > f2fs_bug_on(node_cnt) to __destroy_extent_tree? > > > > > > = > > > > > > static void __destroy_extent_tree(struct inode *inode, enum ext= ent_type > > > > > > type) > > > > > > = > > > > > > =A0=A0=A0=A0=A0=A0=A0=A0=A0 /* free all extent info belong to = this extent tree */ > > > > > > =A0=A0=A0=A0=A0=A0=A0=A0=A0 node_cnt =3D __destroy_extent_node= (inode, type); > > > > > > +=A0=A0=A0=A0=A0=A0 f2fs_bug_on(sbi, atomic_read(&et->node_cnt)= ); > > > > > = > > > > > =A0 =A0=A0=A0=A0/* free all extent info belong to this extent tr= ee */ > > > > > =A0 =A0=A0=A0=A0node_cnt =3D __destroy_extent_node(inode, type); > > > > > = > > > > > =A0 =A0=A0=A0=A0/* delete extent tree entry in radix tree */ > > > > > =A0 =A0=A0=A0=A0mutex_lock(&eti->extent_tree_lock); > > > > > =A0 =A0=A0=A0=A0f2fs_bug_on(sbi, atomic_read(&et->node_cnt));=A0= <--- > > > > > = > > > > > Oh, it has already checked node_cnt, so, maybe we can just remove= the > > > > > check in > > > > > __destroy_extent_node()? > > > > = > > > > Yes. BTW, is it correct to remove the call to f2fs_destroy_extent_n= ode() > > > > in f2fs_drop_inode()? It seems this call is unnecessary, since > > > > f2fs_evict_inode() will eventually delete all extent nodes properly. > > > = > > > I think it's fine to keep it according to original intention "destroy > > > extent_tree for the truncation case" introduced from 3e72f721390d > > > ("f2fs: use extent_cache by default"). It helps the performance w/ > > > in batch extent node release. > > = > > Oh, I see. This patch has already been merged into the dev branch. Which > > of the following approaches would be more appropriate? > > 1. Drop the current patch from the dev branch, then submit a patch to > > remove the f2fs_bug_on() in __destroy_extent_node. > > 2. Send two patches: the first reverts the change, and the second > > removes the f2fs_bug_on() in __destroy_extent_node(). > = > It's near the end of merge window, I think we need to keep dev as > it is, and create another patch to revert previous change and drop > the f2fs_bug_on() as well, what do you think? Yes, I just sent a pull request. If the merge patch doesn't break anything, let's apply a new one only. > = > To Jaegeuk, thoughts? > = > Thanks, > = > > = > > Thanks > > Yongpeng, > > = > > > = > > > Thanks, > > > = > > > > = > > > > Thanks > > > > Yongpeng, > > > > = > > > > > = > > > > > Thanks, > > > > > = > > > > > = > > > > > > = > > > > > > Thanks > > > > > > Yongpeng, > > > > > > = > > > > > > > = > > > > > > > Thanks, > > > > > > > = > > > > > > > > = > > > > > > > > Fixes: 3fc5d5a182f6 ("f2fs: fix to shrink read extent node = in > > > > > > > > batches") > > > > > > > > Cc: stable@vger.kernel.org > > > > > > > > Signed-off-by: Yongpeng Yang > > > > > > > > --- > > > > > > > > =A0=A0=A0 fs/f2fs/extent_cache.c | 17 ++++++++++------- > > > > > > > > =A0=A0=A0 1 file changed, 10 insertions(+), 7 deletions(-) > > > > > > > > = > > > > > > > > diff --git a/fs/f2fs/extent_cache.c b/fs/f2fs/extent_cache.c > > > > > > > > index 0ed84cc065a7..87169fd29d89 100644 > > > > > > > > --- a/fs/f2fs/extent_cache.c > > > > > > > > +++ b/fs/f2fs/extent_cache.c > > > > > > > > @@ -119,9 +119,10 @@ static bool __may_extent_tree(struct i= node > > > > > > > > *inode, enum extent_type type) > > > > > > > > =A0=A0=A0=A0=A0=A0=A0 if (!__init_may_extent_tree(inode, t= ype)) > > > > > > > > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 return false; > > > > > > > > =A0=A0=A0 +=A0=A0=A0 if (is_inode_flag_set(inode, FI_NO_EX= TENT)) > > > > > > > > +=A0=A0=A0=A0=A0=A0=A0 return false; > > > > > > > > + > > > > > > > > =A0=A0=A0=A0=A0=A0=A0 if (type =3D=3D EX_READ) { > > > > > > > > -=A0=A0=A0=A0=A0=A0=A0 if (is_inode_flag_set(inode, FI_NO_E= XTENT)) > > > > > > > > -=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 return false; > > > > > > > > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 if (is_inode_flag_set(in= ode, FI_COMPRESSED_FILE) && > > > > > > > > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0 !f2fs_sb_has_readonly(F2FS_I_SB(inode))) > > > > > > > > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 return false; > > > > > > > > @@ -644,6 +645,8 @@ static unsigned int __destroy_extent_no= de(struct > > > > > > > > inode *inode, > > > > > > > > =A0=A0=A0 =A0=A0=A0=A0=A0 while (atomic_read(&et->node_cnt= )) { > > > > > > > > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 write_lock(&et->lock); > > > > > > > > +=A0=A0=A0=A0=A0=A0=A0 if (!is_inode_flag_set(inode, FI_NO_= EXTENT)) > > > > > > > > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 set_inode_flag(inode, FI= _NO_EXTENT); > > > > > > > > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 node_cnt +=3D __free_ext= ent_tree(sbi, et, nr_shrink); > > > > > > > > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 write_unlock(&et->lock); > > > > > > > > =A0=A0=A0=A0=A0=A0=A0 } > > > > > > > > @@ -688,12 +691,12 @@ static void __update_extent_tree_rang= e(struct > > > > > > > > inode *inode, > > > > > > > > =A0=A0=A0 =A0=A0=A0=A0=A0 write_lock(&et->lock); > > > > > > > > =A0=A0=A0 -=A0=A0=A0 if (type =3D=3D EX_READ) { > > > > > > > > -=A0=A0=A0=A0=A0=A0=A0 if (is_inode_flag_set(inode, FI_NO_E= XTENT)) { > > > > > > > > -=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 write_unlock(&et->lock); > > > > > > > > -=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 return; > > > > > > > > -=A0=A0=A0=A0=A0=A0=A0 } > > > > > > > > +=A0=A0=A0 if (is_inode_flag_set(inode, FI_NO_EXTENT)) { > > > > > > > > +=A0=A0=A0=A0=A0=A0=A0 write_unlock(&et->lock); > > > > > > > > +=A0=A0=A0=A0=A0=A0=A0 return; > > > > > > > > +=A0=A0=A0 } > > > > > > > > =A0=A0=A0 +=A0=A0=A0 if (type =3D=3D EX_READ) { > > > > > > > > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 prev =3D et->largest; > > > > > > > > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 dei.len =3D 0; > > > > > > > = > > > > > > > = > > > > > > > = > > = _______________________________________________ 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 smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 D85F22D23B9 for ; Tue, 21 Apr 2026 21:52:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776808323; cv=none; b=Ha6NT1HWH2dmufR9mybKXymlW8OKfX1p71dpc2iTN3CuNvSdVpoP2ukjoc2oGM85YmoZgGP4q1/YybZ+a2/VmUX2rmAgH6nijMMVrMJHk0J4mlHORUK120HhAQeE+4A3jr805ISgj3JKWReKRC+1rKU3BeST2bnyeHhJgSykRDg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776808323; c=relaxed/simple; bh=OlWtbmYbOWnAJpeScXahNQiA9AtqdGgQZoXaMjcy5tA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=lBXoCCU3QQThpDrgwkUVyD207uBWlvGgHfnnBrSx6QaVbofao16WOMxRZbhv1Jit0r5U+7FYcyJnz5mHEC0t32BjW9bFl9I9Y8lRxDm8sP7a7q/IZkK5Wp+7O0QDKx5Mfn0WwnM5IfS9oNksNXir0cx6MK2+8vF80WaXtgXQmlQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=skK3joQs; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="skK3joQs" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3F858C2BCB0; Tue, 21 Apr 2026 21:52:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776808323; bh=OlWtbmYbOWnAJpeScXahNQiA9AtqdGgQZoXaMjcy5tA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=skK3joQsw1DrbmsPot4bHmwLJukEtMwUCJ72ROrFtW4tv8Dzk+W1Zj+74kvzxq3FG UAKjA21KWp29UOwlnOg4Ypfxjs0LgAJ2Iugee6XhVZAK6/TQqhGUf5cYC9haXrCS0L yq6JeDNCuwlQSN/JOE0BK65HmBjJ+UhaMi87ixYFBKKqlUoZPNiW0+TclJq65LCRNq Hk+BX2Fy5LkhhLVFJZukTfUBbUzYX4bVUV1/f7oxJniS9YT83hZ/ATbYHUXna0bmz7 3wF4f7t/xGZQcUpN2LGnBpbaiXEVznIyQDZ5p5KiqjlqWocEUJGM+jPJ86TjudcDr6 hVWkoWlTi3jwA== Date: Tue, 21 Apr 2026 21:52:01 +0000 From: Jaegeuk Kim To: Chao Yu Cc: Yongpeng Yang , Yongpeng Yang , stable@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Subject: Re: [f2fs-dev] [PATCH] f2fs: fix node_cnt race between extent node destroy and writeback Message-ID: References: <20260403144015.221811-3-monty_pavel@sina.com> <5c222edf-6888-4007-9240-9e7988b2dc71@sina.com> <252cb446-e313-417b-b780-85dcdcf34a87@sina.com> <9b518ad1-18ad-4eb4-86d4-3a27e40a7635@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <9b518ad1-18ad-4eb4-86d4-3a27e40a7635@kernel.org> On 04/21, Chao Yu wrote: > On 4/21/2026 4:44 PM, Yongpeng Yang wrote: > > > > On 4/20/26 15:28, Chao Yu via Linux-f2fs-devel wrote: > > > On 4/19/2026 12:29 AM, Yongpeng Yang wrote: > > > > > > > > On 4/18/26 8:51 AM, Chao Yu via Linux-f2fs-devel wrote: > > > > > On 4/17/26 21:26, Yongpeng Yang wrote: > > > > > > > > > > > > On 4/17/26 17:00, Chao Yu via Linux-f2fs-devel wrote: > > > > > > > On 4/3/26 22:40, Yongpeng Yang wrote: > > > > > > > > From: Yongpeng Yang > > > > > > > > > > > > > > > > f2fs_destroy_extent_node() does not set FI_NO_EXTENT before clearing > > > > > > > > extent nodes. When called from f2fs_drop_inode() with I_SYNC set, > > > > > > > > concurrent kworker writeback can insert new extent nodes into the > > > > > > > > same > > > > > > > > extent tree, racing with the destroy and triggering f2fs_bug_on() in > > > > > > > > __destroy_extent_node(). The scenario is as follows: > > > > > > > > > > > > > > > > drop inode                            writeback > > > > > > > >     - iput > > > > > > > >      - f2fs_drop_inode  // I_SYNC set > > > > > > > >       - f2fs_destroy_extent_node > > > > > > > >        - __destroy_extent_node > > > > > > > >         - while (node_cnt) { > > > > > > > >            write_lock(&et->lock) > > > > > > > >            __free_extent_tree > > > > > > > >            write_unlock(&et->lock) > > > > > > > >                                           - __writeback_single_inode > > > > > > > >                                            - f2fs_outplace_write_data > > > > > > > >                                             - > > > > > > > > f2fs_update_read_extent_cache > > > > > > > >                                              - > > > > > > > > __update_extent_tree_range > > > > > > > >                                               // FI_NO_EXTENT not > > > > > > > > set, > > > > > > > >                                               // insert new extent > > > > > > > > node > > > > > > > >           } // node_cnt == 0, exit while > > > > > > > >         - f2fs_bug_on(node_cnt)  // node_cnt > 0 > > > > > > > > > > > > > > > > Additionally, __update_extent_tree_range() only checks > > > > > > > > FI_NO_EXTENT for > > > > > > > > EX_READ type, leaving EX_BLOCK_AGE updates completely unprotected. > > > > > > > > > > > > > > > > This patch set FI_NO_EXTENT under et->lock in > > > > > > > > __destroy_extent_node(), > > > > > > > > consistent with other callers (__update_extent_tree_range and > > > > > > > > __drop_extent_tree) and check FI_NO_EXTENT for both EX_READ and > > > > > > > > EX_BLOCK_AGE tree. > > > > > > > > > > > > > > I suffered below test failure, then I bisect to this change. > > > > > > > > > > > > > >       generic/475  84s ... [failed, exit status 1]- output mismatch > > > > > > > (see / > > > > > > > share/git/fstests/results//generic/475.out.bad) > > > > > > >       --- tests/generic/475.out   2025-01-12 21:57:40.279440664 +0800 > > > > > > >       +++ /share/git/fstests/results//generic/475.out.bad 2026-04-17 > > > > > > > 12:08:28.000000000 +0800 > > > > > > >       @@ -1,2 +1,6 @@ > > > > > > >        QA output created by 475 > > > > > > >        Silence is golden. > > > > > > >       +mount: /mnt/scratch_f2fs: mount system call failed: Structure > > > > > > > needs > > > > > > > cleaning. > > > > > > >       +       dmesg(1) may have more information after failed mount > > > > > > > system > > > > > > > call. > > > > > > >       +mount failed > > > > > > >       +(see /share/git/fstests/results//generic/475.full for details) > > > > > > >       ... > > > > > > >       (Run 'diff -u /share/git/fstests/tests/generic/475.out / > > > > > > > share/git/ > > > > > > > fstests/results//generic/475.out.bad'  to see the entire diff) > > > > > > > > > > > > > > > > > > > > >       generic/388  73s ... [failed, exit status 1]- output mismatch > > > > > > > (see / > > > > > > > share/git/fstests/results//generic/388.out.bad) > > > > > > >       --- tests/generic/388.out   2025-01-12 21:57:40.275440602 +0800 > > > > > > >       +++ /share/git/fstests/results//generic/388.out.bad 2026-04-17 > > > > > > > 11:58:05.000000000 +0800 > > > > > > >       @@ -1,2 +1,6 @@ > > > > > > >        QA output created by 388 > > > > > > >        Silence is golden. > > > > > > >       +mount: /mnt/scratch_f2fs: mount system call failed: Structure > > > > > > > needs > > > > > > > cleaning. > > > > > > >       +       dmesg(1) may have more information after failed mount > > > > > > > system > > > > > > > call. > > > > > > >       +cycle mount failed > > > > > > >       +(see /share/git/fstests/results//generic/388.full for details) > > > > > > >       ... > > > > > > >       (Run 'diff -u /share/git/fstests/tests/generic/388.out / > > > > > > > share/git/ > > > > > > > fstests/results//generic/388.out.bad'  to see the entire diff) > > > > > > > > > > > > > > > > > > > > >       F2FS-fs (dm-0): sanity_check_extent_cache: inode (ino=1761) > > > > > > > extent > > > > > > > info [220057, 57, 6] is incorrect, run fsck to fix > > > > > > > > > > > > > > I suspect we may miss any extent updates after we set FI_NO_EXTENT in > > > > > > > __destroy_extent_node(), result in failing in > > > > > > > sanity_check_extent_cache(). > > > > > > > > > > > > > > Can we just relocate f2fs_bug_on(node_cnt) rather than complicated > > > > > > > change? > > > > > > > Thoughts? > > > > > > > > > > > > Oh, I overlooked largest extent. How about relocate > > > > > > f2fs_bug_on(node_cnt) to __destroy_extent_tree? > > > > > > > > > > > > static void __destroy_extent_tree(struct inode *inode, enum extent_type > > > > > > type) > > > > > > > > > > > >           /* free all extent info belong to this extent tree */ > > > > > >           node_cnt = __destroy_extent_node(inode, type); > > > > > > +       f2fs_bug_on(sbi, atomic_read(&et->node_cnt)); > > > > > > > > > >       /* free all extent info belong to this extent tree */ > > > > >       node_cnt = __destroy_extent_node(inode, type); > > > > > > > > > >       /* delete extent tree entry in radix tree */ > > > > >       mutex_lock(&eti->extent_tree_lock); > > > > >       f2fs_bug_on(sbi, atomic_read(&et->node_cnt));  <--- > > > > > > > > > > Oh, it has already checked node_cnt, so, maybe we can just remove the > > > > > check in > > > > > __destroy_extent_node()? > > > > > > > > Yes. BTW, is it correct to remove the call to f2fs_destroy_extent_node() > > > > in f2fs_drop_inode()? It seems this call is unnecessary, since > > > > f2fs_evict_inode() will eventually delete all extent nodes properly. > > > > > > I think it's fine to keep it according to original intention "destroy > > > extent_tree for the truncation case" introduced from 3e72f721390d > > > ("f2fs: use extent_cache by default"). It helps the performance w/ > > > in batch extent node release. > > > > Oh, I see. This patch has already been merged into the dev branch. Which > > of the following approaches would be more appropriate? > > 1. Drop the current patch from the dev branch, then submit a patch to > > remove the f2fs_bug_on() in __destroy_extent_node. > > 2. Send two patches: the first reverts the change, and the second > > removes the f2fs_bug_on() in __destroy_extent_node(). > > It's near the end of merge window, I think we need to keep dev as > it is, and create another patch to revert previous change and drop > the f2fs_bug_on() as well, what do you think? Yes, I just sent a pull request. If the merge patch doesn't break anything, let's apply a new one only. > > To Jaegeuk, thoughts? > > Thanks, > > > > > Thanks > > Yongpeng, > > > > > > > > Thanks, > > > > > > > > > > > Thanks > > > > Yongpeng, > > > > > > > > > > > > > > Thanks, > > > > > > > > > > > > > > > > > > > > > > Thanks > > > > > > Yongpeng, > > > > > > > > > > > > > > > > > > > > Thanks, > > > > > > > > > > > > > > > > > > > > > > > Fixes: 3fc5d5a182f6 ("f2fs: fix to shrink read extent node in > > > > > > > > batches") > > > > > > > > Cc: stable@vger.kernel.org > > > > > > > > Signed-off-by: Yongpeng Yang > > > > > > > > --- > > > > > > > >     fs/f2fs/extent_cache.c | 17 ++++++++++------- > > > > > > > >     1 file changed, 10 insertions(+), 7 deletions(-) > > > > > > > > > > > > > > > > diff --git a/fs/f2fs/extent_cache.c b/fs/f2fs/extent_cache.c > > > > > > > > index 0ed84cc065a7..87169fd29d89 100644 > > > > > > > > --- a/fs/f2fs/extent_cache.c > > > > > > > > +++ b/fs/f2fs/extent_cache.c > > > > > > > > @@ -119,9 +119,10 @@ static bool __may_extent_tree(struct inode > > > > > > > > *inode, enum extent_type type) > > > > > > > >         if (!__init_may_extent_tree(inode, type)) > > > > > > > >             return false; > > > > > > > >     +    if (is_inode_flag_set(inode, FI_NO_EXTENT)) > > > > > > > > +        return false; > > > > > > > > + > > > > > > > >         if (type == EX_READ) { > > > > > > > > -        if (is_inode_flag_set(inode, FI_NO_EXTENT)) > > > > > > > > -            return false; > > > > > > > >             if (is_inode_flag_set(inode, FI_COMPRESSED_FILE) && > > > > > > > >                      !f2fs_sb_has_readonly(F2FS_I_SB(inode))) > > > > > > > >                 return false; > > > > > > > > @@ -644,6 +645,8 @@ static unsigned int __destroy_extent_node(struct > > > > > > > > inode *inode, > > > > > > > >           while (atomic_read(&et->node_cnt)) { > > > > > > > >             write_lock(&et->lock); > > > > > > > > +        if (!is_inode_flag_set(inode, FI_NO_EXTENT)) > > > > > > > > +            set_inode_flag(inode, FI_NO_EXTENT); > > > > > > > >             node_cnt += __free_extent_tree(sbi, et, nr_shrink); > > > > > > > >             write_unlock(&et->lock); > > > > > > > >         } > > > > > > > > @@ -688,12 +691,12 @@ static void __update_extent_tree_range(struct > > > > > > > > inode *inode, > > > > > > > >           write_lock(&et->lock); > > > > > > > >     -    if (type == EX_READ) { > > > > > > > > -        if (is_inode_flag_set(inode, FI_NO_EXTENT)) { > > > > > > > > -            write_unlock(&et->lock); > > > > > > > > -            return; > > > > > > > > -        } > > > > > > > > +    if (is_inode_flag_set(inode, FI_NO_EXTENT)) { > > > > > > > > +        write_unlock(&et->lock); > > > > > > > > +        return; > > > > > > > > +    } > > > > > > > >     +    if (type == EX_READ) { > > > > > > > >             prev = et->largest; > > > > > > > >             dei.len = 0; > > > > > > > > > > > > > > > > > > > > > > >