Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3045877pxk; Mon, 7 Sep 2020 01:16:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy84gGkh0SzuvlH4oWuYteu/m1m0eqpnchdXSYE9LysxbavY8uZh7MrWH+OHKNIkOev6e3y X-Received: by 2002:aa7:d7ca:: with SMTP id e10mr19840164eds.191.1599466560215; Mon, 07 Sep 2020 01:16:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599466560; cv=none; d=google.com; s=arc-20160816; b=WtQwdKNoZknQ78bsgC4Hk1HFyhwqgFou6rq5qk1/BVBkdvBfwH569LSSC55LFz9mrR xGWIx+ZZo1ayzBEOPUi/GP9ZjJPIj2abe4RyXlCsL+UQ1hTRrrE7VVNEyMNbMVZlKqR4 BPeVIjFrJsvZB/HQxaM70O4kEeDbFSjIU7dOE4enSExaXYTltK4xstH/dRvZj2aRJ/1B QMuEQ7cfNxm43QVRjgMNCdqh6vx0HOtuAxSFvTIZ0xMRjg03kAsT9eFiYnk4KX8GPMVl mHMH4LHu7jEiPfd88C5CBcvdG/Vejm+FF8J6qf2Bmeqjk8kaV+QpCT4yqjGVuPdwa3ga QA+w== 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:references :in-reply-to:message-id:date:subject:cc:to:from; bh=pbNPHu0MALyQgUJ/hEYd6VR03VXpepyT9ZYjMdQqIKA=; b=cSdOpDQcEZi3gXW/h5CaZ8onTwknkYK/fDRn9KN4e0nyFMYjNtGnW+1g4pI5Ss6rHe sNCxmS3wpYegXrqbYTXUacwWJYDanKl07gAJZsRzqfoReuBqk97Tjukz5AakBEtBdtJ0 Tyz8/TYkvLolGMUwIl1piV3y6UUo+dBBUmqf200iXcsQmn+iy5c87JSXafh9iRR+W8en 6U/vvyJg8tYKwbIpMphwLBQ8mV7+aQNv+XVNOBAhaVXActTJMJ/NPIR3Nqo3j3raY94B EzJY5SoxtRvcjoIKm2RM3yJO/IZ+lnMu45xuv0tpqV1VG+rf8Xkp+OVHRS9jbxvDFUXG OMmQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y62si6367638edy.279.2020.09.07.01.15.37; Mon, 07 Sep 2020 01:16:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728110AbgIGIMR (ORCPT + 99 others); Mon, 7 Sep 2020 04:12:17 -0400 Received: from out30-57.freemail.mail.aliyun.com ([115.124.30.57]:60363 "EHLO out30-57.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727970AbgIGIKi (ORCPT ); Mon, 7 Sep 2020 04:10:38 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R681e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04394;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0U88Pk5E_1599466230; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0U88Pk5E_1599466230) by smtp.aliyun-inc.com(127.0.0.1); Mon, 07 Sep 2020 16:10:30 +0800 From: Baolin Wang To: tj@kernel.org, axboe@kernel.dk Cc: baolin.wang@linux.alibaba.com, baolin.wang7@gmail.com, linux-block@vger.kernel.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/5] blk-throttle: Avoid calculating bps/iops limitation repeatedly Date: Mon, 7 Sep 2020 16:10:16 +0800 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The tg_may_dispatch() will call tg_with_in_bps_limit() and tg_with_in_iops_limit() to check if we can dispatch a bio or not, which will calculate bps/iops limitation multiple times. But tg_may_dispatch() is always called under queue lock, which means the bps/iops limitation will not change in tg_may_dispatch(). So we can calculate the bps/iops limitation only once, and pass them to tg_with_in_bps_limit() and tg_with_in_iops_limit() to avoid calculating bps/iops limitation repeatedly. Signed-off-by: Baolin Wang --- block/blk-throttle.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/block/blk-throttle.c b/block/blk-throttle.c index ca9002d..8719e37 100644 --- a/block/blk-throttle.c +++ b/block/blk-throttle.c @@ -894,7 +894,7 @@ static inline void throtl_trim_slice(struct throtl_grp *tg, bool rw) } static bool tg_with_in_iops_limit(struct throtl_grp *tg, struct bio *bio, - unsigned long *wait) + u32 iops_limit, unsigned long *wait) { bool rw = bio_data_dir(bio); unsigned int io_allowed; @@ -913,7 +913,7 @@ static bool tg_with_in_iops_limit(struct throtl_grp *tg, struct bio *bio, * have been trimmed. */ - tmp = (u64)tg_iops_limit(tg, rw) * jiffy_elapsed_rnd; + tmp = (u64)iops_limit * jiffy_elapsed_rnd; do_div(tmp, HZ); if (tmp > UINT_MAX) @@ -936,7 +936,7 @@ static bool tg_with_in_iops_limit(struct throtl_grp *tg, struct bio *bio, } static bool tg_with_in_bps_limit(struct throtl_grp *tg, struct bio *bio, - unsigned long *wait) + u64 bps_limit, unsigned long *wait) { bool rw = bio_data_dir(bio); u64 bytes_allowed, extra_bytes, tmp; @@ -951,7 +951,7 @@ static bool tg_with_in_bps_limit(struct throtl_grp *tg, struct bio *bio, jiffy_elapsed_rnd = roundup(jiffy_elapsed_rnd, tg->td->throtl_slice); - tmp = tg_bps_limit(tg, rw) * jiffy_elapsed_rnd; + tmp = bps_limit * jiffy_elapsed_rnd; do_div(tmp, HZ); bytes_allowed = tmp; @@ -963,7 +963,7 @@ static bool tg_with_in_bps_limit(struct throtl_grp *tg, struct bio *bio, /* Calc approx time to dispatch */ extra_bytes = tg->bytes_disp[rw] + bio_size - bytes_allowed; - jiffy_wait = div64_u64(extra_bytes * HZ, tg_bps_limit(tg, rw)); + jiffy_wait = div64_u64(extra_bytes * HZ, bps_limit); if (!jiffy_wait) jiffy_wait = 1; @@ -987,6 +987,8 @@ static bool tg_may_dispatch(struct throtl_grp *tg, struct bio *bio, { bool rw = bio_data_dir(bio); unsigned long bps_wait = 0, iops_wait = 0, max_wait = 0; + u64 bps_limit = tg_bps_limit(tg, rw); + u32 iops_limit = tg_iops_limit(tg, rw); /* * Currently whole state machine of group depends on first bio @@ -998,8 +1000,7 @@ static bool tg_may_dispatch(struct throtl_grp *tg, struct bio *bio, bio != throtl_peek_queued(&tg->service_queue.queued[rw])); /* If tg->bps = -1, then BW is unlimited */ - if (tg_bps_limit(tg, rw) == U64_MAX && - tg_iops_limit(tg, rw) == UINT_MAX) { + if (bps_limit == U64_MAX && iops_limit == UINT_MAX) { if (wait) *wait = 0; return true; @@ -1021,8 +1022,8 @@ static bool tg_may_dispatch(struct throtl_grp *tg, struct bio *bio, jiffies + tg->td->throtl_slice); } - if (tg_with_in_bps_limit(tg, bio, &bps_wait) && - tg_with_in_iops_limit(tg, bio, &iops_wait)) { + if (tg_with_in_bps_limit(tg, bio, bps_limit, &bps_wait) && + tg_with_in_iops_limit(tg, bio, iops_limit, &iops_wait)) { if (wait) *wait = 0; return true; -- 1.8.3.1