From nobody Wed Dec 17 09:46:08 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 F37FCC61DF4 for ; Fri, 24 Nov 2023 20:57:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346013AbjKXU5R (ORCPT ); Fri, 24 Nov 2023 15:57:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229677AbjKXU5P (ORCPT ); Fri, 24 Nov 2023 15:57:15 -0500 Received: from mout01.posteo.de (mout01.posteo.de [185.67.36.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6869F12B for ; Fri, 24 Nov 2023 12:57:20 -0800 (PST) Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 41AA4240027 for ; Fri, 24 Nov 2023 21:57:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1700859438; bh=VUY/r48iuYNklA3pOPBW8jilcpXCwFMRejWJXce3tks=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version: Content-Transfer-Encoding:From; b=ATwDadX1/5k2Zv9OtETrV/kpzy03/jc89TOifHaP7JU/FWHtiGOkoCiSZz3d/NBL6 mZEL4wBs20g4K2+C97PEQWM14oeMm434q52x2ViKkqQK4v68S1eCP2l3MJOmLZuK3h KIa1tM+yrCSr3D4fbhYvvr6diYqIvy8t9uBjv+TNlbkumjBs6gD1tFrMzrSssYRIBD F140F3BWnZmfMn3/Va5bXLT9EdsuCxAkDqKo8zRL6ril3YWIPY/nuHAqcg0NsqTLO8 QFHfxB7vHGX6e/ZgIzhvI2uxH4PmzwY663VFposVvBs12atc7dwSoXAio+60zGbgRM iBMDy0+85lQoQ== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4ScS3H31gWz9rxR; Fri, 24 Nov 2023 21:57:15 +0100 (CET) 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 RESEND] nvme: fine-tune sending of first keep-alive Date: Fri, 24 Nov 2023 20:56:59 +0000 Message-Id: <20231124205659.523248-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 Reviewed-by: Sagi Grimberg --- 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 46a4c9c5ea96..8bf24c1cd8bb 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, @@ -4471,6 +4479,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: 5b7ad877e4d81f8904ce83982b1ba5c6e83deccb --=20 2.39.2