summaryrefslogtreecommitdiffstats
path: root/drivers/md/raid1-10.c
diff options
context:
space:
mode:
authorYu Kuai <yukuai3@huawei.com>2023-05-29 21:11:06 +0800
committerSong Liu <song@kernel.org>2023-06-13 15:25:44 -0700
commit460af1f9d9e62acce4a21f9bd00b5bcd5963bcd4 (patch)
treeff7b4f55aac50289863c129e1d5a8e4ce1c3ce42 /drivers/md/raid1-10.c
parent9efcc2c3df7612eea02daa159ae7c6ac44420513 (diff)
downloadlinux-stable-460af1f9d9e62acce4a21f9bd00b5bcd5963bcd4.tar.gz
linux-stable-460af1f9d9e62acce4a21f9bd00b5bcd5963bcd4.tar.bz2
linux-stable-460af1f9d9e62acce4a21f9bd00b5bcd5963bcd4.zip
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 <yukuai3@huawei.com> Signed-off-by: Song Liu <song@kernel.org> Link: https://lore.kernel.org/r/20230529131106.2123367-8-yukuai1@huaweicloud.com
Diffstat (limited to 'drivers/md/raid1-10.c')
-rw-r--r--drivers/md/raid1-10.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/drivers/md/raid1-10.c b/drivers/md/raid1-10.c
index c62bcb17c67b..169ebe296f2d 100644
--- a/drivers/md/raid1-10.c
+++ b/drivers/md/raid1-10.c
@@ -21,6 +21,7 @@
#define IO_MADE_GOOD ((struct bio *)2)
#define BIO_SPECIAL(bio) ((unsigned long)bio <= 2)
+#define MAX_PLUG_BIO 32
/* for managing resync I/O pages */
struct resync_pages {
@@ -31,6 +32,7 @@ struct resync_pages {
struct raid1_plug_cb {
struct blk_plug_cb cb;
struct bio_list pending;
+ unsigned int count;
};
static void rbio_pool_free(void *rbio, void *data)
@@ -129,7 +131,7 @@ static inline void raid1_submit_write(struct bio *bio)
}
static inline bool raid1_add_bio_to_plug(struct mddev *mddev, struct bio *bio,
- blk_plug_cb_fn unplug)
+ blk_plug_cb_fn unplug, int copies)
{
struct raid1_plug_cb *plug = NULL;
struct blk_plug_cb *cb;
@@ -149,6 +151,11 @@ static inline bool raid1_add_bio_to_plug(struct mddev *mddev, struct bio *bio,
plug = container_of(cb, struct raid1_plug_cb, cb);
bio_list_add(&plug->pending, bio);
+ if (++plug->count / MAX_PLUG_BIO >= copies) {
+ list_del(&cb->list);
+ cb->callback(cb, false);
+ }
+
return true;
}