nvme: support traffic based keep-alive
authorSagi Grimberg <sagi@grimberg.me>
Fri, 2 Nov 2018 17:28:15 +0000 (10:28 -0700)
committerJens Axboe <axboe@kernel.dk>
Sat, 8 Dec 2018 05:26:55 +0000 (22:26 -0700)
If the controller supports traffic based keep alive, we restart the keep
alive timer if any admin or io commands was completed during the kato
period.  This prevents a possible starvation of keep alive commands in
the presence of heavy traffic as in such case, we already have a health
indication from the host perspective.

Only set a comp_seen indicator in case the controller supports keep
alive to minimize the overhead for pci controllers.

Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/nvme/host/core.c
drivers/nvme/host/nvme.h
include/linux/nvme.h

index 9de6244a345c6a08d04182934dcf1d8e03af6af2..48ffb1d685c2435b47d9ef0a2d37a37a5bd3f112 100644 (file)
@@ -251,6 +251,9 @@ void nvme_complete_rq(struct request *req)
 
        trace_nvme_complete_rq(req);
 
+       if (nvme_req(req)->ctrl->kas)
+               nvme_req(req)->ctrl->comp_seen = true;
+
        if (unlikely(status != BLK_STS_OK && nvme_req_needs_retry(req))) {
                if ((req->cmd_flags & REQ_NVME_MPATH) &&
                    blk_path_error(status)) {
@@ -839,6 +842,7 @@ static void nvme_keep_alive_end_io(struct request *rq, blk_status_t status)
                return;
        }
 
+       ctrl->comp_seen = false;
        schedule_delayed_work(&ctrl->ka_work, ctrl->kato * HZ);
 }
 
@@ -863,6 +867,15 @@ static void nvme_keep_alive_work(struct work_struct *work)
 {
        struct nvme_ctrl *ctrl = container_of(to_delayed_work(work),
                        struct nvme_ctrl, ka_work);
+       bool comp_seen = ctrl->comp_seen;
+
+       if ((ctrl->ctratt & NVME_CTRL_ATTR_TBKAS) && comp_seen) {
+               dev_dbg(ctrl->device,
+                       "reschedule traffic based keep-alive timer\n");
+               ctrl->comp_seen = false;
+               schedule_delayed_work(&ctrl->ka_work, ctrl->kato * HZ);
+               return;
+       }
 
        if (nvme_keep_alive(ctrl)) {
                /* allocation failure, reset the controller */
index 4be7bbcfe66d7845121c4f9846621f9c2bb57793..f2594d468f29421131c891e6894f43fadb92f66d 100644 (file)
@@ -145,6 +145,7 @@ enum nvme_ctrl_state {
 };
 
 struct nvme_ctrl {
+       bool comp_seen;
        enum nvme_ctrl_state state;
        bool identified;
        spinlock_t lock;
index 753c83a5c01f5d51dfa4d89d27b8b48818b23f39..429c4cf90899af2d6baa77044e59637063b5c3ef 100644 (file)
@@ -200,6 +200,7 @@ enum {
 
 enum nvme_ctrl_attr {
        NVME_CTRL_ATTR_HID_128_BIT      = (1 << 0),
+       NVME_CTRL_ATTR_TBKAS            = (1 << 6),
 };
 
 struct nvme_id_ctrl {