Skip to content

Commit c7275ce

Browse files
ps-ushankarkeithbusch
authored andcommitted
nvme: improve handling of long keep alives
Upon keep alive completion, nvme_keep_alive_work is scheduled with the same delay every time. If keep alive commands are completing slowly, this may cause a keep alive timeout. The following trace illustrates the issue, taking KATO = 8 and TBKAS off for simplicity: 1. t = 0: run nvme_keep_alive_work, send keep alive 2. t = ε: keep alive reaches controller, controller restarts its keep alive timer 3. t = 4: host receives keep alive completion, schedules nvme_keep_alive_work with delay 4 4. t = 8: run nvme_keep_alive_work, send keep alive Here, a keep alive having RTT of 4 causes a delay of at least 8 - ε between the controller receiving successive keep alives. With ε small, the controller is likely to detect a keep alive timeout. Fix this by calculating the RTT of the keep alive command, and adjusting the scheduling delay of the next keep alive work accordingly. Reported-by: Costa Sapuntzakis <costa@purestorage.com> Reported-by: Randy Jennings <randyj@purestorage.com> Signed-off-by: Uday Shankar <ushankar@purestorage.com> Reviewed-by: Hannes Reinecke <hare@suse.de> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Keith Busch <kbusch@kernel.org>
1 parent 774a963 commit c7275ce

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

drivers/nvme/host/core.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1199,6 +1199,20 @@ static enum rq_end_io_ret nvme_keep_alive_end_io(struct request *rq,
11991199
struct nvme_ctrl *ctrl = rq->end_io_data;
12001200
unsigned long flags;
12011201
bool startka = false;
1202+
unsigned long rtt = jiffies - (rq->deadline - rq->timeout);
1203+
unsigned long delay = nvme_keep_alive_work_period(ctrl);
1204+
1205+
/*
1206+
* Subtract off the keepalive RTT so nvme_keep_alive_work runs
1207+
* at the desired frequency.
1208+
*/
1209+
if (rtt <= delay) {
1210+
delay -= rtt;
1211+
} else {
1212+
dev_warn(ctrl->device, "long keepalive RTT (%u ms)\n",
1213+
jiffies_to_msecs(rtt));
1214+
delay = 0;
1215+
}
12021216

12031217
blk_mq_free_request(rq);
12041218

@@ -1217,7 +1231,7 @@ static enum rq_end_io_ret nvme_keep_alive_end_io(struct request *rq,
12171231
startka = true;
12181232
spin_unlock_irqrestore(&ctrl->lock, flags);
12191233
if (startka)
1220-
nvme_queue_keep_alive_work(ctrl);
1234+
queue_delayed_work(nvme_wq, &ctrl->ka_work, delay);
12211235
return RQ_END_IO_NONE;
12221236
}
12231237

0 commit comments

Comments
 (0)