From patchwork Mon Mar 5 12:48:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Khlebnikov X-Patchwork-Id: 10258895 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 90DCB60134 for ; Mon, 5 Mar 2018 12:55:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7F8B5284DA for ; Mon, 5 Mar 2018 12:55:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7112F28A17; Mon, 5 Mar 2018 12:55:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 14ED6284DA for ; Mon, 5 Mar 2018 12:55:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934140AbeCEMzv (ORCPT ); Mon, 5 Mar 2018 07:55:51 -0500 Received: from forwardcorp1o.cmail.yandex.net ([37.9.109.47]:42282 "EHLO forwardcorp1o.cmail.yandex.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934109AbeCEMzv (ORCPT ); Mon, 5 Mar 2018 07:55:51 -0500 X-Greylist: delayed 412 seconds by postgrey-1.27 at vger.kernel.org; Mon, 05 Mar 2018 07:55:50 EST Received: from smtpcorp1o.mail.yandex.net (smtpcorp1o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::30]) by forwardcorp1o.cmail.yandex.net (Yandex) with ESMTP id 4F28F2168A; Mon, 5 Mar 2018 15:48:56 +0300 (MSK) Received: from smtpcorp1o.mail.yandex.net (localhost.localdomain [127.0.0.1]) by smtpcorp1o.mail.yandex.net (Yandex) with ESMTP id 4C98F2440DDD; Mon, 5 Mar 2018 15:48:56 +0300 (MSK) Received: from unknown (unknown [2a02:6b8:0:460:894d:7349:a50a:da26]) by smtpcorp1o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id q5nCzD5f7v-mufe6K8t; Mon, 05 Mar 2018 15:48:56 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client certificate not present) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1520254136; bh=yJCJOu/QfWgzbn/l35ksva3zKYv7uxVH0PNzkvgdLK4=; h=Subject:From:To:Date:Message-ID; b=v2J53ef0tOb/B3TL7HsOBz2SPqnmWAFZHXbCC4/4L3guPdarf40ySHtc4DafrBk2N PV8mH/0Qzt/HD5Qx4YK16l9vL4k4fg423EkyvbLXVCgoyhL2ABxldDVt7XEYu3hOe7 w+QAJBZ5PVN4lfu4QZ9675h4+AceQHI5roKVz8qQ= Authentication-Results: smtpcorp1o.mail.yandex.net; dkim=pass header.i=@yandex-team.ru Subject: [PATCH] block, bfq: keep peak_rate estimation within range 1..2^32-1 From: Konstantin Khlebnikov To: linux-block@vger.kernel.org, Jens Axboe , Paolo Valente , linux-kernel@vger.kernel.org Date: Mon, 05 Mar 2018 15:48:53 +0300 Message-ID: <152025413365.161046.7757556276366364549.stgit@buzz> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Rate should never overflow or become zero because it is used as divider. This patch accumulates it with saturation. Signed-off-by: Konstantin Khlebnikov --- block/bfq-iosched.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c index aeca22d91101..a236c8d541b5 100644 --- a/block/bfq-iosched.c +++ b/block/bfq-iosched.c @@ -2546,7 +2546,8 @@ static void bfq_reset_rate_computation(struct bfq_data *bfqd, static void bfq_update_rate_reset(struct bfq_data *bfqd, struct request *rq) { - u32 rate, weight, divisor; + u32 weight, divisor; + u64 rate; /* * For the convergence property to hold (see comments on @@ -2634,9 +2635,10 @@ static void bfq_update_rate_reset(struct bfq_data *bfqd, struct request *rq) */ bfqd->peak_rate *= divisor-1; bfqd->peak_rate /= divisor; - rate /= divisor; /* smoothing constant alpha = 1/divisor */ + do_div(rate, divisor); /* smoothing constant alpha = 1/divisor */ - bfqd->peak_rate += rate; + /* rate should never overlow or become zero */ + bfqd->peak_rate = clamp_t(u64, rate + bfqd->peak_rate, 1, U32_MAX); update_thr_responsiveness_params(bfqd); reset_computation: