From: Xiao Ni <xni@redhat.com>
To: Guoqing Jiang <guoqing.jiang@linux.dev>
Cc: linux-raid <linux-raid@vger.kernel.org>, Song Liu <song@kernel.org>
Subject: Re: Memory leak when raid10 takeover raid0
Date: Mon, 10 Oct 2022 16:13:39 +0800 [thread overview]
Message-ID: <CALTww2-LVHQdaq-5DQSH13z1aCcLUjN1o4aE-XcfoAnU0pSFbQ@mail.gmail.com> (raw)
In-Reply-To: <CALTww2_jaUVEk-zeobWSn9+yDYfkESKEX6hAKZ+-O+dMzQS+Hg@mail.gmail.com>
How about something like this?
diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index 857c49399c28..c263173a142f 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -393,6 +393,9 @@ static int raid0_run(struct mddev *mddev)
mddev->private = conf;
}
conf = mddev->private;
+
+ init_waitqueue_head(&conf->wait_for_quiescent);
+
if (mddev->queue) {
struct md_rdev *rdev;
@@ -512,6 +515,18 @@ static void raid0_handle_discard(struct mddev
*mddev, struct bio *bio)
bio_endio(bio);
}
+static void raid0_end_request(struct bio *bio)
+{
+ struct bio *orig_bio = bio->bi_private;
+ struct gendisk *disk = orig_bio->bi_bdev->bd_disk;
+ struct mddev *mddev = disk->private;
+ struct r0conf *conf = mddev->private;
+
+ atomic_dec(&conf->bios);
+ bio_put(bio);
+ bio_endio(orig_bio);
+}
+
static bool raid0_make_request(struct mddev *mddev, struct bio *bio)
{
struct r0conf *conf = mddev->private;
@@ -522,6 +537,7 @@ static bool raid0_make_request(struct mddev
*mddev, struct bio *bio)
sector_t orig_sector;
unsigned chunk_sects;
unsigned sectors;
+ struct bio *r0_bio;
if (unlikely(bio->bi_opf & REQ_PREFLUSH)
&& md_flush_request(mddev, bio))
@@ -575,15 +591,20 @@ static bool raid0_make_request(struct mddev
*mddev, struct bio *bio)
return true;
}
- bio_set_dev(bio, tmp_dev->bdev);
- bio->bi_iter.bi_sector = sector + zone->dev_start +
+ r0_bio = bio_alloc_clone(tmp_dev->bdev, bio, GFP_NOIO,
+ &mddev->bio_set);
+
+ r0_bio->bi_private = bio;
+ r0_bio->bi_end_io = raid0_end_request;
+ r0_bio->bi_iter.bi_sector = sector + zone->dev_start +
tmp_dev->data_offset;
if (mddev->gendisk)
- trace_block_bio_remap(bio, disk_devt(mddev->gendisk),
+ trace_block_bio_remap(r0_bio, disk_devt(mddev->gendisk),
bio_sector);
- mddev_check_write_zeroes(mddev, bio);
- submit_bio_noacct(bio);
+ mddev_check_write_zeroes(mddev, r0_bio);
+ atomic_inc(&conf->bios);
+ submit_bio_noacct(r0_bio);
return true;
}
@@ -754,6 +775,10 @@ static void *raid0_takeover(struct mddev *mddev)
static void raid0_quiesce(struct mddev *mddev, int quiesce)
{
+ struct r0conf *conf = mddev->private;
+
+ if (quiesce)
+ wait_event(&conf->wait_for_quiescent,
atomic_read(&conf->bios)==0);
}
static struct md_personality raid0_personality=
diff --git a/drivers/md/raid0.h b/drivers/md/raid0.h
index 3816e5477db1..a0ec5c235962 100644
--- a/drivers/md/raid0.h
+++ b/drivers/md/raid0.h
@@ -27,6 +27,9 @@ struct r0conf {
* by strip_zone->dev */
int nr_strip_zones;
enum r0layout layout;
+ atomic_t bios; /* The bios that submit to
+ * member disks */
+ struct wait_queue_head_t wait_for_quiescent;
};
Regards
Xiao
next prev parent reply other threads:[~2022-10-10 8:13 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-08 9:06 Memory leak when raid10 takeover raid0 Xiao Ni
2022-10-10 0:40 ` Guoqing Jiang
2022-10-10 0:55 ` Guoqing Jiang
2022-10-10 5:48 ` Xiao Ni
2022-10-10 8:13 ` Xiao Ni [this message]
2022-10-11 13:38 ` Guoqing Jiang
2022-10-11 15:49 ` Xiao Ni
2022-10-12 10:58 ` Guoqing Jiang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CALTww2-LVHQdaq-5DQSH13z1aCcLUjN1o4aE-XcfoAnU0pSFbQ@mail.gmail.com \
--to=xni@redhat.com \
--cc=guoqing.jiang@linux.dev \
--cc=linux-raid@vger.kernel.org \
--cc=song@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).