]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
f2fs: fix a deadlock in fsync
authorJin Xu <jinuxstyle@gmail.com>
Mon, 5 Aug 2013 12:02:04 +0000 (20:02 +0800)
committerJaegeuk Kim <jaegeuk.kim@samsung.com>
Tue, 6 Aug 2013 13:00:36 +0000 (22:00 +0900)
This patch fixes a deadlock bug that occurs quite often when there are
concurrent write and fsync on a same file.

Following is the simplified call trace when tasks get hung.

fsync thread:
- f2fs_sync_file
 ...
 - f2fs_write_data_pages
 ...
  - update_extent_cache
  ...
   - update_inode
    - wait_on_page_writeback

bdi writeback thread
- __writeback_single_inode
 - f2fs_write_data_pages
  - mutex_lock(sbi->writepages)

The deadlock happens when the fsync thread waits on a inode page that has
been added to the f2fs' cached bio sbi->bio[NODE], and unfortunately,
no one else could be able to submit the cached bio to block layer for
writeback. This is because the fsync thread already hold a sbi->fs_lock and
the sbi->writepages lock, causing the bdi thread being blocked when attempt
to write data pages for the same inode. At the same time, f2fs_gc thread
does not notice the situation and could not help. Even the sync syscall
gets blocked.

To fix it, we could submit the cached bio first before waiting on a inode page
that is being written back.

Signed-off-by: Jin Xu <jinuxstyle@gmail.com>
[Jaegeuk Kim: add more cases to use f2fs_wait_on_page_writeback]
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
fs/f2fs/data.c
fs/f2fs/f2fs.h
fs/f2fs/gc.c
fs/f2fs/inode.c
fs/f2fs/segment.c

index f458883af815b56e8850210284615fe4f17fcf0b..a7eb529257233f09e0b523f771d7d090a70a87e7 100644 (file)
@@ -37,7 +37,7 @@ static void __set_data_blkaddr(struct dnode_of_data *dn, block_t new_addr)
        struct page *node_page = dn->node_page;
        unsigned int ofs_in_node = dn->ofs_in_node;
 
-       wait_on_page_writeback(node_page);
+       f2fs_wait_on_page_writeback(node_page, NODE, false);
 
        rn = F2FS_NODE(node_page);
 
index 63813befdd822edec4d1320e6daaba94d67ef182..13db10b70e66d8689803dccd8be070d3fcf0b3d6 100644 (file)
@@ -1023,7 +1023,8 @@ int npages_for_summary_flush(struct f2fs_sb_info *);
 void allocate_new_segments(struct f2fs_sb_info *);
 struct page *get_sum_page(struct f2fs_sb_info *, unsigned int);
 struct bio *f2fs_bio_alloc(struct block_device *, int);
-void f2fs_submit_bio(struct f2fs_sb_info *, enum page_type, bool sync);
+void f2fs_submit_bio(struct f2fs_sb_info *, enum page_type, bool);
+void f2fs_wait_on_page_writeback(struct page *, enum page_type, bool);
 void write_meta_page(struct f2fs_sb_info *, struct page *);
 void write_node_page(struct f2fs_sb_info *, struct page *, unsigned int,
                                        block_t, block_t *);
index d286d8be8e6845d0b8b2334190bfcfca9b2bf88e..e6b3ffd5ff6a15430d1f9ae0ebe9457fa14ca1c6 100644 (file)
@@ -422,8 +422,7 @@ next_step:
 
                /* set page dirty and write it */
                if (gc_type == FG_GC) {
-                       f2fs_submit_bio(sbi, NODE, true);
-                       wait_on_page_writeback(node_page);
+                       f2fs_wait_on_page_writeback(node_page, NODE, true);
                        set_page_dirty(node_page);
                } else {
                        if (!PageWriteback(node_page))
@@ -523,10 +522,7 @@ static void move_data_page(struct inode *inode, struct page *page, int gc_type)
        } else {
                struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb);
 
-               if (PageWriteback(page)) {
-                       f2fs_submit_bio(sbi, DATA, true);
-                       wait_on_page_writeback(page);
-               }
+               f2fs_wait_on_page_writeback(page, DATA, true);
 
                if (clear_page_dirty_for_io(page) &&
                        S_ISDIR(inode->i_mode)) {
index debf74308045c6ca046c065a711f5c50773b2f3a..9ab81e7472c5a0239fc2fb1d9ff66fdddd4a4b50 100644 (file)
@@ -151,7 +151,7 @@ void update_inode(struct inode *inode, struct page *node_page)
        struct f2fs_node *rn;
        struct f2fs_inode *ri;
 
-       wait_on_page_writeback(node_page);
+       f2fs_wait_on_page_writeback(node_page, NODE, false);
 
        rn = F2FS_NODE(node_page);
        ri = &(rn->i);
index 9b74ae2137d10a4bcad9a7d5ced77c6ce36ac2be..68e344f9e04274c41f48d3eb7caa1f689eb82625 100644 (file)
@@ -705,6 +705,16 @@ retry:
        trace_f2fs_submit_write_page(page, blk_addr, type);
 }
 
+void f2fs_wait_on_page_writeback(struct page *page,
+                               enum page_type type, bool sync)
+{
+       struct f2fs_sb_info *sbi = F2FS_SB(page->mapping->host->i_sb);
+       if (PageWriteback(page)) {
+               f2fs_submit_bio(sbi, type, sync);
+               wait_on_page_writeback(page);
+       }
+}
+
 static bool __has_curseg_space(struct f2fs_sb_info *sbi, int type)
 {
        struct curseg_info *curseg = CURSEG_I(sbi, type);