]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
nvme: Limit command retries
authorKeith Busch <keith.busch@intel.com>
Mon, 13 Mar 2017 16:06:05 +0000 (09:06 -0700)
committerChuck Anderson <chuck.anderson@oracle.com>
Thu, 1 Jun 2017 20:41:29 +0000 (13:41 -0700)
Many controller implementations will return errors to commands that will
not succeed, but without the DNR bit set. The driver previously retried
these commands an unlimited number of times until the command timeout
has exceeded, which takes an unnecessarilly long period of time.

This patch limits the number of retries a command can have, defaulting
to 5, but is user tunable at load or runtime.

The struct request's 'retries' field is used to track the number of
retries attempted. This is in contrast with scsi's use of this field,
which indicates how many retries are allowed.

Signed-off-by: Keith Busch <keith.busch@intel.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@fb.com>
(cherry picked from commit f80ec966c19b78af4360e26e32e1ab775253105f)

Orabug: 25130845

Signed-off-by: Ashok Vairavan <ashok.vairavan@oracle.com>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/nvme/host/core.c
drivers/nvme/host/nvme.h
drivers/nvme/host/pci.c

index 58573ffa2ae213612062ed8fc6c5546b564d583e..0e783cfa7ea9d9aa945b305a028ddc1177bb5607 100644 (file)
@@ -47,6 +47,11 @@ unsigned char shutdown_timeout = 5;
 module_param(shutdown_timeout, byte, 0644);
 MODULE_PARM_DESC(shutdown_timeout, "timeout in seconds for controller shutdown");
 
+unsigned int nvme_max_retries = 5;
+module_param_named(max_retries, nvme_max_retries, uint, 0644);
+MODULE_PARM_DESC(max_retries, "max number of retries a command may have");
+EXPORT_SYMBOL_GPL(nvme_max_retries);
+
 static int nvme_major;
 module_param(nvme_major, int, 0);
 
index 5e88b21b99d62b27479445720322ff8163992c44..2faa799c7f2f23de7f2d3e9158c5ce17e4c93438 100644 (file)
@@ -38,6 +38,8 @@ extern unsigned char admin_timeout;
 extern unsigned char shutdown_timeout;
 #define SHUTDOWN_TIMEOUT       (shutdown_timeout * HZ)
 
+extern unsigned int nvme_max_retries;
+
 enum {
        NVME_NS_LBA             = 0,
        NVME_NS_LIGHTNVM        = 1,
@@ -202,7 +204,8 @@ static inline int nvme_error_status(u16 status)
 static inline bool nvme_req_needs_retry(struct request *req, u16 status)
 {
        return !(status & NVME_SC_DNR || blk_noretry_request(req)) &&
-               (jiffies - req->start_time) < req->timeout;
+               (jiffies - req->start_time) < req->timeout &&
+               req->retries < nvme_max_retries;
 }
 
 void nvme_cancel_request(struct request *req, void *data, bool reserved);
index 73619d6c3d9bb541932b24f09d5331faf03ebf22..f0b0b0c97d8e48b1d721f856a6c82bd89eb76bc8 100644 (file)
@@ -322,6 +322,12 @@ static int nvme_init_iod(struct request *rq, unsigned size,
        iod->npages = -1;
        iod->nents = 0;
        iod->length = size;
+
+       if (!(rq->cmd_flags & REQ_DONTPREP)) {
+               rq->retries = 0;
+               rq->cmd_flags |= REQ_DONTPREP;
+       }
+
        return 0;
 }
 
@@ -673,6 +679,7 @@ static void nvme_complete_rq(struct request *req)
 
        if (unlikely(req->errors)) {
                if (nvme_req_needs_retry(req, req->errors)) {
+                       req->retries++;
                        nvme_requeue_req(req);
                        return;
                }