]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-6.1/md-raid10-prevent-soft-lockup-while-flush-writes.patch
28085ff5a3e7c53320e59b2e47dcf8b45cd1fbf2
[thirdparty/kernel/stable-queue.git] / queue-6.1 / md-raid10-prevent-soft-lockup-while-flush-writes.patch
1 From 5036866ba258e5dd80caf93c4ce92bf13eef7d82 Mon Sep 17 00:00:00 2001
2 From: Sasha Levin <sashal@kernel.org>
3 Date: Mon, 29 May 2023 21:11:00 +0800
4 Subject: md/raid10: prevent soft lockup while flush writes
5
6 From: Yu Kuai <yukuai3@huawei.com>
7
8 [ Upstream commit 010444623e7f4da6b4a4dd603a7da7469981e293 ]
9
10 Currently, there is no limit for raid1/raid10 plugged bio. While flushing
11 writes, raid1 has cond_resched() while raid10 doesn't, and too many
12 writes can cause soft lockup.
13
14 Follow up soft lockup can be triggered easily with writeback test for
15 raid10 with ramdisks:
16
17 watchdog: BUG: soft lockup - CPU#10 stuck for 27s! [md0_raid10:1293]
18 Call Trace:
19 <TASK>
20 call_rcu+0x16/0x20
21 put_object+0x41/0x80
22 __delete_object+0x50/0x90
23 delete_object_full+0x2b/0x40
24 kmemleak_free+0x46/0xa0
25 slab_free_freelist_hook.constprop.0+0xed/0x1a0
26 kmem_cache_free+0xfd/0x300
27 mempool_free_slab+0x1f/0x30
28 mempool_free+0x3a/0x100
29 bio_free+0x59/0x80
30 bio_put+0xcf/0x2c0
31 free_r10bio+0xbf/0xf0
32 raid_end_bio_io+0x78/0xb0
33 one_write_done+0x8a/0xa0
34 raid10_end_write_request+0x1b4/0x430
35 bio_endio+0x175/0x320
36 brd_submit_bio+0x3b9/0x9b7 [brd]
37 __submit_bio+0x69/0xe0
38 submit_bio_noacct_nocheck+0x1e6/0x5a0
39 submit_bio_noacct+0x38c/0x7e0
40 flush_pending_writes+0xf0/0x240
41 raid10d+0xac/0x1ed0
42
43 Fix the problem by adding cond_resched() to raid10 like what raid1 did.
44
45 Note that unlimited plugged bio still need to be optimized, for example,
46 in the case of lots of dirty pages writeback, this will take lots of
47 memory and io will spend a long time in plug, hence io latency is bad.
48
49 Signed-off-by: Yu Kuai <yukuai3@huawei.com>
50 Signed-off-by: Song Liu <song@kernel.org>
51 Link: https://lore.kernel.org/r/20230529131106.2123367-2-yukuai1@huaweicloud.com
52 Signed-off-by: Sasha Levin <sashal@kernel.org>
53 ---
54 drivers/md/raid10.c | 2 ++
55 1 file changed, 2 insertions(+)
56
57 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
58 index 7b318e7e8d459..009f7ffe4e10c 100644
59 --- a/drivers/md/raid10.c
60 +++ b/drivers/md/raid10.c
61 @@ -920,6 +920,7 @@ static void flush_pending_writes(struct r10conf *conf)
62
63 raid1_submit_write(bio);
64 bio = next;
65 + cond_resched();
66 }
67 blk_finish_plug(&plug);
68 } else
69 @@ -1130,6 +1131,7 @@ static void raid10_unplug(struct blk_plug_cb *cb, bool from_schedule)
70
71 raid1_submit_write(bio);
72 bio = next;
73 + cond_resched();
74 }
75 kfree(plug);
76 }
77 --
78 2.43.0
79