From patchwork Wed Nov 23 06:03:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 24718 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2615097wrr; Tue, 22 Nov 2022 22:06:34 -0800 (PST) X-Google-Smtp-Source: AA0mqf7Q4QAxQQk4lrRzzLgTpHM3JhlddXg9GWt704UyuzrLuJ0wAUmwJ6HITN5KmlqUQ9ISlZAM X-Received: by 2002:a05:6402:5406:b0:467:4b3d:f2ed with SMTP id ev6-20020a056402540600b004674b3df2edmr6995874edb.101.1669183593926; Tue, 22 Nov 2022 22:06:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669183593; cv=none; d=google.com; s=arc-20160816; b=xxSspFkzy6UrA+BQwzgYJjtKkzxu6eBC7IiEK0P1dR+9uv0hjleb4+ay7v6rVFqke7 z/vLVvCve3ASs8NBW+j8Wnb7pbJ5/8Cc/fm1/xLgOvb1+ry+CJ2/aAyUgB+Yu67dCkbL k4VjKXdx8YxtV8sgEa/53FwCLA3qNId4Sh25R6T/YcRbb1q1jbOviw2ZBWgyV1usczbB M443qYUudhqtjpewWRUhZb5IeEcDi1gQjKG/CXyW2Pq7hu5kdGYttHYHIAz+8ja+tNBr vLNNY1XM34mDCUBC7R8i1ORaS+KYeddz1VQyUUgiTCQ2D6XS2WDfUrVsP3Exwmi4HY3b S78A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=LuNYhmntRZTZxnkACGsnMMx/rrTSAYrF0nWhXqx/94o=; b=vtFFf7qsjjhcqUAkiMwRYysZQU92oTQ/vGB7CUzu9NeZiRIP/TiWgSMSTP7D/aMinW jx5vGjSSEmquqULF0JIyMDhZ/wq/jQFRBvsiZPiGEI4w3eMn2dQB7oXDpApK1aCemvRz en2cGIA2Nb5gXO3Y6qs2gfbeGNfPhpX4heLZl/bMsXY5H9TWpp+nTrumQmjZY+dJmB13 wHOmbK1SJ3f5/2qIdiCHXr1aqNfs7o2H9lIN1me4bUdllfb/Gtdf1GFGeGGxzQPVYBm5 5pJgpyYU+xCLk20LJHBUyT7i/3s8s7aPZi1rTu9CspyOwqCCbWaSEA4l2UentH+ObNs0 CPnQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f21-20020a0564021e9500b0045c3f6adb7csi15330329edf.215.2022.11.22.22.06.09; Tue, 22 Nov 2022 22:06:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235909AbiKWGEj (ORCPT + 99 others); Wed, 23 Nov 2022 01:04:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235620AbiKWGEK (ORCPT ); Wed, 23 Nov 2022 01:04:10 -0500 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F3BB729A9; Tue, 22 Nov 2022 22:04:08 -0800 (PST) Received: from kwepemi500016.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4NH9Tv0SYGzJnrQ; Wed, 23 Nov 2022 14:00:51 +0800 (CST) Received: from huawei.com (10.174.178.129) by kwepemi500016.china.huawei.com (7.221.188.220) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 23 Nov 2022 14:04:06 +0800 From: Kemeng Shi To: , , CC: , , , Subject: [PATCH 04/11] blk-throttle: correct calculation of wait time in tg_may_dispatch Date: Wed, 23 Nov 2022 14:03:54 +0800 Message-ID: <20221123060401.20392-5-shikemeng@huawei.com> X-Mailer: git-send-email 2.14.1.windows.1 In-Reply-To: <20221123060401.20392-1-shikemeng@huawei.com> References: <20221123060401.20392-1-shikemeng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.178.129] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemi500016.china.huawei.com (7.221.188.220) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750265856102537435?= X-GMAIL-MSGID: =?utf-8?q?1750265856102537435?= If bps and iops both reach limit, we always return bps wait time as tg_within_iops_limit is after "tg_within_bps_limit(tg, bio, bps_limit) &&" and will not be called if tg_within_bps_limit return true. Fix this by always calling tg_within_bps_limit and tg_within_iops_limit to get wait time for both bps and iops. Observed that: 1. Wait time in tg_within_iops_limit/tg_within_bps_limit need always be stored as wait argument is always passed. 2. Stored wait time is zero if iops/bps is limited otherwise non-zero is stored. Simpfy tg_within_iops_limit/tg_within_bps_limit by removing wait argument and return wait time directly. Caller tg_may_dispatch checks if wait time is zero to find if iops/bps is limited. Signed-off-by: Kemeng Shi --- block/blk-throttle.c | 38 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/block/blk-throttle.c b/block/blk-throttle.c index acfac916ed99..01e30380c19b 100644 --- a/block/blk-throttle.c +++ b/block/blk-throttle.c @@ -815,17 +815,15 @@ static void tg_update_carryover(struct throtl_grp *tg) tg->carryover_ios[READ], tg->carryover_ios[WRITE]); } -static bool tg_within_iops_limit(struct throtl_grp *tg, struct bio *bio, - u32 iops_limit, unsigned long *wait) +static unsigned long tg_within_iops_limit(struct throtl_grp *tg, struct bio *bio, + u32 iops_limit) { bool rw = bio_data_dir(bio); unsigned int io_allowed; unsigned long jiffy_elapsed, jiffy_wait, jiffy_elapsed_rnd; if (iops_limit == UINT_MAX) { - if (wait) - *wait = 0; - return true; + return 0; } jiffy_elapsed = jiffies - tg->slice_start[rw]; @@ -835,21 +833,16 @@ static bool tg_within_iops_limit(struct throtl_grp *tg, struct bio *bio, io_allowed = calculate_io_allowed(iops_limit, jiffy_elapsed_rnd) + tg->carryover_ios[rw]; if (tg->io_disp[rw] + 1 <= io_allowed) { - if (wait) - *wait = 0; - return true; + return 0; } /* Calc approx time to dispatch */ jiffy_wait = jiffy_elapsed_rnd - jiffy_elapsed; - - if (wait) - *wait = jiffy_wait; - return false; + return jiffy_wait; } -static bool tg_within_bps_limit(struct throtl_grp *tg, struct bio *bio, - u64 bps_limit, unsigned long *wait) +static unsigned long tg_within_bps_limit(struct throtl_grp *tg, struct bio *bio, + u64 bps_limit) { bool rw = bio_data_dir(bio); u64 bytes_allowed, extra_bytes; @@ -857,9 +850,7 @@ static bool tg_within_bps_limit(struct throtl_grp *tg, struct bio *bio, unsigned int bio_size = throtl_bio_data_size(bio); if (bps_limit == U64_MAX) { - if (wait) - *wait = 0; - return true; + return 0; } jiffy_elapsed = jiffy_elapsed_rnd = jiffies - tg->slice_start[rw]; @@ -872,9 +863,7 @@ static bool tg_within_bps_limit(struct throtl_grp *tg, struct bio *bio, bytes_allowed = calculate_bytes_allowed(bps_limit, jiffy_elapsed_rnd) + tg->carryover_bytes[rw]; if (tg->bytes_disp[rw] + bio_size <= bytes_allowed) { - if (wait) - *wait = 0; - return true; + return 0; } /* Calc approx time to dispatch */ @@ -889,9 +878,7 @@ static bool tg_within_bps_limit(struct throtl_grp *tg, struct bio *bio, * up we did. Add that time also. */ jiffy_wait = jiffy_wait + (jiffy_elapsed_rnd - jiffy_elapsed); - if (wait) - *wait = jiffy_wait; - return false; + return jiffy_wait; } /* @@ -939,8 +926,9 @@ static bool tg_may_dispatch(struct throtl_grp *tg, struct bio *bio, jiffies + tg->td->throtl_slice); } - if (tg_within_bps_limit(tg, bio, bps_limit, &bps_wait) && - tg_within_iops_limit(tg, bio, iops_limit, &iops_wait)) { + bps_wait = tg_within_bps_limit(tg, bio, bps_limit); + iops_wait = tg_within_iops_limit(tg, bio, iops_limit); + if (bps_wait + iops_wait == 0) { if (wait) *wait = 0; return true;