From patchwork Wed Jul 10 11:51:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sunmin Jeong X-Patchwork-Id: 13729233 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 8EB2CC3DA42 for ; Wed, 10 Jul 2024 11:51:57 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1sRVrW-0001Wc-MP; Wed, 10 Jul 2024 11:51:55 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1sRVrU-0001WW-A5 for linux-f2fs-devel@lists.sourceforge.net; Wed, 10 Jul 2024 11:51:52 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=References:Content-Type:Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=gHyPzavtAOhMzF5x0uy9TBspB1xqaBsxD/vJYPsXsds=; b=beqkfDPmfOhCfJ70xeW+nys/bj d2kfPcSaafSjnmxkrZmjkOj2euI2bV6X5EypOtD7lpKeYHq3e979QJKN9l/7QVTOMyQRyHi+LJY9N RGCZ8w2Fct/+Mmhz3UaJInrx3Pc2Hc2zktDwsht8E0kTZ/mLNTX6Ks3iD1UaykzezuHI=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=References:Content-Type:Content-Transfer-Encoding:MIME-Version:Message-Id :Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=gHyPzavtAOhMzF5x0uy9TBspB1xqaBsxD/vJYPsXsds=; b=m pP5aFzbnT03alxy12KrHx5jnKcDSo4zAfgudtWJ1vtKK9/E57y1HnP+Boxs9jLx+fAxQupwHT7GWm zUH/S4BpSnh441sTLAF1cZ5XwIRzUy7Luj6OvAA/o8osQ0KNS2fuqe0pK9w/nwnCoF7n9aTEfa5zn qAjDBNUvfhUGvD3U=; Received: from mailout4.samsung.com ([203.254.224.34]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1sRVrT-0003ZK-Si for linux-f2fs-devel@lists.sourceforge.net; Wed, 10 Jul 2024 11:51:52 +0000 Received: from epcas1p2.samsung.com (unknown [182.195.41.46]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20240710115139epoutp046f5f0350c0f218f812c5d05bf4115580~g18UXnVbN0787507875epoutp04R for ; Wed, 10 Jul 2024 11:51:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20240710115139epoutp046f5f0350c0f218f812c5d05bf4115580~g18UXnVbN0787507875epoutp04R DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1720612299; bh=gHyPzavtAOhMzF5x0uy9TBspB1xqaBsxD/vJYPsXsds=; h=From:To:Cc:Subject:Date:References:From; b=GIK4I1C3brbFHrro43vjvkil4kTzzqHYxgZSc6BB9B1KaltAqXuMwbvI6LIozEzE5 hkkE1nhG+ANbmMq+8S6+20LFPT1Xn5gnja+0pbzo2k2Pg3S6o5ARJRlzn2GpGiYb3G h2hTGy4pajQ5ouEUG8glHC28MSgQD0YAQMxJmkpQ= Received: from epsnrtp2.localdomain (unknown [182.195.42.163]) by epcas1p4.samsung.com (KnoxPortal) with ESMTP id 20240710115138epcas1p45bc8e7295f85312cbe73f9f9ca4196eb~g18T9MZTu0117501175epcas1p4B; Wed, 10 Jul 2024 11:51:38 +0000 (GMT) Received: from epsmgec1p1-new.samsung.com (unknown [182.195.36.227]) by epsnrtp2.localdomain (Postfix) with ESMTP id 4WJx622jt4z4x9Pv; Wed, 10 Jul 2024 11:51:38 +0000 (GMT) Received: from epcas1p1.samsung.com ( [182.195.41.45]) by epsmgec1p1-new.samsung.com (Symantec Messaging Gateway) with SMTP id 30.B8.19059.AC57E866; Wed, 10 Jul 2024 20:51:38 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas1p2.samsung.com (KnoxPortal) with ESMTPA id 20240710115137epcas1p2ee192f1264c9570c416c706ffa7c23e8~g18SnmrPh1079710797epcas1p2t; Wed, 10 Jul 2024 11:51:37 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20240710115137epsmtrp16b3fde47d90d1ad54b364db5bad011bc~g18Sm7cWW0340803408epsmtrp1i; Wed, 10 Jul 2024 11:51:37 +0000 (GMT) X-AuditID: b6c32a4c-bb9ff70000004a73-e4-668e75ca0352 Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 6A.D6.29940.9C57E866; Wed, 10 Jul 2024 20:51:37 +0900 (KST) Received: from localhost.localdomain (unknown [10.253.98.34]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20240710115137epsmtip1e168ed4f7663dfbdc417c370d5c6c533~g18SZIxrg0402204022epsmtip1E; Wed, 10 Jul 2024 11:51:37 +0000 (GMT) From: Sunmin Jeong To: jaegeuk@kernel.org, chao@kernel.org Date: Wed, 10 Jul 2024 20:51:17 +0900 Message-Id: <20240710115117.61255-1-s_min.jeong@samsung.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrLKsWRmVeSWpSXmKPExsWy7bCmru6p0r40g7fr+C1OTz3LZDG1fS+j xZP1s5gtLi1yt1jQ+pvFYsu/I6wWCzY+YrSYsf8puwOHx4JNpR6bVnWyeexe8JnJo2/LKkaP z5vkAlijsm0yUhNTUosUUvOS81My89JtlbyD453jTc0MDHUNLS3MlRTyEnNTbZVcfAJ03TJz gC5RUihLzCkFCgUkFhcr6dvZFOWXlqQqZOQXl9gqpRak5BSYFegVJ+YWl+al6+WlllgZGhgY mQIVJmRnnH7YzVawRLPibnsTawPjbMUuRk4OCQETiUsbnjN3MXJxCAnsYZT4fuUGI4TziVGi 89B1KOcbo8Ss1w+YYVqW9j5mgkjsZZS48fkPG1zLtwtNjCBVbAI6Eg+n3mYBsUUE1CVOTVrK AlLELHCVUaJ933OwhLCAk8TfU2+YQGwWAVWJ/+tOs4PYvAI2Ers3bWaHWCcvMfPSd6i4oMTJ mU/AepmB4s1bZ4NdLiFwiV3i+8lZUA0uEqf2HGSEsIUlXh3fAhWXknjZ3wZlF0scnb+BHaK5 AeiHrzehEvYSza3NQP9wAG3QlFi/Sx9iGZ/Eu689rCBhCQFeiY42IYhqVYnuR0ugwSItsezY QagpHhKrn35jBbGFBGIluq4/ZJ/AKDcLyQuzkLwwC2HZAkbmVYxSqQXFuempyYYFhrp5qeXw +EzOz93ECE6HWj47GL+v/6t3iJGJg/EQowQHs5II7/wb3WlCvCmJlVWpRfnxRaU5qcWHGE2B ATuRWUo0OR+YkPNK4g1NLA1MzIxMLIwtjc2UxHnPXClLFRJITyxJzU5NLUgt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Ovmalj/85y7sx2p03i6ve2Sth88vG69cNW8rnNpbs6 HEt2VXE2Btx4dnm+8+81M2vuno3hag10EDOeVrmA4bvX3w2fpP7dKzrxSSbOWbAiv/Q3x67l rxUtZj3X+pF39LJt4W3HigyODxv3vOwQXz17MaNOqyXn1cdrPQqiHmX4aH1arL7Y4263lrGd UsPkDO5HRbMva2k+s+hr95O5wZalxFKckWioxVxUnAgAgYO5BMQCAAA= X-CMS-MailID: 20240710115137epcas1p2ee192f1264c9570c416c706ffa7c23e8 X-Msg-Generator: CA CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20240710115137epcas1p2ee192f1264c9570c416c706ffa7c23e8 References: X-Headers-End: 1sRVrT-0003ZK-Si Subject: [f2fs-dev] [PATCH v3 1/2] f2fs: use meta inode for GC of atomic file 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: daehojeong@google.com, stable@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, Sungjong Seo Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net The page cache of the atomic file keeps new data pages which will be stored in the COW file. It can also keep old data pages when GCing the atomic file. In this case, new data can be overwritten by old data if a GC thread sets the old data page as dirty after new data page was evicted. Also, since all writes to the atomic file are redirected to COW inodes, GC for the atomic file is not working well as below. f2fs_gc(gc_type=FG_GC) - select A as a victim segment do_garbage_collect - iget atomic file's inode for block B move_data_page f2fs_do_write_data_page - use dn of cow inode - set fio->old_blkaddr from cow inode - seg_freed is 0 since block B is still valid - goto gc_more and A is selected as victim again To solve the problem, let's separate GC writes and updates in the atomic file by using the meta inode for GC writes. Fixes: 3db1de0e582c ("f2fs: change the current atomic write way") Cc: stable@vger.kernel.org #v5.19+ Reviewed-by: Sungjong Seo Reviewed-by: Yeongjin Gil Signed-off-by: Sunmin Jeong Reviewed-by: Chao Yu --- v2: - replace post_read to meta_gc fs/f2fs/data.c | 4 ++-- fs/f2fs/f2fs.h | 7 ++++++- fs/f2fs/gc.c | 6 +++--- fs/f2fs/segment.c | 6 +++--- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index b6dcb3bcaef7..9a213d03005d 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -2693,7 +2693,7 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio) } /* wait for GCed page writeback via META_MAPPING */ - if (fio->post_read) + if (fio->meta_gc) f2fs_wait_on_block_writeback(inode, fio->old_blkaddr); /* @@ -2788,7 +2788,7 @@ int f2fs_write_single_data_page(struct page *page, int *submitted, .submitted = 0, .compr_blocks = compr_blocks, .need_lock = compr_blocks ? LOCK_DONE : LOCK_RETRY, - .post_read = f2fs_post_read_required(inode) ? 1 : 0, + .meta_gc = f2fs_meta_inode_gc_required(inode) ? 1 : 0, .io_type = io_type, .io_wbc = wbc, .bio = bio, diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index f7ee6c5e371e..796ae11c0fa3 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1211,7 +1211,7 @@ struct f2fs_io_info { unsigned int in_list:1; /* indicate fio is in io_list */ unsigned int is_por:1; /* indicate IO is from recovery or not */ unsigned int encrypted:1; /* indicate file is encrypted */ - unsigned int post_read:1; /* require post read */ + unsigned int meta_gc:1; /* require meta inode GC */ enum iostat_type io_type; /* io type */ struct writeback_control *io_wbc; /* writeback control */ struct bio **bio; /* bio for ipu */ @@ -4263,6 +4263,11 @@ static inline bool f2fs_post_read_required(struct inode *inode) f2fs_compressed_file(inode); } +static inline bool f2fs_meta_inode_gc_required(struct inode *inode) +{ + return f2fs_post_read_required(inode) || f2fs_is_atomic_file(inode); +} + /* * compress.c */ diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index ef667fec9a12..cb3006551ab5 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c @@ -1589,7 +1589,7 @@ static int gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, start_bidx = f2fs_start_bidx_of_node(nofs, inode) + ofs_in_node; - if (f2fs_post_read_required(inode)) { + if (f2fs_meta_inode_gc_required(inode)) { int err = ra_data_block(inode, start_bidx); f2fs_up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); @@ -1640,7 +1640,7 @@ static int gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, start_bidx = f2fs_start_bidx_of_node(nofs, inode) + ofs_in_node; - if (f2fs_post_read_required(inode)) + if (f2fs_meta_inode_gc_required(inode)) err = move_data_block(inode, start_bidx, gc_type, segno, off); else @@ -1648,7 +1648,7 @@ static int gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, segno, off); if (!err && (gc_type == FG_GC || - f2fs_post_read_required(inode))) + f2fs_meta_inode_gc_required(inode))) submitted++; if (locked) { diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 4db1add43e36..77ef46b384b4 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -3851,7 +3851,7 @@ int f2fs_inplace_write_data(struct f2fs_io_info *fio) goto drop_bio; } - if (fio->post_read) + if (fio->meta_gc) f2fs_truncate_meta_inode_pages(sbi, fio->new_blkaddr, 1); stat_inc_inplace_blocks(fio->sbi); @@ -4021,7 +4021,7 @@ void f2fs_wait_on_block_writeback(struct inode *inode, block_t blkaddr) struct f2fs_sb_info *sbi = F2FS_I_SB(inode); struct page *cpage; - if (!f2fs_post_read_required(inode)) + if (!f2fs_meta_inode_gc_required(inode)) return; if (!__is_valid_data_blkaddr(blkaddr)) @@ -4040,7 +4040,7 @@ 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_post_read_required(inode)) + if (!f2fs_meta_inode_gc_required(inode)) return; for (i = 0; i < len; i++) From patchwork Wed Jul 10 11:51:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sunmin Jeong X-Patchwork-Id: 13729234 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 CDD3FC3DA42 for ; Wed, 10 Jul 2024 11:52:04 +0000 (UTC) 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.95) (envelope-from ) id 1sRVrd-0006v5-GE; Wed, 10 Jul 2024 11:52:02 +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.95) (envelope-from ) id 1sRVrc-0006uR-3o for linux-f2fs-devel@lists.sourceforge.net; Wed, 10 Jul 2024 11:52:01 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=References:Content-Type:Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=c5n/UByZUePQ6P5a5OPEpG605PoUTj8f9/67DLiQcfc=; b=S8YWykefghd71jcjs2lrvvvjRG ATjFllH8V84KMKvDzUq6EdVjNSN3TLDCl1C74buR75ARSPm9tEWR+LezRZtYnVGyVO/5MbUXtcEYN pYMuxXCuexwIMmFfPyivjLNN2OnX2BDB93WD6pVj8jopj+OcRU70cYUbHPEhnW4kB9Y0=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=References:Content-Type:Content-Transfer-Encoding:MIME-Version:Message-Id :Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=c5n/UByZUePQ6P5a5OPEpG605PoUTj8f9/67DLiQcfc=; b=O 0VskgRMxEG3halH8Zv+V7YtBkOFD8sTl/3OQoeKqicqzFZ63TJZuxlZw/gpcqPKksruvyYhWL/6fo PKWfzGC5Sr0xmSJMmnWpZFtOebtKdcvo9kZjJmcDf64VKKcDDoW9Hymp6A/XljiWfG9FOTS1AWUka lP0qK+dFlldBrVpM=; Received: from mailout3.samsung.com ([203.254.224.33]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1sRVrc-0003bN-Iq for linux-f2fs-devel@lists.sourceforge.net; Wed, 10 Jul 2024 11:52:01 +0000 Received: from epcas1p1.samsung.com (unknown [182.195.41.45]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20240710115152epoutp036c44a0c381dd1cc322b66114cb02ff09~g18hG-yFw0979709797epoutp03p for ; Wed, 10 Jul 2024 11:51:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20240710115152epoutp036c44a0c381dd1cc322b66114cb02ff09~g18hG-yFw0979709797epoutp03p DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1720612312; bh=c5n/UByZUePQ6P5a5OPEpG605PoUTj8f9/67DLiQcfc=; h=From:To:Cc:Subject:Date:References:From; b=Y/t1V8bOOlI2gZ4T6GSKLTbTZ9XdJWKXK5i9GL5hohSqMude2XKo8YAl88dAPs5DD 92izUCqqcRlCLY0cwUA1k1pwEyk8+xC4bO2+Uq8SRwwXDl6xhwnDgi+ptTZUZXz8xb pZVLDRjb59o1dQekRfGB7Hww/WosgtMM05MJmkdQ= Received: from epsnrtp4.localdomain (unknown [182.195.42.165]) by epcas1p2.samsung.com (KnoxPortal) with ESMTP id 20240710115152epcas1p2f6439636838d8e3f13dcc9fbdb311f07~g18gwGyQ70796007960epcas1p2b; Wed, 10 Jul 2024 11:51:52 +0000 (GMT) Received: from epsmgec1p1.samsung.com (unknown [182.195.38.249]) by epsnrtp4.localdomain (Postfix) with ESMTP id 4WJx6J0hmkz4x9Q1; Wed, 10 Jul 2024 11:51:52 +0000 (GMT) Received: from epcas1p3.samsung.com ( [182.195.41.47]) by epsmgec1p1.samsung.com (Symantec Messaging Gateway) with SMTP id DB.BB.08602.7D57E866; Wed, 10 Jul 2024 20:51:51 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas1p3.samsung.com (KnoxPortal) with ESMTPA id 20240710115151epcas1p3a7dbc6b3f69375d64d51f32f4ce3d9a4~g18froSvE0041400414epcas1p3Y; Wed, 10 Jul 2024 11:51:51 +0000 (GMT) Received: from epsmgmcp1.samsung.com (unknown [182.195.42.82]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20240710115151epsmtrp217c92a633c913dbf67c72da4601e16eb~g18fqOByo0777407774epsmtrp2Y; Wed, 10 Jul 2024 11:51:51 +0000 (GMT) X-AuditID: b6c32a33-40dff7000000219a-eb-668e75d75fef Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgmcp1.samsung.com (Symantec Messaging Gateway) with SMTP id 4C.C7.18846.7D57E866; Wed, 10 Jul 2024 20:51:51 +0900 (KST) Received: from localhost.localdomain (unknown [10.253.98.34]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20240710115151epsmtip2f2140da5c4bda4c870ef9f602e542a5b~g18fgX5fM1952319523epsmtip2j; Wed, 10 Jul 2024 11:51:51 +0000 (GMT) From: Sunmin Jeong To: jaegeuk@kernel.org, chao@kernel.org Date: Wed, 10 Jul 2024 20:51:43 +0900 Message-Id: <20240710115143.61315-1-s_min.jeong@samsung.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrBKsWRmVeSWpSXmKPExsWy7bCmvu710r40g1svTSxOTz3LZDG1fS+j xZP1s5gtLi1yt1jQ+pvFYsu/I6wWCzY+YrSYsf8puwOHx4JNpR6bVnWyeexe8JnJo2/LKkaP z5vkAlijsm0yUhNTUosUUvOS81My89JtlbyD453jTc0MDHUNLS3MlRTyEnNTbZVcfAJ03TJz gC5RUihLzCkFCgUkFhcr6dvZFOWXlqQqZOQXl9gqpRak5BSYFegVJ+YWl+al6+WlllgZGhgY mQIVJmRnHFx8kq3giG7F8ltX2RsYT6t2MXJwSAiYSDz4oNvFyMUhJLCDUWLj5FUsEM4nRomb r3azwjmfX69k72LkBOv4sOALO0RiJ6PEutZHCFWHNs0Gq2IT0JF4OPU2C4gtIqAucWrSUrC5 zAJXGSXa9z0HSwgL2Etc3fMWrIFFQFViw5drrCA2r4CNxKlXjWwQ6+QlZl76zg4RF5Q4OfMJ WC8zULx562xmkKESApfYJfq+n2GFaHCR6F/4ggXCFpZ4dXwL1N1SEp/f7YUaWixxdP4Gdojm BkaJG19vQhXZSzS3NrOBgoZZQFNi/S59iGV8Eu++9rBCQoxXoqNNCKJaVaL70RJmCFtaYtmx g1BTPICmfAFbJSQQKzHj/GmmCYxys5C8MAvJC7MQli1gZF7FKJZaUJybnppsWGAIj8rk/NxN jOAkqGW8g/Hy/H96hxiZOBgPMUpwMCuJ8M6/0Z0mxJuSWFmVWpQfX1Sak1p8iNEUGKgTmaVE k/OBaTivJN7QxNLAxMzIxMLY0thMSZz3zJWyVCGB9MSS1OzU1ILUIpg+Jg5OqQam9XMWzg2R ZOEzP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I5/ZbshOm/84JWF/qgT7XjHnQ2nXOXef muG69PubmRteHNirrr7+7RXWCatav+T+2vCmfpOqyX/Op98UO+9N1M0zfyZn23jf7axE5Rr9 2fzvtFwls4Uuv9rzXrKmuS320OWZuTNvfM3k5V7yneFnTsI/jZl+fmyeVp/5TyneW/CIbUpP T9nhuO/Tqt+qF95ZXPXxKK/c0pVKLMUZiYZazEXFiQDElAokwAIAAA== X-CMS-MailID: 20240710115151epcas1p3a7dbc6b3f69375d64d51f32f4ce3d9a4 X-Msg-Generator: CA CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20240710115151epcas1p3a7dbc6b3f69375d64d51f32f4ce3d9a4 References: X-Headers-End: 1sRVrc-0003bN-Iq Subject: [f2fs-dev] [PATCH v3 2/2] f2fs: use meta inode for GC of COW file 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: daehojeong@google.com, stable@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, Sungjong Seo Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net In case of the COW file, new updates and GC writes are already separated to page caches of the atomic file and COW file. As some cases that use the meta inode for GC, there are some race issues between a foreground thread and GC thread. To handle them, we need to take care when to invalidate and wait writeback of GC pages in COW files as the case of using the meta inode. Also, a pointer from the COW inode to the original inode is required to check the state of original pages. For the former, we can solve the problem by using the meta inode for GC of COW files. Then let's get a page from the original inode in move_data_block when GCing the COW file to avoid race condition. Fixes: 3db1de0e582c ("f2fs: change the current atomic write way") Cc: stable@vger.kernel.org #v5.19+ Reviewed-by: Sungjong Seo Reviewed-by: Yeongjin Gil Signed-off-by: Sunmin Jeong Reviewed-by: Chao Yu --- v3: - make the mapping variable to select a proper inode v2: - use union for cow inode to point to atomic inode fs/f2fs/data.c | 2 +- fs/f2fs/f2fs.h | 13 +++++++++++-- fs/f2fs/file.c | 3 +++ fs/f2fs/gc.c | 7 +++++-- fs/f2fs/inline.c | 2 +- fs/f2fs/inode.c | 3 ++- 6 files changed, 23 insertions(+), 7 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 9a213d03005d..f6b1782f965a 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -2606,7 +2606,7 @@ bool f2fs_should_update_outplace(struct inode *inode, struct f2fs_io_info *fio) return true; if (IS_NOQUOTA(inode)) return true; - if (f2fs_is_atomic_file(inode)) + if (f2fs_used_in_atomic_write(inode)) return true; /* rewrite low ratio compress data w/ OPU mode to avoid fragmentation */ if (f2fs_compressed_file(inode) && diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 796ae11c0fa3..4a8621e4a33a 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -843,7 +843,11 @@ struct f2fs_inode_info { struct task_struct *atomic_write_task; /* store atomic write task */ struct extent_tree *extent_tree[NR_EXTENT_CACHES]; /* cached extent_tree entry */ - struct inode *cow_inode; /* copy-on-write inode for atomic write */ + union { + struct inode *cow_inode; /* copy-on-write inode for atomic write */ + struct inode *atomic_inode; + /* point to atomic_inode, available only for cow_inode */ + }; /* avoid racing between foreground op and gc */ struct f2fs_rwsem i_gc_rwsem[2]; @@ -4263,9 +4267,14 @@ static inline bool f2fs_post_read_required(struct inode *inode) f2fs_compressed_file(inode); } +static inline bool f2fs_used_in_atomic_write(struct inode *inode) +{ + return f2fs_is_atomic_file(inode) || f2fs_is_cow_file(inode); +} + static inline bool f2fs_meta_inode_gc_required(struct inode *inode) { - return f2fs_post_read_required(inode) || f2fs_is_atomic_file(inode); + return f2fs_post_read_required(inode) || f2fs_used_in_atomic_write(inode); } /* diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index e4a7cff00796..547e7ec32b1f 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -2183,6 +2183,9 @@ static int f2fs_ioc_start_atomic_write(struct file *filp, bool truncate) set_inode_flag(fi->cow_inode, FI_COW_FILE); clear_inode_flag(fi->cow_inode, FI_INLINE_DATA); + + /* Set the COW inode's atomic_inode to the atomic inode */ + F2FS_I(fi->cow_inode)->atomic_inode = inode; } else { /* Reuse the already created COW inode */ ret = f2fs_do_truncate_blocks(fi->cow_inode, 0, true); diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index cb3006551ab5..724bbcb447d3 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c @@ -1171,7 +1171,8 @@ static bool is_alive(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, static int ra_data_block(struct inode *inode, pgoff_t index) { struct f2fs_sb_info *sbi = F2FS_I_SB(inode); - struct address_space *mapping = inode->i_mapping; + struct address_space *mapping = f2fs_is_cow_file(inode) ? + F2FS_I(inode)->atomic_inode->i_mapping : inode->i_mapping; struct dnode_of_data dn; struct page *page; struct f2fs_io_info fio = { @@ -1260,6 +1261,8 @@ static int ra_data_block(struct inode *inode, pgoff_t index) static int move_data_block(struct inode *inode, block_t bidx, int gc_type, unsigned int segno, int off) { + struct address_space *mapping = f2fs_is_cow_file(inode) ? + F2FS_I(inode)->atomic_inode->i_mapping : inode->i_mapping; struct f2fs_io_info fio = { .sbi = F2FS_I_SB(inode), .ino = inode->i_ino, @@ -1282,7 +1285,7 @@ static int move_data_block(struct inode *inode, block_t bidx, CURSEG_ALL_DATA_ATGC : CURSEG_COLD_DATA; /* do not read out */ - page = f2fs_grab_cache_page(inode->i_mapping, bidx, false); + page = f2fs_grab_cache_page(mapping, bidx, false); if (!page) return -ENOMEM; diff --git a/fs/f2fs/inline.c b/fs/f2fs/inline.c index 1fba5728be70..cca7d448e55c 100644 --- a/fs/f2fs/inline.c +++ b/fs/f2fs/inline.c @@ -16,7 +16,7 @@ static bool support_inline_data(struct inode *inode) { - if (f2fs_is_atomic_file(inode)) + if (f2fs_used_in_atomic_write(inode)) return false; if (!S_ISREG(inode->i_mode) && !S_ISLNK(inode->i_mode)) return false; diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c index 7a3e2458b2d9..18dea43e694b 100644 --- a/fs/f2fs/inode.c +++ b/fs/f2fs/inode.c @@ -804,8 +804,9 @@ void f2fs_evict_inode(struct inode *inode) f2fs_abort_atomic_write(inode, true); - if (fi->cow_inode) { + if (fi->cow_inode && f2fs_is_cow_file(fi->cow_inode)) { clear_inode_flag(fi->cow_inode, FI_COW_FILE); + F2FS_I(fi->cow_inode)->atomic_inode = NULL; iput(fi->cow_inode); fi->cow_inode = NULL; }