All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jaegeuk Kim <jaegeuk@kernel.org>
To: Kinglong Mee <kinglongmee@gmail.com>
Cc: Chao Yu <yuchao0@huawei.com>,
	chao@kernel.org, linux-kernel@vger.kernel.org,
	linux-f2fs-devel@lists.sourceforge.net
Subject: Re: [f2fs-dev] [PATCH] f2fs: cover update_free_nid_bitmap with free_list_lock
Date: Mon, 13 Mar 2017 12:57:35 -0700	[thread overview]
Message-ID: <20170313195735.GD41055@jaegeuk.local> (raw)
In-Reply-To: <5cd19a42-0941-2dbd-fbae-b885b79cb227@gmail.com>

On 03/13, Kinglong Mee wrote:
> On 3/13/2017 20:10, Chao Yu wrote:
> > free_nid_bitmap and free_nid_count in update_free_nid_bitmap should be
> > updated atomically, use free_list_lock cover them to avoid race in
> 
> nid_list_lock?

Think so.
I merged a modified one in dev-test and started to test it.

Thanks,

> 
> Reviewed-by: Kinglong Mee <kinglongmee@gmail.com>
> 
> > concurrent scenario.
> > 
> > Signed-off-by: Chao Yu <yuchao0@huawei.com>
> > ---
> >  fs/f2fs/f2fs.h |  1 -
> >  fs/f2fs/node.c | 27 +++++++++++----------------
> >  2 files changed, 11 insertions(+), 17 deletions(-)
> > 
> > diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> > index 843ce39502bc..d905e53ba524 100644
> > --- a/fs/f2fs/f2fs.h
> > +++ b/fs/f2fs/f2fs.h
> > @@ -561,7 +561,6 @@ struct f2fs_nm_info {
> >  	unsigned char (*free_nid_bitmap)[NAT_ENTRY_BITMAP_SIZE];
> >  	unsigned char *nat_block_bitmap;
> >  	unsigned short *free_nid_count;	/* free nid count of NAT block */
> > -	spinlock_t free_nid_lock;	/* protect updating of nid count */
> >  
> >  	/* for checkpoint */
> >  	char *nat_bitmap;		/* NAT bitmap pointer */
> > diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
> > index 11df8ab32478..3bfffd744f87 100644
> > --- a/fs/f2fs/node.c
> > +++ b/fs/f2fs/node.c
> > @@ -1815,7 +1815,7 @@ static void remove_free_nid(struct f2fs_sb_info *sbi, nid_t nid)
> >  }
> >  
> >  static void update_free_nid_bitmap(struct f2fs_sb_info *sbi, nid_t nid,
> > -			bool set, bool build, bool locked)
> > +							bool set, bool build)
> >  {
> >  	struct f2fs_nm_info *nm_i = NM_I(sbi);
> >  	unsigned int nat_ofs = NAT_BLOCK_OFFSET(nid);
> > @@ -1829,14 +1829,10 @@ static void update_free_nid_bitmap(struct f2fs_sb_info *sbi, nid_t nid,
> >  	else
> >  		__clear_bit_le(nid_ofs, nm_i->free_nid_bitmap[nat_ofs]);
> >  
> > -	if (!locked)
> > -		spin_lock(&nm_i->free_nid_lock);
> >  	if (set)
> >  		nm_i->free_nid_count[nat_ofs]++;
> >  	else if (!build)
> >  		nm_i->free_nid_count[nat_ofs]--;
> > -	if (!locked)
> > -		spin_unlock(&nm_i->free_nid_lock);
> >  }
> >  
> >  static void scan_nat_page(struct f2fs_sb_info *sbi,
> > @@ -1865,7 +1861,9 @@ static void scan_nat_page(struct f2fs_sb_info *sbi,
> >  		f2fs_bug_on(sbi, blk_addr == NEW_ADDR);
> >  		if (blk_addr == NULL_ADDR)
> >  			freed = add_free_nid(sbi, start_nid, true);
> > -		update_free_nid_bitmap(sbi, start_nid, freed, true, false);
> > +		spin_lock(&NM_I(sbi)->nid_list_lock);
> > +		update_free_nid_bitmap(sbi, start_nid, freed, true);
> > +		spin_unlock(&NM_I(sbi)->nid_list_lock);
> >  	}
> >  }
> >  
> > @@ -2020,7 +2018,7 @@ bool alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid)
> >  		__insert_nid_to_list(sbi, i, ALLOC_NID_LIST, false);
> >  		nm_i->available_nids--;
> >  
> > -		update_free_nid_bitmap(sbi, *nid, false, false, false);
> > +		update_free_nid_bitmap(sbi, *nid, false, false);
> >  
> >  		spin_unlock(&nm_i->nid_list_lock);
> >  		return true;
> > @@ -2076,7 +2074,7 @@ void alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t nid)
> >  
> >  	nm_i->available_nids++;
> >  
> > -	update_free_nid_bitmap(sbi, nid, true, false, false);
> > +	update_free_nid_bitmap(sbi, nid, true, false);
> >  
> >  	spin_unlock(&nm_i->nid_list_lock);
> >  
> > @@ -2406,11 +2404,11 @@ static void __flush_nat_entry_set(struct f2fs_sb_info *sbi,
> >  			add_free_nid(sbi, nid, false);
> >  			spin_lock(&NM_I(sbi)->nid_list_lock);
> >  			NM_I(sbi)->available_nids++;
> > -			update_free_nid_bitmap(sbi, nid, true, false, false);
> > +			update_free_nid_bitmap(sbi, nid, true, false);
> >  			spin_unlock(&NM_I(sbi)->nid_list_lock);
> >  		} else {
> >  			spin_lock(&NM_I(sbi)->nid_list_lock);
> > -			update_free_nid_bitmap(sbi, nid, false, false, false);
> > +			update_free_nid_bitmap(sbi, nid, false, false);
> >  			spin_unlock(&NM_I(sbi)->nid_list_lock);
> >  		}
> >  	}
> > @@ -2535,10 +2533,10 @@ inline void load_free_nid_bitmap(struct f2fs_sb_info *sbi)
> >  		nid = i * NAT_ENTRY_PER_BLOCK;
> >  		last_nid = (i + 1) * NAT_ENTRY_PER_BLOCK;
> >  
> > -		spin_lock(&nm_i->free_nid_lock);
> > +		spin_lock(&NM_I(sbi)->nid_list_lock);
> >  		for (; nid < last_nid; nid++)
> > -			update_free_nid_bitmap(sbi, nid, true, true, true);
> > -		spin_unlock(&nm_i->free_nid_lock);
> > +			update_free_nid_bitmap(sbi, nid, true, true);
> > +		spin_unlock(&NM_I(sbi)->nid_list_lock);
> >  	}
> >  
> >  	for (i = 0; i < nm_i->nat_blocks; i++) {
> > @@ -2629,9 +2627,6 @@ static int init_free_nid_cache(struct f2fs_sb_info *sbi)
> >  					sizeof(unsigned short), GFP_KERNEL);
> >  	if (!nm_i->free_nid_count)
> >  		return -ENOMEM;
> > -
> > -	spin_lock_init(&nm_i->free_nid_lock);
> > -
> >  	return 0;
> >  }
> >  
> > 

WARNING: multiple messages have this Message-ID (diff)
From: Jaegeuk Kim <jaegeuk@kernel.org>
To: Kinglong Mee <kinglongmee@gmail.com>
Cc: linux-kernel@vger.kernel.org, chao@kernel.org,
	linux-f2fs-devel@lists.sourceforge.net
Subject: Re: [PATCH] f2fs: cover update_free_nid_bitmap with free_list_lock
Date: Mon, 13 Mar 2017 12:57:35 -0700	[thread overview]
Message-ID: <20170313195735.GD41055@jaegeuk.local> (raw)
In-Reply-To: <5cd19a42-0941-2dbd-fbae-b885b79cb227@gmail.com>

On 03/13, Kinglong Mee wrote:
> On 3/13/2017 20:10, Chao Yu wrote:
> > free_nid_bitmap and free_nid_count in update_free_nid_bitmap should be
> > updated atomically, use free_list_lock cover them to avoid race in
> 
> nid_list_lock?

Think so.
I merged a modified one in dev-test and started to test it.

Thanks,

> 
> Reviewed-by: Kinglong Mee <kinglongmee@gmail.com>
> 
> > concurrent scenario.
> > 
> > Signed-off-by: Chao Yu <yuchao0@huawei.com>
> > ---
> >  fs/f2fs/f2fs.h |  1 -
> >  fs/f2fs/node.c | 27 +++++++++++----------------
> >  2 files changed, 11 insertions(+), 17 deletions(-)
> > 
> > diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> > index 843ce39502bc..d905e53ba524 100644
> > --- a/fs/f2fs/f2fs.h
> > +++ b/fs/f2fs/f2fs.h
> > @@ -561,7 +561,6 @@ struct f2fs_nm_info {
> >  	unsigned char (*free_nid_bitmap)[NAT_ENTRY_BITMAP_SIZE];
> >  	unsigned char *nat_block_bitmap;
> >  	unsigned short *free_nid_count;	/* free nid count of NAT block */
> > -	spinlock_t free_nid_lock;	/* protect updating of nid count */
> >  
> >  	/* for checkpoint */
> >  	char *nat_bitmap;		/* NAT bitmap pointer */
> > diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
> > index 11df8ab32478..3bfffd744f87 100644
> > --- a/fs/f2fs/node.c
> > +++ b/fs/f2fs/node.c
> > @@ -1815,7 +1815,7 @@ static void remove_free_nid(struct f2fs_sb_info *sbi, nid_t nid)
> >  }
> >  
> >  static void update_free_nid_bitmap(struct f2fs_sb_info *sbi, nid_t nid,
> > -			bool set, bool build, bool locked)
> > +							bool set, bool build)
> >  {
> >  	struct f2fs_nm_info *nm_i = NM_I(sbi);
> >  	unsigned int nat_ofs = NAT_BLOCK_OFFSET(nid);
> > @@ -1829,14 +1829,10 @@ static void update_free_nid_bitmap(struct f2fs_sb_info *sbi, nid_t nid,
> >  	else
> >  		__clear_bit_le(nid_ofs, nm_i->free_nid_bitmap[nat_ofs]);
> >  
> > -	if (!locked)
> > -		spin_lock(&nm_i->free_nid_lock);
> >  	if (set)
> >  		nm_i->free_nid_count[nat_ofs]++;
> >  	else if (!build)
> >  		nm_i->free_nid_count[nat_ofs]--;
> > -	if (!locked)
> > -		spin_unlock(&nm_i->free_nid_lock);
> >  }
> >  
> >  static void scan_nat_page(struct f2fs_sb_info *sbi,
> > @@ -1865,7 +1861,9 @@ static void scan_nat_page(struct f2fs_sb_info *sbi,
> >  		f2fs_bug_on(sbi, blk_addr == NEW_ADDR);
> >  		if (blk_addr == NULL_ADDR)
> >  			freed = add_free_nid(sbi, start_nid, true);
> > -		update_free_nid_bitmap(sbi, start_nid, freed, true, false);
> > +		spin_lock(&NM_I(sbi)->nid_list_lock);
> > +		update_free_nid_bitmap(sbi, start_nid, freed, true);
> > +		spin_unlock(&NM_I(sbi)->nid_list_lock);
> >  	}
> >  }
> >  
> > @@ -2020,7 +2018,7 @@ bool alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid)
> >  		__insert_nid_to_list(sbi, i, ALLOC_NID_LIST, false);
> >  		nm_i->available_nids--;
> >  
> > -		update_free_nid_bitmap(sbi, *nid, false, false, false);
> > +		update_free_nid_bitmap(sbi, *nid, false, false);
> >  
> >  		spin_unlock(&nm_i->nid_list_lock);
> >  		return true;
> > @@ -2076,7 +2074,7 @@ void alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t nid)
> >  
> >  	nm_i->available_nids++;
> >  
> > -	update_free_nid_bitmap(sbi, nid, true, false, false);
> > +	update_free_nid_bitmap(sbi, nid, true, false);
> >  
> >  	spin_unlock(&nm_i->nid_list_lock);
> >  
> > @@ -2406,11 +2404,11 @@ static void __flush_nat_entry_set(struct f2fs_sb_info *sbi,
> >  			add_free_nid(sbi, nid, false);
> >  			spin_lock(&NM_I(sbi)->nid_list_lock);
> >  			NM_I(sbi)->available_nids++;
> > -			update_free_nid_bitmap(sbi, nid, true, false, false);
> > +			update_free_nid_bitmap(sbi, nid, true, false);
> >  			spin_unlock(&NM_I(sbi)->nid_list_lock);
> >  		} else {
> >  			spin_lock(&NM_I(sbi)->nid_list_lock);
> > -			update_free_nid_bitmap(sbi, nid, false, false, false);
> > +			update_free_nid_bitmap(sbi, nid, false, false);
> >  			spin_unlock(&NM_I(sbi)->nid_list_lock);
> >  		}
> >  	}
> > @@ -2535,10 +2533,10 @@ inline void load_free_nid_bitmap(struct f2fs_sb_info *sbi)
> >  		nid = i * NAT_ENTRY_PER_BLOCK;
> >  		last_nid = (i + 1) * NAT_ENTRY_PER_BLOCK;
> >  
> > -		spin_lock(&nm_i->free_nid_lock);
> > +		spin_lock(&NM_I(sbi)->nid_list_lock);
> >  		for (; nid < last_nid; nid++)
> > -			update_free_nid_bitmap(sbi, nid, true, true, true);
> > -		spin_unlock(&nm_i->free_nid_lock);
> > +			update_free_nid_bitmap(sbi, nid, true, true);
> > +		spin_unlock(&NM_I(sbi)->nid_list_lock);
> >  	}
> >  
> >  	for (i = 0; i < nm_i->nat_blocks; i++) {
> > @@ -2629,9 +2627,6 @@ static int init_free_nid_cache(struct f2fs_sb_info *sbi)
> >  					sizeof(unsigned short), GFP_KERNEL);
> >  	if (!nm_i->free_nid_count)
> >  		return -ENOMEM;
> > -
> > -	spin_lock_init(&nm_i->free_nid_lock);
> > -
> >  	return 0;
> >  }
> >  
> > 

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

  reply	other threads:[~2017-03-13 19:57 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-13 12:10 [PATCH] f2fs: cover update_free_nid_bitmap with free_list_lock Chao Yu
2017-03-13 12:10 ` Chao Yu
2017-03-13 12:22 ` [f2fs-dev] " Kinglong Mee
2017-03-13 12:22   ` Kinglong Mee
2017-03-13 19:57   ` Jaegeuk Kim [this message]
2017-03-13 19:57     ` Jaegeuk Kim
2017-03-14  1:34     ` [f2fs-dev] " Chao Yu
2017-03-14  1:34       ` 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=20170313195735.GD41055@jaegeuk.local \
    --to=jaegeuk@kernel.org \
    --cc=chao@kernel.org \
    --cc=kinglongmee@gmail.com \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=yuchao0@huawei.com \
    /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 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.