vfs: re-implement writeback_inodes_sb(_nr)_if_idle() and rename them
Subsystems (4)
PATCH RESEND 1/2 vfs: re-implement writeback_inodes_sb(_nr)_if_idle() and rename them
writeback_inodes_sb(_nr)_if_idle() is re-implemented by replacing down_read() with down_read_trylock() because
- If ->s_umount is write locked, then the sb is not idle. That is writeback_inodes_sb(_nr)_if_idle() needn't wait for the lock.
- writeback_inodes_sb(_nr)_if_idle() grabs s_umount lock when it want to start writeback, it may bring us deadlock problem when doing umount. (Ex. Btrfs has such a problem, see the following URL
http://marc.info/?l=linux-btrfs&m=133540923510561&w=2)
The name of these two functions is cumbersome, so rename them to try_to_writeback_inodes_sb(_nr).
This idea came from Christoph Hellwig.
Some code is from the patch of Kamal Mostafa.
---
Many users who use btrfs met the deadlock problem caused by writeback_inodes_sb(_nr)_if_idle(), so I send this patch again and hope it will be received as soon as possible if nobody objects.
--- fs/btrfs/extent-tree.c | 4 ++-- fs/ext4/inode.c | 2 +- fs/fs-writeback.c | 45 ++++++++++++++++++++------------------------- include/linux/writeback.h | 6 +++--- 4 files changed, 26 insertions(+), 31 deletions(-)
fs/btrfs/extent-tree.c +2 -2
@@ -3706,8 +3706,8 @@ static void shrink_delalloc(struct btrfs_root *root, u64 to_reclaim, u64 orig,while (delalloc_bytes && loops <3 ) { max_reclaim =min (delalloc_bytes, to_reclaim); nr_pages = max_reclaim >>PAGE_CACHE_SHIFT ; -writeback_inodes_sb_nr_if_idle (root->fs_info->sb, nr_pages, -WB_REASON_FS_FREE_SPACE ); +try_to_writeback_inodes_sb_nr (root->fs_info->sb, nr_pages, +WB_REASON_FS_FREE_SPACE );spin_lock (&space_info->lock); if (space_info->bytes_used + space_info->bytes_reserved +
fs/ext4/inode.c +1 -1
@@ -2476,7 +2476,7 @@ static int ext4_nonda_switch(struct super_block *sb)* start pushing delalloc when 1/2 of free blocks are dirty. */ if (free_blocks <2 * dirty_blocks) -writeback_inodes_sb_if_idle (sb,WB_REASON_FS_FREE_SPACE ); +try_to_writeback_inodes_sb (sb,WB_REASON_FS_FREE_SPACE );return 0 ; }
fs/fs-writeback.c +20 -25
74 lines not on this page · raw message
include/linux/writeback.h +3 -3
@@ -87,9 +87,9 @@ int inode_wait(void *);void writeback_inodes_sb (struct super_block *,enum wb_reason reason);void writeback_inodes_sb_nr (struct super_block *,unsigned long nr,enum wb_reason reason); -int writeback_inodes_sb_if_idle (struct super_block *,enum wb_reason reason); -int writeback_inodes_sb_nr_if_idle (struct super_block *,unsigned long nr, -enum wb_reason reason); +int try_to_writeback_inodes_sb (struct super_block *,enum wb_reason reason); +int try_to_writeback_inodes_sb_nr (struct super_block *,unsigned long nr, +enum wb_reason reason);void sync_inodes_sb (struct super_block *);long writeback_inodes_wb (struct bdi_writeback *wb,long nr_pages,enum wb_reason reason);
Signature · 1 line
1.6.5.2
Quoted 9 lines · Miao Xie
writeback_inodes_sb(_nr)_if_idle() is re-implemented by replacing
down_read()withdown_read_trylock()because
- If ->s_umount is write locked, then the sb is not idle. That is writeback_inodes_sb(_nr)_if_idle() needn't wait for the lock.
- writeback_inodes_sb(_nr)_if_idle() grabss_umountlock when it want to start writeback, it may bring us deadlock problem when doing umount. (Ex. Btrfs has such a problem, see the following URLhttp://marc.info/?l=linux-btrfs&m=133540923510561&w=2)
Quoted 7 lines
The name of these two functions is cumbersome, so rename them to
try_to_writeback_inodes_sb(_nr).This idea came from Christoph Hellwig.
Some code is from the patch of Kamal Mostafa.Signed-off-by Miao Xie <[email protected]>
Quoted 3 lines
---
Many users who use btrfs met the deadlock problem caused by writeback_inodes_sb(_nr)_if_idle(), so I send this patch again and hope it will be received as soon as possible if nobody objects.
Yes please, this makes testing of the 'autodefrag' mount option hard as the deadlock occurs frequently upon umount (when there's a background snapshot cleanup in progress).
Quoted 1 line
From the user's POV, the autodefrag improves performance, it's not yet
on by default until it proves to be stable, the deadlocks were standing in the way for long.
thanks,
david
Quoted 6 lines · David Sterba
Quoted 2 lines
Many users who use btrfs met the deadlock problem caused by writeback_inodes_sb(_nr)_if_idle(), so I send this patch again and hope it will be received as soon as possible if nobody objects.
Yes please, this makes testing of the 'autodefrag' mount option hard as the deadlock occurs frequently upon umount (when there's a background snapshot cleanup in progress).
We have another report of the deadlock and it's without 'autodefrag' mount, triggered by snapshot cleaning under low space conditions.
I have added the patch to SLES kernel some time ago and haven't observed the deadlock since.
Please queue the patch for 3.7, we cannot fix it locally within btrfs.
Thanks,
david