Skip to content

Commit 136cfcb

Browse files
shifteekeithbusch
authored andcommitted
nvme: fine-tune sending of first keep-alive
Keep-alive commands are sent half-way through the kato period. This normally works well but fails when the keep-alive system is started when we are more than half way through the kato. This can happen on larger setups or due to host delays. With this change we now time the initial keep-alive command from the controller initialisation time, rather than the keep-alive mechanism activation time. Signed-off-by: Mark O'Donovan <[email protected]> Reviewed-by: Sagi Grimberg <[email protected]> Signed-off-by: Keith Busch <[email protected]>
1 parent bb6cc25 commit 136cfcb

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

drivers/nvme/host/core.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,8 +1192,16 @@ static unsigned long nvme_keep_alive_work_period(struct nvme_ctrl *ctrl)
11921192

11931193
static void nvme_queue_keep_alive_work(struct nvme_ctrl *ctrl)
11941194
{
1195-
queue_delayed_work(nvme_wq, &ctrl->ka_work,
1196-
nvme_keep_alive_work_period(ctrl));
1195+
unsigned long now = jiffies;
1196+
unsigned long delay = nvme_keep_alive_work_period(ctrl);
1197+
unsigned long ka_next_check_tm = ctrl->ka_last_check_time + delay;
1198+
1199+
if (time_after(now, ka_next_check_tm))
1200+
delay = 0;
1201+
else
1202+
delay = ka_next_check_tm - now;
1203+
1204+
queue_delayed_work(nvme_wq, &ctrl->ka_work, delay);
11971205
}
11981206

11991207
static enum rq_end_io_ret nvme_keep_alive_end_io(struct request *rq,
@@ -4471,6 +4479,7 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev,
44714479
INIT_DELAYED_WORK(&ctrl->failfast_work, nvme_failfast_work);
44724480
memset(&ctrl->ka_cmd, 0, sizeof(ctrl->ka_cmd));
44734481
ctrl->ka_cmd.common.opcode = nvme_admin_keep_alive;
4482+
ctrl->ka_last_check_time = jiffies;
44744483

44754484
BUILD_BUG_ON(NVME_DSM_MAX_RANGES * sizeof(struct nvme_dsm_range) >
44764485
PAGE_SIZE);

0 commit comments

Comments
 (0)