From nobody Wed Dec 17 09:45:57 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64DCEC25B67 for ; Thu, 26 Oct 2023 15:29:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345448AbjJZP3P (ORCPT ); Thu, 26 Oct 2023 11:29:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231200AbjJZP3N (ORCPT ); Thu, 26 Oct 2023 11:29:13 -0400 Received: from mout02.posteo.de (mout02.posteo.de [185.67.36.66]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A99D187 for ; Thu, 26 Oct 2023 08:29:08 -0700 (PDT) Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 73AAB240106 for ; Thu, 26 Oct 2023 17:29:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1698334146; bh=H64qUyJiele93axV3rB3BVXjSk5GIMWyc2Mutlt6LLs=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version: Content-Transfer-Encoding:From; b=PpyfEGVH22Gu+tpAxSQXOPSj556OPsPQV3DIadsQDbDG226YkoPexZurUNJIGzgHa 79vfltvsc6QBRvPLz+OPYpDLmXq4h7cFqFs5YZyrUyLAlHCf1YL513LRsEFApuUsWK kXCp/+l4UdqS8/X9xpdwisxQsawxKSlyR7aylWYOxoQSh6jIFVKfKnFPVxxfzNyZjE UCyKD2CGfyQIFV3KKjPbwgZcA2HBwsQPFxnh/Se3MnYxqxrBajiBITmhFbNsT8Cm6E Uz2EY15Ki77Yqg+Ac0YgdCIURJIcidT+UxZKUHF1GZhjblNwysvkMdOc/rtYnrUVpM +ym2OeADlpIPw== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4SGV800Z7cz9rxN; Thu, 26 Oct 2023 17:29:03 +0200 (CEST) From: Mark O'Donovan To: linux-kernel@vger.kernel.org Cc: linux-nvme@lists.infradead.org, sagi@grimberg.me, hch@lst.de, axboe@kernel.dk, kbusch@kernel.org, hare@suse.de, Mark O'Donovan Subject: [PATCH] nvme: fine-tune sending of first keep-alive Date: Thu, 26 Oct 2023 15:28:57 +0000 Message-Id: <20231026152857.176594-1-shiftee@posteo.net> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 --- drivers/nvme/host/core.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 21783aa2ee8e..f3ca3e1d4a74 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -1192,8 +1192,16 @@ static unsigned long nvme_keep_alive_work_period(str= uct nvme_ctrl *ctrl) =20 static void nvme_queue_keep_alive_work(struct nvme_ctrl *ctrl) { - queue_delayed_work(nvme_wq, &ctrl->ka_work, - nvme_keep_alive_work_period(ctrl)); + unsigned long now =3D jiffies; + unsigned long delay =3D nvme_keep_alive_work_period(ctrl); + unsigned long ka_next_check_tm =3D ctrl->ka_last_check_time + delay; + + if (time_after(now, ka_next_check_tm)) + delay =3D 0; + else + delay =3D ka_next_check_tm - now; + + queue_delayed_work(nvme_wq, &ctrl->ka_work, delay); } =20 static enum rq_end_io_ret nvme_keep_alive_end_io(struct request *rq, @@ -4451,6 +4459,7 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct dev= ice *dev, INIT_DELAYED_WORK(&ctrl->failfast_work, nvme_failfast_work); memset(&ctrl->ka_cmd, 0, sizeof(ctrl->ka_cmd)); ctrl->ka_cmd.common.opcode =3D nvme_admin_keep_alive; + ctrl->ka_last_check_time =3D jiffies; =20 BUILD_BUG_ON(NVME_DSM_MAX_RANGES * sizeof(struct nvme_dsm_range) > PAGE_SIZE); base-commit: 611da07b89fdd53f140d7b33013f255bf0ed8f34 --=20 2.39.2