Zhihao Cheng
9a9dc60da7
fs-writeback: writeback_sb_inodes:Recalculate 'wrote' according skipped pages
...
commit 68f4c6eba70df70a720188bce95c85570ddfcc87 upstream.
Commit 505a666ee3fc ("writeback: plug writeback in wb_writeback() and
writeback_inodes_wb()") has us holding a plug during wb_writeback, which
may cause a potential ABBA dead lock:
wb_writeback fat_file_fsync
blk_start_plug(&plug)
for (;;) {
iter i-1: some reqs have been added into plug->mq_list // LOCK A
iter i:
progress = __writeback_inodes_wb(wb, work)
. writeback_sb_inodes // fat's bdev
. __writeback_single_inode
. . generic_writepages
. . __block_write_full_page
. . . . __generic_file_fsync
. . . . sync_inode_metadata
. . . . writeback_single_inode
. . . . __writeback_single_inode
. . . . fat_write_inode
. . . . __fat_write_inode
. . . . sync_dirty_buffer // fat's bdev
. . . . lock_buffer(bh) // LOCK B
. . . . submit_bh
. . . . blk_mq_get_tag // LOCK A
. . . trylock_buffer(bh) // LOCK B
. . . redirty_page_for_writepage
. . . wbc->pages_skipped++
. . --wbc->nr_to_write
. wrote += write_chunk - wbc.nr_to_write // wrote > 0
. requeue_inode
. redirty_tail_locked
if (progress) // progress > 0
continue;
iter i+1:
queue_io
// similar process with iter i, infinite for-loop !
}
blk_finish_plug(&plug) // flush plug won't be called
Above process triggers a hungtask like:
[ 399.044861] INFO: task bb:2607 blocked for more than 30 seconds.
[ 399.046824] Not tainted 5.18.0-rc1-00005-gefae4d9eb6a2-dirty
[ 399.051539] task:bb state:D stack: 0 pid: 2607 ppid:
2426 flags:0x00004000
[ 399.051556] Call Trace:
[ 399.051570] __schedule+0x480/0x1050
[ 399.051592] schedule+0x92/0x1a0
[ 399.051602] io_schedule+0x22/0x50
[ 399.051613] blk_mq_get_tag+0x1d3/0x3c0
[ 399.051640] __blk_mq_alloc_requests+0x21d/0x3f0
[ 399.051657] blk_mq_submit_bio+0x68d/0xca0
[ 399.051674] __submit_bio+0x1b5/0x2d0
[ 399.051708] submit_bio_noacct+0x34e/0x720
[ 399.051718] submit_bio+0x3b/0x150
[ 399.051725] submit_bh_wbc+0x161/0x230
[ 399.051734] __sync_dirty_buffer+0xd1/0x420
[ 399.051744] sync_dirty_buffer+0x17/0x20
[ 399.051750] __fat_write_inode+0x289/0x310
[ 399.051766] fat_write_inode+0x2a/0xa0
[ 399.051783] __writeback_single_inode+0x53c/0x6f0
[ 399.051795] writeback_single_inode+0x145/0x200
[ 399.051803] sync_inode_metadata+0x45/0x70
[ 399.051856] __generic_file_fsync+0xa3/0x150
[ 399.051880] fat_file_fsync+0x1d/0x80
[ 399.051895] vfs_fsync_range+0x40/0xb0
[ 399.051929] __x64_sys_fsync+0x18/0x30
In my test, 'need_resched()' (which is imported by 590dca3a71 "fs-writeback:
unplug before cond_resched in writeback_sb_inodes") in function
'writeback_sb_inodes()' seldom comes true, unless cond_resched() is deleted
from write_cache_pages().
Fix it by correcting wrote number according number of skipped pages
in writeback_sb_inodes().
Goto Link to find a reproducer.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=215837
Cc: stable@vger.kernel.org # v4.3
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20220510133805.1988292-1-chengzhihao1@huawei.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2022-06-09 10:21:22 +02:00
..
2022-01-20 09:17:50 +01:00
2020-10-24 12:26:05 -07:00
2021-03-04 11:38:37 +01:00
2022-06-09 10:20:56 +02:00
2020-10-16 11:11:22 -07:00
2020-09-18 16:45:50 -04:00
2021-01-06 14:56:52 +01:00
2022-06-09 10:20:49 +02:00
2021-03-30 14:32:07 +02:00
2022-05-18 10:23:47 +02:00
2022-06-09 10:20:48 +02:00
2022-03-02 11:42:52 +01:00
2020-09-18 16:45:50 -04:00
2021-11-18 14:03:54 +01:00
2022-01-27 10:54:02 +01:00
2022-02-01 17:25:39 +01:00
2022-01-27 10:54:10 +01:00
2021-05-26 12:06:55 +02:00
2020-11-25 16:55:02 +01:00
2020-09-18 16:45:50 -04:00
2021-12-01 09:19:05 +01:00
2022-06-06 08:42:42 +02:00
2022-04-08 14:40:18 +02:00
2022-06-09 10:21:10 +02:00
2022-06-09 10:21:21 +02:00
2022-06-09 10:20:58 +02:00
2021-09-18 13:40:15 +02:00
2022-03-16 14:16:01 +01:00
2022-06-09 10:20:57 +02:00
2021-07-31 08:16:12 +02:00
2021-05-19 10:13:10 +02:00
2021-04-14 08:42:06 +02:00
2020-09-18 16:45:50 -04:00
2022-04-27 13:53:54 +02:00
2022-06-09 10:21:06 +02:00
2021-11-12 14:58:33 +01:00
2022-04-27 13:53:57 +02:00
2022-04-08 14:39:52 +02:00
2022-06-09 10:20:57 +02:00
2021-01-27 11:55:29 +01:00
2021-09-18 13:40:30 +02:00
2022-04-13 21:01:01 +02:00
2022-06-09 10:21:20 +02:00
2020-12-30 11:53:45 +01:00
2022-06-06 08:42:45 +02:00
2022-05-25 09:17:54 +02:00
2022-06-09 10:21:03 +02:00
2022-04-08 14:40:33 +02:00
2022-03-23 09:13:27 +01:00
2020-09-22 23:39:45 -04:00
2022-01-20 09:17:50 +01:00
2021-12-22 09:30:58 +01:00
2022-06-09 10:21:17 +02:00
2022-04-08 14:39:56 +02:00
2021-09-30 10:11:08 +02:00
2020-09-18 16:45:50 -04:00
2022-02-23 12:00:59 +01:00
2020-10-16 11:11:22 -07:00
2021-08-12 13:22:19 +02:00
2020-10-24 12:26:05 -07:00
2021-05-19 10:13:10 +02:00
2020-10-02 12:02:30 +02:00
2020-09-18 16:45:50 -04:00
2022-03-02 11:42:54 +01:00
2022-04-13 21:00:53 +02:00
2022-02-01 17:25:39 +01:00
2020-10-24 12:26:05 -07:00
2020-09-10 14:03:31 -07:00
2021-10-17 10:43:33 +02:00
2021-10-06 15:55:46 +02:00
2022-06-06 08:42:42 +02:00
2022-05-09 09:05:06 +02:00
2021-12-14 11:32:40 +01:00
2022-04-08 14:40:44 +02:00
2022-04-08 14:40:45 +02:00
2022-06-09 10:20:47 +02:00
2021-03-17 17:06:35 +01:00
2021-06-03 09:00:45 +02:00
2020-10-18 09:27:09 -07:00
2022-04-08 14:40:45 +02:00
2020-10-14 14:54:45 -07:00
2022-06-09 10:21:16 +02:00
2021-04-14 08:41:58 +02:00
2021-05-11 14:47:12 +02:00
2022-04-08 14:39:57 +02:00
2021-09-15 09:50:27 +02:00
2022-05-18 10:23:48 +02:00
2022-04-08 14:40:30 +02:00
2022-02-08 18:30:36 +01:00
2020-10-13 18:38:27 -07:00
2022-06-09 10:21:22 +02:00
2020-08-23 17:36:59 -05:00
2021-11-26 10:39:22 +01:00
2021-07-31 08:16:11 +02:00
2022-06-06 08:42:41 +02:00
2021-09-18 13:40:06 +02:00
2021-02-13 13:54:56 +01:00
2022-05-25 09:17:54 +02:00
2021-02-17 11:02:21 +01:00
2021-10-27 09:56:51 +02:00
2020-11-22 10:48:22 -08:00
2021-03-20 10:43:44 +01:00
2020-10-23 11:33:41 -07:00
2022-02-01 17:25:48 +01:00
2021-08-26 08:35:57 -04:00
2021-07-14 16:55:59 +02:00
2022-06-06 08:42:41 +02:00
2021-03-17 17:06:13 +01:00
2020-12-30 11:54:02 +01:00
2020-10-23 11:33:41 -07:00
2021-04-21 13:00:54 +02:00
2020-10-15 09:48:49 -07:00
2022-01-29 10:26:11 +01:00
2021-07-20 16:05:59 +02:00
2021-12-14 11:32:40 +01:00
2020-10-24 12:40:18 -07:00
2022-04-27 13:53:54 +02:00
2020-08-27 16:06:47 -04:00
2022-02-23 12:00:59 +01:00
2021-10-27 09:56:51 +02:00
2020-10-13 18:38:27 -07:00