linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
* [f2fs-dev] [PATCH -next 0/4] rebuild compressed extent and support
@ 2022-09-21  7:57 Zhang Qilong via Linux-f2fs-devel
  2022-09-21  7:57 ` [f2fs-dev] [PATCH -next 1/4] f2fs: rebuild compressed extent cache update code for readonly-fs Zhang Qilong via Linux-f2fs-devel
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Zhang Qilong via Linux-f2fs-devel @ 2022-09-21  7:57 UTC (permalink / raw)
  To: jaegeuk, chao; +Cc: linux-f2fs-devel

For readonly format image, we first rebuild the code of updating
extent, and then support caching extent for no-compressed file.
Its idea is almost same with original design. At last we remove
the limit for no-compressed file that enable it use extent.

Zhang Qilong (4):
  f2fs: rebuild compressed extent cache update code for readonly-fs
  f2fs: extent cache: support extent for no-compressed file
  f2fs: rename f2fs_update_extent_tree_range_compressed
  f2fs: remove the limit and no-compressed file could use extent

 fs/f2fs/compress.c     | 24 -------------
 fs/f2fs/extent_cache.c | 80 ++++++++++++++++++++++++++++++++++++++++--
 fs/f2fs/f2fs.h         | 11 ++----
 fs/f2fs/node.c         | 20 ++---------
 4 files changed, 83 insertions(+), 52 deletions(-)

-- 
2.25.1



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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [f2fs-dev] [PATCH -next 1/4] f2fs: rebuild compressed extent cache update code for readonly-fs
  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
  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
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Zhang Qilong via Linux-f2fs-devel @ 2022-09-21  7:57 UTC (permalink / raw)
  To: jaegeuk, chao; +Cc: linux-f2fs-devel

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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [f2fs-dev] [PATCH -next 2/4] f2fs: extent cache: support extent for no-compressed file
  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 ` [f2fs-dev] [PATCH -next 1/4] f2fs: rebuild compressed extent cache update code for readonly-fs Zhang Qilong via Linux-f2fs-devel
@ 2022-09-21  7:57 ` 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
  3 siblings, 1 reply; 6+ messages in thread
From: Zhang Qilong via Linux-f2fs-devel @ 2022-09-21  7:57 UTC (permalink / raw)
  To: jaegeuk, chao; +Cc: linux-f2fs-devel

No-compressed file may suffer read performance issue due to it can't
use extent cache or the largest extent in inode can't covered other
parts of continuous blocks in readonly format f2fs image.

Now it won't build extent cacge tree for no-compressed file in
readonly format f2fs image.

For readonly format f2fs image, maybe the no-compressed file don't
have the largest extent, or it have more than one part which have
internally continuous blocks. So we add extent cache tree for the
no-compressed file in readonly format f2fs image.

The cache policy is almost same with compressed file. The difference
is that, the no-compressed file part will set min-number of continuous
blocks F2FS_MIN_EXTENT_LEN in order to reduce cache fragmentation.

Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
---
 fs/f2fs/extent_cache.c | 52 ++++++++++++++++++++++++++++++++++--------
 1 file changed, 42 insertions(+), 10 deletions(-)

diff --git a/fs/f2fs/extent_cache.c b/fs/f2fs/extent_cache.c
index 387d53a61270..7e39381edca0 100644
--- a/fs/f2fs/extent_cache.c
+++ b/fs/f2fs/extent_cache.c
@@ -695,9 +695,12 @@ static void f2fs_update_extent_tree_range_compressed(struct inode *inode,
 	set_extent_info(&ei, fofs, blkaddr, llen);
 	ei.c_len = c_len;
 
-	if (!__try_merge_extent_node(sbi, et, &ei, prev_en, next_en))
+	if (!__try_merge_extent_node(sbi, et, &ei, prev_en, next_en)) {
+		if (!c_len && llen < F2FS_MIN_EXTENT_LEN)
+			goto unlock_out;
 		__insert_extent_tree(sbi, et, &ei,
 				insert_p, insert_parent, leftmost);
+	}
 unlock_out:
 	write_unlock(&et->lock);
 }
@@ -726,24 +729,53 @@ static unsigned int f2fs_cluster_blocks_are_contiguous(struct dnode_of_data *dn)
 	return compressed ? i - 1 : i;
 }
 
+/*
+ * check whether normal file blocks are contiguous, and add extent cache
+ * entry only if remained blocks are logically and physically contiguous.
+ */
+static unsigned int f2fs_normal_blocks_are_contiguous(struct dnode_of_data *dn)
+{
+	int i = 0;
+	struct inode *inode = dn->inode;
+	block_t first_blkaddr = data_blkaddr(inode, dn->node_page,
+						dn->ofs_in_node);
+	unsigned int max_blocks = ADDRS_PER_PAGE(dn->node_page, inode)
+					- dn->ofs_in_node;
+
+	for (i = 1; i < max_blocks; i++) {
+		block_t blkaddr = data_blkaddr(inode, dn->node_page,
+				dn->ofs_in_node + i);
+
+		if (!__is_valid_data_blkaddr(blkaddr) ||
+				first_blkaddr + i != blkaddr)
+			return i;
+	}
+
+	return 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);
+	unsigned int c_len = 0;
+	unsigned int llen = 0;
 	block_t blkaddr;
 
-	if (!c_len)
-		return;
-
 	blkaddr = f2fs_data_blkaddr(dn);
-	if (blkaddr == COMPRESS_ADDR)
-		blkaddr = data_blkaddr(dn->inode, dn->node_page,
+	if (f2fs_compressed_file(dn->inode)) {
+		c_len = f2fs_cluster_blocks_are_contiguous(dn);
+		if (!c_len)
+			return;
+		llen = F2FS_I(dn->inode)->i_cluster_size;
+		if (blkaddr == COMPRESS_ADDR)
+			blkaddr = data_blkaddr(dn->inode, dn->node_page,
 					dn->ofs_in_node + 1);
+	} else {
+		llen = f2fs_normal_blocks_are_contiguous(dn);
+	}
 
 	f2fs_update_extent_tree_range_compressed(dn->inode,
-				index, blkaddr,
-				F2FS_I(dn->inode)->i_cluster_size,
-				c_len);
+				index, blkaddr, llen, c_len);
 }
 #endif
 
-- 
2.25.1



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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [f2fs-dev] [PATCH -next 3/4] f2fs: rename f2fs_update_extent_tree_range_compressed
  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 ` [f2fs-dev] [PATCH -next 1/4] f2fs: rebuild compressed extent cache update code for readonly-fs Zhang Qilong via Linux-f2fs-devel
  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  7:57 ` 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
  3 siblings, 0 replies; 6+ messages in thread
From: Zhang Qilong via Linux-f2fs-devel @ 2022-09-21  7:57 UTC (permalink / raw)
  To: jaegeuk, chao; +Cc: linux-f2fs-devel

f2fs_update_extent_tree_range_compressed caches both of compressed
and no-compressed extent entry, so we should getting rid of the
"compressed" word will be more appropriate. And we just rename it to
f2fs_readonly_update_extent_tree_range.

Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
---
 fs/f2fs/extent_cache.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/f2fs/extent_cache.c b/fs/f2fs/extent_cache.c
index 7e39381edca0..c59a0ec41e69 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
-static void f2fs_update_extent_tree_range_compressed(struct inode *inode,
+static void f2fs_readonly_update_extent_tree_range(struct inode *inode,
 				pgoff_t fofs, block_t blkaddr, unsigned int llen,
 				unsigned int c_len)
 {
@@ -774,8 +774,8 @@ void f2fs_readonly_update_extent_cache(struct dnode_of_data *dn,
 		llen = f2fs_normal_blocks_are_contiguous(dn);
 	}
 
-	f2fs_update_extent_tree_range_compressed(dn->inode,
-				index, blkaddr, llen, c_len);
+	f2fs_readonly_update_extent_tree_range(dn->inode, index,
+						blkaddr, llen, c_len);
 }
 #endif
 
-- 
2.25.1



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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [f2fs-dev] [PATCH -next 4/4] f2fs: remove the limit and no-compressed file could use extent
  2022-09-21  7:57 [f2fs-dev] [PATCH -next 0/4] rebuild compressed extent and support Zhang Qilong via Linux-f2fs-devel
                   ` (2 preceding siblings ...)
  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 ` Zhang Qilong via Linux-f2fs-devel
  3 siblings, 0 replies; 6+ messages in thread
From: Zhang Qilong via Linux-f2fs-devel @ 2022-09-21  7:57 UTC (permalink / raw)
  To: jaegeuk, chao; +Cc: linux-f2fs-devel

It have supported caching extent of no-compressed file and we
just remove the limit in readonly format f2fs image.

Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
---
 fs/f2fs/node.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index 4f500c2ecee8..880259bec0e4 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -845,11 +845,8 @@ int f2fs_get_dnode_of_data(struct dnode_of_data *dn, pgoff_t index, int mode)
 	dn->node_page = npage[level];
 	dn->data_blkaddr = f2fs_data_blkaddr(dn);
 
-	if (is_inode_flag_set(dn->inode, FI_COMPRESSED_FILE) &&
-					f2fs_sb_has_readonly(sbi)) {
-
+	if (f2fs_sb_has_readonly(sbi))
 		f2fs_readonly_update_extent_cache(dn, index);
-	}
 
 	return 0;
 
-- 
2.25.1



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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [f2fs-dev] [PATCH -next 2/4] f2fs: extent cache: support extent for no-compressed file
  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
  0 siblings, 0 replies; 6+ messages in thread
From: Chao Yu @ 2022-09-21 10:40 UTC (permalink / raw)
  To: Zhang Qilong, jaegeuk; +Cc: linux-f2fs-devel

On 2022/9/21 15:57, Zhang Qilong wrote:
> No-compressed file may suffer read performance issue due to it can't
> use extent cache or the largest extent in inode can't covered other
> parts of continuous blocks in readonly format f2fs image.
> 
> Now it won't build extent cacge tree for no-compressed file in
> readonly format f2fs image.
> 
> For readonly format f2fs image, maybe the no-compressed file don't
> have the largest extent, or it have more than one part which have

Why it can not have largest extent in f2fs_inode?

Thanks,

> internally continuous blocks. So we add extent cache tree for the
> no-compressed file in readonly format f2fs image.
> 
> The cache policy is almost same with compressed file. The difference
> is that, the no-compressed file part will set min-number of continuous
> blocks F2FS_MIN_EXTENT_LEN in order to reduce cache fragmentation.
> 
> Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
> ---
>   fs/f2fs/extent_cache.c | 52 ++++++++++++++++++++++++++++++++++--------
>   1 file changed, 42 insertions(+), 10 deletions(-)
> 
> diff --git a/fs/f2fs/extent_cache.c b/fs/f2fs/extent_cache.c
> index 387d53a61270..7e39381edca0 100644
> --- a/fs/f2fs/extent_cache.c
> +++ b/fs/f2fs/extent_cache.c
> @@ -695,9 +695,12 @@ static void f2fs_update_extent_tree_range_compressed(struct inode *inode,
>   	set_extent_info(&ei, fofs, blkaddr, llen);
>   	ei.c_len = c_len;
>   
> -	if (!__try_merge_extent_node(sbi, et, &ei, prev_en, next_en))
> +	if (!__try_merge_extent_node(sbi, et, &ei, prev_en, next_en)) {
> +		if (!c_len && llen < F2FS_MIN_EXTENT_LEN)
> +			goto unlock_out;
>   		__insert_extent_tree(sbi, et, &ei,
>   				insert_p, insert_parent, leftmost);
> +	}
>   unlock_out:
>   	write_unlock(&et->lock);
>   }
> @@ -726,24 +729,53 @@ static unsigned int f2fs_cluster_blocks_are_contiguous(struct dnode_of_data *dn)
>   	return compressed ? i - 1 : i;
>   }
>   
> +/*
> + * check whether normal file blocks are contiguous, and add extent cache
> + * entry only if remained blocks are logically and physically contiguous.
> + */
> +static unsigned int f2fs_normal_blocks_are_contiguous(struct dnode_of_data *dn)
> +{
> +	int i = 0;
> +	struct inode *inode = dn->inode;
> +	block_t first_blkaddr = data_blkaddr(inode, dn->node_page,
> +						dn->ofs_in_node);
> +	unsigned int max_blocks = ADDRS_PER_PAGE(dn->node_page, inode)
> +					- dn->ofs_in_node;
> +
> +	for (i = 1; i < max_blocks; i++) {
> +		block_t blkaddr = data_blkaddr(inode, dn->node_page,
> +				dn->ofs_in_node + i);
> +
> +		if (!__is_valid_data_blkaddr(blkaddr) ||
> +				first_blkaddr + i != blkaddr)
> +			return i;
> +	}
> +
> +	return 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);
> +	unsigned int c_len = 0;
> +	unsigned int llen = 0;
>   	block_t blkaddr;
>   
> -	if (!c_len)
> -		return;
> -
>   	blkaddr = f2fs_data_blkaddr(dn);
> -	if (blkaddr == COMPRESS_ADDR)
> -		blkaddr = data_blkaddr(dn->inode, dn->node_page,
> +	if (f2fs_compressed_file(dn->inode)) {
> +		c_len = f2fs_cluster_blocks_are_contiguous(dn);
> +		if (!c_len)
> +			return;
> +		llen = F2FS_I(dn->inode)->i_cluster_size;
> +		if (blkaddr == COMPRESS_ADDR)
> +			blkaddr = data_blkaddr(dn->inode, dn->node_page,
>   					dn->ofs_in_node + 1);
> +	} else {
> +		llen = f2fs_normal_blocks_are_contiguous(dn);
> +	}
>   
>   	f2fs_update_extent_tree_range_compressed(dn->inode,
> -				index, blkaddr,
> -				F2FS_I(dn->inode)->i_cluster_size,
> -				c_len);
> +				index, blkaddr, llen, c_len);
>   }
>   #endif
>   


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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-09-21 10:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [f2fs-dev] [PATCH -next 1/4] f2fs: rebuild compressed extent cache update code for readonly-fs Zhang Qilong via Linux-f2fs-devel
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

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).