Skip to content

Commit 460af1f

Browse files
YuKuai-huaweiliu-song-6
authored andcommitted
md/raid1-10: limit the number of plugged bio
bio can be added to plug infinitely, and following writeback test can trigger huge amount of plugged bio: Test script: modprobe brd rd_nr=4 rd_size=10485760 mdadm -CR /dev/md0 -l10 -n4 /dev/ram[0123] --assume-clean --bitmap=internal echo 0 > /proc/sys/vm/dirty_background_ratio fio -filename=/dev/md0 -ioengine=libaio -rw=write -bs=4k -numjobs=1 -iodepth=128 -name=test Test result: Monitor /sys/block/md0/inflight will found that inflight keep increasing until fio finish writing, after running for about 2 minutes: [root@fedora ~]# cat /sys/block/md0/inflight 0 4474191 Fix the problem by limiting the number of plugged bio based on the number of copies for original bio. Signed-off-by: Yu Kuai <[email protected]> Signed-off-by: Song Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 9efcc2c commit 460af1f

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

drivers/md/raid1-10.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#define IO_MADE_GOOD ((struct bio *)2)
2222

2323
#define BIO_SPECIAL(bio) ((unsigned long)bio <= 2)
24+
#define MAX_PLUG_BIO 32
2425

2526
/* for managing resync I/O pages */
2627
struct resync_pages {
@@ -31,6 +32,7 @@ struct resync_pages {
3132
struct raid1_plug_cb {
3233
struct blk_plug_cb cb;
3334
struct bio_list pending;
35+
unsigned int count;
3436
};
3537

3638
static void rbio_pool_free(void *rbio, void *data)
@@ -129,7 +131,7 @@ static inline void raid1_submit_write(struct bio *bio)
129131
}
130132

131133
static inline bool raid1_add_bio_to_plug(struct mddev *mddev, struct bio *bio,
132-
blk_plug_cb_fn unplug)
134+
blk_plug_cb_fn unplug, int copies)
133135
{
134136
struct raid1_plug_cb *plug = NULL;
135137
struct blk_plug_cb *cb;
@@ -149,6 +151,11 @@ static inline bool raid1_add_bio_to_plug(struct mddev *mddev, struct bio *bio,
149151

150152
plug = container_of(cb, struct raid1_plug_cb, cb);
151153
bio_list_add(&plug->pending, bio);
154+
if (++plug->count / MAX_PLUG_BIO >= copies) {
155+
list_del(&cb->list);
156+
cb->callback(cb, false);
157+
}
158+
152159

153160
return true;
154161
}

drivers/md/raid1.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1565,7 +1565,7 @@ static void raid1_write_request(struct mddev *mddev, struct bio *bio,
15651565
r1_bio->sector);
15661566
/* flush_pending_writes() needs access to the rdev so...*/
15671567
mbio->bi_bdev = (void *)rdev;
1568-
if (!raid1_add_bio_to_plug(mddev, mbio, raid1_unplug)) {
1568+
if (!raid1_add_bio_to_plug(mddev, mbio, raid1_unplug, disks)) {
15691569
spin_lock_irqsave(&conf->device_lock, flags);
15701570
bio_list_add(&conf->pending_bio_list, mbio);
15711571
spin_unlock_irqrestore(&conf->device_lock, flags);

drivers/md/raid10.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1314,7 +1314,7 @@ static void raid10_write_one_disk(struct mddev *mddev, struct r10bio *r10_bio,
13141314

13151315
atomic_inc(&r10_bio->remaining);
13161316

1317-
if (!raid1_add_bio_to_plug(mddev, mbio, raid10_unplug)) {
1317+
if (!raid1_add_bio_to_plug(mddev, mbio, raid10_unplug, conf->copies)) {
13181318
spin_lock_irqsave(&conf->device_lock, flags);
13191319
bio_list_add(&conf->pending_bio_list, mbio);
13201320
spin_unlock_irqrestore(&conf->device_lock, flags);

0 commit comments

Comments
 (0)