Skip to contentSkip to conversation

f2fs: check sit bitmap under sentry_lock

PATCH In review Chao Yu 3 participants 3 messages Nov 13, 2017 – Nov 15, 2017 F2FS file system

lore
Share & tools
lore

Chao Yu

author
#0 lore raw

PATCH 1/1 f2fs: check sit bitmap under sentry_lock

This patch protects sit bitmap accessing in __check_sit_bitmap with sentry_lock, meanwhile, in allocate_data_block, f2fs_wait_discard_bio will not access/update sit cache, let's exclude it from sentry_lock's region.

---
 fs/f2fs/segment.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
fs/f2fs/segment.c +6 -1
index c117e0913f2a..464696b1612a 100644
@@ -894,6 +894,8 @@ void __check_sit_bitmap(struct f2fs_sb_info *sbi,
 	unsigned long offset, size, max_blocks = sbi->blocks_per_seg;
 	unsigned long *map;
 
+	down_read(&SIT_I(sbi)->sentry_lock);
+
 	while (blk < end) {
 		segno = GET_SEGNO(sbi, blk);
 		sentry = get_seg_entry(sbi, segno);
@@ -908,6 +910,8 @@ void __check_sit_bitmap(struct f2fs_sb_info *sbi,
 		f2fs_bug_on(sbi, offset != size);
 		blk = START_BLOCK(sbi, segno + 1);
 	}
+
+	up_read(&SIT_I(sbi)->sentry_lock);
 #endif
 }
 
@@ -2527,12 +2531,13 @@ void allocate_data_block(struct f2fs_sb_info *sbi, struct page *page,
 	down_read(&SM_I(sbi)->curseg_lock);
 
 	mutex_lock(&curseg->curseg_mutex);
-	down_write(&sit_i->sentry_lock);
 
 	*new_blkaddr = NEXT_FREE_BLKADDR(sbi, curseg);
 
 	f2fs_wait_discard_bio(sbi, *new_blkaddr);
 
+	down_write(&sit_i->sentry_lock);
+
 	/*
 	 * __add_sum_entry should be resided under the curseg_mutex
 	 * because, this function updates a summary entry in the
Signature · 1 line
2.15.0.55.gc2ece9dc4de6
maintainer
#1 lore raw

Hi Jaegeuk,

Please drop this patch first, as it still can trigger deadlock as below, sorry about this mistake.

- f2fs_put_super
- f2fs_wait_discard_bios
- __issue_discard_cmd
- lock(&dcc->cmd_lock); A
- __check_sit_bitmap
- down_read(&sit_i->sentry_lock) B

- do_write_page
- allocate_data_block
- down_write(&sit_i->sentry_lock) B
- locate_dirty_segment
- lock(&dirty_i->seglist_lock) C

- write_checkpoint
- clear_prefree_segments
- lock(&dirty_i->seglist_lock) C
- f2fs_issue_discard
- __issue_discard_async
- __queue_discard_cmd
- __update_discard_tree_range
- lock(&dcc->cmd_lock) A

Thanks,

Quoted 37 lines · Chao Yu

This patch protects sit bitmap accessing in __check_sit_bitmap with sentry_lock, meanwhile, in allocate_data_block, f2fs_wait_discard_bio will not access/update sit cache, let's exclude it from sentry_lock's region.>

---
 fs/f2fs/segment.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
fs/f2fs/segment.c +4 -1
index c117e0913f2a..464696b1612a 100644
@@ -894,6 +894,8 @@ void __check_sit_bitmap(struct f2fs_sb_info *sbi,
 	unsigned long offset, size, max_blocks = sbi->blocks_per_seg;
 	unsigned long *map;
 
+	down_read(&SIT_I(sbi)->sentry_lock);
+
 	while (blk < end) {
 		segno = GET_SEGNO(sbi, blk);
 		sentry = get_seg_entry(sbi, segno);
@@ -908,6 +910,8 @@ void __check_sit_bitmap(struct f2fs_sb_info *sbi,
 		f2fs_bug_on(sbi, offset != size);
 		blk = START_BLOCK(sbi, segno + 1);
 	}
+
+	up_read(&SIT_I(sbi)->sentry_lock);
 #endif
 }
 
@@ -2527,12 +2531,13 @@ void allocate_data_block(struct f2fs_sb_info *sbi, struct page *page,
 	down_read(&SM_I(sbi)->curseg_lock);
 
 	mutex_lock(&curseg->curseg_mutex);
-	down_write(&sit_i->sentry_lock);

fs/f2fs/segment.c void allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, · line 2543

Quoted 10 lines
fs/f2fs/segment.c +2 -0
 
 	*new_blkaddr = NEXT_FREE_BLKADDR(sbi, curseg);
 
 	f2fs_wait_discard_bio(sbi, *new_blkaddr);
 
+	down_write(&sit_i->sentry_lock);
+
 	/*
 	 * __add_sum_entry should be resided under the curseg_mutex
 	 * because, this function updates a summary entry in the

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

maintainer
#2 lore raw
Quoted 4 lines · Chao Yu

Hi Jaegeuk,

Please drop this patch first, as it still can trigger deadlock as below, sorry about this mistake.

Got it. Thank you.

Quoted 65 lines

- f2fs_put_super
- f2fs_wait_discard_bios
- __issue_discard_cmd
- lock(&dcc->cmd_lock); A
- __check_sit_bitmap
- down_read(&sit_i->sentry_lock) B

- do_write_page
- allocate_data_block
- down_write(&sit_i->sentry_lock) B
- locate_dirty_segment
- lock(&dirty_i->seglist_lock) C

- write_checkpoint
- clear_prefree_segments
- lock(&dirty_i->seglist_lock) C
- f2fs_issue_discard
- __issue_discard_async
- __queue_discard_cmd
- __update_discard_tree_range
- lock(&dcc->cmd_lock) A

Thanks,

Quoted 39 lines · Chao Yu

This patch protects sit bitmap accessing in __check_sit_bitmap with sentry_lock, meanwhile, in allocate_data_block, f2fs_wait_discard_bio will not access/update sit cache, let's exclude it from sentry_lock's region.>

---
 fs/f2fs/segment.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
fs/f2fs/segment.c +4 -1
index c117e0913f2a..464696b1612a 100644
@@ -894,6 +894,8 @@ void __check_sit_bitmap(struct f2fs_sb_info *sbi,
 	unsigned long offset, size, max_blocks = sbi->blocks_per_seg;
 	unsigned long *map;
 
+	down_read(&SIT_I(sbi)->sentry_lock);
+
 	while (blk < end) {
 		segno = GET_SEGNO(sbi, blk);
 		sentry = get_seg_entry(sbi, segno);
@@ -908,6 +910,8 @@ void __check_sit_bitmap(struct f2fs_sb_info *sbi,
 		f2fs_bug_on(sbi, offset != size);
 		blk = START_BLOCK(sbi, segno + 1);
 	}
+
+	up_read(&SIT_I(sbi)->sentry_lock);
 #endif
 }
 
@@ -2527,12 +2531,13 @@ void allocate_data_block(struct f2fs_sb_info *sbi, struct page *page,
 	down_read(&SM_I(sbi)->curseg_lock);
 
 	mutex_lock(&curseg->curseg_mutex);
-	down_write(&sit_i->sentry_lock);
 
 	*new_blkaddr = NEXT_FREE_BLKADDR(sbi, curseg);
 
Quoted 8 lines

fs/f2fs/segment.c void allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, · line 2543

Quoted 8 lines
fs/f2fs/segment.c +2 -0
 	f2fs_wait_discard_bio(sbi, *new_blkaddr);
 
+	down_write(&sit_i->sentry_lock);
+
 	/*
 	 * __add_sum_entry should be resided under the curseg_mutex
 	 * because, this function updates a summary entry in the

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