From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796093690; b=fh6YQd7UKurZwHAU8Cri2fkOzd+IwHcfNgbPh0VqsoRQwnPFHFXwPM+0VWqnk6l7EnuX dgL++8uu9pX2MAhNJF7OxZHZJJCPH82NeARkMBhkMB1TkrCjZDXReLFj2e/n/ji23nAcm WLkNUOJ2EiHM8/ZcWrd3V+OnfVieBT4V8+fC3aNg2QC+rbxKOaAjdYAIMDrmfWjXV/eaE IpvgIpmHJ7xc30Qy/vnpIAYvVyt6JSIGRJnwgbM7MjrX8KvVVLxrj8WYG7Mm/SQxzWpUP pkaU12T4xiC6US7dqWnYLV1eOJDuI5zzU7pooVizDj2V0SCnXJWbQBdVYylQFmDdFuQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796093690; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=gu7ZgSelnzzn5d6ReK48fTgtckcAMYexQMZqSTWcnvI=; b=EJneQUSy0yCPI/XnebnisZ/rGmYUnmCdoodYugmh4SpgHOc26Cuw2lP8tzE0G339XAL9 4qWbOD6A5LigjZLw9qWTc9SmtKSli+jhoqYxebWZxjrtkAOnu++wAFimkAekJCGrTYhxk cSDwAV/O1feK81kGb03TRx3JmkFF4qSQnIfRs6jsPX4ON2uK+lSGZDNdhMiTB2Qx8S2Ts mK+4mRYma7Bq+cQ+6CwiMSZu1yGGF0UDZQD5YVGp2/Gbljk7UYUdxvDql/lh3a3Dv5huq gxWHExDitOORXSgo/aF2aJ6wAeuP4enuDOPIRsbqLsCZpB9cGMxHHxDnOefapACA2XA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=lQ0WUCaz; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 204E2606A31A; Tue, 1 Dec 2026 02:54:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=lQ0WUCaz Received: by smtp.kernel.org (Postfix) with ESMTPSA id 830FB1F000C1; Tue, 1 Dec 2026 02:54:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796093689; bh=gu7ZgSelnzzn5d6ReK48fTgtckcAMYexQMZqSTWcnvI=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=lQ0WUCazDSKChzQJmK2UlH8Z1Tggx5CqO+aCnCKcosTecX2EeVcrczux0ZO1k2e7F jRLdd/+jjF5qKHSdC2HwLBg05qmAtnEcgS9n2G6rrpLI0bL7WrMuInwxbPcE/+zAJp lAuLmhXg6x5lbQMEY3s/tdOSY+fDFQKpeC7lIJXtdMY8t7NyQT42/p6FlWaXTX5r+t vIzUSzt4dVR1s/cSF4SzFhjDFsLdy934r6lQbJEcVmDew63Dir5wISCzDNLJv4Q4M1 mx0N9N9GvLN4+SYD07DmfB16MIacOJcaKv8HtbDf3Pdevs7qARhSSBFzYB9p81DEgW L3b0tENarscEA== Date: Tue, 1 Dec 2026 02:54:48 +0000 From: Jaegeuk Kim To: Chao Yu Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Subject: Re: [f2fs-dev] [PATCH v2 4/7] f2fs: fix to truncate stale meta cache entry on in-place update Message-ID: References: <20261127105608.537148-8-chao@kernel.org> <20261127105608.537148-11-chao@kernel.org> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261127105608.537148-11-chao@kernel.org> Hi Chao, Let's consider this along with 6/7 patch. On 11/27, Chao Yu via Linux-f2fs-devel wrote: > From: Chao Yu > > GC migrates data blocks of the inode which requires meta inode GC via > meta cache, and it trusts an uptodate entry w/o reading the block from > disk again, in both ra_data_block() and move_data_block(). > > However, in-place update paths only truncate the entry if the inode > requires meta inode GC at the time of writing: > - f2fs_inplace_write_data() checks fio->meta_gc > - f2fs_wait_on_block_writeback_range() for DIO checks > f2fs_meta_inode_gc_required() > > f2fs_meta_inode_gc_required() returns true for atomic and COW files, > which is a temporary state, so an entry cached during atomic write, or > cached before the block was donated by F2FS_IOC_MOVE_RANGE, can survive > in-place update once the owner does not require meta inode GC, then GC > will migrate stale data from the entry once the owner requires meta > inode GC again, resulting in overwriting valid data. > > Case #1: atomic write > > - App (file F) - GC > - ioctl(F2FS_IOC_START_ATOMIC_WRITE) > : f2fs_meta_inode_gc_required(F) is true > - write F[k], k != j > - gc_data_segment() phase 3 > - ra_data_block(F, j) > : cache F[j] in META[P] > - ioctl(F2FS_IOC_COMMIT_ATOMIC_WRITE) > - f2fs_commit_atomic_write() > - f2fs_down_write(i_gc_rwsem[WRITE]) > - gc_data_segment() phase 4 > - f2fs_down_write_trylock(i_gc_rwsem[WRITE]) > : fail, skip F[j] > - __f2fs_commit_atomic_write() > : only F[k] is replaced, F[j] is still mapped to P > - f2fs_up_write(i_gc_rwsem[WRITE]) > - f2fs_abort_atomic_write() > - clear_inode_flag(FI_ATOMIC_FILE) > - write F[j] w/ new data, fdatasync() > - f2fs_inplace_write_data() > : fio->meta_gc is false, META[P] becomes stale > - ioctl(F2FS_IOC_START_ATOMIC_WRITE) > - gc_data_segment() phase 3 > - ra_data_block(F, j) > : META[P] is uptodate, skip reading > - gc_data_segment() phase 4 > - move_data_block(F, j) > : META[P] is uptodate, skip reading > - memcpy(tentry, sentry) > - f2fs_update_data_blkaddr(newaddr) > : F[j] was rolled back to old data > > Case #2: F2FS_IOC_MOVE_RANGE > > - Thread A (src) - GC - Thread B (dst) > - write src[i], P is not checkpointed > - ioctl(F2FS_IOC_START_ATOMIC_WRITE) > - gc_data_segment() phase 3 > - ra_data_block(src, i) > : cache src[i] in META[P] > - gc_data_segment() phase 4 > : fail to lock i_gc_rwsem, skip src[i] > - ioctl(F2FS_IOC_ABORT_ATOMIC_WRITE) > - f2fs_abort_atomic_write() > - clear_inode_flag(FI_ATOMIC_FILE) > - ioctl(F2FS_IOC_MOVE_RANGE, src[i] -> dst[j]) > - f2fs_move_file_range() > - __exchange_data_block() > - __read_out_blkaddrs() > : P is not checkpointed, do not invalidate it > - __clone_blkaddrs() > - f2fs_replace_block(dst[j], P) > - write dst[j] w/ new data, fdatasync() > - f2fs_inplace_write_data() > : fio->meta_gc is false, META[P] becomes stale > - ioctl(F2FS_IOC_START_ATOMIC_WRITE) > - gc_data_segment() > - ra_data_block(dst, j) > - move_data_block(dst, j) > : migrate stale data in META[P] > : dst[j] was overwritten w/ src[i]'s old data > > DIO overwrite has the same issue, since f2fs_map_blocks() w/ > F2FS_GET_BLOCK_DIO calls f2fs_wait_on_block_writeback_range() for the > block which will be overwritten in place. > > Before commit 570e2ccc7cb3 ("f2fs: avoid reading already updated pages > during GC"), ra_data_block() always read the block from disk, then the > stale entry would be updated before move_data_block() used it. > > Let's always truncate the meta cache entry in f2fs_inplace_write_data() > and f2fs_wait_on_block_writeback_range() regardless of current state of > the inode, and only wait for writeback of the cache entry when the inode > requires meta inode GC. > > Cc: stable@vger.kernel.org > Fixes: b40a2b003709 ("f2fs: use meta inode for GC of atomic file") > Signed-off-by: Chao Yu > --- > v2: > - rebase to the latest dev-test branch. > > fs/f2fs/segment.c | 23 ++++++++++++++++------- > 1 file changed, 16 insertions(+), 7 deletions(-) > > diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c > index 73dc88aa6dde..1bfe1802f7dd 100644 > --- a/fs/f2fs/segment.c > +++ b/fs/f2fs/segment.c > @@ -4305,8 +4305,13 @@ int f2fs_inplace_write_data(struct f2fs_io_info *fio) > goto drop_bio; > } > > - if (fio->meta_gc) > - f2fs_truncate_meta_caches(sbi, fio->new_blkaddr, 1); > + /* > + * GC may have cached this block in meta cache while its owner was in > + * atomic write or before it was donated by F2FS_IOC_MOVE_RANGE, so > + * truncate it regardless of fio->meta_gc to avoid that GC migrates > + * stale data from meta cache later. > + */ > + f2fs_truncate_meta_caches(sbi, fio->new_blkaddr, 1); > > stat_inc_inplace_blocks(fio->sbi); > > @@ -4494,12 +4499,16 @@ void f2fs_wait_on_block_writeback_range(struct inode *inode, block_t blkaddr, > struct f2fs_sb_info *sbi = F2FS_I_SB(inode); > block_t i; > > - if (!f2fs_meta_inode_gc_required(inode)) > - return; > - > - for (i = 0; i < len; i++) > - f2fs_wait_on_block_writeback(inode, blkaddr + i); > + if (f2fs_meta_inode_gc_required(inode)) { > + for (i = 0; i < len; i++) > + f2fs_wait_on_block_writeback(inode, blkaddr + i); > + } > > + /* > + * GC may have cached these blocks in meta cache while their owner > + * required meta inode GC, truncate them regardless of current state > + * of the inode, since DIO may overwrite them in place. > + */ > f2fs_truncate_meta_caches(sbi, blkaddr, len); > } > > -- > 2.49.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 lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E57C606A31A for ; Tue, 1 Dec 2026 02:55:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=lists.sourceforge.net header.i=@lists.sourceforge.net header.a=rsa-sha256 header.s=beta header.b=GD2bwrfw; dkim=fail reason="signature verification failed" (1024-bit key, unprotected) header.d=sourceforge.net header.i=@sourceforge.net header.a=rsa-sha256 header.s=x header.b=LHRad1SZ; dkim=fail reason="signature verification failed" (1024-bit key, unprotected) header.d=sf.net header.i=@sf.net header.a=rsa-sha256 header.s=x header.b=WcoYkQPJ; dkim=neutral header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=lQ0WUCaz 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-Unsubscribe-Post:List-Owner; bh=TQkmGx+CwgkLjSuFl/7+k1hxL6hEpsq7/ajqG1e4X+I=; b=GD2bwrfw1nmPxEGFUIrEwJNsmG es9IqJOCd0u7iPr5OpzwGZ77QZ6qTVblIyebtmkb9S9U6PRV+61ZkuMZxWjlCeT2OxY8zSvs7iYWb sGoym+wW4x5LH1kTRHQZHUJlnO1zu1fh79orz4CuaeB++OYnkYQlr95K3Z44BoHIhODo=; Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.100.1) (envelope-from ) id 1xYE1C-000000002Em-3oBG; Tue, 01 Dec 2026 02:54:58 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.100.1) (envelope-from ) id 1xYE1B-000000002Ef-15cB for linux-f2fs-devel@lists.sourceforge.net; Tue, 01 Dec 2026 02:54:57 +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-Unsubscribe-Post:List-Subscribe:List-Post:List-Owner:List-Archive; bh=gu7ZgSelnzzn5d6ReK48fTgtckcAMYexQMZqSTWcnvI=; b=LHRad1SZtnTmUyFf6vjDIz9RM5 psqgA1ZvUP0DnnQ/hHFIS05hC4VewzlJOPUE3fRlDNFKkjf/edi33z0R/ZBhxEHAUGmGDhCn1atw1 P2627vLN0+lsx06WL/w4fgl9B5L/wLMqxkS/66biEH/8zb1/7WWvU0ftvBFkqeMzYiZc=; 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-Unsubscribe-Post: List-Subscribe:List-Post:List-Owner:List-Archive; bh=gu7ZgSelnzzn5d6ReK48fTgtckcAMYexQMZqSTWcnvI=; b=WcoYkQPJ7WU2W0Oqs/UUmKAYRN sHzWH3AjxxEOwtTKiguMKAHi+QMawsA/zsmkdrb1PKbx3Wg6aNRWHk6YkgQRtnF9S9hlHsDz7u/7P aFjxbcRadcH5CE0bpH7mqbhujYgqZPSPfLdhz+BiK+lV1ildo0LvKEfJ7GjbtFO8mSj0=; Received: from tor.source.kernel.org ([172.105.4.254]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xYE19-000000001lQ-3Pkg for linux-f2fs-devel@lists.sourceforge.net; Tue, 01 Dec 2026 02:54:57 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id F34CF60ED1 for ; Tue, 1 Dec 2026 02:54:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 830FB1F000C1; Tue, 1 Dec 2026 02:54:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796093689; bh=gu7ZgSelnzzn5d6ReK48fTgtckcAMYexQMZqSTWcnvI=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=lQ0WUCazDSKChzQJmK2UlH8Z1Tggx5CqO+aCnCKcosTecX2EeVcrczux0ZO1k2e7F jRLdd/+jjF5qKHSdC2HwLBg05qmAtnEcgS9n2G6rrpLI0bL7WrMuInwxbPcE/+zAJp lAuLmhXg6x5lbQMEY3s/tdOSY+fDFQKpeC7lIJXtdMY8t7NyQT42/p6FlWaXTX5r+t vIzUSzt4dVR1s/cSF4SzFhjDFsLdy934r6lQbJEcVmDew63Dir5wISCzDNLJv4Q4M1 mx0N9N9GvLN4+SYD07DmfB16MIacOJcaKv8HtbDf3Pdevs7qARhSSBFzYB9p81DEgW L3b0tENarscEA== Date: Tue, 1 Dec 2026 02:54:48 +0000 To: Chao Yu Message-ID: References: <20261127105608.537148-8-chao@kernel.org> <20261127105608.537148-11-chao@kernel.org> X-Archived-By: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20261127105608.537148-11-chao@kernel.org> X-Spam-Score: -0.2 (/) X-Headers-End: 1xYE19-000000001lQ-3Pkg Subject: Re: [f2fs-dev] [PATCH v2 4/7] f2fs: fix to truncate stale meta cache entry on in-place update X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , From: Jaegeuk Kim via Linux-f2fs-devel Reply-To: Jaegeuk Kim Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-16.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Hi Chao, Let's consider this along with 6/7 patch. On 11/27, Chao Yu via Linux-f2fs-devel wrote: > From: Chao Yu > > GC migrates data blocks of the inode which requires meta inode GC via > meta cache, and it trusts an uptodate entry w/o reading the block from > disk again, in both ra_data_block() and move_data_block(). > > However, in-place update paths only truncate the entry if the inode > requires meta inode GC at the time of writing: > - f2fs_inplace_write_data() checks fio->meta_gc > - f2fs_wait_on_block_writeback_range() for DIO checks > f2fs_meta_inode_gc_required() > > f2fs_meta_inode_gc_required() returns true for atomic and COW files, > which is a temporary state, so an entry cached during atomic write, or > cached before the block was donated by F2FS_IOC_MOVE_RANGE, can survive > in-place update once the owner does not require meta inode GC, then GC > will migrate stale data from the entry once the owner requires meta > inode GC again, resulting in overwriting valid data. > > Case #1: atomic write > > - App (file F) - GC > - ioctl(F2FS_IOC_START_ATOMIC_WRITE) > : f2fs_meta_inode_gc_required(F) is true > - write F[k], k != j > - gc_data_segment() phase 3 > - ra_data_block(F, j) > : cache F[j] in META[P] > - ioctl(F2FS_IOC_COMMIT_ATOMIC_WRITE) > - f2fs_commit_atomic_write() > - f2fs_down_write(i_gc_rwsem[WRITE]) > - gc_data_segment() phase 4 > - f2fs_down_write_trylock(i_gc_rwsem[WRITE]) > : fail, skip F[j] > - __f2fs_commit_atomic_write() > : only F[k] is replaced, F[j] is still mapped to P > - f2fs_up_write(i_gc_rwsem[WRITE]) > - f2fs_abort_atomic_write() > - clear_inode_flag(FI_ATOMIC_FILE) > - write F[j] w/ new data, fdatasync() > - f2fs_inplace_write_data() > : fio->meta_gc is false, META[P] becomes stale > - ioctl(F2FS_IOC_START_ATOMIC_WRITE) > - gc_data_segment() phase 3 > - ra_data_block(F, j) > : META[P] is uptodate, skip reading > - gc_data_segment() phase 4 > - move_data_block(F, j) > : META[P] is uptodate, skip reading > - memcpy(tentry, sentry) > - f2fs_update_data_blkaddr(newaddr) > : F[j] was rolled back to old data > > Case #2: F2FS_IOC_MOVE_RANGE > > - Thread A (src) - GC - Thread B (dst) > - write src[i], P is not checkpointed > - ioctl(F2FS_IOC_START_ATOMIC_WRITE) > - gc_data_segment() phase 3 > - ra_data_block(src, i) > : cache src[i] in META[P] > - gc_data_segment() phase 4 > : fail to lock i_gc_rwsem, skip src[i] > - ioctl(F2FS_IOC_ABORT_ATOMIC_WRITE) > - f2fs_abort_atomic_write() > - clear_inode_flag(FI_ATOMIC_FILE) > - ioctl(F2FS_IOC_MOVE_RANGE, src[i] -> dst[j]) > - f2fs_move_file_range() > - __exchange_data_block() > - __read_out_blkaddrs() > : P is not checkpointed, do not invalidate it > - __clone_blkaddrs() > - f2fs_replace_block(dst[j], P) > - write dst[j] w/ new data, fdatasync() > - f2fs_inplace_write_data() > : fio->meta_gc is false, META[P] becomes stale > - ioctl(F2FS_IOC_START_ATOMIC_WRITE) > - gc_data_segment() > - ra_data_block(dst, j) > - move_data_block(dst, j) > : migrate stale data in META[P] > : dst[j] was overwritten w/ src[i]'s old data > > DIO overwrite has the same issue, since f2fs_map_blocks() w/ > F2FS_GET_BLOCK_DIO calls f2fs_wait_on_block_writeback_range() for the > block which will be overwritten in place. > > Before commit 570e2ccc7cb3 ("f2fs: avoid reading already updated pages > during GC"), ra_data_block() always read the block from disk, then the > stale entry would be updated before move_data_block() used it. > > Let's always truncate the meta cache entry in f2fs_inplace_write_data() > and f2fs_wait_on_block_writeback_range() regardless of current state of > the inode, and only wait for writeback of the cache entry when the inode > requires meta inode GC. > > Cc: stable@vger.kernel.org > Fixes: b40a2b003709 ("f2fs: use meta inode for GC of atomic file") > Signed-off-by: Chao Yu > --- > v2: > - rebase to the latest dev-test branch. > > fs/f2fs/segment.c | 23 ++++++++++++++++------- > 1 file changed, 16 insertions(+), 7 deletions(-) > > diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c > index 73dc88aa6dde..1bfe1802f7dd 100644 > --- a/fs/f2fs/segment.c > +++ b/fs/f2fs/segment.c > @@ -4305,8 +4305,13 @@ int f2fs_inplace_write_data(struct f2fs_io_info *fio) > goto drop_bio; > } > > - if (fio->meta_gc) > - f2fs_truncate_meta_caches(sbi, fio->new_blkaddr, 1); > + /* > + * GC may have cached this block in meta cache while its owner was in > + * atomic write or before it was donated by F2FS_IOC_MOVE_RANGE, so > + * truncate it regardless of fio->meta_gc to avoid that GC migrates > + * stale data from meta cache later. > + */ > + f2fs_truncate_meta_caches(sbi, fio->new_blkaddr, 1); > > stat_inc_inplace_blocks(fio->sbi); > > @@ -4494,12 +4499,16 @@ void f2fs_wait_on_block_writeback_range(struct inode *inode, block_t blkaddr, > struct f2fs_sb_info *sbi = F2FS_I_SB(inode); > block_t i; > > - if (!f2fs_meta_inode_gc_required(inode)) > - return; > - > - for (i = 0; i < len; i++) > - f2fs_wait_on_block_writeback(inode, blkaddr + i); > + if (f2fs_meta_inode_gc_required(inode)) { > + for (i = 0; i < len; i++) > + f2fs_wait_on_block_writeback(inode, blkaddr + i); > + } > > + /* > + * GC may have cached these blocks in meta cache while their owner > + * required meta inode GC, truncate them regardless of current state > + * of the inode, since DIO may overwrite them in place. > + */ > f2fs_truncate_meta_caches(sbi, blkaddr, len); > } > > -- > 2.49.0 > > > > _______________________________________________ > Linux-f2fs-devel mailing list > Linux-f2fs-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel