From patchwork Wed Nov 23 06:03:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 24714 Return-Path: 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 + 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 ); 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 To: , , CC: , , , 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 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?1750265763899912392?= X-GMAIL-MSGID: =?utf-8?q?1750265763899912392?= 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 --- block/blk-throttle.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) 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]++;