Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] nvme-pci: fix single segment detection
@ 2019-05-09 11:04 Christoph Hellwig
  2019-05-09 11:24 ` Ming Lei
  2019-05-12 15:20 ` Sagi Grimberg
  0 siblings, 2 replies; 6+ messages in thread
From: Christoph Hellwig @ 2019-05-09 11:04 UTC (permalink / raw)


blk_rq_nr_phys_segments isn't exactly accurate at the request/bio
level, so work around that fact with a few crude sanity checks.  To
be fixed for real in the block layer soon.

Fixes: 297910571f08 ("nvme-pci: optimize mapping single segment requests using SGLs")
Signed-off-by: Christoph Hellwig <hch at lst.de>
---
 drivers/nvme/host/pci.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index 2a8708c9ac18..9a4253be2723 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -824,7 +824,15 @@ static blk_status_t nvme_map_data(struct nvme_dev *dev, struct request *req,
 	blk_status_t ret = BLK_STS_RESOURCE;
 	int nr_mapped;
 
-	if (blk_rq_nr_phys_segments(req) == 1) {
+	/*
+	 * Crude hack to work around the block layer accounting for the fact
+	 * that the SG mapping can merge multiple physically contigous segments
+	 * in blk_rq_nr_phys_segments() despite the fact that not everyone is
+	 * mapping the request to a scatterlist.  To be fixed for real in the
+	 * block layer eventually..
+	 */
+	if (blk_rq_nr_phys_segments(req) == 1 &&
+	    !req->bio->bi_next && req->bio->bi_vcnt == 1) {
 		struct bio_vec bv = req_bvec(req);
 
 		if (!is_pci_p2pdma_page(bv.bv_page)) {
-- 
2.20.1

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

* [PATCH] nvme-pci: fix single segment detection
  2019-05-09 11:04 [PATCH] nvme-pci: fix single segment detection Christoph Hellwig
@ 2019-05-09 11:24 ` Ming Lei
  2019-05-09 12:34   ` Christoph Hellwig
  2019-05-12 15:20 ` Sagi Grimberg
  1 sibling, 1 reply; 6+ messages in thread
From: Ming Lei @ 2019-05-09 11:24 UTC (permalink / raw)


On Thu, May 09, 2019@01:04:09PM +0200, Christoph Hellwig wrote:
> blk_rq_nr_phys_segments isn't exactly accurate at the request/bio
> level, so work around that fact with a few crude sanity checks.  To
> be fixed for real in the block layer soon.
> 
> Fixes: 297910571f08 ("nvme-pci: optimize mapping single segment requests using SGLs")
> Signed-off-by: Christoph Hellwig <hch at lst.de>
> ---
>  drivers/nvme/host/pci.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
> index 2a8708c9ac18..9a4253be2723 100644
> --- a/drivers/nvme/host/pci.c
> +++ b/drivers/nvme/host/pci.c
> @@ -824,7 +824,15 @@ static blk_status_t nvme_map_data(struct nvme_dev *dev, struct request *req,
>  	blk_status_t ret = BLK_STS_RESOURCE;
>  	int nr_mapped;
>  
> -	if (blk_rq_nr_phys_segments(req) == 1) {
> +	/*
> +	 * Crude hack to work around the block layer accounting for the fact
> +	 * that the SG mapping can merge multiple physically contigous segments
> +	 * in blk_rq_nr_phys_segments() despite the fact that not everyone is
> +	 * mapping the request to a scatterlist.  To be fixed for real in the
> +	 * block layer eventually..
> +	 */
> +	if (blk_rq_nr_phys_segments(req) == 1 &&
> +	    !req->bio->bi_next && req->bio->bi_vcnt == 1) {
>  		struct bio_vec bv = req_bvec(req);

I'd suggest to fix block layer instead of working around the issue here,
then any driver may benefit from the fix.

Especially checking bio->bi_vcnt is just a hack, and drivers should
never use .bi_vcnt.


Thanks,
Ming

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

* [PATCH] nvme-pci: fix single segment detection
  2019-05-09 11:24 ` Ming Lei
@ 2019-05-09 12:34   ` Christoph Hellwig
  2019-05-09 13:31     ` Ming Lei
  0 siblings, 1 reply; 6+ messages in thread
From: Christoph Hellwig @ 2019-05-09 12:34 UTC (permalink / raw)


On Thu, May 09, 2019@07:24:12PM +0800, Ming Lei wrote:
> I'd suggest to fix block layer instead of working around the issue here,
> then any driver may benefit from the fix.

That is my plan, and I started on it.  But the fix isn't trivial, and
will probably take a while and be invasive.

> Especially checking bio->bi_vcnt is just a hack, and drivers should
> never use .bi_vcnt.

That is why it is explicitly commented as a hack.  But a good enough
one to still speed up typical 4K I/Os - one a bio has been cloned
chances are very high we don't care about the fast path any more.

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

* [PATCH] nvme-pci: fix single segment detection
  2019-05-09 12:34   ` Christoph Hellwig
@ 2019-05-09 13:31     ` Ming Lei
  2019-05-13  6:26       ` Christoph Hellwig
  0 siblings, 1 reply; 6+ messages in thread
From: Ming Lei @ 2019-05-09 13:31 UTC (permalink / raw)


On Thu, May 09, 2019@02:34:06PM +0200, Christoph Hellwig wrote:
> On Thu, May 09, 2019@07:24:12PM +0800, Ming Lei wrote:
> > I'd suggest to fix block layer instead of working around the issue here,
> > then any driver may benefit from the fix.
> 
> That is my plan, and I started on it.  But the fix isn't trivial, and
> will probably take a while and be invasive.
> 
> > Especially checking bio->bi_vcnt is just a hack, and drivers should
> > never use .bi_vcnt.
> 
> That is why it is explicitly commented as a hack.  But a good enough
> one to still speed up typical 4K I/Os - one a bio has been cloned
> chances are very high we don't care about the fast path any more.

NVMe hasn't max segment size limit, so fair enough for typical
4K IO workload:

Reviewed-by: Ming Lei <ming.lei at redhat.com>


Thanks,
Ming

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

* [PATCH] nvme-pci: fix single segment detection
  2019-05-09 11:04 [PATCH] nvme-pci: fix single segment detection Christoph Hellwig
  2019-05-09 11:24 ` Ming Lei
@ 2019-05-12 15:20 ` Sagi Grimberg
  1 sibling, 0 replies; 6+ messages in thread
From: Sagi Grimberg @ 2019-05-12 15:20 UTC (permalink / raw)


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

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

* [PATCH] nvme-pci: fix single segment detection
  2019-05-09 13:31     ` Ming Lei
@ 2019-05-13  6:26       ` Christoph Hellwig
  0 siblings, 0 replies; 6+ messages in thread
From: Christoph Hellwig @ 2019-05-13  6:26 UTC (permalink / raw)


So actually, after running out ways to make any of my complex block
layer fix ideas work I have a simple fix for the block layer now.

Lets see if is acceptable..

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

end of thread, other threads:[~2019-05-13  6:26 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-05-09 11:04 [PATCH] nvme-pci: fix single segment detection Christoph Hellwig
2019-05-09 11:24 ` Ming Lei
2019-05-09 12:34   ` Christoph Hellwig
2019-05-09 13:31     ` Ming Lei
2019-05-13  6:26       ` Christoph Hellwig
2019-05-12 15:20 ` Sagi Grimberg

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