From patchwork Mon Mar 26 14:06:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Valente X-Patchwork-Id: 132405 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp3886856ljb; Mon, 26 Mar 2018 07:06:46 -0700 (PDT) X-Google-Smtp-Source: AG47ELvBDT8Wtc5KbgZQL8hWrm3aiSLzAp1q/vgJSQ/lIB5JMGCsAlqReYPQRvu7d0veuZaJyXmN X-Received: by 10.101.101.133 with SMTP id u5mr28387795pgv.151.1522073206283; Mon, 26 Mar 2018 07:06:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522073206; cv=none; d=google.com; s=arc-20160816; b=fZroPEkRt5Q/ofKVEi5ov+B+4PSwY6IVk+GEPY7yOeMyI6H4QSgYEYuvNZcDILPFou nn7QyxcVlyWZPgxWUN4dsNaQ6wCWmJESkOPwaCnPmZ9JY4U20IQaQCAXGDPjqFkDed+a ctRh2fY90otdMcXIBYAZsZ9R8Upsos4gAINjtb1Jz7oUItVN1x4uKDGYx9vzwAx/Bl6n rEcxTKTs1pyEz0wUaGz4RPsMZt/AN2p4TjH8xDlkISngH4aADyQh0S9B+FUykPXqJK+Z BWkPnFaAY1j7F6y78don3NkKXaHeUjAc11ebKKetuQRH63o8MZOCU78UBycCoWszWMJP +PnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=Q5tZPtJoXlSguzH6IrDNVd99Sdo2dEYw82S2wEugmkc=; b=uM0fXI0Keq3Rqo4YZ2yi2Rz/edRAPVe0nhC6dQoskUyvaUioupLB/69hLxXpQ4L9pC vxIjn/bObpv3lmUqE2qXWnRuJnUjT0uQ1bc7tvM/p7vir1HKGszysmE0KMxCUNFnjcsk A4A5GlOPwY9qwlhH9HneqEwGMBVM07pNPT5O3JK+Xv8z1G6reycvFQ5JQVTg2j41y2eT yJyBtNwtE73/Mmv/yJAo8adowdvtVCzh1bcncS1wagdjjb70fTxehANJcVMrnF2BVtsp Vxc2PwS9oz9aJKPLiscDEezuuEMJKeMZyHzLMy6hYFyLopz9bMQtrwRpvVDHb7PdpEzL +Vqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cvX5L0UM; 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 q26si10292862pgd.280.2018.03.26.07.06.46; Mon, 26 Mar 2018 07:06:46 -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=cvX5L0UM; 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 S1752077AbeCZOGn (ORCPT + 28 others); Mon, 26 Mar 2018 10:06:43 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:55008 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752015AbeCZOGl (ORCPT ); Mon, 26 Mar 2018 10:06:41 -0400 Received: by mail-wm0-f68.google.com with SMTP id h76so15683894wme.4 for ; Mon, 26 Mar 2018 07:06:41 -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; bh=Q5tZPtJoXlSguzH6IrDNVd99Sdo2dEYw82S2wEugmkc=; b=cvX5L0UMZhKDK/VHKCGwEjl9rrc1UJXRamb+o/uKARdcKN8L13SFjcwIi/xiLJ59fi f/F+7H0skScOMcpT1n424XgAaweM5b9Q1VwO4oQ8Y+aZNRpFHUKlfnbXkrDHmLwaE/0K bU9mPZr8IioDNZsalyxfoFUXeRePjboFHwgOc= 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; bh=Q5tZPtJoXlSguzH6IrDNVd99Sdo2dEYw82S2wEugmkc=; b=roIVSQ+33CRwqb+ycUxDV5UXCetLvhK+ZsgmLsmQN8MQ46fl9xaXeXXL5FKrcsbo2W eITaRMwphRIm2KHXanMCK1FFG7svy/7125sVM8wbDvRJZc6RRF0KTdyk0Hcy8LI9HUt7 xIlZAc/UcgT1Hm0iaCx4UhNz0Etx0fgFtWIQ33zMcTPX6sX/SZykM1oLpD6aCc65rZ9n rlxRDX2GmerVU0MTGbW+/RkKAIzSI6QXRiuHhtx5IbuoslhB1D19BVVZS0PitEFDe+un UZTwjlQ0RzEyO6RW/E+qXzUQvPpOh5E2DqCYjUVBzwemtTU46nv7yzi12JJjU509Q4Rm hyiQ== X-Gm-Message-State: AElRT7G1ux/newCkQZTKtGQde3T5txBtvVAJKhI3m+iSKfqmdqGrmy+Y wHfYCCItoXlOWZiHoqTY/KhvDQ== X-Received: by 10.28.177.86 with SMTP id a83mr15224241wmf.143.1522073200400; Mon, 26 Mar 2018 07:06:40 -0700 (PDT) Received: from localhost.localdomain (146-241-17-196.dyn.eolo.it. [146.241.17.196]) by smtp.gmail.com with ESMTPSA id c187sm3912642wmf.18.2018.03.26.07.06.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Mar 2018 07:06:39 -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, linus.walleij@linaro.org, bfq-iosched@googlegroups.com, oleksandr@natalenko.name, khlebnikov@yandex-team.ru, Paolo Valente Subject: [PATCH BUGFIX] block, bfq: lower-bound the estimated peak rate to 1 Date: Mon, 26 Mar 2018 16:06:24 +0200 Message-Id: <20180326140624.2295-1-paolo.valente@linaro.org> X-Mailer: git-send-email 2.16.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If a storage device handled by BFQ happens to be slower than 7.5 KB/s for a certain amount of time (in the order of a second), then the estimated peak rate of the device, maintained in BFQ, becomes equal to 0. The reason is the limited precision with which the rate is represented (details on the range of representable values in the comments introduced by this commit). This leads to a division-by-zero error where the estimated peak rate is used as divisor. Such a type of failure has been reported in [1]. This commit addresses this issue by: 1. Lower-bounding the estimated peak rate to 1 2. Adding and improving comments on the range of rates representable [1] https://www.spinics.net/lists/kernel/msg2739205.html Signed-off-by: Konstantin Khlebnikov Signed-off-by: Paolo Valente --- block/bfq-iosched.c | 25 ++++++++++++++++++++++++- block/bfq-iosched.h | 2 +- 2 files changed, 25 insertions(+), 2 deletions(-) -- 2.16.1 diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c index aeca22d91101..f0ecd98509d8 100644 --- a/block/bfq-iosched.c +++ b/block/bfq-iosched.c @@ -201,7 +201,20 @@ static struct kmem_cache *bfq_pool; /* Target observation time interval for a peak-rate update (ns) */ #define BFQ_RATE_REF_INTERVAL NSEC_PER_SEC -/* Shift used for peak rate fixed precision calculations. */ +/* + * Shift used for peak-rate fixed precision calculations. + * With + * - the current shift: 16 positions + * - the current type used to store rate: u32 + * - the current unit of measure for rate: [sectors/usec], or, more precisely, + * [(sectors/usec) / 2^BFQ_RATE_SHIFT] to take into account the shift, + * the range of rates that can be stored is + * [1 / 2^BFQ_RATE_SHIFT, 2^(32 - BFQ_RATE_SHIFT)] sectors/usec = + * [1 / 2^16, 2^16] sectors/usec = [15e-6, 65536] sectors/usec = + * [15, 65G] sectors/sec + * Which, assuming a sector size of 512B, corresponds to a range of + * [7.5K, 33T] B/sec + */ #define BFQ_RATE_SHIFT 16 /* @@ -2637,6 +2650,16 @@ static void bfq_update_rate_reset(struct bfq_data *bfqd, struct request *rq) rate /= divisor; /* smoothing constant alpha = 1/divisor */ bfqd->peak_rate += rate; + + /* + * For a very slow device, bfqd->peak_rate can reach 0 (see + * the minimum representable values reported in the comments + * on BFQ_RATE_SHIFT). Push to 1 if this happens, to avoid + * divisions by zero where bfqd->peak_rate is used as a + * divisor. + */ + bfqd->peak_rate = max_t(u32, 1, bfqd->peak_rate); + update_thr_responsiveness_params(bfqd); reset_computation: diff --git a/block/bfq-iosched.h b/block/bfq-iosched.h index 350c39ae2896..ae2f3dadec44 100644 --- a/block/bfq-iosched.h +++ b/block/bfq-iosched.h @@ -499,7 +499,7 @@ struct bfq_data { u64 delta_from_first; /* * Current estimate of the device peak rate, measured in - * [BFQ_RATE_SHIFT * sectors/usec]. The left-shift by + * [(sectors/usec) / 2^BFQ_RATE_SHIFT]. The left-shift by * BFQ_RATE_SHIFT is performed to increase precision in * fixed-point calculations. */