linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
From: Chao Yu <chao@kernel.org>
To: Fengnan Chang <fengnanchang@gmail.com>, jaegeuk@kernel.org
Cc: Fengnan Chang <changfengnan@vivo.com>,
	linux-f2fs-devel@lists.sourceforge.net
Subject: Re: [f2fs-dev] [PATCH v3 3/3] f2fs: support compressed file write/read amplifiction
Date: Sun, 24 Jul 2022 17:58:28 +0800	[thread overview]
Message-ID: <a931509e-aba2-1d67-789a-72b830d872cc@kernel.org> (raw)
In-Reply-To: <20220717053207.192372-4-fengnanchang@gmail.com>

On 2022/7/17 13:32, Fengnan Chang wrote:
> From: Fengnan Chang <changfengnan@vivo.com>
> 
> Try to support compressed file write and amplifiction accounting.
> 
> Signed-off-by: Fengnan Chang <changfengnan@vivo.com>
> ---
>   fs/f2fs/data.c  | 26 +++++++++++++++++++++-----
>   fs/f2fs/debug.c |  7 +++++--
>   fs/f2fs/f2fs.h  | 34 ++++++++++++++++++++++++++++++++++
>   3 files changed, 60 insertions(+), 7 deletions(-)
> 
> diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
> index d2d2cfd54210..d0532958835b 100644
> --- a/fs/f2fs/data.c
> +++ b/fs/f2fs/data.c
> @@ -2132,7 +2132,7 @@ int f2fs_read_multi_pages(struct compress_ctx *cc, struct bio **bio_ret,
>   	struct extent_info ei = {0, };
>   	bool from_dnode = true;
>   	int i;
> -	int ret = 0;
> +	int ret = 0, nr_cache_hit = 0;
>   
>   	f2fs_bug_on(sbi, f2fs_cluster_is_empty(cc));
>   
> @@ -2223,6 +2223,7 @@ int f2fs_read_multi_pages(struct compress_ctx *cc, struct bio **bio_ret,
>   		if (f2fs_load_compressed_page(sbi, page, blkaddr)) {
>   			if (atomic_dec_and_test(&dic->remaining_pages))
>   				f2fs_decompress_cluster(dic);
> +			nr_cache_hit++;
>   			continue;
>   		}
>   
> @@ -2261,6 +2262,15 @@ int f2fs_read_multi_pages(struct compress_ctx *cc, struct bio **bio_ret,
>   		*last_block_in_bio = blkaddr;
>   	}
>   
> +	if (cc->nr_cpages - nr_cache_hit > cc->nr_rpages)
> +		f2fs_i_compr_ra_blocks_update(inode,
> +				cc->nr_cpages - nr_cache_hit - cc->nr_rpages,

I guess nr_rpages is not accurate here, due to it always equals to cluster_size,
however user may just want to read one page data.

Hmm...I found iostat framework has already accounted FS_CDATA_READ_IO IO, how
about adjusting it to support accounting compressed inode's read/write IOs?

Thanks,

> +				true);
> +	else
> +		f2fs_i_compr_ra_blocks_update(inode,
> +				cc->nr_rpages - cc->nr_cpages + nr_cache_hit,
> +				false);
> +
>   	if (from_dnode)
>   		f2fs_put_dnode(&dn);
>   
> @@ -2929,11 +2939,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);
> @@ -3067,7 +3077,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
> @@ -3133,6 +3142,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;
>   }
>   
> @@ -3482,6 +3497,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 c92625ef16d0..2bbf7fa49097 100644
> --- a/fs/f2fs/debug.c
> +++ b/fs/f2fs/debug.c
> @@ -136,6 +136,8 @@ 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->compr_ra_blocks = atomic64_read(&sbi->compr_ra_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;
> @@ -383,8 +385,9 @@ 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, RA Blocks %lld\n",
> +			   si->compr_inode, si->compr_blocks,
> +			   si->compr_wa_blocks, si->compr_ra_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 06d0370fd760..9d0429e91718 100644
> --- a/fs/f2fs/f2fs.h
> +++ b/fs/f2fs/f2fs.h
> @@ -1749,6 +1749,8 @@ 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 */
> +	atomic64_t compr_ra_blocks;		/* # of compressed RA blocks */
>   	atomic_t max_aw_cnt;			/* max # of atomic writes */
>   	unsigned int io_skip_bggc;		/* skip background gc for in-flight IO */
>   	unsigned int other_skip_bggc;		/* skip background gc for other reasons */
> @@ -3829,6 +3831,8 @@ 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;
> +	long long compr_ra_blocks;
>   	int aw_cnt, max_aw_cnt;
>   	unsigned int valid_count, valid_node_count, valid_inode_count, discard_blks;
>   	unsigned int bimodal, avg_vblocks;
> @@ -3916,6 +3920,14 @@ 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_add_compr_ra_blocks(inode, blocks)				\
> +	(atomic64_add(blocks, &F2FS_I_SB(inode)->compr_ra_blocks))
> +#define stat_sub_compr_ra_blocks(inode, blocks)				\
> +	(atomic64_sub(blocks, &F2FS_I_SB(inode)->compr_ra_blocks))
>   #define stat_inc_meta_count(sbi, blkaddr)				\
>   	do {								\
>   		if (blkaddr < SIT_I(sbi)->sit_base_addr)		\
> @@ -4000,6 +4012,10 @@ 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_add_compr_ra_blocks(inode, blocks)		do { } while (0)
> +#define stat_sub_compr_ra_blocks(inode, blocks)		do { } while (0)
>   #define stat_update_max_atomic_write(inode)		do { } while (0)
>   #define stat_inc_meta_count(sbi, blkaddr)		do { } while (0)
>   #define stat_inc_seg_type(sbi, curseg)			do { } while (0)
> @@ -4428,6 +4444,24 @@ 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 void f2fs_i_compr_ra_blocks_update(struct inode *inode,
> +						u64 blocks, bool add)
> +{
> +	if (add)
> +		stat_add_compr_ra_blocks(inode, blocks);
> +	else
> +		stat_sub_compr_ra_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

  reply	other threads:[~2022-07-24  9:58 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-17  5:32 [f2fs-dev] [PATCH v3 0/3] support compressed file write/read amplifiction Fengnan Chang
2022-07-17  5:32 ` [f2fs-dev] [PATCH v3 1/3] f2fs: intorduce f2fs_all_cluster_page_ready Fengnan Chang
2022-07-24  9:33   ` Chao Yu
2022-07-17  5:32 ` [f2fs-dev] [PATCH v3 2/3] f2fs: use onstack pages instead of pvec Fengnan Chang
2022-07-17  5:32 ` [f2fs-dev] [PATCH v3 3/3] f2fs: support compressed file write/read amplifiction Fengnan Chang
2022-07-24  9:58   ` Chao Yu [this message]
2022-07-25 13:00     ` fengnan chang
2022-07-24  9:36 ` [f2fs-dev] [PATCH v3 0/3] " Chao Yu

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=a931509e-aba2-1d67-789a-72b830d872cc@kernel.org \
    --to=chao@kernel.org \
    --cc=changfengnan@vivo.com \
    --cc=fengnanchang@gmail.com \
    --cc=jaegeuk@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    /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).