From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB8A8C32792 for ; Thu, 3 Oct 2019 16:52:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A294B2070B for ; Thu, 3 Oct 2019 16:52:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570121557; bh=ZRce7myZfk1QI63VqGi7nz03HZhFbaacZxkzZTBauw0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=wFC6RXicuEnS6JavbCvXrUS5Nfeiti+M0a2UEr1G0hrCg/mO0BMgs8cjbkqztS1Te DpIHg2N1pBMgi+OYPDFHRo/Fftvidp66srvNGuFI+ZUmm6HMgi2vInO2gxAoB2Kqam ywPBvekyQN2RFGmxK1H+qofGntaJArtC6q4cOInY= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406211AbfJCQwg (ORCPT ); Thu, 3 Oct 2019 12:52:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:40344 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406209AbfJCQwg (ORCPT ); Thu, 3 Oct 2019 12:52:36 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 473D321783; Thu, 3 Oct 2019 16:52:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570121555; bh=ZRce7myZfk1QI63VqGi7nz03HZhFbaacZxkzZTBauw0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nkJ5ejQYK5UYiW8nfglbqh50SjaUglw9iBNPpVFqgt/JiyGOJtiQGQJDl5PN7DEEq 9pHMlAUdt1k3T6gj/KZKqy7Fx5vhOp01DlXflVGfoDH1s35y3SfjCfnUPIrIjWbtBD 40qgLdsqLgJ0TKLbvrgqAyQp+/TYvmbMhnayyRWc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, NeilBrown , Song Liu , Jack Wang Subject: [PATCH 5.3 322/344] md: only call set_in_sync() when it is expected to succeed. Date: Thu, 3 Oct 2019 17:54:47 +0200 Message-Id: <20191003154610.763756994@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191003154540.062170222@linuxfoundation.org> References: <20191003154540.062170222@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: NeilBrown commit 480523feae581ab714ba6610388a3b4619a2f695 upstream. Since commit 4ad23a976413 ("MD: use per-cpu counter for writes_pending"), set_in_sync() is substantially more expensive: it can wait for a full RCU grace period which can be 10s of milliseconds. So we should only call it when the cost is justified. md_check_recovery() currently calls set_in_sync() every time it finds anything to do (on non-external active arrays). For an array performing resync or recovery, this will be quite often. Each call will introduce a delay to the md thread, which can noticeable affect IO submission latency. In md_check_recovery() we only need to call set_in_sync() if 'safemode' was non-zero at entry, meaning that there has been not recent IO. So we save this "safemode was nonzero" state, and only call set_in_sync() if it was non-zero. This measurably reduces mean and maximum IO submission latency during resync/recovery. Reported-and-tested-by: Jack Wang Fixes: 4ad23a976413 ("MD: use per-cpu counter for writes_pending") Cc: stable@vger.kernel.org (v4.12+) Signed-off-by: NeilBrown Signed-off-by: Song Liu Signed-off-by: Greg Kroah-Hartman --- drivers/md/md.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -8910,6 +8910,7 @@ void md_check_recovery(struct mddev *mdd if (mddev_trylock(mddev)) { int spares = 0; + bool try_set_sync = mddev->safemode != 0; if (!mddev->external && mddev->safemode == 1) mddev->safemode = 0; @@ -8955,7 +8956,7 @@ void md_check_recovery(struct mddev *mdd } } - if (!mddev->external && !mddev->in_sync) { + if (try_set_sync && !mddev->external && !mddev->in_sync) { spin_lock(&mddev->lock); set_in_sync(mddev); spin_unlock(&mddev->lock);