Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp1017838rdb; Sat, 7 Oct 2023 08:18:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF8bgmd+cwN+mwuYDuhp7MD5+nAMGOEhxRcmsa07juJh1Lk2P9gw0ct+S0WjD7ikyMHLcCf X-Received: by 2002:aa7:8890:0:b0:692:6d3f:4858 with SMTP id z16-20020aa78890000000b006926d3f4858mr11653887pfe.17.1696691895418; Sat, 07 Oct 2023 08:18:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696691895; cv=none; d=google.com; s=arc-20160816; b=uqhBIDUXTE9jqn0BMq+FaJAiNnpm8hbAgkR075gr4x/IPbRybx7K/jjj+dXzjx3C2v JhU5qsmLDY/GzOlPYcSTsxXmo3O1SOV0wZG9J8zDSFGMzf8Swup2pmHTXJsJ/GP+P7Cm nt9VIJXststCmVzNRx5NF8O9YmIZpF27Qn9RVhllRKxhhUA1rJeg8l23LXlqwCr+Muw5 I48S0heQY3lxMpOGNU0NHOmevWmF67PjGZZxJWIS7peEwAsRx2FF/q0q+8sUVwUi0b5k E7KdpAkT8UWUCyNyztkRKKvXLd51u1Awu07qq83PwaW6JKuksoA2jpqYl7rzVvDnME65 pLjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=PPtQSncuXiGIg7RBOh+ShvADCBAgeQPrkAF7VWeTPLA=; fh=04M1hjVXfXDpd9ZOIt5CSKP6T2LExGAZaHAJ7nnFAc0=; b=GMd5be++MEH5Z3elge15crH+3LSnDC6W99LnqL+W+jf8PWGbyMl4WIM1QWHuAwZQhp BcmN1PqsMCFEptEFNMUW5vR0oe/Seeu9yyOjdis7vc/SRW1/mUAMm5epesrcPYBZx8ol Pj8o1DFU3lhEyp+Z/7G5wYUGiuvaFaeWZidc2OSuh/oO5loOhonlGOlI9ocRLp+st3Pj 2CPcj+xUDAR3oBmayIsNRydpWJhNM1RfgmKl4G3rC0hHicKERmPZxKAa2hAm6QZX4wSA qxxrPv4URLoYf6zN6yBN1os3YFfMgl+Ux65s//WicjtE8U+fjBV5pU+l+pWI33/kVNb3 XfzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=GT6dStVz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id o2-20020a634102000000b00573ed0023e1si6011837pga.333.2023.10.07.08.18.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Oct 2023 08:18:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=GT6dStVz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 518C780981B3; Sat, 7 Oct 2023 08:18:14 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343960AbjJGPSL (ORCPT + 99 others); Sat, 7 Oct 2023 11:18:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343946AbjJGPSJ (ORCPT ); Sat, 7 Oct 2023 11:18:09 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28453B9 for ; Sat, 7 Oct 2023 08:17:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696691841; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=PPtQSncuXiGIg7RBOh+ShvADCBAgeQPrkAF7VWeTPLA=; b=GT6dStVzZdvzg2Om4Y1MSThfyvc9HpOqd4XH3TZvFucM16WiJoGU0FLZd/M4oGlibdG5PN jfmVFGOFGV7ojyxcfiN6hcsD+QwVrGD2zbRnNnWoBQ9eVhliVHsryiqimP31LfQNwILz9z QbSKXV+0druArXujbr0nry2hvAVoKgw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-677-fko8I_r8MS2GPNjMFFWdRg-1; Sat, 07 Oct 2023 11:17:10 -0400 X-MC-Unique: fko8I_r8MS2GPNjMFFWdRg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1FCE885A5A8; Sat, 7 Oct 2023 15:17:10 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.224.9]) by smtp.corp.redhat.com (Postfix) with SMTP id 1BA47215670B; Sat, 7 Oct 2023 15:17:06 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Sat, 7 Oct 2023 17:16:11 +0200 (CEST) Date: Sat, 7 Oct 2023 17:16:08 +0200 From: Oleg Nesterov To: Yu Kuai Cc: Li Nan , Khazhy Kumykov , tj@kernel.org, josef@toxicpanda.com, axboe@kernel.dk, cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, houtao1@huawei.com, yangerkun@huawei.com, "yukuai (C)" Subject: Re: [PATCH] blk-throttle: Calculate allowed value only when the throttle is enabled Message-ID: <20231007151607.GA24726@redhat.com> References: <20230928015858.1809934-1-linan666@huaweicloud.com> <4ace01e8-6815-29d0-70ce-4632818ca701@huaweicloud.com> <20231005162417.GA32420@redhat.com> <0a8f34aa-ced9-e613-3e5f-b5e53a3ef3d9@huaweicloud.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0a8f34aa-ced9-e613-3e5f-b5e53a3ef3d9@huaweicloud.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,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 (snail.vger.email [0.0.0.0]); Sat, 07 Oct 2023 08:18:14 -0700 (PDT) On 10/07, Yu Kuai wrote: > > >>>probably need to remove the mul_u64_u64_div_u64 and check for > >>>overflow/potential overflow ourselves? > > > >probably yes... > > How about this? > > diff --git a/block/blk-throttle.c b/block/blk-throttle.c > index 1101fb6f6cc8..5482c316a103 100644 > --- a/block/blk-throttle.c > +++ b/block/blk-throttle.c > @@ -723,6 +723,10 @@ static unsigned int calculate_io_allowed(u32 > iops_limit, > > static u64 calculate_bytes_allowed(u64 bps_limit, unsigned long > jiffy_elapsed) > { > + if (jiffy_elapsed > HZ && > + bps_limit > mul_u64_u64_div_u64(U64_MAX, (u64)HZ, > (u64)jiffy_elapsed); > + return U64_MAX; > + I can't suggest anything better... but I do not know if it is possible that HZ > jiffy_elapsed. If yes, then mul_u64_u64_div_u64() above is not safe too. Oleg.