Re: [PATCH] ublk: optimize ublk_rq_has_data()

From: Ming Lei

Date: Tue Apr 21 2026 - 19:51:42 EST


On Tue, Apr 21, 2026 at 01:47:42PM -0600, Caleb Sander Mateos wrote:
> ublk_rq_has_data() currently uses bio_has_data(), which involves 2
> indirections and several branches. Use blk_rq_bytes() instead, which
> performs a single indirection with no branches.
>
> Signed-off-by: Caleb Sander Mateos <csander@xxxxxxxxxxxxxxx>
> ---
> drivers/block/ublk_drv.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
> index ef8a0705e68b..5f9b3c3876f4 100644
> --- a/drivers/block/ublk_drv.c
> +++ b/drivers/block/ublk_drv.c
> @@ -1172,11 +1172,11 @@ static inline struct ublk_queue *ublk_get_queue(struct ublk_device *dev,
> return dev->queues[qid];
> }
>
> static inline bool ublk_rq_has_data(const struct request *rq)
> {
> - return bio_has_data(rq->bio);
> + return blk_rq_bytes(rq);
> }

blk_rq_bytes() doesn't return the actual payload data bytes, such as,
discard command, but bio_has_data() does.


thanks,
Ming