linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
From: Jaegeuk Kim <jaegeuk@kernel.org>
To: Chao Yu <chao@kernel.org>
Cc: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net
Subject: Re: [f2fs-dev] [PATCH v2 1/2] f2fs: introduce get_available_block_count() for cleanup
Date: Fri, 6 Sep 2019 16:10:27 -0700	[thread overview]
Message-ID: <20190906231027.GB71848@jaegeuk-macbookpro.roam.corp.google.com> (raw)
In-Reply-To: <6c5da795-4929-3bb6-fdbf-e103a2bcd431@kernel.org>

On 09/03, Chao Yu wrote:
> On 2019-9-3 6:54, Jaegeuk Kim wrote:
> > On 08/31, Chao Yu wrote:
> >> There are very similar codes in inc_valid_block_count() and
> >> inc_valid_node_count() which is used for available user block
> >> count calculation.
> >>
> >> This patch introduces a new helper get_available_block_count()
> >> to include those common codes, and used it instead for cleanup.
> >>
> >> Signed-off-by: Chao Yu <yuchao0@huawei.com>
> >> ---
> >> v2:
> >> - fix panic during recovery
> >>  fs/f2fs/f2fs.h | 47 +++++++++++++++++++++++++++--------------------
> >>  1 file changed, 27 insertions(+), 20 deletions(-)
> >>
> >> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> >> index a89ad8cab821..9c010e6cba5c 100644
> >> --- a/fs/f2fs/f2fs.h
> >> +++ b/fs/f2fs/f2fs.h
> >> @@ -1756,6 +1756,27 @@ static inline bool __allow_reserved_blocks(struct f2fs_sb_info *sbi,
> >>  	return false;
> >>  }
> >>  
> >> +static inline unsigned int get_available_block_count(struct f2fs_sb_info *sbi,
> >> +						struct inode *inode, bool cap)
> >> +{
> >> +	block_t avail_user_block_count;
> >> +
> >> +	avail_user_block_count = sbi->user_block_count -
> >> +					sbi->current_reserved_blocks;
> >> +
> >> +	if (!__allow_reserved_blocks(sbi, inode, cap))
> >> +		avail_user_block_count -= F2FS_OPTION(sbi).root_reserved_blocks;
> >> +
> >> +	if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) {
> >> +		if (avail_user_block_count > sbi->unusable_block_count)
> >> +			avail_user_block_count -= sbi->unusable_block_count;
> >> +		else
> >> +			avail_user_block_count = 0;
> >> +	}
> >> +
> >> +	return avail_user_block_count;
> >> +}
> >> +
> >>  static inline void f2fs_i_blocks_write(struct inode *, block_t, bool, bool);
> >>  static inline int inc_valid_block_count(struct f2fs_sb_info *sbi,
> >>  				 struct inode *inode, blkcnt_t *count)
> >> @@ -1782,17 +1803,8 @@ static inline int inc_valid_block_count(struct f2fs_sb_info *sbi,
> >>  
> >>  	spin_lock(&sbi->stat_lock);
> >>  	sbi->total_valid_block_count += (block_t)(*count);
> >> -	avail_user_block_count = sbi->user_block_count -
> >> -					sbi->current_reserved_blocks;
> >> +	avail_user_block_count = get_available_block_count(sbi, inode, true);
> >>  
> >> -	if (!__allow_reserved_blocks(sbi, inode, true))
> >> -		avail_user_block_count -= F2FS_OPTION(sbi).root_reserved_blocks;
> >> -	if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) {
> >> -		if (avail_user_block_count > sbi->unusable_block_count)
> >> -			avail_user_block_count -= sbi->unusable_block_count;
> >> -		else
> >> -			avail_user_block_count = 0;
> >> -	}
> >>  	if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) {
> >>  		diff = sbi->total_valid_block_count - avail_user_block_count;
> >>  		if (diff > *count)
> >> @@ -2005,7 +2017,8 @@ static inline int inc_valid_node_count(struct f2fs_sb_info *sbi,
> >>  					struct inode *inode, bool is_inode)
> >>  {
> >>  	block_t	valid_block_count;
> >> -	unsigned int valid_node_count, user_block_count;
> >> +	unsigned int valid_node_count;
> >> +	unsigned int avail_user_block_count;
> >>  	int err;
> >>  
> >>  	if (is_inode) {
> >> @@ -2027,16 +2040,10 @@ static inline int inc_valid_node_count(struct f2fs_sb_info *sbi,
> >>  
> >>  	spin_lock(&sbi->stat_lock);
> >>  
> >> -	valid_block_count = sbi->total_valid_block_count +
> >> -					sbi->current_reserved_blocks + 1;
> >> -
> >> -	if (!__allow_reserved_blocks(sbi, inode, false))
> >> -		valid_block_count += F2FS_OPTION(sbi).root_reserved_blocks;
> >> -	user_block_count = sbi->user_block_count;
> >> -	if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED)))
> >> -		user_block_count -= sbi->unusable_block_count;
> >> +	valid_block_count = sbi->total_valid_block_count + 1;
> >> +	avail_user_block_count = get_available_block_count(sbi, inode, false);
> > 
> > This doesn't look like same?
> 
> Actually, calculations of block count in inc_valid_node_count() and
> inc_valid_block_count() should be the same, I've no idea why we use different
> policy for reserved block for root user.

Hmm, for now, let's defer to discuss this.

> 
> Thanks,
> 
> > 
> >>  
> >> -	if (unlikely(valid_block_count > user_block_count)) {
> >> +	if (unlikely(valid_block_count > avail_user_block_count)) {
> >>  		spin_unlock(&sbi->stat_lock);
> >>  		goto enospc;
> >>  	}
> >> -- 
> >> 2.18.0.rc1


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

      reply	other threads:[~2019-09-06 23:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-31  9:54 [f2fs-dev] [PATCH v2 1/2] f2fs: introduce get_available_block_count() for cleanup Chao Yu
2019-08-31  9:54 ` [f2fs-dev] [PATCH v2 2/2] f2fs: fix to reserve space for IO align feature Chao Yu
2019-09-02 22:54 ` [f2fs-dev] [PATCH v2 1/2] f2fs: introduce get_available_block_count() for cleanup Jaegeuk Kim
2019-09-02 23:29   ` Chao Yu
2019-09-06 23:10     ` Jaegeuk Kim [this message]

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=20190906231027.GB71848@jaegeuk-macbookpro.roam.corp.google.com \
    --to=jaegeuk@kernel.org \
    --cc=chao@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    /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).