Skip to contentSkip to conversation

rebuild compressed extent and support

PATCH In review Zhang Qilong via Linux-f2fs-devel 2 participants 6 messages Sep 21, 2022 F2FS file system

lore
Share & tools
lore
#0 lore raw

cover rebuild compressed extent and support

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(-)
Signature · 8 lines
2.25.1



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
#1 lore raw

PATCH 1/4 f2fs: rebuild compressed extent cache update code for readonly-fs

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.

---
 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(-)
fs/f2fs/compress.c +0 -24
index c16bab5bd600..400e01fbefb3 100644
@@ -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,
fs/f2fs/extent_cache.c +45 -1

58 lines not on this page · raw message

fs/f2fs/f2fs.h +3 -8
index 3cdfe56df5e2..f597dc6251e8 100644
@@ -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)
fs/f2fs/node.c +2 -15
index 23291f1575d3..4f500c2ecee8 100644
@@ -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:
Signature · 8 lines
2.25.1



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
#2 lore raw

PATCH 2/4 f2fs: extent cache: support extent for no-compressed file

In reply to Zhang Qilong via 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.

---
 fs/f2fs/extent_cache.c | 52 ++++++++++++++++++++++++++++++++++--------
 1 file changed, 42 insertions(+), 10 deletions(-)
fs/f2fs/extent_cache.c +42 -10
index 387d53a61270..7e39381edca0 100644
@@ -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
 
Signature · 8 lines
2.25.1



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
maintainer
#3 lore raw

Re: [f2fs-dev] [PATCH -next 2/4] f2fs: extent cache: support extent for no-compressed file

Quoted 9 lines · Zhang Qilong

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,

Quoted 83 lines

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.

---
  fs/f2fs/extent_cache.c | 52 ++++++++++++++++++++++++++++++++++--------
  1 file changed, 42 insertions(+), 10 deletions(-)
fs/f2fs/extent_cache.c +40 -7
index 387d53a61270..7e39381edca0 100644
@@ -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);

fs/f2fs/extent_cache.c static unsigned int f2fs_cluster_blocks_are_contiguous(struct dnode_of_data *dn) · line 781

Quoted 10 lines
fs/f2fs/extent_cache.c +2 -3
+	}
 
  	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
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#4 lore raw

PATCH 3/4 f2fs: rename f2fs_update_extent_tree_range_compressed

In reply to Zhang Qilong via 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.

---
 fs/f2fs/extent_cache.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/f2fs/extent_cache.c +3 -3
index 7e39381edca0..c59a0ec41e69 100644
@@ -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
 
Signature · 8 lines
2.25.1



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
#5 lore raw

PATCH 4/4 f2fs: remove the limit and no-compressed file could use extent

In reply to Zhang Qilong via Linux-f2fs-devel

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

---
 fs/f2fs/node.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
fs/f2fs/node.c +1 -4
index 4f500c2ecee8..880259bec0e4 100644
@@ -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;
 
Signature · 8 lines
2.25.1



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel