Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp1209472rdb; Sat, 7 Oct 2023 18:26:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH+8c0vcV9cBYMlZ0t3SagqJBnKfd8W9k0CgocQ5jrWJT9mR8ysfOLJ0ue3gW69piVO0qNR X-Received: by 2002:a17:902:dacd:b0:1bb:2020:be0d with SMTP id q13-20020a170902dacd00b001bb2020be0dmr15462748plx.14.1696728408758; Sat, 07 Oct 2023 18:26:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696728408; cv=none; d=google.com; s=arc-20160816; b=ExnZngvc/tPH9jy4y3vIs4Oh/RtCxukuYTqOIjB4U1T1lMgfuosu0KQSw42RhU7Mfq gUdNJno3CH8dh9+3IqmsYTrxvbtp4cPXZVaBI8AFjQ4G21ZFhbsJUI35Z9q2H5NCfsGW lHkUeuuSHTVPlIzTu9+YCcax5CSxvR9v2u1fXdnJmHVH653/vDCeJvBihWGc7Mtphtse fIOo5DlKPM5pU+CSaz7pKbL02Y7EwT3NrY4aNqPzZAZ2IpHptricIvsplXsE5U7D2lVe L5GUkQI8Ayqpn0pGIVWoWgKXwk6DrFvhZeiYdyjBw/kEF4X516O5k3BLvBens5NdKT/l +1rA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=S55fpk5WnlhlA1067YgpoNz69sA1DWzcNE3OsorMcH4=; fh=R90/+rMy8AyI/g0FAfwShcmhAT1OIgNunBAfnYG+Nj0=; b=DH4IPRWLuTqVDZyCtbH/HPTO9GmV9NlZPktou2P2/DXFgIG+Ob0pMKsbRWRnFsRgEd NMbTniH90BKG6S3CTvhqrIan81Grz/F5++rO28DgP3bWq7sKS4RAu/M9ql7jPX76t3gK KYzu6qr0OfTavlALo1UVepp7EYHHYlDGrZa8G4s7RXiWlqpnpx2/6yL5tGtImlQWRNVM KvDzKRIKzNZICqGL05Egc7mFCX2zVyMIxIFtvw5uKnUtofeFfNeHz0OwUzZr6n9umvUM pQDg/T+YL25R2hLb7+TFAg4f1YXWovtd19r0SQe6vz71Ui3dXZs9gj+Ixm4gkezAuiBJ 7AFA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id ku7-20020a170903288700b001c589ba4a1bsi6584826plb.83.2023.10.07.18.26.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Oct 2023 18:26:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id 173B980A415C; Sat, 7 Oct 2023 18:26:46 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344249AbjJHB0d (ORCPT + 99 others); Sat, 7 Oct 2023 21:26:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229717AbjJHB0c (ORCPT ); Sat, 7 Oct 2023 21:26:32 -0400 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2267F92; Sat, 7 Oct 2023 18:26:31 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4S34J16QzKz4f3jJL; Sun, 8 Oct 2023 09:26:25 +0800 (CST) Received: from [10.174.176.73] (unknown [10.174.176.73]) by APP4 (Coremail) with SMTP id gCh0CgCHHt5BBSJl_IqfCQ--.51241S3; Sun, 08 Oct 2023 09:26:27 +0800 (CST) Subject: Re: [PATCH] blk-throttle: Calculate allowed value only when the throttle is enabled To: Oleg Nesterov , 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)" 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> <20231007151607.GA24726@redhat.com> From: Yu Kuai Message-ID: <21843836-7265-f903-a7d5-e77b07dd5a71@huaweicloud.com> Date: Sun, 8 Oct 2023 09:26:25 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20231007151607.GA24726@redhat.com> Content-Type: text/plain; charset=gbk; format=flowed Content-Transfer-Encoding: 8bit X-CM-TRANSID: gCh0CgCHHt5BBSJl_IqfCQ--.51241S3 X-Coremail-Antispam: 1UD129KBjvdXoWruryUWFWrXr1rJF18JFWxXrb_yoWkJrg_XF 4DAas7Crn0qF48ZFWDKFnxCrsxuw1UXrWvga48Wr17Zwnaqa1kAa47G3y8Gr45XFWfCrsx Cr1DAF15XFsI9jkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUb3AFF20E14v26r4j6ryUM7CY07I20VC2zVCF04k26cxKx2IYs7xG 6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8w A2z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j 6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oV Cq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0 I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r 4UM4x0Y48IcVAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2kI c2xKxwCYjI0SjxkI62AI1cAE67vIY487MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4 AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE 17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMI IF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_WFyUJVCq 3wCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCT nIWIevJa73UjIFyTuYvjfUoOJ5UUUUU X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=2.2 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email 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 (groat.vger.email [0.0.0.0]); Sat, 07 Oct 2023 18:26:46 -0700 (PDT) X-Spam-Level: ** Hi, ?? 2023/10/07 23:16, Oleg Nesterov ะด??: > 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. Well, 'jiffy_elapsed > HZ' is judged before mul_u64_u64_div_u64(). Overflow can only happen if the above 2 conditions passed, and U64_MAX is returned. Thanks, Kuai > > Oleg. > > . >