Skip to contentSkip to conversation

f2fs: fix an infinite loop when flush nodes in cp

PATCH In review Yunlei He 2 participants 2 messages Nov 16, 2016 – Nov 17, 2016 F2FS file system

lore
Share & tools
lore

Yunlei He

author
#0 lore raw

PATCH 1/1 f2fs: fix an infinite loop when flush nodes in cp

Thread A Thread B

- write_checkpoint
- block_operations
-blk_start_plug
-sync_node_pages - f2fs_do_sync_file
- fsync_node_pages
- f2fs_wait_on_page_writeback

Thread A wait for global F2FS_DIRTY_NODES decreased to zero, it start a plug list, some requests have been added to this list. Thread B lock one dirty node page, and wait this page write back. But this page has been in plug list of thread A with PG_writeback flag. Thread A keep on running and its plug list has no chance to finish, so it seems a deadlock between cp and fsync path.

This patch add a wait on page write back before set node page dirty to avoid this problem.

---
 fs/f2fs/node.c | 1 +
 1 file changed, 1 insertion(+)
fs/f2fs/node.c +1 -0
index 38cc07d..1de25f8 100644
@@ -1410,6 +1410,7 @@ int fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode,
 			"Retry to write fsync mark: ino=%u, idx=%lx",
 					ino, last_page->index);
 		lock_page(last_page);
+		f2fs_wait_on_page_writeback(last_page, NODE, true);
 		set_page_dirty(last_page);
 		unlock_page(last_page);
 		goto retry;
Signature · 4 lines
2.10.1


------------------------------------------------------------------------------
Reviewed-by on v1 1/1
#1 lore raw
Quoted 16 lines · Yunlei He

Thread A Thread B

- write_checkpoint
- block_operations
-blk_start_plug
-sync_node_pages - f2fs_do_sync_file
- fsync_node_pages
- f2fs_wait_on_page_writeback

Thread A wait for global F2FS_DIRTY_NODES decreased to zero, it start a plug list, some requests have been added to this list. Thread B lock one dirty node page, and wait this page write back. But this page has been in plug list of thread A with PG_writeback flag. Thread A keep on running and its plug list has no chance to finish, so it seems a deadlock between cp and fsync path.

Quoted 5 lines

This patch add a wait on page write back before set node page dirty to avoid this problem.

------------------------------------------------------------------------------