linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
From: Zhang Qilong via Linux-f2fs-devel <linux-f2fs-devel@lists.sourceforge.net>
To: <jaegeuk@kernel.org>, <chao@kernel.org>
Cc: linux-f2fs-devel@lists.sourceforge.net
Subject: [f2fs-dev] [PATCH -next 1/4] f2fs: rebuild compressed extent cache update code for readonly-fs
Date: Wed, 21 Sep 2022 15:57:34 +0800	[thread overview]
Message-ID: <20220921075737.36708-2-zhangqilong3@huawei.com> (raw)
In-Reply-To: <20220921075737.36708-1-zhangqilong3@huawei.com>

The motivation of rebuilding comes from:
 a) If we don't enable the compress config, it will build some
    unnecessary code into target in f2fs_get_dnode_of_data
 b) The f2fs_cluster_blocks_are_contiguous is called only when
    updating compressed extent cache and being called once in
    extent_cache.c
So, we rebuild it by adding f2fs_readonly_update_extent_cache()
to update compressed extent cache in readonly-fs and moving
f2fs_update_extent_tree_range_compressed and f2fs_cluster_blocks_are_contiguous
into extent_cache.c. Both function can be implemented internally
in extent_cache.c.

Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
---
 fs/f2fs/compress.c     | 24 ----------------------
 fs/f2fs/extent_cache.c | 46 +++++++++++++++++++++++++++++++++++++++++-
 fs/f2fs/f2fs.h         | 11 +++-------
 fs/f2fs/node.c         | 17 ++--------------
 4 files changed, 50 insertions(+), 48 deletions(-)

diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c
index c16bab5bd600..400e01fbefb3 100644
--- a/fs/f2fs/compress.c
+++ b/fs/f2fs/compress.c
@@ -1789,30 +1789,6 @@ void f2fs_put_page_dic(struct page *page, bool in_task)
 	f2fs_put_dic(dic, 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)
-{
-	bool compressed = f2fs_data_blkaddr(dn) == COMPRESS_ADDR;
-	int i = compressed ? 1 : 0;
-	block_t first_blkaddr = data_blkaddr(dn->inode, dn->node_page,
-						dn->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);
-
-		if (!__is_valid_data_blkaddr(blkaddr))
-			break;
-		if (first_blkaddr + i - (compressed ? 1 : 0) != blkaddr)
-			return 0;
-	}
-
-	return compressed ? i - 1 : i;
-}
-
 const struct address_space_operations f2fs_compress_aops = {
 	.release_folio = f2fs_release_folio,
 	.invalidate_folio = f2fs_invalidate_folio,
diff --git a/fs/f2fs/extent_cache.c b/fs/f2fs/extent_cache.c
index 746abfda3b66..387d53a61270 100644
--- a/fs/f2fs/extent_cache.c
+++ b/fs/f2fs/extent_cache.c
@@ -663,7 +663,7 @@ static void f2fs_update_extent_tree_range(struct inode *inode,
 }
 
 #ifdef CONFIG_F2FS_FS_COMPRESSION
-void f2fs_update_extent_tree_range_compressed(struct inode *inode,
+static void f2fs_update_extent_tree_range_compressed(struct inode *inode,
 				pgoff_t fofs, block_t blkaddr, unsigned int llen,
 				unsigned int c_len)
 {
@@ -701,6 +701,50 @@ void f2fs_update_extent_tree_range_compressed(struct inode *inode,
 unlock_out:
 	write_unlock(&et->lock);
 }
+
+/*
+ * check whether cluster blocks are contiguous, and add extent cache entry
+ * only if cluster blocks are logically and physically contiguous.
+ */
+static unsigned int f2fs_cluster_blocks_are_contiguous(struct dnode_of_data *dn)
+{
+	bool compressed = f2fs_data_blkaddr(dn) == COMPRESS_ADDR;
+	int i = compressed ? 1 : 0;
+	block_t first_blkaddr = data_blkaddr(dn->inode, dn->node_page,
+						dn->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);
+
+		if (!__is_valid_data_blkaddr(blkaddr))
+			break;
+		if (first_blkaddr + i - (compressed ? 1 : 0) != blkaddr)
+				return 0;
+	}
+
+	return compressed ? i - 1 : i;
+}
+
+void f2fs_readonly_update_extent_cache(struct dnode_of_data *dn,
+					pgoff_t index)
+{
+	unsigned int c_len = f2fs_cluster_blocks_are_contiguous(dn);
+	block_t blkaddr;
+
+	if (!c_len)
+		return;
+
+	blkaddr = f2fs_data_blkaddr(dn);
+	if (blkaddr == COMPRESS_ADDR)
+		blkaddr = data_blkaddr(dn->inode, dn->node_page,
+					dn->ofs_in_node + 1);
+
+	f2fs_update_extent_tree_range_compressed(dn->inode,
+				index, blkaddr,
+				F2FS_I(dn->inode)->i_cluster_size,
+				c_len);
+}
 #endif
 
 unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink)
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 3cdfe56df5e2..f597dc6251e8 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -4221,9 +4221,7 @@ int f2fs_write_multi_pages(struct compress_ctx *cc,
 						struct writeback_control *wbc,
 						enum iostat_type io_type);
 int f2fs_is_compressed_cluster(struct inode *inode, pgoff_t index);
-void f2fs_update_extent_tree_range_compressed(struct inode *inode,
-				pgoff_t fofs, block_t blkaddr, unsigned int llen,
-				unsigned int c_len);
+void f2fs_readonly_update_extent_cache(struct dnode_of_data *dn, pgoff_t index);
 int f2fs_read_multi_pages(struct compress_ctx *cc, struct bio **bio_ret,
 				unsigned nr_pages, sector_t *last_block_in_bio,
 				bool is_readahead, bool for_write);
@@ -4231,7 +4229,6 @@ 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);
 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);
@@ -4287,7 +4284,6 @@ 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 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) { }
@@ -4304,9 +4300,8 @@ static inline bool f2fs_load_compressed_page(struct f2fs_sb_info *sbi,
 static inline void f2fs_invalidate_compress_pages(struct f2fs_sb_info *sbi,
 							nid_t ino) { }
 #define inc_compr_inode_stat(inode)		do { } while (0)
-static inline void f2fs_update_extent_tree_range_compressed(struct inode *inode,
-				pgoff_t fofs, block_t blkaddr, unsigned int llen,
-				unsigned int c_len) { }
+static inline void f2fs_readonly_update_extent_cache(struct dnode_of_data *dn,
+							pgoff_t index) { }
 #endif
 
 static inline int set_compress_context(struct inode *inode)
diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index 23291f1575d3..4f500c2ecee8 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -847,23 +847,10 @@ 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);
-		block_t blkaddr;
 
-		if (!c_len)
-			goto out;
-
-		blkaddr = f2fs_data_blkaddr(dn);
-		if (blkaddr == COMPRESS_ADDR)
-			blkaddr = data_blkaddr(dn->inode, dn->node_page,
-						dn->ofs_in_node + 1);
-
-		f2fs_update_extent_tree_range_compressed(dn->inode,
-					index, blkaddr,
-					F2FS_I(dn->inode)->i_cluster_size,
-					c_len);
+		f2fs_readonly_update_extent_cache(dn, index);
 	}
-out:
+
 	return 0;
 
 release_pages:
-- 
2.25.1



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

  reply	other threads:[~2022-09-21  7:54 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-21  7:57 [f2fs-dev] [PATCH -next 0/4] rebuild compressed extent and support Zhang Qilong via Linux-f2fs-devel
2022-09-21  7:57 ` Zhang Qilong via Linux-f2fs-devel [this message]
2022-09-21  7:57 ` [f2fs-dev] [PATCH -next 2/4] f2fs: extent cache: support extent for no-compressed file Zhang Qilong via Linux-f2fs-devel
2022-09-21 10:40   ` Chao Yu
2022-09-21  7:57 ` [f2fs-dev] [PATCH -next 3/4] f2fs: rename f2fs_update_extent_tree_range_compressed Zhang Qilong via Linux-f2fs-devel
2022-09-21  7:57 ` [f2fs-dev] [PATCH -next 4/4] f2fs: remove the limit and no-compressed file could use extent Zhang Qilong via Linux-f2fs-devel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220921075737.36708-2-zhangqilong3@huawei.com \
    --to=linux-f2fs-devel@lists.sourceforge.net \
    --cc=chao@kernel.org \
    --cc=jaegeuk@kernel.org \
    --cc=zhangqilong3@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).