From patchwork Mon Feb 26 07:35:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 13571385 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 78743C48BF6 for ; Mon, 26 Feb 2024 07:36:21 +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 1reVXA-0004FC-4q; Mon, 26 Feb 2024 07:36:21 +0000 Received: from [172.30.20.202] (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 1reVWm-0004EN-EF for linux-f2fs-devel@lists.sourceforge.net; Mon, 26 Feb 2024 07:35:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=5HG4MWd5T3KHVIQNzZO3t4OTPKGD3eDzImKMZe1jtqs=; b=ESHf3T75NYZ/EZbvrGrZ4/kxvf BVqUfe/0lrlpt+e5EAU8b1dzpBiaGAUAbodsFNvmn39BRN0Z9fcPVMtIQSX+vmTcsg3QwUxK4HttW WPTEzTqvdTmUcFNtC4yY1R3VInUY+XQ3fXGo2ErRuOk7NXWZ3ZL0j+BF8QDVNxP2bAR0=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject:Cc:To:From :Sender:Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=5HG4MWd5T3KHVIQNzZO3t4OTPKGD3eDzImKMZe1jtqs=; b=b sCNSBoscwbucRf9/LzJKAQoghjW96sywCr8ArpFyx1K7296dSPlwvKVL5A+ux9Jrm9qT9hyBm6F5E 9woVmMjCt5C+VBW0tMUmhJaOFbs7QeExt2zGdFXV/6dVbJVgbGhQAelKmFLb3QxfEiCTSAZowltXP Y9baY912dLnASbrA=; Received: from dfw.source.kernel.org ([139.178.84.217]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1reVWm-0002xs-It for linux-f2fs-devel@lists.sourceforge.net; Mon, 26 Feb 2024 07:35:57 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 31E3560F32 for ; Mon, 26 Feb 2024 07:35:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7BAF0C43390; Mon, 26 Feb 2024 07:35:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708932945; bh=xYW4vWigmlTDvWjBbKDHIv6Pc+z/yoRDygV1eUyCs3s=; h=From:To:Cc:Subject:Date:From; b=Xa7ptxQB7eVKCaBz+kFs8H+z7DLqwuPctA+AeKlsNaiFrv8t3/L5MS6DC2ogMVQKU fRFMU95DpzuU2UkSVvoAtyMVWWwm3ZLhJD9uzvyjoYGhb4CtbptUmqApgi9IZGwadZ SygTwNGQWG9BzOCywONdVGxk+fm9PpOTqukLesEZVh9+l2dojQR9j/6IxA3+QXywvo f9jVeYxRcOceEb7rdkuIMJ4IjViJiXhtxEgQAUUFO6h8gSIURMT3G/HN9FcSGHYyxi TJANZ9ZO1xm3fwXVJRRQGocuKpVfyEREn06qnV0bvSRqSrT157YcnSfz0ZGS4OTEQ7 GQLZE7t3BmFrQ== From: Chao Yu To: jaegeuk@kernel.org Date: Mon, 26 Feb 2024 15:35:38 +0800 Message-Id: <20240226073539.2509926-1-chao@kernel.org> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Headers-End: 1reVWm-0002xs-It Subject: [f2fs-dev] [PATCH 1/2] f2fs: ro: compress: fix to avoid caching unaligned extent 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: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net Mapping info from dump.f2fs: i_addr[0x2d] cluster flag [0xfffffffe : 4294967294] i_addr[0x2e] [0x 10428 : 66600] i_addr[0x2f] [0x 10429 : 66601] i_addr[0x30] [0x 1042a : 66602] f2fs_io fiemap 37 1 /mnt/f2fs/disk-58390c8c.raw Previsouly, it missed to align fofs and ofs_in_node to cluster_size, result in adding incorrect read extent cache, fix it. Before: f2fs_update_read_extent_tree_range: dev = (253,48), ino = 5, pgofs = 37, len = 4, blkaddr = 66600, c_len = 3 After: f2fs_update_read_extent_tree_range: dev = (253,48), ino = 5, pgofs = 36, len = 4, blkaddr = 66600, c_len = 3 Fixes: 94afd6d6e525 ("f2fs: extent cache: support unaligned extent") Signed-off-by: Chao Yu --- fs/f2fs/compress.c | 10 ++++++---- fs/f2fs/f2fs.h | 6 ++++-- fs/f2fs/node.c | 20 ++++++++++++++------ 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c index f821681886b8..21f03d119d4d 100644 --- a/fs/f2fs/compress.c +++ b/fs/f2fs/compress.c @@ -1841,16 +1841,18 @@ void f2fs_put_page_dic(struct page *page, bool in_task) * check whether cluster blocks are contiguous, and add extent cache entry * only if cluster blocks are logically and physically contiguous. */ -unsigned int f2fs_cluster_blocks_are_contiguous(struct dnode_of_data *dn) +unsigned int f2fs_cluster_blocks_are_contiguous(struct dnode_of_data *dn, + unsigned int ofs_in_node) { - bool compressed = f2fs_data_blkaddr(dn) == COMPRESS_ADDR; + bool compressed = data_blkaddr(dn->inode, dn->node_page, + ofs_in_node) == COMPRESS_ADDR; int i = compressed ? 1 : 0; block_t first_blkaddr = data_blkaddr(dn->inode, dn->node_page, - dn->ofs_in_node + i); + ofs_in_node + i); for (i += 1; i < F2FS_I(dn->inode)->i_cluster_size; i++) { block_t blkaddr = data_blkaddr(dn->inode, dn->node_page, - dn->ofs_in_node + i); + ofs_in_node + i); if (!__is_valid_data_blkaddr(blkaddr)) break; diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 51701fc66200..33fd02716cf3 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -4307,7 +4307,8 @@ struct decompress_io_ctx *f2fs_alloc_dic(struct compress_ctx *cc); void f2fs_decompress_end_io(struct decompress_io_ctx *dic, bool failed, bool in_task); void f2fs_put_page_dic(struct page *page, bool in_task); -unsigned int f2fs_cluster_blocks_are_contiguous(struct dnode_of_data *dn); +unsigned int f2fs_cluster_blocks_are_contiguous(struct dnode_of_data *dn, + unsigned int ofs_in_node); int f2fs_init_compress_ctx(struct compress_ctx *cc); void f2fs_destroy_compress_ctx(struct compress_ctx *cc, bool reuse); void f2fs_init_compress_info(struct f2fs_sb_info *sbi); @@ -4364,7 +4365,8 @@ static inline void f2fs_put_page_dic(struct page *page, bool in_task) { WARN_ON_ONCE(1); } -static inline unsigned int f2fs_cluster_blocks_are_contiguous(struct dnode_of_data *dn) { return 0; } +static inline unsigned int f2fs_cluster_blocks_are_contiguous( + struct dnode_of_data *dn, unsigned int ofs_in_node) { return 0; } static inline bool f2fs_sanity_check_cluster(struct dnode_of_data *dn) { return false; } static inline int f2fs_init_compress_inode(struct f2fs_sb_info *sbi) { return 0; } static inline void f2fs_destroy_compress_inode(struct f2fs_sb_info *sbi) { } diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index 51241996b9ec..b3de6d6cdb02 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c @@ -852,21 +852,29 @@ int f2fs_get_dnode_of_data(struct dnode_of_data *dn, pgoff_t index, int mode) if (is_inode_flag_set(dn->inode, FI_COMPRESSED_FILE) && f2fs_sb_has_readonly(sbi)) { - unsigned int c_len = f2fs_cluster_blocks_are_contiguous(dn); + unsigned int cluster_size = F2FS_I(dn->inode)->i_cluster_size; + unsigned int ofs_in_node = dn->ofs_in_node; + pgoff_t fofs = index; + unsigned int c_len; block_t blkaddr; + /* should align fofs and ofs_in_node to cluster_size */ + if (fofs % cluster_size) { + fofs = round_down(fofs, cluster_size); + ofs_in_node = round_down(ofs_in_node, cluster_size); + } + + c_len = f2fs_cluster_blocks_are_contiguous(dn, ofs_in_node); if (!c_len) goto out; - blkaddr = f2fs_data_blkaddr(dn); + blkaddr = data_blkaddr(dn->inode, dn->node_page, ofs_in_node); if (blkaddr == COMPRESS_ADDR) blkaddr = data_blkaddr(dn->inode, dn->node_page, - dn->ofs_in_node + 1); + ofs_in_node + 1); f2fs_update_read_extent_tree_range_compressed(dn->inode, - index, blkaddr, - F2FS_I(dn->inode)->i_cluster_size, - c_len); + fofs, blkaddr, cluster_size, c_len); } out: return 0; From patchwork Mon Feb 26 07:35:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 13571384 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 8D1B7C48BF6 for ; Mon, 26 Feb 2024 07:35: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 1reVWm-0002xZ-0T; Mon, 26 Feb 2024 07:35:56 +0000 Received: from [172.30.20.202] (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 1reVWk-0002xP-AF for linux-f2fs-devel@lists.sourceforge.net; Mon, 26 Feb 2024 07:35:54 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: 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=nEPJ26NFMrTmL49thufpcKhb2K7Qjw5iU5l47qd9Nlw=; b=Cqv6taY9jljpo5y9S6UO1afXrm oK73FFCIAXddwWqMfltBPBdKoVcm93rpag6C635JtjO6wzoF1rzaaemg9PbEC5MNWmLa/loHtnGGc 4YN6UxBGOjLXpit6LgMSFMRMbvQy70PgwDTNL8p1K5qVM77vgcYre06u/wcsZeZG1CJ8=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: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=nEPJ26NFMrTmL49thufpcKhb2K7Qjw5iU5l47qd9Nlw=; b=PDYkOBgD+4Y/mJaoirHfMSTWvs izR1rdltxdRrCbTZ9qeHfiSiqbweVM/wBFZdHeHZoupH0oq2+1pdCYqD+PE2jV46lGswWYaNwl6EJ TL88OUNXq81TDYZmybDZxz6ds9wSnoeCKmKustpxJPtGWEZnrsTdnhCoskbadf5ugLnA=; Received: from dfw.source.kernel.org ([139.178.84.217]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1reVWj-0002xq-Oh for linux-f2fs-devel@lists.sourceforge.net; Mon, 26 Feb 2024 07:35:54 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 4E3AD60FA5 for ; Mon, 26 Feb 2024 07:35:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C106C433B2; Mon, 26 Feb 2024 07:35:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708932947; bh=DM7lCeAQkkrdeMDm7IxgfNbaFgZdno2MS54NUJmA8dw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I3ajVGpgQc6l7+OU17u75YYhHNroOTJz8hHJTRRGAnv31ib+bQX+ozAzTBiBlyody 2trvL2ADY8ta0KNNzk6otf5eBw74LSiUdxJURZJgqTmT8SckTYPAwS1AO+ykCMImQy 2L74/p3AcflUs0sYfV6OVwSsN6l78h659dpZsrI6uciQzUVioiuGLSxXRuG9+99DJX Zt6L4BprJAHNjZJx+BjVzuOtUIlubCWPyXKRfmZUSfOqZdTfirUQuZ32PMcuuEnUvC /3OV5svysGVXzPXYeF5YwxKHZpa8twJqYPGmkPfShE9aHNaDRDwEjs8RrDAmAutWnC nZRx0aWJ7IAqA== From: Chao Yu To: jaegeuk@kernel.org Date: Mon, 26 Feb 2024 15:35:39 +0800 Message-Id: <20240226073539.2509926-2-chao@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240226073539.2509926-1-chao@kernel.org> References: <20240226073539.2509926-1-chao@kernel.org> MIME-Version: 1.0 X-Headers-End: 1reVWj-0002xq-Oh Subject: [f2fs-dev] [PATCH 2/2] f2fs: ro: don't start discard thread for readonly image 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: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net [ 9299.893835] F2FS-fs (vdd): Allow to mount readonly mode only mount: /mnt/f2fs: WARNING: source write-protected, mounted read-only. root@qemu:/ ps -ef|grep f2fs root 94 2 0 03:46 ? 00:00:00 [kworker/u17:0-f2fs_post_read_wq] root 6282 2 0 06:21 ? 00:00:00 [f2fs_discard-253:48] There will be no deletion in readonly image, let's skip starting discard thread to save system resources. Signed-off-by: Chao Yu --- fs/f2fs/segment.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index b486fe4485f9..cc27c5440188 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -2253,6 +2253,12 @@ int f2fs_start_discard_thread(struct f2fs_sb_info *sbi) struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info; int err = 0; + if (f2fs_sb_has_readonly(sbi)) { + f2fs_info(sbi, + "Skip to start discard thread for readonly image"); + return 0; + } + if (!f2fs_realtime_discard_enable(sbi)) return 0;