nvme: Limit command retries
authorKeith Busch <keith.busch@intel.com>
Tue, 12 Jul 2016 23:20:31 +0000 (16:20 -0700)
committerJens Axboe <axboe@fb.com>
Tue, 12 Jul 2016 23:20:31 +0000 (16:20 -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>
drivers/nvme/host/core.c
drivers/nvme/host/nvme.h
drivers/nvme/host/pci.c

index a51946a35dcf5c1d4d69893068000131af1b9077..86a0c661e74cb875b3c10d4ebf53e0ec0d86b835 100644 (file)
@@ -48,6 +48,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 1bd42d5f9e0efd18c126dcad25489a6780e6f1c0..ab18b78102bf21438836365897585c8fdcc614b4 100644 (file)
@@ -41,6 +41,8 @@ extern unsigned char shutdown_timeout;
 #define NVME_DEFAULT_KATO      5
 #define NVME_KATO_GRACE                10
 
+extern unsigned int nvme_max_retries;
+
 enum {
        NVME_NS_LBA             = 0,
        NVME_NS_LIGHTNVM        = 1,
@@ -239,7 +241,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 846a42977068a383f9d2ff32fba74ea4db81f0ab..120f9b8c926eb3686900e87af34ece82d27e2d6b 100644 (file)
@@ -310,6 +310,11 @@ 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;
 }
 
@@ -623,6 +628,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;
                }