Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2942567rdh; Wed, 27 Sep 2023 19:08:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHN0CtOLLndEaBWzahapa+iBnr+OXsfYv2JlLbezYh7zvh4y6Yd1IXp4SQrdQ6UMRXg5+ZC X-Received: by 2002:a05:6a00:1a4b:b0:690:fd48:1aa4 with SMTP id h11-20020a056a001a4b00b00690fd481aa4mr12822022pfv.0.1695866909698; Wed, 27 Sep 2023 19:08:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695866909; cv=none; d=google.com; s=arc-20160816; b=C9CznZxuuTSy5l/RHZ3IruxRtj6I9gL0lyfHaVi/y5zzDHG1tPMywefOQZZNSZT5Ur GvAVRrgz/ssmhTLcCxoFvEDT3uVMjOivPwT+Fr1yzvdg6Iyog+kicDcNTdvAaepHAYgo 6JHZYMw1sk7PcBJNSAKS5n0co9gE2ZNrGbTd+VBqpE1tjHsoOsErpNS4OvkqqTgRBgsx VLx10GcK3jmr3hc0VKVohR46qLnuqqLeUnohs9YBX+50VQpcNv6v+hGVR3eGjCyoB7+6 +cRH1wkaKaGdOoz3xr0HZfAIyZ/nxuuAy++pj85C7Ar7b7GjOjKdJjj/6z4yV0DaJIKH UFIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=1UwCxwq+95L4F86FAVMlL9QEz613GaV0rL64kjeZXhg=; fh=ov6gDd06M3bxNguWbiuHu2eEQ3vFonzN67fwIvB46H0=; b=P/o+7j0xQRI9o9TBolm6SphgAURPvGh6AIvSTL7t48WJrYbb3YVdJvmrAAPaQq8bZq 8fSKTVLFikEBGsO4ty8gJ2kOaYpXG7nIWfvD4oMf+QIq1UHTcfPO9zMHjYr8bl75c2tF o6XPuIPmva9Uc28JmTexbRws62lbuy8FeL6P0W24C2sO6cY1wygqJhgkArRy+/upMnQi Sm/nCjYpfrO9f9Ca6Xz1+LeU0GGdwxOOxxEqY4/syoc9MeTNvSDreq6h+DuDworZ4MA9 NcLTT2VB+8PTngVzZEcE1kVODijFNPyBdgLJWcMOpuqOS8dgDESWTM7w5tFglikxh7nw De6A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id r20-20020a6560d4000000b00565ead2509asi16616415pgv.199.2023.09.27.19.08.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 19:08:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 12B378374E7A; Wed, 27 Sep 2023 19:05:29 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229983AbjI1CFT (ORCPT + 99 others); Wed, 27 Sep 2023 22:05:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229437AbjI1CFS (ORCPT ); Wed, 27 Sep 2023 22:05:18 -0400 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 162C5AC; Wed, 27 Sep 2023 19:05:16 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4RwxdH31Wpz4f3kGD; Thu, 28 Sep 2023 10:05:07 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP4 (Coremail) with SMTP id gCh0CgB3BdVU3xRlbOxHBg--.51493S4; Thu, 28 Sep 2023 10:05:09 +0800 (CST) From: linan666@huaweicloud.com To: tj@kernel.org, josef@toxicpanda.com, axboe@kernel.dk, yukuai3@huawei.com Cc: cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linan122@huawei.com, yi.zhang@huawei.com, houtao1@huawei.com, yangerkun@huawei.com Subject: [PATCH] blk-throttle: Calculate allowed value only when the throttle is enabled Date: Thu, 28 Sep 2023 09:58:58 +0800 Message-Id: <20230928015858.1809934-1-linan666@huaweicloud.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: gCh0CgB3BdVU3xRlbOxHBg--.51493S4 X-Coremail-Antispam: 1UD129KBjvJXoW7Zw4DJr45Jw1DuFWUurW8Crg_yoW8uryDpF WfGr17Gr4aqF93KF43JasIvF15JrZ7Cr98J398X3sYyFWYk348Krn7ur40qFy2vF97Zayr J34jqr95AF42kaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9Fb4IE77IF4wAFF20E14v26r4j6ryUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x 0267AKxVW0oVCq3wAac4AC62xK8xCEY4vEwIxC4wAS0I0E0xvYzxvE52x082IY62kv0487 Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aV AFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4IIrI8v6xkF 7I0E8cxan2IY04v7M4kE6xkIj40Ew7xC0wCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7x kEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E 67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCw CI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6rW3Jr0E 3s1lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcS sGvfC2KfnxnUUI43ZEXa7IU1kpnJUUUUU== X-CM-SenderInfo: polqt0awwwqx5xdzvxpfor3voofrz/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Wed, 27 Sep 2023 19:05:29 -0700 (PDT) From: Li Nan When the throttle of bps is not enabled, tg_bps_limit() returns U64_MAX, which is be used in calculate_bytes_allowed(), and divide 0 error will happen. To fix it, only calculate allowed value when the throttle of bps/iops is enabled and the value will be used. Fixes: e8368b57c006 ("blk-throttle: use calculate_io/bytes_allowed() for throtl_trim_slice()") Reported-by: Changhui Zhong Closes: https://lore.kernel.org/all/CAGVVp+Vt6idZtxfU9jF=VSbu145Wi-d-WnAZx_hEfOL8yLZgBA@mail.gmail.com Signed-off-by: Li Nan --- block/blk-throttle.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/block/blk-throttle.c b/block/blk-throttle.c index 38a881cf97d0..3c9a74ab9f0e 100644 --- a/block/blk-throttle.c +++ b/block/blk-throttle.c @@ -730,8 +730,10 @@ static u64 calculate_bytes_allowed(u64 bps_limit, unsigned long jiffy_elapsed) static inline void throtl_trim_slice(struct throtl_grp *tg, bool rw) { unsigned long time_elapsed; - long long bytes_trim; - int io_trim; + long long bytes_trim = 0; + int io_trim = 0; + u64 bps_limit; + u32 iops_limit; BUG_ON(time_before(tg->slice_end[rw], tg->slice_start[rw])); @@ -758,11 +760,14 @@ static inline void throtl_trim_slice(struct throtl_grp *tg, bool rw) if (!time_elapsed) return; - bytes_trim = calculate_bytes_allowed(tg_bps_limit(tg, rw), - time_elapsed) + - tg->carryover_bytes[rw]; - io_trim = calculate_io_allowed(tg_iops_limit(tg, rw), time_elapsed) + - tg->carryover_ios[rw]; + bps_limit = tg_bps_limit(tg, rw); + iops_limit = tg_iops_limit(tg, rw); + if (tg->bytes_disp[rw] > 0 && bps_limit != U64_MAX) + bytes_trim = calculate_bytes_allowed(bps_limit, + time_elapsed) + tg->carryover_bytes[rw]; + if (tg->io_disp[rw] > 0 && iops_limit != UINT_MAX) + io_trim = calculate_io_allowed(iops_limit, time_elapsed) + + tg->carryover_ios[rw]; if (bytes_trim <= 0 && io_trim <= 0) return; -- 2.39.2