mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] raid10_handle_discard() reuses r10bio objects from r10bio_pool.
@ 2026-05-15  9:30 Chen Cheng
  2026-05-21  2:10 ` Xiao Ni
  2026-05-21  5:32 ` Yu Kuai
  0 siblings, 2 replies; 3+ messages in thread
From: Chen Cheng @ 2026-05-15  9:30 UTC (permalink / raw)
  To: Yu Kuai; +Cc: Chen Cheng, linux-raid, linux-kernel

From: Chen Cheng <chencheng@fnnas.com>

put_all_bios() always drops devs[i].bio, but it only drops
devs[i].repl_bio when r10_bio->read_slot < 0. If discard reuses an
r10bio that was previously used for a read, read_slot can still be
non-negative, and discard cleanup can skip bio_put() on repl_bio.

Reset read_slot to -1 when preparing an r10bio for discard so the
replacement bio is always released correctly.

Signed-off-by: Chen Cheng <chencheng@fnnas.com>
---
 drivers/md/raid10.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 39085e7dd6d2..7dc2a5a127e8 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -1727,6 +1727,7 @@ static int raid10_handle_discard(struct mddev *mddev, struct bio *bio)
 	r10_bio->mddev = mddev;
 	r10_bio->state = 0;
 	r10_bio->sectors = 0;
+	r10_bio->read_slot = -1;
 	memset(r10_bio->devs, 0, sizeof(r10_bio->devs[0]) * geo->raid_disks);
 	wait_blocked_dev(mddev, r10_bio);
 
-- 
2.54.0

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] raid10_handle_discard() reuses r10bio objects from r10bio_pool.
  2026-05-15  9:30 [PATCH] raid10_handle_discard() reuses r10bio objects from r10bio_pool Chen Cheng
@ 2026-05-21  2:10 ` Xiao Ni
  2026-05-21  5:32 ` Yu Kuai
  1 sibling, 0 replies; 3+ messages in thread
From: Xiao Ni @ 2026-05-21  2:10 UTC (permalink / raw)
  To: Chen Cheng; +Cc: Yu Kuai, linux-raid, linux-kernel

On Fri, May 15, 2026 at 6:11 PM Chen Cheng <chencheng@fnnas.com> wrote:
>
> From: Chen Cheng <chencheng@fnnas.com>
>
> put_all_bios() always drops devs[i].bio, but it only drops
> devs[i].repl_bio when r10_bio->read_slot < 0. If discard reuses an
> r10bio that was previously used for a read, read_slot can still be
> non-negative, and discard cleanup can skip bio_put() on repl_bio.
>
> Reset read_slot to -1 when preparing an r10bio for discard so the
> replacement bio is always released correctly.
>
> Signed-off-by: Chen Cheng <chencheng@fnnas.com>
> ---
>  drivers/md/raid10.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
> index 39085e7dd6d2..7dc2a5a127e8 100644
> --- a/drivers/md/raid10.c
> +++ b/drivers/md/raid10.c
> @@ -1727,6 +1727,7 @@ static int raid10_handle_discard(struct mddev *mddev, struct bio *bio)
>         r10_bio->mddev = mddev;
>         r10_bio->state = 0;
>         r10_bio->sectors = 0;
> +       r10_bio->read_slot = -1;
>         memset(r10_bio->devs, 0, sizeof(r10_bio->devs[0]) * geo->raid_disks);
>         wait_blocked_dev(mddev, r10_bio);
>
> --
> 2.54.0
>

Hi Chen

The title usually uses a format such as md/raid10: xxxx

This patch looks good to me.
Reviewed-by: Xiao Ni <xiao@kernel.org>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] raid10_handle_discard() reuses r10bio objects from r10bio_pool.
  2026-05-15  9:30 [PATCH] raid10_handle_discard() reuses r10bio objects from r10bio_pool Chen Cheng
  2026-05-21  2:10 ` Xiao Ni
@ 2026-05-21  5:32 ` Yu Kuai
  1 sibling, 0 replies; 3+ messages in thread
From: Yu Kuai @ 2026-05-21  5:32 UTC (permalink / raw)
  To: Chen Cheng, yukuai; +Cc: linux-raid, linux-kernel

在 2026/5/15 17:30, Chen Cheng 写道:

> From: Chen Cheng <chencheng@fnnas.com>
>
> put_all_bios() always drops devs[i].bio, but it only drops
> devs[i].repl_bio when r10_bio->read_slot < 0. If discard reuses an
> r10bio that was previously used for a read, read_slot can still be
> non-negative, and discard cleanup can skip bio_put() on repl_bio.
>
> Reset read_slot to -1 when preparing an r10bio for discard so the
> replacement bio is always released correctly.
>
> Signed-off-by: Chen Cheng <chencheng@fnnas.com>
> ---
>   drivers/md/raid10.c | 1 +
>   1 file changed, 1 insertion(+)
>
> diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
> index 39085e7dd6d2..7dc2a5a127e8 100644
> --- a/drivers/md/raid10.c
> +++ b/drivers/md/raid10.c
> @@ -1727,6 +1727,7 @@ static int raid10_handle_discard(struct mddev *mddev, struct bio *bio)
>   	r10_bio->mddev = mddev;
>   	r10_bio->state = 0;
>   	r10_bio->sectors = 0;
> +	r10_bio->read_slot = -1;
>   	memset(r10_bio->devs, 0, sizeof(r10_bio->devs[0]) * geo->raid_disks);
>   	wait_blocked_dev(mddev, r10_bio);
>   

Applied with the subject fix:

md/raid10: reset read_slot when reusing r10bio for discard

-- 
Thansk,
Kuai

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-05-21  5:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-05-15  9:30 [PATCH] raid10_handle_discard() reuses r10bio objects from r10bio_pool Chen Cheng
2026-05-21  2:10 ` Xiao Ni
2026-05-21  5:32 ` Yu Kuai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®