From patchwork Thu Sep 21 09:04:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Valente X-Patchwork-Id: 113201 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp1771285qgf; Thu, 21 Sep 2017 02:04:47 -0700 (PDT) X-Received: by 10.98.223.210 with SMTP id d79mr4907692pfl.67.1505984687130; Thu, 21 Sep 2017 02:04:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505984687; cv=none; d=google.com; s=arc-20160816; b=OC1XzByjy08ZVCRH1I4hXbaCi7BWF92anb8Oou9RJuNqLwES++LPk4MyOw44acKI4j iDZWdP6FCRkAtA4boTxeo+9ZheByQAZj52gLcsywuL5kFtFp3U7FUMZWADIKIqt5nAvt y7H6abS6BRwX/THVmqEzBM7l2/kNeE1vPN0Rw4MBlSsAlp0s/vo3qHU7WKYuqjiIlh2G 2qOX2cjaD7OC466fAiunL/5AXBvK7tTFuVSPtZ5DMoxrjGO3oEl2qaMblR7T2TkhqG/l dYbFnUSAFi/CiZA1ZMm5vxUTVcwLLna/dLbZ3M+RUu6NdzvDWuzMkiVBXtSkbOPjMa6p aKBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=uNlQFKFV+Wjj6fYjhJGqhZUyrQ/O6Mb11TIDJfMIsUY=; b=ymojvtOmEsEdZdWxVJkBIEZwzlqqbfdMbMuw7MVEitda54wz/NTWFfx2Dbo0fzd3pi FDpF/C/DztZ7iocvRx+vKITav9rbCNcXNimQAO7wfbsVGzjVNE67oLWAGhRFZ1W8dvr2 nOSX7e+YAhKBoD3sCTqFn20v4U2leIJEVaIN9Dmbeff9XIwbfofSsCWhB+kAiFc9T7oX 7KCN9wE36183+R2ZvNJp7ya1pb/Pcj8ONnNxGoG1ljeau02O2canBFbbCFFnr0hwzLJh yog9civfxT2Pcsi+o4PY9IpzDMDjcgzz+UW9FcIDcaILood2Zz47KQXAJ9TBzwzBzV5Y 7g3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BNh5Ll53; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a6si717279pll.406.2017.09.21.02.04.46; Thu, 21 Sep 2017 02:04:47 -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=@linaro.org header.s=google header.b=BNh5Ll53; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752053AbdIUJEn (ORCPT + 26 others); Thu, 21 Sep 2017 05:04:43 -0400 Received: from mail-wr0-f179.google.com ([209.85.128.179]:50441 "EHLO mail-wr0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751930AbdIUJEj (ORCPT ); Thu, 21 Sep 2017 05:04:39 -0400 Received: by mail-wr0-f179.google.com with SMTP id w12so4009053wrc.7 for ; Thu, 21 Sep 2017 02:04:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=uNlQFKFV+Wjj6fYjhJGqhZUyrQ/O6Mb11TIDJfMIsUY=; b=BNh5Ll53WgOWL3yr3be09uPAffWbTCRztp+QqdaAfZidzP20mnKO8b2NP0sr1ePNAN at4/X2vpEPBT5WXao3ofQw0ai6DJpElyM9/ecZYOsqDqcPljOo/qb4zczQ9/4OFom1UG A3Viep4LKvWoICFWF6X9O8aPBV5t69dyl8ZyI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=uNlQFKFV+Wjj6fYjhJGqhZUyrQ/O6Mb11TIDJfMIsUY=; b=t+wn1gLtcxlDQ33H9LavyiNGhJP8NX19X5HHYKdWe77SnR2GCMxdQy3w7sWNANj79k OtKG5S7Z4gHSO4vhPPFCkXZ4GXMEvxXPvs9bZ/vt775cgZeahjcZOnMvkqtHW0gmxH8J iObnFGWgE+5i9stp07lcDvz/wrBq7d3tYExIj7qmyGQ0j96DUEvRd3upjWeQlbftAxla 6XZOq+tpQxOGNJ3eCOnC8OV5WGgXEGws++R0re2Wq4HXtiafGwViRXRi3L/3PMREKxsH 5WP2io1J1lDbbYwT7t51qUOU8OjOHzGFG3yDRcl/iWH8Z4SJBS2aYJSdPvElXbKdAmPG 0Dvg== X-Gm-Message-State: AHPjjUg0TSZEe9V5dKW1zV41b5KenmLAcocqBR6cLrgN/b9QpIBka9+6 o1Aih7Y0uPqaQ9GAOA0ni+1J3ptmGeQ= X-Google-Smtp-Source: AOwi7QCFmD1Tj+iNnizs7nKivETWMNJeIAtHb6X6DVHKLp5FXWl5eIMuwzunzApAM8qntczUbyWwxg== X-Received: by 10.223.182.71 with SMTP id i7mr1170202wre.43.1505984678128; Thu, 21 Sep 2017 02:04:38 -0700 (PDT) Received: from localhost.localdomain ([185.14.11.73]) by smtp.gmail.com with ESMTPSA id o59sm804032wrc.45.2017.09.21.02.04.36 (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 21 Sep 2017 02:04:37 -0700 (PDT) From: Paolo Valente To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, ulf.hansson@linaro.org, broonie@kernel.org, lee.tibbert@gmail.com, oleksandr@natalenko.name, mirkomontanari91@gmail.com, angeloruocco90@gmail.com, mauro.andreolini@unimore.it, Paolo Valente Subject: [PATCH BUGFIX/IMPROVEMENT 1/4] block, bfq: fix wrong init of saved start time for weight raising Date: Thu, 21 Sep 2017 11:04:00 +0200 Message-Id: <20170921090403.3217-2-paolo.valente@linaro.org> X-Mailer: git-send-email 2.10.0 In-Reply-To: <20170921090403.3217-1-paolo.valente@linaro.org> References: <20170921090403.3217-1-paolo.valente@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This commit fixes a bug that causes bfq to fail to guarantee a high responsiveness on some drives, if there is heavy random read+write I/O in the background. More precisely, such a failure allowed this bug to be found [1], but the bug may well cause other yet unreported anomalies. BFQ raises the weight of the bfq_queues associated with soft real-time applications, to privilege the I/O, and thus reduce latency, for these applications. This mechanism is named soft-real-time weight raising in BFQ. A soft real-time period may happen to be nested into an interactive weight raising period, i.e., it may happen that, when a bfq_queue switches to a soft real-time weight-raised state, the bfq_queue is already being weight-raised because deemed interactive too. In this case, BFQ saves in a special variable wr_start_at_switch_to_srt, the time instant when the interactive weight-raising period started for the bfq_queue, i.e., the time instant when BFQ started to deem the bfq_queue interactive. This value is then used to check whether the interactive weight-raising period would still be in progress when the soft real-time weight-raising period ends. If so, interactive weight raising is restored for the bfq_queue. This restore is useful, in particular, because it prevents bfq_queues from losing their interactive weight raising prematurely, as a consequence of spurious, short-lived soft real-time weight-raising periods caused by wrong detections as soft real-time. If, instead, a bfq_queue switches to soft-real-time weight raising while it *is not* already in an interactive weight-raising period, then the variable wr_start_at_switch_to_srt has no meaning during the following soft real-time weight-raising period. Unfortunately the handling of this case is wrong in BFQ: not only the variable is not flagged somehow as meaningless, but it is also set to the time when the switch to soft real-time weight-raising occurs. This may cause an interactive weight-raising period to be considered mistakenly as still in progress, and thus a spurious interactive weight-raising period to start for the bfq_queue, at the end of the soft-real-time weight-raising period. In particular the spurious interactive weight-raising period will be considered as still in progress, if the soft-real-time weight-raising period does not last very long. The bfq_queue will then be wrongly privileged and, if I/O bound, will unjustly steal bandwidth to truly interactive or soft real-time bfq_queues, harming responsiveness and low latency. This commit fixes this issue by just setting wr_start_at_switch_to_srt to minus infinity (farthest past time instant according to jiffies macros): when the soft-real-time weight-raising period ends, certainly no interactive weight-raising period will be considered as still in progress. [1] Background I/O Type: Random - Background I/O mix: Reads and writes - Application to start: LibreOffice Writer in http://www.phoronix.com/scan.php?page=news_item&px=Linux-4.13-IO-Laptop Signed-off-by: Paolo Valente Signed-off-by: Angelo Ruocco Tested-by: Oleksandr Natalenko Tested-by: Lee Tibbert Tested-by: Mirko Montanari --- block/bfq-iosched.c | 50 +++++++++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 19 deletions(-) -- 2.10.0 diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c index a4783da..c25955c 100644 --- a/block/bfq-iosched.c +++ b/block/bfq-iosched.c @@ -1202,6 +1202,24 @@ static unsigned int bfq_wr_duration(struct bfq_data *bfqd) return dur; } +/* + * Return the farthest future time instant according to jiffies + * macros. + */ +static unsigned long bfq_greatest_from_now(void) +{ + return jiffies + MAX_JIFFY_OFFSET; +} + +/* + * Return the farthest past time instant according to jiffies + * macros. + */ +static unsigned long bfq_smallest_from_now(void) +{ + return jiffies - MAX_JIFFY_OFFSET; +} + static void bfq_update_bfqq_wr_on_rq_arrival(struct bfq_data *bfqd, struct bfq_queue *bfqq, unsigned int old_wr_coeff, @@ -1216,7 +1234,19 @@ static void bfq_update_bfqq_wr_on_rq_arrival(struct bfq_data *bfqd, bfqq->wr_coeff = bfqd->bfq_wr_coeff; bfqq->wr_cur_max_time = bfq_wr_duration(bfqd); } else { - bfqq->wr_start_at_switch_to_srt = jiffies; + /* + * No interactive weight raising in progress + * here: assign minus infinity to + * wr_start_at_switch_to_srt, to make sure + * that, at the end of the soft-real-time + * weight raising periods that is starting + * now, no interactive weight-raising period + * may be wrongly considered as still in + * progress (and thus actually started by + * mistake). + */ + bfqq->wr_start_at_switch_to_srt = + bfq_smallest_from_now(); bfqq->wr_coeff = bfqd->bfq_wr_coeff * BFQ_SOFTRT_WEIGHT_FACTOR; bfqq->wr_cur_max_time = @@ -2897,24 +2927,6 @@ static unsigned long bfq_bfqq_softrt_next_start(struct bfq_data *bfqd, jiffies + nsecs_to_jiffies(bfqq->bfqd->bfq_slice_idle) + 4); } -/* - * Return the farthest future time instant according to jiffies - * macros. - */ -static unsigned long bfq_greatest_from_now(void) -{ - return jiffies + MAX_JIFFY_OFFSET; -} - -/* - * Return the farthest past time instant according to jiffies - * macros. - */ -static unsigned long bfq_smallest_from_now(void) -{ - return jiffies - MAX_JIFFY_OFFSET; -} - /** * bfq_bfqq_expire - expire a queue. * @bfqd: device owning the queue.