linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [f2fs-dev] [PATCH] f2fs: split sbi->write_mutex for DATA/NODE/META to avoid unnecessary race
@ 2013-11-19  1:43 Chao Yu
  2013-11-19  3:18 ` Jaegeuk Kim
  0 siblings, 1 reply; 4+ messages in thread
From: Chao Yu @ 2013-11-19  1:43 UTC (permalink / raw)
  To: ???; +Cc: linux-fsdevel, linux-kernel, linux-f2fs-devel, 谭姝

All DATA/NODE/META bio buffers in superblock is protected by 
'sbi->write_mutex', but each bio buffer area is independent, So we 
should split write_mutex to three for DATA/NODE/META.

Signed-off-by: Chao Yu <chao2.yu@samsung.com>
---
 fs/f2fs/f2fs.h    |    2 +-
 fs/f2fs/segment.c |    8 ++++----
 fs/f2fs/super.c   |    4 +++-
 3 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 2df1e61..1c67521 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -362,7 +362,7 @@ struct f2fs_sb_info {
 	struct f2fs_sm_info *sm_info;		/* segment manager */
 	struct bio *bio[NR_PAGE_TYPE];		/* bios to merge */
 	sector_t last_block_in_bio[NR_PAGE_TYPE];	/* last block number */
-	struct mutex write_mutex;		/* mutex for writing IOs */
+	struct mutex write_mutex[NR_PAGE_TYPE];	/* mutex for writing IOs */
 
 	/* for checkpoint */
 	struct f2fs_checkpoint *ckpt;		/* raw checkpoint pointer */
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 556965f..a36713ae 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -661,9 +661,9 @@ void f2fs_submit_bio(struct f2fs_sb_info *sbi, enum
page_type type, bool sync)
 	if (!sbi->bio[btype])
 		return;
 
-	mutex_lock(&sbi->write_mutex);
+	mutex_lock(&sbi->write_mutex[type]);
 	do_submit_bio(sbi, type, sync);
-	mutex_unlock(&sbi->write_mutex);
+	mutex_unlock(&sbi->write_mutex[type]);
 }
 
 static void submit_write_page(struct f2fs_sb_info *sbi, struct page *page,
@@ -674,7 +674,7 @@ static void submit_write_page(struct f2fs_sb_info *sbi,
struct page *page,
 
 	verify_block_addr(sbi, blk_addr);
 
-	mutex_lock(&sbi->write_mutex);
+	mutex_lock(&sbi->write_mutex[type]);
 
 	inc_page_count(sbi, F2FS_WRITEBACK);
 
@@ -709,7 +709,7 @@ retry:
 
 	sbi->last_block_in_bio[type] = blk_addr;
 
-	mutex_unlock(&sbi->write_mutex);
+	mutex_unlock(&sbi->write_mutex[type]);
 	trace_f2fs_submit_write_page(page, blk_addr, type);
 }
 
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index f56941c..6928c0a 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -874,7 +874,9 @@ static int f2fs_fill_super(struct super_block *sb, void
*data, int silent)
 	mutex_init(&sbi->node_write);
 	sbi->por_doing = false;
 	spin_lock_init(&sbi->stat_lock);
-	mutex_init(&sbi->write_mutex);
+	mutex_init(&sbi->write_mutex[DATA]);
+	mutex_init(&sbi->write_mutex[NODE]);
+	mutex_init(&sbi->write_mutex[META]);
 	init_rwsem(&sbi->cp_rwsem);
 	init_waitqueue_head(&sbi->cp_wait);
 	init_sb_info(sbi);
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [f2fs-dev] [PATCH] f2fs: split sbi->write_mutex for DATA/NODE/META to avoid unnecessary race
  2013-11-19  1:43 [f2fs-dev] [PATCH] f2fs: split sbi->write_mutex for DATA/NODE/META to avoid unnecessary race Chao Yu
@ 2013-11-19  3:18 ` Jaegeuk Kim
  2013-11-19  3:36   ` Jaegeuk Kim
  0 siblings, 1 reply; 4+ messages in thread
From: Jaegeuk Kim @ 2013-11-19  3:18 UTC (permalink / raw)
  To: Chao Yu; +Cc: linux-fsdevel, linux-kernel, linux-f2fs-devel, 谭姝

Hi,

2013-11-19 (화), 09:43 +0800, Chao Yu:
> All DATA/NODE/META bio buffers in superblock is protected by 
> 'sbi->write_mutex', but each bio buffer area is independent, So we 
> should split write_mutex to three for DATA/NODE/META.

Agreed, one comment below though.
Anyway I'll send v2.
Thanks, :)

> 
> Signed-off-by: Chao Yu <chao2.yu@samsung.com>
> ---
>  fs/f2fs/f2fs.h    |    2 +-
>  fs/f2fs/segment.c |    8 ++++----
>  fs/f2fs/super.c   |    4 +++-
>  3 files changed, 8 insertions(+), 6 deletions(-)
> 
> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> index 2df1e61..1c67521 100644
> --- a/fs/f2fs/f2fs.h
> +++ b/fs/f2fs/f2fs.h
> @@ -362,7 +362,7 @@ struct f2fs_sb_info {
>  	struct f2fs_sm_info *sm_info;		/* segment manager */
>  	struct bio *bio[NR_PAGE_TYPE];		/* bios to merge */
>  	sector_t last_block_in_bio[NR_PAGE_TYPE];	/* last block number */
> -	struct mutex write_mutex;		/* mutex for writing IOs */
> +	struct mutex write_mutex[NR_PAGE_TYPE];	/* mutex for writing IOs */
>  
>  	/* for checkpoint */
>  	struct f2fs_checkpoint *ckpt;		/* raw checkpoint pointer */
> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
> index 556965f..a36713ae 100644
> --- a/fs/f2fs/segment.c
> +++ b/fs/f2fs/segment.c
> @@ -661,9 +661,9 @@ void f2fs_submit_bio(struct f2fs_sb_info *sbi, enum
> page_type type, bool sync)
>  	if (!sbi->bio[btype])
>  		return;
>  
> -	mutex_lock(&sbi->write_mutex);
> +	mutex_lock(&sbi->write_mutex[type]);

btype instead of type.

>  	do_submit_bio(sbi, type, sync);
> -	mutex_unlock(&sbi->write_mutex);
> +	mutex_unlock(&sbi->write_mutex[type]);
>  }
>  
>  static void submit_write_page(struct f2fs_sb_info *sbi, struct page *page,
> @@ -674,7 +674,7 @@ static void submit_write_page(struct f2fs_sb_info *sbi,
> struct page *page,
>  
>  	verify_block_addr(sbi, blk_addr);
>  
> -	mutex_lock(&sbi->write_mutex);
> +	mutex_lock(&sbi->write_mutex[type]);
>  
>  	inc_page_count(sbi, F2FS_WRITEBACK);
>  
> @@ -709,7 +709,7 @@ retry:
>  
>  	sbi->last_block_in_bio[type] = blk_addr;
>  
> -	mutex_unlock(&sbi->write_mutex);
> +	mutex_unlock(&sbi->write_mutex[type]);
>  	trace_f2fs_submit_write_page(page, blk_addr, type);
>  }
>  
> diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
> index f56941c..6928c0a 100644
> --- a/fs/f2fs/super.c
> +++ b/fs/f2fs/super.c
> @@ -874,7 +874,9 @@ static int f2fs_fill_super(struct super_block *sb, void
> *data, int silent)
>  	mutex_init(&sbi->node_write);
>  	sbi->por_doing = false;
>  	spin_lock_init(&sbi->stat_lock);
> -	mutex_init(&sbi->write_mutex);
> +	mutex_init(&sbi->write_mutex[DATA]);
> +	mutex_init(&sbi->write_mutex[NODE]);
> +	mutex_init(&sbi->write_mutex[META]);
>  	init_rwsem(&sbi->cp_rwsem);
>  	init_waitqueue_head(&sbi->cp_wait);
>  	init_sb_info(sbi);

-- 
Jaegeuk Kim
Samsung


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [f2fs-dev] [PATCH] f2fs: split sbi->write_mutex for DATA/NODE/META to avoid unnecessary race
  2013-11-19  3:18 ` Jaegeuk Kim
@ 2013-11-19  3:36   ` Jaegeuk Kim
  2013-11-19  4:56     ` Chao Yu
  0 siblings, 1 reply; 4+ messages in thread
From: Jaegeuk Kim @ 2013-11-19  3:36 UTC (permalink / raw)
  To: Chao Yu; +Cc: linux-fsdevel, linux-kernel, linux-f2fs-devel

Hi,

I think we don't need to make two patches for this.
How about this?

>From 71c27f78e72d680edcd7b1c0917842343044653c Mon Sep 17 00:00:00 2001
From: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date: Mon, 18 Nov 2013 17:16:17 +0900
Subject: [PATCH] f2fs: use sbi->write_mutex for write bios

This patch removes an unnecessary semaphore (i.e., sbi->bio_sem).
There is no reason to use the semaphore when f2fs submits read and write
IOs.
Instead, let's use a write mutex and cover the sbi->bio[] by the lock.

Change log from v1:
 o split write_mutex suggested by Chao Yu

Chao described,
"All DATA/NODE/META bio buffers in superblock is protected by
'sbi->write_mutex', but each bio buffer area is independent, So we
should split write_mutex to three for DATA/NODE/META."

Signed-off-by: Chao Yu <chao2.yu@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
---
 fs/f2fs/data.c    |  4 ----
 fs/f2fs/f2fs.h    |  2 +-
 fs/f2fs/segment.c | 13 +++++++++----
 fs/f2fs/super.c   |  6 +++++-
 4 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 076a60c..5920639 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -383,8 +383,6 @@ int f2fs_readpage(struct f2fs_sb_info *sbi, struct
page *page,
 
 	trace_f2fs_readpage(page, blk_addr, type);
 
-	down_read(&sbi->bio_sem);
-
 	/* Allocate a new bio */
 	bio = f2fs_bio_alloc(bdev, 1);
 
@@ -394,13 +392,11 @@ int f2fs_readpage(struct f2fs_sb_info *sbi, struct
page *page,
 
 	if (bio_add_page(bio, page, PAGE_CACHE_SIZE, 0) < PAGE_CACHE_SIZE) {
 		bio_put(bio);
-		up_read(&sbi->bio_sem);
 		f2fs_put_page(page, 1);
 		return -EFAULT;
 	}
 
 	submit_bio(type, bio);
-	up_read(&sbi->bio_sem);
 	return 0;
 }
 
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 6a49554..6e67f28 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -374,7 +374,7 @@ struct f2fs_sb_info {
 	struct f2fs_sm_info *sm_info;		/* segment manager */
 	struct bio *bio[NR_PAGE_TYPE];		/* bios to merge */
 	sector_t last_block_in_bio[NR_PAGE_TYPE];	/* last block number */
-	struct rw_semaphore bio_sem;		/* IO semaphore */
+	struct mutex write_mutex[NR_PAGE_TYPE];	/* mutex for writing IOs */
 
 	/* for checkpoint */
 	struct f2fs_checkpoint *ckpt;		/* raw checkpoint pointer */
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index dad5f1a..119af0b 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -871,9 +871,14 @@ static void do_submit_bio(struct f2fs_sb_info *sbi,
 
 void f2fs_submit_bio(struct f2fs_sb_info *sbi, enum page_type type,
bool sync)
 {
-	down_write(&sbi->bio_sem);
+	enum page_type btype = PAGE_TYPE_OF_BIO(type);
+
+	if (!sbi->bio[btype])
+		return;
+
+	mutex_lock(&sbi->write_mutex[btype]);
 	do_submit_bio(sbi, type, sync);
-	up_write(&sbi->bio_sem);
+	mutex_unlock(&sbi->write_mutex[btype]);
 }
 
 static void submit_write_page(struct f2fs_sb_info *sbi, struct page
*page,
@@ -884,7 +889,7 @@ static void submit_write_page(struct f2fs_sb_info
*sbi, struct page *page,
 
 	verify_block_addr(sbi, blk_addr);
 
-	down_write(&sbi->bio_sem);
+	mutex_lock(&sbi->write_mutex[type]);
 
 	inc_page_count(sbi, F2FS_WRITEBACK);
 
@@ -919,7 +924,7 @@ retry:
 
 	sbi->last_block_in_bio[type] = blk_addr;
 
-	up_write(&sbi->bio_sem);
+	mutex_unlock(&sbi->write_mutex[type]);
 	trace_f2fs_submit_write_page(page, blk_addr, type);
 }
 
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index a022412..e194578 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -820,6 +820,7 @@ static int f2fs_fill_super(struct super_block *sb,
void *data, int silent)
 	struct buffer_head *raw_super_buf;
 	struct inode *root;
 	long err = -EINVAL;
+	int i;
 
 	/* allocate memory for f2fs-specific super block info */
 	sbi = kzalloc(sizeof(struct f2fs_sb_info), GFP_KERNEL);
@@ -876,7 +877,10 @@ static int f2fs_fill_super(struct super_block *sb,
void *data, int silent)
 	mutex_init(&sbi->node_write);
 	sbi->por_doing = false;
 	spin_lock_init(&sbi->stat_lock);
-	init_rwsem(&sbi->bio_sem);
+
+	for (i = 0; i < NR_PAGE_TYPE; i++)
+		mutex_init(&sbi->write_mutex[i]);
+
 	init_rwsem(&sbi->cp_rwsem);
 	init_waitqueue_head(&sbi->cp_wait);
 	init_sb_info(sbi);
-- 
1.8.4.474.g128a96c



-- 
Jaegeuk Kim
Samsung


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* RE: [f2fs-dev] [PATCH] f2fs: split sbi->write_mutex for DATA/NODE/META to avoid unnecessary race
  2013-11-19  3:36   ` Jaegeuk Kim
@ 2013-11-19  4:56     ` Chao Yu
  0 siblings, 0 replies; 4+ messages in thread
From: Chao Yu @ 2013-11-19  4:56 UTC (permalink / raw)
  To: jaegeuk.kim; +Cc: linux-fsdevel, linux-kernel, linux-f2fs-devel

Hi

> -----Original Message-----
> From: Jaegeuk Kim [mailto:jaegeuk.kim@samsung.com]
> Sent: Tuesday, November 19, 2013 11:36 AM
> To: Chao Yu
> Cc: linux-fsdevel@vger.kernel.org; linux-kernel@vger.kernel.org;
> linux-f2fs-devel@lists.sourceforge.net
> Subject: Re: [f2fs-dev] [PATCH] f2fs: split sbi->write_mutex for DATA/NODE/META to
> avoid unnecessary race
> 
> Hi,
> 
> I think we don't need to make two patches for this.
> How about this?

This could be reasonable,
And I will refer to this patch.

> 
> From 71c27f78e72d680edcd7b1c0917842343044653c Mon Sep 17 00:00:00 2001
> From: Jaegeuk Kim <jaegeuk.kim@samsung.com>
> Date: Mon, 18 Nov 2013 17:16:17 +0900
> Subject: [PATCH] f2fs: use sbi->write_mutex for write bios
> 
> This patch removes an unnecessary semaphore (i.e., sbi->bio_sem).
> There is no reason to use the semaphore when f2fs submits read and write
> IOs.
> Instead, let's use a write mutex and cover the sbi->bio[] by the lock.
> 
> Change log from v1:
>  o split write_mutex suggested by Chao Yu
> 
> Chao described,
> "All DATA/NODE/META bio buffers in superblock is protected by
> 'sbi->write_mutex', but each bio buffer area is independent, So we
> should split write_mutex to three for DATA/NODE/META."
> 
> Signed-off-by: Chao Yu <chao2.yu@samsung.com>
> Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
> ---
>  fs/f2fs/data.c    |  4 ----
>  fs/f2fs/f2fs.h    |  2 +-
>  fs/f2fs/segment.c | 13 +++++++++----
>  fs/f2fs/super.c   |  6 +++++-
>  4 files changed, 15 insertions(+), 10 deletions(-)
> 
> diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
> index 076a60c..5920639 100644
> --- a/fs/f2fs/data.c
> +++ b/fs/f2fs/data.c
> @@ -383,8 +383,6 @@ int f2fs_readpage(struct f2fs_sb_info *sbi, struct
> page *page,
> 
>  	trace_f2fs_readpage(page, blk_addr, type);
> 
> -	down_read(&sbi->bio_sem);
> -
>  	/* Allocate a new bio */
>  	bio = f2fs_bio_alloc(bdev, 1);
> 
> @@ -394,13 +392,11 @@ int f2fs_readpage(struct f2fs_sb_info *sbi, struct
> page *page,
> 
>  	if (bio_add_page(bio, page, PAGE_CACHE_SIZE, 0) < PAGE_CACHE_SIZE) {
>  		bio_put(bio);
> -		up_read(&sbi->bio_sem);
>  		f2fs_put_page(page, 1);
>  		return -EFAULT;
>  	}
> 
>  	submit_bio(type, bio);
> -	up_read(&sbi->bio_sem);
>  	return 0;
>  }
> 
> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> index 6a49554..6e67f28 100644
> --- a/fs/f2fs/f2fs.h
> +++ b/fs/f2fs/f2fs.h
> @@ -374,7 +374,7 @@ struct f2fs_sb_info {
>  	struct f2fs_sm_info *sm_info;		/* segment manager */
>  	struct bio *bio[NR_PAGE_TYPE];		/* bios to merge */
>  	sector_t last_block_in_bio[NR_PAGE_TYPE];	/* last block number */
> -	struct rw_semaphore bio_sem;		/* IO semaphore */
> +	struct mutex write_mutex[NR_PAGE_TYPE];	/* mutex for writing IOs */
> 
>  	/* for checkpoint */
>  	struct f2fs_checkpoint *ckpt;		/* raw checkpoint pointer */
> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
> index dad5f1a..119af0b 100644
> --- a/fs/f2fs/segment.c
> +++ b/fs/f2fs/segment.c
> @@ -871,9 +871,14 @@ static void do_submit_bio(struct f2fs_sb_info *sbi,
> 
>  void f2fs_submit_bio(struct f2fs_sb_info *sbi, enum page_type type,
> bool sync)
>  {
> -	down_write(&sbi->bio_sem);
> +	enum page_type btype = PAGE_TYPE_OF_BIO(type);
> +
> +	if (!sbi->bio[btype])
> +		return;
> +
> +	mutex_lock(&sbi->write_mutex[btype]);
>  	do_submit_bio(sbi, type, sync);
> -	up_write(&sbi->bio_sem);
> +	mutex_unlock(&sbi->write_mutex[btype]);
>  }
> 
>  static void submit_write_page(struct f2fs_sb_info *sbi, struct page
> *page,
> @@ -884,7 +889,7 @@ static void submit_write_page(struct f2fs_sb_info
> *sbi, struct page *page,
> 
>  	verify_block_addr(sbi, blk_addr);
> 
> -	down_write(&sbi->bio_sem);
> +	mutex_lock(&sbi->write_mutex[type]);
> 
>  	inc_page_count(sbi, F2FS_WRITEBACK);
> 
> @@ -919,7 +924,7 @@ retry:
> 
>  	sbi->last_block_in_bio[type] = blk_addr;
> 
> -	up_write(&sbi->bio_sem);
> +	mutex_unlock(&sbi->write_mutex[type]);
>  	trace_f2fs_submit_write_page(page, blk_addr, type);
>  }
> 
> diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
> index a022412..e194578 100644
> --- a/fs/f2fs/super.c
> +++ b/fs/f2fs/super.c
> @@ -820,6 +820,7 @@ static int f2fs_fill_super(struct super_block *sb,
> void *data, int silent)
>  	struct buffer_head *raw_super_buf;
>  	struct inode *root;
>  	long err = -EINVAL;
> +	int i;
> 
>  	/* allocate memory for f2fs-specific super block info */
>  	sbi = kzalloc(sizeof(struct f2fs_sb_info), GFP_KERNEL);
> @@ -876,7 +877,10 @@ static int f2fs_fill_super(struct super_block *sb,
> void *data, int silent)
>  	mutex_init(&sbi->node_write);
>  	sbi->por_doing = false;
>  	spin_lock_init(&sbi->stat_lock);
> -	init_rwsem(&sbi->bio_sem);
> +
> +	for (i = 0; i < NR_PAGE_TYPE; i++)
> +		mutex_init(&sbi->write_mutex[i]);
> +
>  	init_rwsem(&sbi->cp_rwsem);
>  	init_waitqueue_head(&sbi->cp_wait);
>  	init_sb_info(sbi);
> --
> 1.8.4.474.g128a96c
> 
> 
> 
> --
> Jaegeuk Kim
> Samsung


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-11-19  4:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-19  1:43 [f2fs-dev] [PATCH] f2fs: split sbi->write_mutex for DATA/NODE/META to avoid unnecessary race Chao Yu
2013-11-19  3:18 ` Jaegeuk Kim
2013-11-19  3:36   ` Jaegeuk Kim
2013-11-19  4:56     ` Chao Yu

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).