Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3054306pxb; Fri, 12 Feb 2021 08:07:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJx9nYacarI71JRv1iAJeDFyjAmOr0oCfwRFJYdhR7FznAxVqK1KwAUhQ1Qypstn//mTdFiQ X-Received: by 2002:a17:906:3ad0:: with SMTP id z16mr3746680ejd.72.1613146035025; Fri, 12 Feb 2021 08:07:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613146035; cv=none; d=google.com; s=arc-20160816; b=rZ1183SWsdRrDJ95GK598ii3hfhx9lyTH5TA4G6kWYvjRFdrZDeow1LZg3uQ6J2w8x zVJ4Ra4sivNWge9IOIUlf55BJnMT2Q/hYigzZUCE3iX0ss/kJ5+FWLEZltcALXCNd1ff ubJPkzooqiP6+zjU85kA6aMLuLN7UqlLLoAYsSKz6AUQ+Hnx66RFXrE2HwTOVMwu7Roh dM4AT+zAdMB1PQnisR9JeINMKqsl8MFvuAkLK1XHXF3/45qAtPjklXvlSPNF+3yNtbxR jMafMWg1aWuzB1YZHaqp2aQYf1sFqaZnP8QTQUZcT/TZ4Xc6YrtHGmrgWqAXomQyypvb Un9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:subject:from :references:cc:to; bh=/xS9bihXGbEEu6sq9I+lAM6YBxplAae5gC9C58xHfEI=; b=oN7BFQcmXg9GvEMm6hvblew19jkyOrAQYoeBb1yUuw26N1/Pxuqw2mmmjDjqncBsmy yisyLdV7i0bTsdwERW+9jZZO8vfWcPsRJeiZtg68DOvBBrKDoaK4LyKimizFs/jgtZRq 7HNv9gSTZF0QBn92L22cIiXe8i9LOGZq78G37JUYp0N45iZCrG6yk4KU59N2zglby185 9ZLMDqxl6n4KoKI4yAocIIll6VDBkhIjLHbydtgHGpuu4mPn0caAa/KdbADHswacdIr4 avA+ZwtjRy692TzweFdUhM4JiVFsqhBolD6KqkFGV/eEp3wJKdIYjTgu/NRChFJRO/5O EFBw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p5si6081043ejo.398.2021.02.12.08.06.48; Fri, 12 Feb 2021 08:07:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232116AbhBLQCk (ORCPT + 99 others); Fri, 12 Feb 2021 11:02:40 -0500 Received: from mx2.suse.de ([195.135.220.15]:52506 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229679AbhBLQCg (ORCPT ); Fri, 12 Feb 2021 11:02:36 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 704D5AC90; Fri, 12 Feb 2021 16:01:53 +0000 (UTC) To: David Laight , "Gustavo A. R. Silva" , Kent Overstreet , "David S. Miller" , Christina Jacob , Hariprasad Kelam , Sunil Goutham , Jesse Brandeburg Cc: "linux-bcache@vger.kernel.org" , "linux-kernel@vger.kernel.org" , dongdong tao References: <20210212125028.GA264620@embeddedor> <0a2eb2e143ad480cbce3f84c3c920b5f@AcuMS.aculab.com> From: Coly Li Subject: Re: [PATCH][next] bcache: Use 64-bit arithmetic instead of 32-bit Message-ID: Date: Sat, 13 Feb 2021 00:01:47 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-Version: 1.0 In-Reply-To: <0a2eb2e143ad480cbce3f84c3c920b5f@AcuMS.aculab.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/12/21 11:31 PM, David Laight wrote: >>> if (c->gc_stats.in_use <= BCH_WRITEBACK_FRAGMENT_THRESHOLD_MID) { >>> - fp_term = dc->writeback_rate_fp_term_low * >>> + fp_term = (int64_t)dc->writeback_rate_fp_term_low * >>> (c->gc_stats.in_use - BCH_WRITEBACK_FRAGMENT_THRESHOLD_LOW); >>> } else if (c->gc_stats.in_use <= BCH_WRITEBACK_FRAGMENT_THRESHOLD_HIGH) { >>> - fp_term = dc->writeback_rate_fp_term_mid * >>> + fp_term = (int64_t)dc->writeback_rate_fp_term_mid * >>> (c->gc_stats.in_use - BCH_WRITEBACK_FRAGMENT_THRESHOLD_MID); >>> } else { >>> - fp_term = dc->writeback_rate_fp_term_high * >>> + fp_term = (int64_t)dc->writeback_rate_fp_term_high * >>> (c->gc_stats.in_use - BCH_WRITEBACK_FRAGMENT_THRESHOLD_HIGH); >>> } >>> fps = div_s64(dirty, dirty_buckets) * fp_term; >>> >> >> Hmm, should such thing be handled by compiler ? Otherwise this kind of >> potential overflow issue will be endless time to time. >> >> I am not a compiler expert, should we have to do such explicit type cast >> all the time ? > Hi David, I add Dongdong Tao Cced, who is author of this patch. Could you please offer me more information about the following lines? Let me ask more for my questions. > We do to get a 64bit product from two 32bit values. > An alternative for the above would be: > fp_term = c->gc_stats.in_use - BCH_WRITEBACK_FRAGMENT_THRESHOLD_HIGH; > fp_term *= dc->writeback_rate_fp_term_high; The original line is, fp_term = dc->writeback_rate_fp_term_high * (c->gc_stats.in_use - BCH_WRITEBACK_FRAGMENT_THRESHOLD_HIGH) The first value dc->writeback_rate_fp_term_high is unsigned int (32bit), and the second value (c->gc_stats.in_use - BCH_WRITEBACK_FRAGMENT_THRESHOLD_HIGH) is unsigned int (32bit) too. And fp_term is 64bit, if the product is larger than 32bits, the compiler should know fp_term is 64bit and upgrade the product to 64bit. The above is just my guess, because I feel compiling should have the clue for the product upgrade to avoid overflow. But I almost know nothing about compiler internal .... > > I hope BCH_WRITEBACK_FRAGMENT_THRESHOLD_LOW is zero :-) Why BCH_WRITEBACK_FRAGMENT_THRESHOLD_LOW being zero can be helpful to avoid the overflow ? Could you please to provide more detailed information. I am not challenging you, I just want to extend my knowledge by learning from you. Thanks in advance. Coly Li