[PATCHv5 1/2] block: accumulate memory segment gaps per bio

Keith Busch kbusch at kernel.org
Tue Nov 11 05:25:38 PST 2025


On Tue, Nov 11, 2025 at 06:14:24PM +0800, Yu Kuai wrote:
> >
> At least from blk_try_merge(), blk_discard_mergable() do return false,
> however, following checking passed and we end up to the back merge patch.
> 
> blk_try_merge
>   if (blk_discard_mergable())
>     // false due to max_discard_segments is 1
>   else if (...)
>    return ELEVATOR_BACK_MERGE
> 
> Perhaps are you suggesting to change this to:
> 
>   enum elv_merge blk_try_merge(struct request *rq, struct bio *bio)
>   {
> -       if (blk_discard_mergable(rq))
> -               return ELEVATOR_DISCARD_MERGE;
> -       else if (blk_rq_pos(rq) + blk_rq_sectors(rq) == bio->bi_iter.bi_sector)
> +       if (req_op(rq) == REQ_OP_DISCARD) {
> +               if (blk_discard_mergable((rq)))
> +                       return ELEVATOR_DISCARD_MERGE;
> +               return ELEVATOR_NO_MERGE;
> +       }
> +
> +       if (blk_rq_pos(rq) + blk_rq_sectors(rq) == bio->bi_iter.bi_sector)
>                  return ELEVATOR_BACK_MERGE;
> -       else if (blk_rq_pos(rq) - bio_sectors(bio) == bio->bi_iter.bi_sector)
> +       if (blk_rq_pos(rq) - bio_sectors(bio) == bio->bi_iter.bi_sector)
>                  return ELEVATOR_FRONT_MERGE;
>          return ELEVATOR_NO_MERGE;
>   }
> 
> And the same for other callers for blk_discard_mergable().

Ah, so we're merging a discard for a device that doesn't support
vectored discard. I think we still want to be able to front/back merge
such requests, though.



More information about the Linux-nvme mailing list