Skip to contentSkip to conversation

f2fs: protect new segment allocation in expand_inode_data

PATCH In review Daeho Jeong 2 participants 3 messages Jun 1, 2020 – Jun 3, 2020 F2FS file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 f2fs: protect new segment allocation in expand_inode_data

From: Daeho Jeong <[email protected]>

Found a new segemnt allocation without f2fs_lock_op() in expand_inode_data(). So, when we do fallocate() for a pinned file and trigger checkpoint very frequently and simultaneously. F2FS gets stuck in the below code of do_checkpoint() forever.

f2fs_sync_meta_pages(sbi, META, LONG_MAX, FS_CP_META_IO); /* Wait for all dirty meta pages to be submitted for IO */
<= if fallocate() here,
f2fs_wait_on_all_pages(sbi, F2FS_DIRTY_META); <= it'll wait forever.

---
 fs/f2fs/file.c | 4 ++++
 1 file changed, 4 insertions(+)
fs/f2fs/file.c +4 -0
index f7de2a1da528..14ace885baa9 100644
@@ -1660,7 +1660,11 @@ static int expand_inode_data(struct inode *inode, loff_t offset,
 
 		down_write(&sbi->pin_sem);
 		map.m_seg_type = CURSEG_COLD_DATA_PINNED;
+
+		f2fs_lock_op(sbi);
 		f2fs_allocate_new_segments(sbi, CURSEG_COLD_DATA);
+		f2fs_unlock_op(sbi);
+
 		err = f2fs_map_blocks(inode, &map, 1, F2FS_GET_BLOCK_PRE_DIO);
 		up_write(&sbi->pin_sem);
 
Signature · 1 line
2.27.0.rc0.183.gde8f92d652-goog
#1 lore raw
Quoted 7 lines · Daeho Jeong

From: Daeho Jeong <[email protected]>

Found a new segemnt allocation without f2fs_lock_op() in expand_inode_data(). So, when we do fallocate() for a pinned file and trigger checkpoint very frequently and simultaneously. F2FS gets stuck in the below code of do_checkpoint() forever.

Quoted 7 lines

f2fs_sync_meta_pages(sbi, META, LONG_MAX, FS_CP_META_IO); /* Wait for all dirty meta pages to be submitted for IO */
<= if fallocate() here,
f2fs_wait_on_all_pages(sbi, F2FS_DIRTY_META); <= it'll wait forever.

Daeho,

I guess Jaegeuk could add the tag when merging this patch, we don't have to resend the patch if there is no updates on code and message.

Thanks,

Quoted 21 lines
---
 fs/f2fs/file.c | 4 ++++
 1 file changed, 4 insertions(+)
fs/f2fs/file.c +4 -0
index f7de2a1da528..14ace885baa9 100644
@@ -1660,7 +1660,11 @@ static int expand_inode_data(struct inode *inode, loff_t offset,
 
 		down_write(&sbi->pin_sem);
 		map.m_seg_type = CURSEG_COLD_DATA_PINNED;
+
+		f2fs_lock_op(sbi);
 		f2fs_allocate_new_segments(sbi, CURSEG_COLD_DATA);
+		f2fs_unlock_op(sbi);
+
 		err = f2fs_map_blocks(inode, &map, 1, F2FS_GET_BLOCK_PRE_DIO);
 		up_write(&sbi->pin_sem);
 
#2 lore raw

Oh, thanks for notification!

2020년 6월 3일 (수) 오후 3:59, Chao Yu <[email protected]>님이 작성:

Quoted 45 lines · Daeho Jeong
Quoted 7 lines

From: Daeho Jeong <[email protected]>

Found a new segemnt allocation without f2fs_lock_op() in expand_inode_data(). So, when we do fallocate() for a pinned file and trigger checkpoint very frequently and simultaneously. F2FS gets stuck in the below code of do_checkpoint() forever.

Quoted 7 lines

f2fs_sync_meta_pages(sbi, META, LONG_MAX, FS_CP_META_IO); /* Wait for all dirty meta pages to be submitted for IO */
<= if fallocate() here,
f2fs_wait_on_all_pages(sbi, F2FS_DIRTY_META); <= it'll wait forever.

Daeho,

I guess Jaegeuk could add the tag when merging this patch, we don't have to resend the patch if there is no updates on code and message.

Thanks,

Quoted 21 lines
---
 fs/f2fs/file.c | 4 ++++
 1 file changed, 4 insertions(+)
fs/f2fs/file.c +4 -0
index f7de2a1da528..14ace885baa9 100644
@@ -1660,7 +1660,11 @@ static int expand_inode_data(struct inode *inode, loff_t offset,
 
              down_write(&sbi->pin_sem);
              map.m_seg_type = CURSEG_COLD_DATA_PINNED;
+
+             f2fs_lock_op(sbi);
              f2fs_allocate_new_segments(sbi, CURSEG_COLD_DATA);
+             f2fs_unlock_op(sbi);
+
              err = f2fs_map_blocks(inode, &map, 1, F2FS_GET_BLOCK_PRE_DIO);
              up_write(&sbi->pin_sem);