f2fs: avoid deadlock during evict after f2fs_gc
authorJaegeuk Kim <jaegeuk.kim@samsung.com>
Tue, 30 Apr 2013 02:33:27 +0000 (11:33 +0900)
committerJaegeuk Kim <jaegeuk.kim@samsung.com>
Wed, 8 May 2013 10:54:08 +0000 (19:54 +0900)
commit531ad7d58c6476c5856653448b4c7d26427502b4
tree6b890195ebfd773fa55ec580ce2248a2a47d5452
parentac5d156c78a68b39955ee9b09498ba93831c77d7
f2fs: avoid deadlock during evict after f2fs_gc

o Deadlock case #1

Thread 1:
- writeback_sb_inodes
 - do_writepages
  - f2fs_write_data_pages
   - write_cache_pages
    - f2fs_write_data_page
     - f2fs_balance_fs
      - wait mutex_lock(gc_mutex)

Thread 2:
- f2fs_balance_fs
 - mutex_lock(gc_mutex)
 - f2fs_gc
  - f2fs_iget
   - wait iget_locked(inode->i_lock)

Thread 3:
- do_unlinkat
 - iput
  - lock(inode->i_lock)
   - evict
    - inode_wait_for_writeback

o Deadlock case #2

Thread 1:
- __writeback_single_inode
 : set I_SYNC
  - do_writepages
   - f2fs_write_data_page
    - f2fs_balance_fs
     - f2fs_gc
      - iput
       - evict
        - inode_wait_for_writeback(I_SYNC)

In order to avoid this, even though iput is called with the zero-reference
count, we need to stop the eviction procedure if the inode is on writeback.
So this patch links f2fs_drop_inode which checks the I_SYNC flag.

Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
fs/f2fs/data.c
fs/f2fs/namei.c
fs/f2fs/super.c