Message ID | 20221123060401.20392-3-shikemeng@huawei.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2614524wrr; Tue, 22 Nov 2022 22:05:05 -0800 (PST) X-Google-Smtp-Source: AA0mqf6EcloImk5KNdfDRy96PDd+EXnjH92Po33HkKsIinOm3ZNaUu62zG3vKblbrvut9cVtyQh1 X-Received: by 2002:a63:1111:0:b0:46f:f93b:ddc8 with SMTP id g17-20020a631111000000b0046ff93bddc8mr9598815pgl.389.1669183505486; Tue, 22 Nov 2022 22:05:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669183505; cv=none; d=google.com; s=arc-20160816; b=KZLrPbnRjwJTGA9c8aipoUF22gBkA24S0+A3lLeG3hjgfoyITJxddottaJdC2dav0Z ne0tcP/VCly+JyPY03c5O8ngKB6oIkQjey6nNlN6V90y53aYORf/BmAUOz4JMRPptODA CVSjKqUcARWropfBDPwfS/G5PFFI1IV7QZm/ynSyMk0qe/wskLml13xm280Bc+PBFvSq IvK7kiHaLTU2MalyBCHs5CrsYNfW009OmPdq554uSY4UquQLnbfZHAd9Wl9d1zMT1T+Z 78BIfjBCBce0YHb3DBhm/Xt+U1msW878xvvRsz21l0CcrlLoBTjBnyuSq++w1gv8gX8w XQ+g== 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=PLG/6xOlzKuVWjSjCLfh02rt5akE/IGgFH/WCEl3xI4=; b=bTf/3fPW0urZG1Q7FnQWm22WfhP2eW+cPYK/Wirv5dmJMCoblUd4I6ADQ7/f087l6h 23egfpLqe2mzMB1hfnw/bK5nKxbmyFU7wbsLIDuWeBK+bqOho9Fo3SCHK/TU8rCm77d1 /BdhtkiqrzUzaGop4P6DFCxVj8snpW7koIEMDM0MCnYvU40aB9EdBOFfMBmrKdU4+wf7 OROAufu3S8TxG5ZbaD+HE5YOFLbWJsJ7iRsHJ/6TtCcJNZd6yDZzf1Yp1NQcLyL5zGWU ioUxXtZ4ENTuRseMvROrhOH+1/N0Mm93/8wGo/POl2/CFP1Gy9trnskh4l5Q/DmT38We 061Q== 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 n15-20020a6546cf000000b00476f238d259si16690603pgr.420.2022.11.22.22.04.52; Tue, 22 Nov 2022 22:05:05 -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 S235875AbiKWGEX (ORCPT <rfc822;cjcooper78@gmail.com> + 99 others); Wed, 23 Nov 2022 01:04:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235548AbiKWGEK (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 23 Nov 2022 01:04:10 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2994CF2C07; Tue, 22 Nov 2022 22:04:07 -0800 (PST) Received: from kwepemi500016.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4NH9Y31DHdz15MqG; Wed, 23 Nov 2022 14:03:35 +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:05 +0800 From: Kemeng Shi <shikemeng@huawei.com> To: <tj@kernel.org>, <josef@toxicpanda.com>, <axboe@kernel.dk> CC: <cgroups@vger.kernel.org>, <linux-block@vger.kernel.org>, <linux-kernel@vger.kernel.org>, <shikemeng@huawei.com> Subject: [PATCH 02/11] blk-throttle: Fix that bps of child could exceed bps limited in parent Date: Wed, 23 Nov 2022 14:03:52 +0800 Message-ID: <20221123060401.20392-3-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 Content-Type: text/plain 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750265763899912392?= X-GMAIL-MSGID: =?utf-8?q?1750265763899912392?= |
Series |
A few bugfix and cleanup patches for blk-throttle
|
|
Commit Message
Kemeng Shi
Nov. 23, 2022, 6:03 a.m. UTC
Consider situation as following (on the default hierarchy):
HDD
|
root (bps limit: 4k)
|
child (bps limit :8k)
|
fio bs=8k
Rate of fio is supposed to be 4k, but result is 8k. Reason is as
following:
Size of single IO from fio is larger than bytes allowed in one
throtl_slice in child, so IOs are always queued in child group first.
When queued IOs in child are dispatched to parent group, BIO_BPS_THROTTLED
is set and these IOs will not be limited by tg_within_bps_limit anymore.
Fix this by:
1. Limit IO with BIO_BPS_THROTTLED flag in tg_within_bps_limit.
2. Ignore BIO_BPS_THROTTLED flag when accouting in throtl_charge_bio.
There changes have no influence on situation which is not on the default
hierarchy as each group is a single root group without parent.
Signed-off-by: Kemeng Shi <shikemeng@huawei.com>
---
block/blk-throttle.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
Comments
On Wed, Nov 23, 2022 at 02:03:52PM +0800, Kemeng Shi wrote: > @@ -964,10 +963,8 @@ static void throtl_charge_bio(struct throtl_grp *tg, struct bio *bio) > unsigned int bio_size = throtl_bio_data_size(bio); > > /* Charge the bio to the group */ > - if (!bio_flagged(bio, BIO_BPS_THROTTLED)) { > - tg->bytes_disp[rw] += bio_size; > - tg->last_bytes_disp[rw] += bio_size; > - } > + tg->bytes_disp[rw] += bio_size; > + tg->last_bytes_disp[rw] += bio_size; Are you sure this isn't gonna lead to double accounting? IIRC, the primary purpose of this flag is avoiding duplicate accounting of bios which end up going through the throttling path multiple times for whatever reason and we've had numerous breakages around it. To address the problem you're describing in this patch, wouldn't it make more sense to set the flag only when the bio traversed the entire tree rather than after each tg? Thanks.
on 11/24/2022 2:09 AM, Tejun Heo wrote: > On Wed, Nov 23, 2022 at 02:03:52PM +0800, Kemeng Shi wrote: >> @@ -964,10 +963,8 @@ static void throtl_charge_bio(struct throtl_grp *tg, struct bio *bio) >> unsigned int bio_size = throtl_bio_data_size(bio); >> >> /* Charge the bio to the group */ >> - if (!bio_flagged(bio, BIO_BPS_THROTTLED)) { >> - tg->bytes_disp[rw] += bio_size; >> - tg->last_bytes_disp[rw] += bio_size; >> - } >> + tg->bytes_disp[rw] += bio_size; >> + tg->last_bytes_disp[rw] += bio_size; > > Are you sure this isn't gonna lead to double accounting? IIRC, the primary > purpose of this flag is avoiding duplicate accounting of bios which end up > going through the throttling path multiple times for whatever reason and > we've had numerous breakages around it. Sorry for the mistake, this change does lead to double accounting. > To address the problem you're describing in this patch, wouldn't it make > more sense to set the flag only when the bio traversed the entire tree > rather than after each tg? I will address the problem in this way in next version. Thanks for the advice.
diff --git a/block/blk-throttle.c b/block/blk-throttle.c index 96aa53e30e28..b33bcf53b36e 100644 --- a/block/blk-throttle.c +++ b/block/blk-throttle.c @@ -856,8 +856,7 @@ static bool tg_within_bps_limit(struct throtl_grp *tg, struct bio *bio, unsigned long jiffy_elapsed, jiffy_wait, jiffy_elapsed_rnd; unsigned int bio_size = throtl_bio_data_size(bio); - /* no need to throttle if this bio's bytes have been accounted */ - if (bps_limit == U64_MAX || bio_flagged(bio, BIO_BPS_THROTTLED)) { + if (bps_limit == U64_MAX) { if (wait) *wait = 0; return true; @@ -964,10 +963,8 @@ static void throtl_charge_bio(struct throtl_grp *tg, struct bio *bio) unsigned int bio_size = throtl_bio_data_size(bio); /* Charge the bio to the group */ - if (!bio_flagged(bio, BIO_BPS_THROTTLED)) { - tg->bytes_disp[rw] += bio_size; - tg->last_bytes_disp[rw] += bio_size; - } + tg->bytes_disp[rw] += bio_size; + tg->last_bytes_disp[rw] += bio_size; tg->io_disp[rw]++; tg->last_io_disp[rw]++;