linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] nvme-pci: calculate iod and avg_seg_size just before use them
@ 2018-01-11  5:09 Jianchao Wang
  2018-01-11 15:48 ` Keith Busch
  0 siblings, 1 reply; 4+ messages in thread
From: Jianchao Wang @ 2018-01-11  5:09 UTC (permalink / raw)
  To: keith.busch, axboe, hch, sagi; +Cc: linux-nvme, linux-kernel

The calculation of iod and avg_seg_size maybe meaningless if
nvme_pci_use_sgls returns before uses them. So calculate
just before use them.

Signed-off-by: Jianchao Wang <jianchao.w.wang@oracle.com>
---
 drivers/nvme/host/pci.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index 0530432..733b4f4 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -772,16 +772,19 @@ static blk_status_t nvme_pci_setup_sgls(struct nvme_dev *dev,
 
 static inline bool nvme_pci_use_sgls(struct nvme_dev *dev, struct request *req)
 {
-	struct nvme_iod *iod = blk_mq_rq_to_pdu(req);
+	struct nvme_iod *iod;
 	unsigned int avg_seg_size;
 
-	avg_seg_size = DIV_ROUND_UP(blk_rq_payload_bytes(req),
-			blk_rq_nr_phys_segments(req));
-
 	if (!(dev->ctrl.sgls & ((1 << 0) | (1 << 1))))
 		return false;
+
+	iod = blk_mq_rq_to_pdu(req);
 	if (!iod->nvmeq->qid)
 		return false;
+
+	avg_seg_size = DIV_ROUND_UP(blk_rq_payload_bytes(req),
+			blk_rq_nr_phys_segments(req));
+
 	if (!sgl_threshold || avg_seg_size < sgl_threshold)
 		return false;
 	return true;
-- 
2.7.4

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

* Re: [PATCH] nvme-pci: calculate iod and avg_seg_size just before use them
  2018-01-11  5:09 [PATCH] nvme-pci: calculate iod and avg_seg_size just before use them Jianchao Wang
@ 2018-01-11 15:48 ` Keith Busch
  2018-01-12  1:31   ` jianchao.wang
  2018-01-14  9:28   ` Sagi Grimberg
  0 siblings, 2 replies; 4+ messages in thread
From: Keith Busch @ 2018-01-11 15:48 UTC (permalink / raw)
  To: Jianchao Wang; +Cc: axboe, hch, sagi, linux-nvme, linux-kernel

On Thu, Jan 11, 2018 at 01:09:39PM +0800, Jianchao Wang wrote:
> The calculation of iod and avg_seg_size maybe meaningless if
> nvme_pci_use_sgls returns before uses them. So calculate
> just before use them.

The compiler will do the right thing here, but I see what you mean. I
think Christoph has some SGL improvements coming, though, that will
obviate this.

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

* Re: [PATCH] nvme-pci: calculate iod and avg_seg_size just before use them
  2018-01-11 15:48 ` Keith Busch
@ 2018-01-12  1:31   ` jianchao.wang
  2018-01-14  9:28   ` Sagi Grimberg
  1 sibling, 0 replies; 4+ messages in thread
From: jianchao.wang @ 2018-01-12  1:31 UTC (permalink / raw)
  To: Keith Busch; +Cc: axboe, hch, sagi, linux-nvme, linux-kernel

Hi Keith

Thanks for your kindly response.

On 01/11/2018 11:48 PM, Keith Busch wrote:
> On Thu, Jan 11, 2018 at 01:09:39PM +0800, Jianchao Wang wrote:
>> The calculation of iod and avg_seg_size maybe meaningless if
>> nvme_pci_use_sgls returns before uses them. So calculate
>> just before use them.
> 
> The compiler will do the right thing here, but I see what you mean. I
> think Christoph has some SGL improvements coming, though, that will
> obviate this.
> 
Yeah, that's great.

Thanks
Jianchao

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

* Re: [PATCH] nvme-pci: calculate iod and avg_seg_size just before use them
  2018-01-11 15:48 ` Keith Busch
  2018-01-12  1:31   ` jianchao.wang
@ 2018-01-14  9:28   ` Sagi Grimberg
  1 sibling, 0 replies; 4+ messages in thread
From: Sagi Grimberg @ 2018-01-14  9:28 UTC (permalink / raw)
  To: Keith Busch, Jianchao Wang; +Cc: axboe, hch, linux-nvme, linux-kernel


>> The calculation of iod and avg_seg_size maybe meaningless if
>> nvme_pci_use_sgls returns before uses them. So calculate
>> just before use them.
> 
> The compiler will do the right thing here, but I see what you mean. I
> think Christoph has some SGL improvements coming, though, that will
> obviate this.

I think that if its not coming for 4.16, it should be easy enough to
take it in.

FWIW,

Reviewed-by: Sagi Grimberg <sagi@grimberg.me>

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

end of thread, other threads:[~2018-01-14  9:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-11  5:09 [PATCH] nvme-pci: calculate iod and avg_seg_size just before use them Jianchao Wang
2018-01-11 15:48 ` Keith Busch
2018-01-12  1:31   ` jianchao.wang
2018-01-14  9:28   ` Sagi Grimberg

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).