Skip to contentSkip to conversation

ublk: optimize ublk_rq_has_data()

PATCH In review Caleb Sander Mateos 2 participants 4 messages Apr 21 – Apr 22

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ublk: optimize ublk_rq_has_data()

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.

---
 drivers/block/ublk_drv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/ublk_drv.c +1 -1
index ef8a0705e68b..5f9b3c3876f4 100644
@@ -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);
 }
 
 static inline struct ublksrv_io_desc *
 ublk_queue_cmd_buf(struct ublk_device *ub, int q_id)
 {
Signature · 1 line
2.45.2
maintainer
#1 lore raw
Quoted 14 lines · Caleb Sander Mateos

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.

---
 drivers/block/ublk_drv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/ublk_drv.c +0 -0
index ef8a0705e68b..5f9b3c3876f4 100644

drivers/block/ublk_drv.c static inline struct ublk_queue *ublk_get_queue(struct ublk_device *dev, · line 1178

Quoted 8 lines
drivers/block/ublk_drv.c +1 -1
@@ -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

#2 lore raw
Quoted 19 lines · Ming Lei
Quoted 17 lines · Caleb Sander Mateos

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.

---
 drivers/block/ublk_drv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/ublk_drv.c +0 -0
index ef8a0705e68b..5f9b3c3876f4 100644
@@ -1172,11 +1172,11 @@ static inline struct ublk_queue *ublk_get_queue(struct ublk_device *dev,
      return dev->queues[qid];
 }
 
Quoted 8 lines

drivers/block/ublk_drv.c static inline struct ublk_queue *ublk_get_queue(struct ublk_device *dev, · line 1178

Quoted 5 lines
drivers/block/ublk_drv.c +1 -1
 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.

So you're saying that on a discard, rq->__data_len is set to bio->bi_iter.bi_size, which represents the number of bytes being trimmed even though there's no data payload? I guess we could check req_op(rq) here to at least avoid the bio indirection.

Thanks,
Caleb

maintainer
#3 lore raw
Quoted 29 lines · Caleb Sander Mateos
Quoted 19 lines · Ming Lei
Quoted 17 lines · Caleb Sander Mateos

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.

---
 drivers/block/ublk_drv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/ublk_drv.c +0 -0
index ef8a0705e68b..5f9b3c3876f4 100644
@@ -1172,11 +1172,11 @@ static inline struct ublk_queue *ublk_get_queue(struct ublk_device *dev,
      return dev->queues[qid];
 }
 
Quoted 8 lines

drivers/block/ublk_drv.c static inline struct ublk_queue *ublk_get_queue(struct ublk_device *dev, · line 1178

Quoted 5 lines
drivers/block/ublk_drv.c +1 -1
 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.

Quoted 4 lines

So you're saying that on a discard, rq->__data_len is set to bio->bi_iter.bi_size, which represents the number of bytes being trimmed even though there's no data payload? I guess we could check req_op(rq) here to at least avoid the bio indirection.

Yeah, you may add blk_has_data() or open-code it.

Thanks,
Ming