All of lore.kernel.org
 help / color / mirror / Atom feed
* [f2fs-dev] [PATCH 0/3] *** support compressed file write amplifiction accounting ***
@ 2022-04-29  6:54 Fengnan Chang via Linux-f2fs-devel
  2022-04-29  6:54 ` [f2fs-dev] [PATCH 1/3] f2fs: intorduce f2fs_all_cluster_page_uptodate Fengnan Chang via Linux-f2fs-devel
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Fengnan Chang via Linux-f2fs-devel @ 2022-04-29  6:54 UTC (permalink / raw)
  To: jaegeuk, chao; +Cc: Fengnan Chang, linux-f2fs-devel

Optimise f2fs_write_cache_pages, and support compressed file write
amplifiction accounting.

Fengnan Chang (3):
  f2fs: intorduce f2fs_all_cluster_page_uptodate
  f2fs: use onstack pages instead of pvec
  f2fs: support compressed file write amplifiction accounting

 fs/f2fs/compress.c | 27 ++++++++++++++++++++++++---
 fs/f2fs/data.c     | 33 +++++++++++++++++++++------------
 fs/f2fs/debug.c    |  5 +++--
 fs/f2fs/f2fs.h     | 22 +++++++++++++++++++++-
 4 files changed, 69 insertions(+), 18 deletions(-)

-- 
2.32.0



_______________________________________________
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 1/3] f2fs: intorduce f2fs_all_cluster_page_uptodate
  2022-04-29  6:54 [f2fs-dev] [PATCH 0/3] *** support compressed file write amplifiction accounting *** Fengnan Chang via Linux-f2fs-devel
@ 2022-04-29  6:54 ` Fengnan Chang via Linux-f2fs-devel
  2022-05-06  8:01   ` Chao Yu
  2022-04-29  6:54 ` [f2fs-dev] [PATCH 2/3] f2fs: use onstack pages instead of pvec Fengnan Chang via Linux-f2fs-devel
  2022-04-29  6:54 ` [f2fs-dev] [PATCH 3/3] f2fs: support compressed file write amplifiction accounting Fengnan Chang via Linux-f2fs-devel
  2 siblings, 1 reply; 6+ messages in thread
From: Fengnan Chang via Linux-f2fs-devel @ 2022-04-29  6:54 UTC (permalink / raw)
  To: jaegeuk, chao; +Cc: Fengnan Chang, linux-f2fs-devel

Intorduce f2fs_all_cluster_page_uptodate, try to reduce call
f2fs_prepare_compress_overwrite.

Signed-off-by: Fengnan Chang <changfengnan@vivo.com>
---
 fs/f2fs/compress.c | 23 ++++++++++++++++++++++-
 fs/f2fs/data.c     |  5 +++++
 fs/f2fs/f2fs.h     |  2 ++
 3 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c
index 12a56f9e1572..11499fd3dd6b 100644
--- a/fs/f2fs/compress.c
+++ b/fs/f2fs/compress.c
@@ -871,6 +871,28 @@ bool f2fs_cluster_can_merge_page(struct compress_ctx *cc, pgoff_t index)
 	return is_page_in_cluster(cc, index);
 }
 
+bool f2fs_all_cluster_page_uptodate(struct compress_ctx *cc, struct pagevec *pvec,
+				int index, int nr_pages)
+{
+	unsigned long pgidx;
+	int i;
+
+	pgidx = pvec->pages[index]->index;
+	if (pgidx % cc->cluster_size)
+		return false;
+
+	if (nr_pages - index < cc->cluster_size)
+		return false;
+
+	for (i = 0; i < cc->cluster_size; i++) {
+		if (pvec->pages[index + i]->index != pgidx + i)
+			return false;
+		if (!PageUptodate(pvec->pages[index + i]))
+			return false;
+	}
+
+	return true;
+}
 bool f2fs_all_cluster_page_loaded(struct compress_ctx *cc, struct pagevec *pvec,
 				int index, int nr_pages)
 {
@@ -881,7 +903,6 @@ bool f2fs_all_cluster_page_loaded(struct compress_ctx *cc, struct pagevec *pvec,
 		return false;
 
 	pgidx = pvec->pages[index]->index;
-
 	for (i = 1; i < cc->cluster_size; i++) {
 		if (pvec->pages[index + i]->index != pgidx + i)
 			return false;
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 9a1a526f2092..b8204d91fed4 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -2967,6 +2967,11 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
 				if (!f2fs_cluster_is_empty(&cc))
 					goto lock_page;
 
+				if (f2fs_all_cluster_page_uptodate(&cc,
+					&pvec, i, nr_pages)) {
+					goto lock_page;
+				}
+
 				ret2 = f2fs_prepare_compress_overwrite(
 							inode, &pagep,
 							page->index, &fsdata);
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 38cbed0f544e..b4bed1e983bb 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -4180,6 +4180,8 @@ bool f2fs_cluster_can_merge_page(struct compress_ctx *cc, pgoff_t index);
 bool f2fs_all_cluster_page_loaded(struct compress_ctx *cc, struct pagevec *pvec,
 				int index, int nr_pages);
 bool f2fs_sanity_check_cluster(struct dnode_of_data *dn);
+bool f2fs_all_cluster_page_uptodate(struct compress_ctx *cc, struct pagevec *pvec,
+				int index, int nr_pages);
 void f2fs_compress_ctx_add_page(struct compress_ctx *cc, struct page *page);
 int f2fs_write_multi_pages(struct compress_ctx *cc,
 						int *submitted,
-- 
2.32.0



_______________________________________________
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 2/3] f2fs: use onstack pages instead of pvec
  2022-04-29  6:54 [f2fs-dev] [PATCH 0/3] *** support compressed file write amplifiction accounting *** Fengnan Chang via Linux-f2fs-devel
  2022-04-29  6:54 ` [f2fs-dev] [PATCH 1/3] f2fs: intorduce f2fs_all_cluster_page_uptodate Fengnan Chang via Linux-f2fs-devel
@ 2022-04-29  6:54 ` Fengnan Chang via Linux-f2fs-devel
  2022-04-29  6:54 ` [f2fs-dev] [PATCH 3/3] f2fs: support compressed file write amplifiction accounting Fengnan Chang via Linux-f2fs-devel
  2 siblings, 0 replies; 6+ messages in thread
From: Fengnan Chang via Linux-f2fs-devel @ 2022-04-29  6:54 UTC (permalink / raw)
  To: jaegeuk, chao; +Cc: Fengnan Chang, linux-f2fs-devel

Since pvec have 15 pages, it not a multiple of 4, when write compressed
pages, write in 64K as a unit, it will call pagevec_lookup_range_tag
agagin, sometimes this will take a lot of time.
Use onstack pages instead of pvec to mitigate this problem.

Signed-off-by: Fengnan Chang <changfengnan@vivo.com>
---
 fs/f2fs/compress.c | 14 +++++++-------
 fs/f2fs/data.c     | 16 +++++++---------
 fs/f2fs/f2fs.h     |  5 +++--
 3 files changed, 17 insertions(+), 18 deletions(-)

diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c
index 11499fd3dd6b..bebaae51863a 100644
--- a/fs/f2fs/compress.c
+++ b/fs/f2fs/compress.c
@@ -871,13 +871,13 @@ bool f2fs_cluster_can_merge_page(struct compress_ctx *cc, pgoff_t index)
 	return is_page_in_cluster(cc, index);
 }
 
-bool f2fs_all_cluster_page_uptodate(struct compress_ctx *cc, struct pagevec *pvec,
+bool f2fs_all_cluster_page_uptodate(struct compress_ctx *cc, struct page **pages,
 				int index, int nr_pages)
 {
 	unsigned long pgidx;
 	int i;
 
-	pgidx = pvec->pages[index]->index;
+	pgidx = pages[index]->index;
 	if (pgidx % cc->cluster_size)
 		return false;
 
@@ -885,15 +885,15 @@ bool f2fs_all_cluster_page_uptodate(struct compress_ctx *cc, struct pagevec *pve
 		return false;
 
 	for (i = 0; i < cc->cluster_size; i++) {
-		if (pvec->pages[index + i]->index != pgidx + i)
+		if (pages[index + i]->index != pgidx + i)
 			return false;
-		if (!PageUptodate(pvec->pages[index + i]))
+		if (!PageUptodate(pages[index + i]))
 			return false;
 	}
 
 	return true;
 }
-bool f2fs_all_cluster_page_loaded(struct compress_ctx *cc, struct pagevec *pvec,
+bool f2fs_all_cluster_page_loaded(struct compress_ctx *cc, struct page **pages,
 				int index, int nr_pages)
 {
 	unsigned long pgidx;
@@ -902,9 +902,9 @@ bool f2fs_all_cluster_page_loaded(struct compress_ctx *cc, struct pagevec *pvec,
 	if (nr_pages - index < cc->cluster_size)
 		return false;
 
-	pgidx = pvec->pages[index]->index;
+	pgidx = pages[index]->index;
 	for (i = 1; i < cc->cluster_size; i++) {
-		if (pvec->pages[index + i]->index != pgidx + i)
+		if (pages[index + i]->index != pgidx + i)
 			return false;
 	}
 
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index b8204d91fed4..dd9a97f6900c 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -2872,7 +2872,7 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
 {
 	int ret = 0;
 	int done = 0, retry = 0;
-	struct pagevec pvec;
+	struct page *pages[F2FS_ONSTACK_PAGES];
 	struct f2fs_sb_info *sbi = F2FS_M_SB(mapping);
 	struct bio *bio = NULL;
 	sector_t last_block;
@@ -2903,8 +2903,6 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
 	int submitted = 0;
 	int i;
 
-	pagevec_init(&pvec);
-
 	if (get_dirty_pages(mapping->host) <=
 				SM_I(F2FS_M_SB(mapping))->min_hot_blocks)
 		set_inode_flag(mapping->host, FI_HOT_DATA);
@@ -2930,13 +2928,13 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
 		tag_pages_for_writeback(mapping, index, end);
 	done_index = index;
 	while (!done && !retry && (index <= end)) {
-		nr_pages = pagevec_lookup_range_tag(&pvec, mapping, &index, end,
-				tag);
+		nr_pages = find_get_pages_range_tag(mapping, &index, end,
+				tag, F2FS_ONSTACK_PAGES, pages);
 		if (nr_pages == 0)
 			break;
 
 		for (i = 0; i < nr_pages; i++) {
-			struct page *page = pvec.pages[i];
+			struct page *page = pages[i];
 			bool need_readd;
 readd:
 			need_readd = false;
@@ -2968,7 +2966,7 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
 					goto lock_page;
 
 				if (f2fs_all_cluster_page_uptodate(&cc,
-					&pvec, i, nr_pages)) {
+					pages, i, nr_pages)) {
 					goto lock_page;
 				}
 
@@ -2983,7 +2981,7 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
 					(!f2fs_compress_write_end(inode,
 						fsdata, page->index, 1) ||
 					 !f2fs_all_cluster_page_loaded(&cc,
-						&pvec, i, nr_pages))) {
+						pages, i, nr_pages))) {
 					retry = 1;
 					break;
 				}
@@ -3073,7 +3071,7 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
 			if (need_readd)
 				goto readd;
 		}
-		pagevec_release(&pvec);
+		release_pages(pages, nr_pages);
 		cond_resched();
 	}
 #ifdef CONFIG_F2FS_FS_COMPRESSION
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index b4bed1e983bb..4b005d7f326a 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -597,6 +597,7 @@ enum {
 #define RECOVERY_MAX_RA_BLOCKS		BIO_MAX_VECS
 #define RECOVERY_MIN_RA_BLOCKS		1
 
+#define F2FS_ONSTACK_PAGES	16	/* nr of onstack pages */
 struct rb_entry {
 	struct rb_node rb_node;		/* rb node located in rb-tree */
 	union {
@@ -4177,10 +4178,10 @@ void f2fs_end_read_compressed_page(struct page *page, bool failed,
 							block_t blkaddr);
 bool f2fs_cluster_is_empty(struct compress_ctx *cc);
 bool f2fs_cluster_can_merge_page(struct compress_ctx *cc, pgoff_t index);
-bool f2fs_all_cluster_page_loaded(struct compress_ctx *cc, struct pagevec *pvec,
+bool f2fs_all_cluster_page_loaded(struct compress_ctx *cc, struct page **pages,
 				int index, int nr_pages);
 bool f2fs_sanity_check_cluster(struct dnode_of_data *dn);
-bool f2fs_all_cluster_page_uptodate(struct compress_ctx *cc, struct pagevec *pvec,
+bool f2fs_all_cluster_page_uptodate(struct compress_ctx *cc, struct page **pages,
 				int index, int nr_pages);
 void f2fs_compress_ctx_add_page(struct compress_ctx *cc, struct page *page);
 int f2fs_write_multi_pages(struct compress_ctx *cc,
-- 
2.32.0



_______________________________________________
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 3/3] f2fs: support compressed file write amplifiction accounting
  2022-04-29  6:54 [f2fs-dev] [PATCH 0/3] *** support compressed file write amplifiction accounting *** Fengnan Chang via Linux-f2fs-devel
  2022-04-29  6:54 ` [f2fs-dev] [PATCH 1/3] f2fs: intorduce f2fs_all_cluster_page_uptodate Fengnan Chang via Linux-f2fs-devel
  2022-04-29  6:54 ` [f2fs-dev] [PATCH 2/3] f2fs: use onstack pages instead of pvec Fengnan Chang via Linux-f2fs-devel
@ 2022-04-29  6:54 ` Fengnan Chang via Linux-f2fs-devel
  2022-05-06  8:13   ` Chao Yu
  2 siblings, 1 reply; 6+ messages in thread
From: Fengnan Chang via Linux-f2fs-devel @ 2022-04-29  6:54 UTC (permalink / raw)
  To: jaegeuk, chao; +Cc: Fengnan Chang, linux-f2fs-devel

Try to support compressed file write amplifiction accounting.

Signed-off-by: Fengnan Chang <changfengnan@vivo.com>
---
 fs/f2fs/data.c  | 14 ++++++++++----
 fs/f2fs/debug.c |  5 +++--
 fs/f2fs/f2fs.h  | 17 +++++++++++++++++
 3 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index dd9a97f6900c..fe64f2328c97 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -2900,11 +2900,11 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
 	int range_whole = 0;
 	xa_mark_t tag;
 	int nwritten = 0;
-	int submitted = 0;
+	int submitted = 0, raw_dirty_pages = 0;
 	int i;

-	if (get_dirty_pages(mapping->host) <=
-				SM_I(F2FS_M_SB(mapping))->min_hot_blocks)
+	raw_dirty_pages = get_dirty_pages(mapping->host);
+	if (raw_dirty_pages <= SM_I(F2FS_M_SB(mapping))->min_hot_blocks)
 		set_inode_flag(mapping->host, FI_HOT_DATA);
 	else
 		clear_inode_flag(mapping->host, FI_HOT_DATA);
@@ -3039,7 +3039,6 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
 #endif
 			nwritten += submitted;
 			wbc->nr_to_write -= submitted;
-
 			if (unlikely(ret)) {
 				/*
 				 * keep nr_to_write, since vfs uses this to
@@ -3105,6 +3104,12 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
 	if (bio)
 		f2fs_submit_merged_ipu_write(sbi, &bio, NULL);
 
+	if (f2fs_compressed_file(inode)) {
+		if (nwritten > raw_dirty_pages)
+			f2fs_i_compr_wa_blocks_update(inode, nwritten - raw_dirty_pages, true);
+		else
+			f2fs_i_compr_wa_blocks_update(inode, raw_dirty_pages - nwritten, false);
+	}
 	return ret;
 }
 
@@ -3369,6 +3374,7 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,
 			err = ret;
 			goto fail;
 		} else if (ret) {
+			f2fs_i_compr_wa_blocks_update(inode, ret - 1, true);
 			return 0;
 		}
 	}
diff --git a/fs/f2fs/debug.c b/fs/f2fs/debug.c
index fcdf253cd211..d5e1ab7abedb 100644
--- a/fs/f2fs/debug.c
+++ b/fs/f2fs/debug.c
@@ -139,6 +139,7 @@ static void update_general_status(struct f2fs_sb_info *sbi)
 	si->inline_dir = atomic_read(&sbi->inline_dir);
 	si->compr_inode = atomic_read(&sbi->compr_inode);
 	si->compr_blocks = atomic64_read(&sbi->compr_blocks);
+	si->compr_wa_blocks = atomic64_read(&sbi->compr_wa_blocks);
 	si->append = sbi->im[APPEND_INO].ino_num;
 	si->update = sbi->im[UPDATE_INO].ino_num;
 	si->orphans = sbi->im[ORPHAN_INO].ino_num;
@@ -389,8 +390,8 @@ static int stat_show(struct seq_file *s, void *v)
 			   si->inline_inode);
 		seq_printf(s, "  - Inline_dentry Inode: %u\n",
 			   si->inline_dir);
-		seq_printf(s, "  - Compressed Inode: %u, Blocks: %llu\n",
-			   si->compr_inode, si->compr_blocks);
+		seq_printf(s, "  - Compressed Inode: %u, Blocks: %llu, WA Blocks: %lld\n",
+			   si->compr_inode, si->compr_blocks, si->compr_wa_blocks);
 		seq_printf(s, "  - Orphan/Append/Update Inode: %u, %u, %u\n",
 			   si->orphans, si->append, si->update);
 		seq_printf(s, "\nMain area: %d segs, %d secs %d zones\n",
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 4b005d7f326a..42030a8cef45 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -1750,6 +1750,7 @@ struct f2fs_sb_info {
 	atomic_t inline_dir;			/* # of inline_dentry inodes */
 	atomic_t compr_inode;			/* # of compressed inodes */
 	atomic64_t compr_blocks;		/* # of compressed blocks */
+	atomic64_t compr_wa_blocks;		/* # of compressed WA blocks */
 	atomic_t vw_cnt;			/* # of volatile writes */
 	atomic_t max_aw_cnt;			/* max # of atomic writes */
 	atomic_t max_vw_cnt;			/* max # of volatile writes */
@@ -3828,6 +3829,7 @@ struct f2fs_stat_info {
 	int inline_xattr, inline_inode, inline_dir, append, update, orphans;
 	int compr_inode;
 	unsigned long long compr_blocks;
+	long long compr_wa_blocks;
 	int aw_cnt, max_aw_cnt, vw_cnt, max_vw_cnt;
 	unsigned int valid_count, valid_node_count, valid_inode_count, discard_blks;
 	unsigned int bimodal, avg_vblocks;
@@ -3916,6 +3918,10 @@ static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi)
 		(atomic64_add(blocks, &F2FS_I_SB(inode)->compr_blocks))
 #define stat_sub_compr_blocks(inode, blocks)				\
 		(atomic64_sub(blocks, &F2FS_I_SB(inode)->compr_blocks))
+#define stat_add_compr_wa_blocks(inode, blocks)				\
+	(atomic64_add(blocks, &F2FS_I_SB(inode)->compr_wa_blocks))
+#define stat_sub_compr_wa_blocks(inode, blocks)				\
+	(atomic64_sub(blocks, &F2FS_I_SB(inode)->compr_wa_blocks))
 #define stat_inc_meta_count(sbi, blkaddr)				\
 	do {								\
 		if (blkaddr < SIT_I(sbi)->sit_base_addr)		\
@@ -4011,6 +4017,8 @@ void f2fs_update_sit_info(struct f2fs_sb_info *sbi);
 #define stat_dec_compr_inode(inode)			do { } while (0)
 #define stat_add_compr_blocks(inode, blocks)		do { } while (0)
 #define stat_sub_compr_blocks(inode, blocks)		do { } while (0)
+#define stat_add_compr_wa_blocks(inode, blocks)	do { } while (0)
+#define stat_sub_compr_wa_blocks(inode, blocks)	do { } while (0)
 #define stat_update_max_atomic_write(inode)		do { } while (0)
 #define stat_inc_volatile_write(inode)			do { } while (0)
 #define stat_dec_volatile_write(inode)			do { } while (0)
@@ -4445,6 +4453,15 @@ static inline void f2fs_i_compr_blocks_update(struct inode *inode,
 	f2fs_mark_inode_dirty_sync(inode, true);
 }
 
+static inline void f2fs_i_compr_wa_blocks_update(struct inode *inode,
+						u64 blocks, bool add)
+{
+	if (add)
+		stat_add_compr_wa_blocks(inode, blocks);
+	else
+		stat_sub_compr_wa_blocks(inode, blocks);
+}
+
 static inline int block_unaligned_IO(struct inode *inode,
 				struct kiocb *iocb, struct iov_iter *iter)
 {
-- 
2.32.0



_______________________________________________
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 1/3] f2fs: intorduce f2fs_all_cluster_page_uptodate
  2022-04-29  6:54 ` [f2fs-dev] [PATCH 1/3] f2fs: intorduce f2fs_all_cluster_page_uptodate Fengnan Chang via Linux-f2fs-devel
@ 2022-05-06  8:01   ` Chao Yu
  0 siblings, 0 replies; 6+ messages in thread
From: Chao Yu @ 2022-05-06  8:01 UTC (permalink / raw)
  To: Fengnan Chang, jaegeuk; +Cc: linux-f2fs-devel

On 2022/4/29 14:54, Fengnan Chang wrote:
> Intorduce f2fs_all_cluster_page_uptodate, try to reduce call
> f2fs_prepare_compress_overwrite.

Hmm... it's better to describe in which case newly introduced
function can improve performance...

> 
> Signed-off-by: Fengnan Chang <changfengnan@vivo.com>
> ---
>   fs/f2fs/compress.c | 23 ++++++++++++++++++++++-
>   fs/f2fs/data.c     |  5 +++++
>   fs/f2fs/f2fs.h     |  2 ++
>   3 files changed, 29 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c
> index 12a56f9e1572..11499fd3dd6b 100644
> --- a/fs/f2fs/compress.c
> +++ b/fs/f2fs/compress.c
> @@ -871,6 +871,28 @@ bool f2fs_cluster_can_merge_page(struct compress_ctx *cc, pgoff_t index)
>   	return is_page_in_cluster(cc, index);
>   }
>   
> +bool f2fs_all_cluster_page_uptodate(struct compress_ctx *cc, struct pagevec *pvec,
> +				int index, int nr_pages)

Is it possible to merge f2fs_all_cluster_page_uptodate and
f2fs_all_cluster_page_loaded() into a common function, something like:
f2fs_all_cluster_page_ready(bool update)?

Thanks,

> +{
> +	unsigned long pgidx;
> +	int i;
> +
> +	pgidx = pvec->pages[index]->index;
> +	if (pgidx % cc->cluster_size)
> +		return false;
> +
> +	if (nr_pages - index < cc->cluster_size)
> +		return false;
> +
> +	for (i = 0; i < cc->cluster_size; i++) {
> +		if (pvec->pages[index + i]->index != pgidx + i)
> +			return false;
> +		if (!PageUptodate(pvec->pages[index + i]))
> +			return false;
> +	}
> +
> +	return true;
> +}
>   bool f2fs_all_cluster_page_loaded(struct compress_ctx *cc, struct pagevec *pvec,
>   				int index, int nr_pages)
>   {
> @@ -881,7 +903,6 @@ bool f2fs_all_cluster_page_loaded(struct compress_ctx *cc, struct pagevec *pvec,
>   		return false;
>   
>   	pgidx = pvec->pages[index]->index;
> -
>   	for (i = 1; i < cc->cluster_size; i++) {
>   		if (pvec->pages[index + i]->index != pgidx + i)
>   			return false;
> diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
> index 9a1a526f2092..b8204d91fed4 100644
> --- a/fs/f2fs/data.c
> +++ b/fs/f2fs/data.c
> @@ -2967,6 +2967,11 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
>   				if (!f2fs_cluster_is_empty(&cc))
>   					goto lock_page;
>   
> +				if (f2fs_all_cluster_page_uptodate(&cc,
> +					&pvec, i, nr_pages)) {
> +					goto lock_page;
> +				}
> +
>   				ret2 = f2fs_prepare_compress_overwrite(
>   							inode, &pagep,
>   							page->index, &fsdata);
> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> index 38cbed0f544e..b4bed1e983bb 100644
> --- a/fs/f2fs/f2fs.h
> +++ b/fs/f2fs/f2fs.h
> @@ -4180,6 +4180,8 @@ bool f2fs_cluster_can_merge_page(struct compress_ctx *cc, pgoff_t index);
>   bool f2fs_all_cluster_page_loaded(struct compress_ctx *cc, struct pagevec *pvec,
>   				int index, int nr_pages);
>   bool f2fs_sanity_check_cluster(struct dnode_of_data *dn);
> +bool f2fs_all_cluster_page_uptodate(struct compress_ctx *cc, struct pagevec *pvec,
> +				int index, int nr_pages);
>   void f2fs_compress_ctx_add_page(struct compress_ctx *cc, struct page *page);
>   int f2fs_write_multi_pages(struct compress_ctx *cc,
>   						int *submitted,


_______________________________________________
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

* Re: [f2fs-dev] [PATCH 3/3] f2fs: support compressed file write amplifiction accounting
  2022-04-29  6:54 ` [f2fs-dev] [PATCH 3/3] f2fs: support compressed file write amplifiction accounting Fengnan Chang via Linux-f2fs-devel
@ 2022-05-06  8:13   ` Chao Yu
  0 siblings, 0 replies; 6+ messages in thread
From: Chao Yu @ 2022-05-06  8:13 UTC (permalink / raw)
  To: Fengnan Chang, jaegeuk; +Cc: linux-f2fs-devel

On 2022/4/29 14:54, Fengnan Chang wrote:
> Try to support compressed file write amplifiction accounting.

Well, how about adding this info into iostat fwk? including read amplification?

Thanks,

> 
> Signed-off-by: Fengnan Chang <changfengnan@vivo.com>
> ---
>   fs/f2fs/data.c  | 14 ++++++++++----
>   fs/f2fs/debug.c |  5 +++--
>   fs/f2fs/f2fs.h  | 17 +++++++++++++++++
>   3 files changed, 30 insertions(+), 6 deletions(-)
> 
> diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
> index dd9a97f6900c..fe64f2328c97 100644
> --- a/fs/f2fs/data.c
> +++ b/fs/f2fs/data.c
> @@ -2900,11 +2900,11 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
>   	int range_whole = 0;
>   	xa_mark_t tag;
>   	int nwritten = 0;
> -	int submitted = 0;
> +	int submitted = 0, raw_dirty_pages = 0;
>   	int i;
> 
> -	if (get_dirty_pages(mapping->host) <=
> -				SM_I(F2FS_M_SB(mapping))->min_hot_blocks)
> +	raw_dirty_pages = get_dirty_pages(mapping->host);
> +	if (raw_dirty_pages <= SM_I(F2FS_M_SB(mapping))->min_hot_blocks)
>   		set_inode_flag(mapping->host, FI_HOT_DATA);
>   	else
>   		clear_inode_flag(mapping->host, FI_HOT_DATA);
> @@ -3039,7 +3039,6 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
>   #endif
>   			nwritten += submitted;
>   			wbc->nr_to_write -= submitted;
> -
>   			if (unlikely(ret)) {
>   				/*
>   				 * keep nr_to_write, since vfs uses this to
> @@ -3105,6 +3104,12 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
>   	if (bio)
>   		f2fs_submit_merged_ipu_write(sbi, &bio, NULL);
>   
> +	if (f2fs_compressed_file(inode)) {
> +		if (nwritten > raw_dirty_pages)
> +			f2fs_i_compr_wa_blocks_update(inode, nwritten - raw_dirty_pages, true);
> +		else
> +			f2fs_i_compr_wa_blocks_update(inode, raw_dirty_pages - nwritten, false);
> +	}
>   	return ret;
>   }
>   
> @@ -3369,6 +3374,7 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,
>   			err = ret;
>   			goto fail;
>   		} else if (ret) {
> +			f2fs_i_compr_wa_blocks_update(inode, ret - 1, true);
>   			return 0;
>   		}
>   	}
> diff --git a/fs/f2fs/debug.c b/fs/f2fs/debug.c
> index fcdf253cd211..d5e1ab7abedb 100644
> --- a/fs/f2fs/debug.c
> +++ b/fs/f2fs/debug.c
> @@ -139,6 +139,7 @@ static void update_general_status(struct f2fs_sb_info *sbi)
>   	si->inline_dir = atomic_read(&sbi->inline_dir);
>   	si->compr_inode = atomic_read(&sbi->compr_inode);
>   	si->compr_blocks = atomic64_read(&sbi->compr_blocks);
> +	si->compr_wa_blocks = atomic64_read(&sbi->compr_wa_blocks);
>   	si->append = sbi->im[APPEND_INO].ino_num;
>   	si->update = sbi->im[UPDATE_INO].ino_num;
>   	si->orphans = sbi->im[ORPHAN_INO].ino_num;
> @@ -389,8 +390,8 @@ static int stat_show(struct seq_file *s, void *v)
>   			   si->inline_inode);
>   		seq_printf(s, "  - Inline_dentry Inode: %u\n",
>   			   si->inline_dir);
> -		seq_printf(s, "  - Compressed Inode: %u, Blocks: %llu\n",
> -			   si->compr_inode, si->compr_blocks);
> +		seq_printf(s, "  - Compressed Inode: %u, Blocks: %llu, WA Blocks: %lld\n",
> +			   si->compr_inode, si->compr_blocks, si->compr_wa_blocks);
>   		seq_printf(s, "  - Orphan/Append/Update Inode: %u, %u, %u\n",
>   			   si->orphans, si->append, si->update);
>   		seq_printf(s, "\nMain area: %d segs, %d secs %d zones\n",
> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> index 4b005d7f326a..42030a8cef45 100644
> --- a/fs/f2fs/f2fs.h
> +++ b/fs/f2fs/f2fs.h
> @@ -1750,6 +1750,7 @@ struct f2fs_sb_info {
>   	atomic_t inline_dir;			/* # of inline_dentry inodes */
>   	atomic_t compr_inode;			/* # of compressed inodes */
>   	atomic64_t compr_blocks;		/* # of compressed blocks */
> +	atomic64_t compr_wa_blocks;		/* # of compressed WA blocks */
>   	atomic_t vw_cnt;			/* # of volatile writes */
>   	atomic_t max_aw_cnt;			/* max # of atomic writes */
>   	atomic_t max_vw_cnt;			/* max # of volatile writes */
> @@ -3828,6 +3829,7 @@ struct f2fs_stat_info {
>   	int inline_xattr, inline_inode, inline_dir, append, update, orphans;
>   	int compr_inode;
>   	unsigned long long compr_blocks;
> +	long long compr_wa_blocks;
>   	int aw_cnt, max_aw_cnt, vw_cnt, max_vw_cnt;
>   	unsigned int valid_count, valid_node_count, valid_inode_count, discard_blks;
>   	unsigned int bimodal, avg_vblocks;
> @@ -3916,6 +3918,10 @@ static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi)
>   		(atomic64_add(blocks, &F2FS_I_SB(inode)->compr_blocks))
>   #define stat_sub_compr_blocks(inode, blocks)				\
>   		(atomic64_sub(blocks, &F2FS_I_SB(inode)->compr_blocks))
> +#define stat_add_compr_wa_blocks(inode, blocks)				\
> +	(atomic64_add(blocks, &F2FS_I_SB(inode)->compr_wa_blocks))
> +#define stat_sub_compr_wa_blocks(inode, blocks)				\
> +	(atomic64_sub(blocks, &F2FS_I_SB(inode)->compr_wa_blocks))
>   #define stat_inc_meta_count(sbi, blkaddr)				\
>   	do {								\
>   		if (blkaddr < SIT_I(sbi)->sit_base_addr)		\
> @@ -4011,6 +4017,8 @@ void f2fs_update_sit_info(struct f2fs_sb_info *sbi);
>   #define stat_dec_compr_inode(inode)			do { } while (0)
>   #define stat_add_compr_blocks(inode, blocks)		do { } while (0)
>   #define stat_sub_compr_blocks(inode, blocks)		do { } while (0)
> +#define stat_add_compr_wa_blocks(inode, blocks)	do { } while (0)
> +#define stat_sub_compr_wa_blocks(inode, blocks)	do { } while (0)
>   #define stat_update_max_atomic_write(inode)		do { } while (0)
>   #define stat_inc_volatile_write(inode)			do { } while (0)
>   #define stat_dec_volatile_write(inode)			do { } while (0)
> @@ -4445,6 +4453,15 @@ static inline void f2fs_i_compr_blocks_update(struct inode *inode,
>   	f2fs_mark_inode_dirty_sync(inode, true);
>   }
>   
> +static inline void f2fs_i_compr_wa_blocks_update(struct inode *inode,
> +						u64 blocks, bool add)
> +{
> +	if (add)
> +		stat_add_compr_wa_blocks(inode, blocks);
> +	else
> +		stat_sub_compr_wa_blocks(inode, blocks);
> +}
> +
>   static inline int block_unaligned_IO(struct inode *inode,
>   				struct kiocb *iocb, struct iov_iter *iter)
>   {


_______________________________________________
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-05-06  8:14 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-29  6:54 [f2fs-dev] [PATCH 0/3] *** support compressed file write amplifiction accounting *** Fengnan Chang via Linux-f2fs-devel
2022-04-29  6:54 ` [f2fs-dev] [PATCH 1/3] f2fs: intorduce f2fs_all_cluster_page_uptodate Fengnan Chang via Linux-f2fs-devel
2022-05-06  8:01   ` Chao Yu
2022-04-29  6:54 ` [f2fs-dev] [PATCH 2/3] f2fs: use onstack pages instead of pvec Fengnan Chang via Linux-f2fs-devel
2022-04-29  6:54 ` [f2fs-dev] [PATCH 3/3] f2fs: support compressed file write amplifiction accounting Fengnan Chang via Linux-f2fs-devel
2022-05-06  8:13   ` Chao Yu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.