Received: by 2002:a05:7412:8598:b0:f9:33c2:5753 with SMTP id n24csp479083rdh; Tue, 19 Dec 2023 05:02:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IH0HLhP/0RzDAKH+/sUHsQGgFTRWV4BrlJZrD/BcDI0CaMLzuvuTm11SGf4pCqRybCiusFa X-Received: by 2002:a05:620a:22a3:b0:77f:b146:89c1 with SMTP id p3-20020a05620a22a300b0077fb14689c1mr6929653qkh.136.1702990936827; Tue, 19 Dec 2023 05:02:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702990936; cv=none; d=google.com; s=arc-20160816; b=XBHxizyk5ys/Prc7HGxUBn1On/aNp5LYwXe1BbmBkJi4dscXDa705CaZrrMU6iXqZi 8Dn+ylDw4h/oW2a/Q+apr9kiHBLeGA4PYgBkuJt82WV1W6NorHfqSwuao2EuL2ONzCuN vZAvS84TqDETa1sert0A7o4bIKEOQdKPxRUEFaxMTdj1XQGnyCgmWSLW1E5joeoRDEBz loOEPASxR+pW8Q7+vyGEQiJO3WliEGvElkyhvvnaP17WBPnZaSTQ28O8r1KtqxDfj3nQ WpjwaUwjjVfmMYjdiFQgSKzTkESJrnlBJTTMGvCjHRRgmX9u5S+L05TQ2mLK/rt5Irrq d/tA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Aso/PSABcXQ/18wC+IQ9g/IA0o4shEADqRKW81TUoxw=; fh=clujZbPAUwM86QRn1WnC5L4505gpd0Fd7jlPElyq4Vg=; b=rytvKsNXbMu9PNU9Xt8Q39HHmyAfqphQAZVQB5FI16/DQppG8V8bAIBV6ruG87GB2t 8NS86E5WL5k7VM8ouq+wbj8Bw5JBYGq6pKJ8kir/RrHMHsiBgAar5aAeZwds4PTRjxKp Xb0qt5CWbwP07lNXKTmptecs47oB1h2b2nebCGx+HUAu5gSatPULf+3PHD1kM4hTB5bM NtQqKK/uf56lbwqi8TGoIwWD/xEiW8UiNoVZvtfEdtqGR1EtfXbyDKgBABW/5pfK2avY hWscpAv0/nXKTlsoi6maxvsmHw/bANteNuZAGjO3pP2g3tpjBWPulCUOAqVk2hsmc+lW 0JLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=dilU4n7r; spf=pass (google.com: domain of linux-kernel+bounces-5228-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-5228-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 10-20020a05620a040a00b007743391acf0si24732881qkp.324.2023.12.19.05.02.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 05:02:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-5228-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=dilU4n7r; spf=pass (google.com: domain of linux-kernel+bounces-5228-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-5228-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 926801C241C2 for ; Tue, 19 Dec 2023 13:02:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3458E18E39; Tue, 19 Dec 2023 13:02:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="dilU4n7r" X-Original-To: linux-kernel@vger.kernel.org Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 24BDE18E13; Tue, 19 Dec 2023 13:02:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=Aso/PSABcXQ/18wC+IQ9g/IA0o4shEADqRKW81TUoxw=; b=dilU4n7ryxuYedzFlRzioKja08 4qj4ySuGV9Ae6scuCXIItPCot64QClJ3OZL0DgZB1yBLjM7y/FcLrj1rvgWN8c7Zr0E5riKO2k0RE DUgvs/tfgogxwmzjpe/1h5UZl+e4jDniEebdOYXZVtVvww2NBkcIctFHWyYnCGiueh18lET6gfdGy XnblBn1md0RYvkpieKhEV22DdCyikiwtmTJY6E2ISWD1LSvLFuRX9N8Hqf4Vx1ITNQf10gamCX5/v hMgDUxOZCRiFaK/z7sdIIKcFI33+jI5CqyhInR1ylG7vEbtJdw/2aj0HsbuILnihcFPhQKLNct1xV vlz4RYcQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1rFZjG-002z7C-LZ; Tue, 19 Dec 2023 13:01:46 +0000 Date: Tue, 19 Dec 2023 13:01:46 +0000 From: Matthew Wilcox To: Jingbo Xu Cc: shr@devkernel.io, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, joseph.qi@linux.alibaba.com, linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org Subject: Re: [PATCH v2 2/2] mm: fix arithmetic for max_prop_frac when setting max_ratio Message-ID: References: <20231219024246.65654-1-jefflexu@linux.alibaba.com> <20231219024246.65654-3-jefflexu@linux.alibaba.com> <5460aaf1-44f6-475f-b980-cb9058cc1df4@linux.alibaba.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5460aaf1-44f6-475f-b980-cb9058cc1df4@linux.alibaba.com> On Tue, Dec 19, 2023 at 01:58:21PM +0800, Jingbo Xu wrote: > On 12/19/23 12:06 PM, Matthew Wilcox wrote: > > On Tue, Dec 19, 2023 at 10:42:46AM +0800, Jingbo Xu wrote: > >> } else { > >> bdi->max_ratio = max_ratio; > >> - bdi->max_prop_frac = (FPROP_FRAC_BASE * max_ratio) / 100; > >> + bdi->max_prop_frac = div64_u64(FPROP_FRAC_BASE * max_ratio, > >> + 100 * BDI_RATIO_SCALE); > >> } > > > > Why use div64_u64 here? > > > > FPROP_FRAC_BASE is an unsigned long. max_ratio is an unsigned int, so > > the numerator is an unsigned long. BDI_RATIO_SCALE is 10,000, so the > > numerator is an unsigned int. There's no 64-bit arithmetic needed here. > > Yes, div64_u64() is actually not needed here. So it seems > > bdi->max_prop_frac = FPROP_FRAC_BASE * max_ratio / 100 / BDI_RATIO_SCALE; > > is adequate? I'd rather spell that as: bdi->max_prop_frac = (FPROP_FRAC_BASE * max_ratio) / (100 * BDI_RATIO_SCALE); It's closer to how you'd write it out mathematically and so it reads more easily. At least for me.