Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp70606ybp; Thu, 3 Oct 2019 10:18:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqwZPNjMi3CUIOqDV4t8wYZVwKVhx61bsIjVDdvJET98c5ENA4wBl2SRWHZsj57PEriqIsI7 X-Received: by 2002:a05:6402:1501:: with SMTP id f1mr10776708edw.76.1570123100381; Thu, 03 Oct 2019 10:18:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570123100; cv=none; d=google.com; s=arc-20160816; b=yEW95ZLSIjuB8E6jUv4piLA9JpZtEpW3QZoz7Mi6DyQWVWvbxtp2rsHdjk3Th+HeKl 5fd5uW0jj/fao2QOAOUlDdojfE9KLBvtuudEyl6dSYZuc6m4QSincaxlJiKMNJGQ5H8K B1maQIg0qXRaJL3Tz4L7u3TCbkffVvjqeoeShz+bA8anWPlDwrozJaU1MTUkx28+NdF9 ibe/QGcILtcP9pR0sinQjEL05u8ipCDnVP/ZR61B8eamC3BRTIEn0/98MvPb5YS3elYd /d1f00tyc1IrREV18ZG20XvQcOrhoRIup+khJFV4hMP8D+pwarj9Qf/vnk3y8UAhv91C ls5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=nep8u0l2q1Z9GbV0okXQxNvpbCXSbPuaQgIjuXTNx9k=; b=HrakiA+bCq9gaSsZmeARJkmSJUAcZnFeGnxWW+1Dmq63VIadMQ/rseEQm8Aoq/KqaO /SzoEDGQmNJy/wM5JDW1euuPffgfjXtkRQ+9d8wF2D7Y7gkmwIaMK1EWUuTMooX1EYCv LsWB+T9/Dd/wR0P1dsY8VKQCAvUZ3ZV8sU4Zpq8PpQpYaJvv1OLxkSlavLEWvlOatSbT wSi2KNcFzgJmQ9xN9KJn6JRIrCDWFym+RtWOA1KrLYVrgIjrt1cp3I0BpQr9/9sCmrRB hCrVlldtET96JPPnFjSsj4BiaBBdoUbWgEQboEyIzF6zck8nUvACH4doXLwyGDLzcPpP P+5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=11hD+IM9; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c19si2160456ede.360.2019.10.03.10.17.55; Thu, 03 Oct 2019 10:18:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=11hD+IM9; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390601AbfJCRQd (ORCPT + 99 others); Thu, 3 Oct 2019 13:16:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:53550 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389869AbfJCQYF (ORCPT ); Thu, 3 Oct 2019 12:24:05 -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 836F12054F; Thu, 3 Oct 2019 16:24:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570119845; bh=XmbnGcaONG9HpypkGHQkc7eQpNqgmmYMiBsIZ+oy6Xk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=11hD+IM9y6MOGFApoG7muc4fmSGQYr20iwQK8Kn72/cmT48rbKnFJgPrazS8Kkygj LjUoMD9b7opM+YINAFssFWQItcqHAPMuNnsZ8VD07YAJPHQxSB9UWIvUexBTYLB0Fk E4l8dbSjVxTeD/XJRqHMpxoRpSfPehxg3Ekf02JE= 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 4.19 198/211] md: only call set_in_sync() when it is expected to succeed. Date: Thu, 3 Oct 2019 17:54:24 +0200 Message-Id: <20191003154529.445841708@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191003154447.010950442@linuxfoundation.org> References: <20191003154447.010950442@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 @@ -8807,6 +8807,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; @@ -8852,7 +8853,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);