Received: by 2002:a05:7412:8598:b0:f9:33c2:5753 with SMTP id n24csp229386rdh; Mon, 18 Dec 2023 18:03:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IGDC5X4d0EfGveKjcaIPP2Vpee68ZKbtbf53XhuXn7bdtewqxdOtpskak1xrF9XNk3zkqdM X-Received: by 2002:a05:6a20:6a0c:b0:18f:97c:4f36 with SMTP id p12-20020a056a206a0c00b0018f097c4f36mr10146048pzk.66.1702951435939; Mon, 18 Dec 2023 18:03:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702951435; cv=none; d=google.com; s=arc-20160816; b=BVNkSmfj0MnrGQr4D+R4gIEDnfGXA2+irgZngihPQ7dJMzhRtOlrXVKdZ2PyBYXslg b4uYfMjF0fe7ibUNvboPbyYWacqcIgvqopbf4umMCZ8xyf0k4tGdk5Ajv3Qva+uNBZFQ 0irwlZ5M1YFDU9w9fhOWldXbiSISkanvG1g9t11No3YVPpiTnf1U3gGhG/XVsHCvafOa tg3vNt2h7i00lxprTlEn/ZhogSL1z3WvVOTaAevdGdXIOd62mLtGP81BBZLXZ5BWaHWZ JuKeNLREWRqH++JIrfEoiLlttvTw6mTGTlAyM3YTBv1kgniteVk+PHbwK7vAmyXeCoC2 0ORA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=+zDVJliNUoxO+aQxQNF6xBuweA+aX4fyJ3ZG2mJOeko=; fh=giPdduEfj2f6iWVp4pUr0Fs3ttK3kiDRSwPlrNT/mxw=; b=WxQZm9HvdX+tMRMvarBs8NNa41cm3UACfB5ReFDh4/Y33r31CaDnQhPZahizJ4fgzj mQucKD03nDQsktNPmaVnyj8ZzRLBYQvXVcmkVN6SOgvb26TN6xriXOHl4+/7h9ugvzPg M39ZV+67bRc9/kFeuWC3naaFcnjlCyM+/5EonKzWFjIF4OMYZSPb5UctGNONZs+UZjI3 mVOZUNuKPnHICij8fvK1enHZlqR32rj/YdafzKTSLfjtsbOUQrd9AE6MpsJSWSWzr/W2 BvfnM9W5ZjCsEguDTHaRQ682WB0cqX/PDSy6bnILEeWCpXlrSgBmKQ4KU3xJdPdWd7cJ GmHw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-4576-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4576-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id c12-20020a170902b68c00b001d0b4bfcbc7si18560587pls.27.2023.12.18.18.03.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 18:03:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-4576-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-4576-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4576-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 95FCF286269 for ; Tue, 19 Dec 2023 02:03:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8D2F11FB9; Tue, 19 Dec 2023 02:03:50 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from out30-98.freemail.mail.aliyun.com (out30-98.freemail.mail.aliyun.com [115.124.30.98]) (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 62768187F for ; Tue, 19 Dec 2023 02:03:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R171e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045192;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0VyogQL4_1702951421; Received: from 30.221.145.29(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VyogQL4_1702951421) by smtp.aliyun-inc.com; Tue, 19 Dec 2023 10:03:42 +0800 Message-ID: <112dd87b-1072-4568-93d5-3b13ed818511@linux.alibaba.com> Date: Tue, 19 Dec 2023 10:03:40 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] mm: fix arithmetic for bdi min_ratio and max_ratio Content-Language: en-US To: Andrew Morton Cc: shr@devkernel.io, linux-mm@kvack.org, linux-kernel@vger.kernel.org, joseph.qi@linux.alibaba.com References: <20231218031640.77983-1-jefflexu@linux.alibaba.com> <20231218102117.c91ab02353ff76b952f3ec9e@linux-foundation.org> From: Jingbo Xu In-Reply-To: <20231218102117.c91ab02353ff76b952f3ec9e@linux-foundation.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 12/19/23 2:21 AM, Andrew Morton wrote: > On Mon, 18 Dec 2023 11:16:40 +0800 Jingbo Xu wrote: > >> bdi->[min|max]_ratio are both part per million. Fix the wrong >> arithmetic when setting bdi's min_ratio and max_ratio. >> >> Fixes: efc3e6ad53ea ("mm: split off __bdi_set_max_ratio() function") >> Fixes: 8021fb3232f2 ("mm: split off __bdi_set_min_ratio() function") > > As we have two Fixes:, it would be better to have two patches please. Sounds reasonable. Thanks. > >> --- a/mm/page-writeback.c >> +++ b/mm/page-writeback.c >> @@ -692,7 +692,6 @@ static int __bdi_set_min_ratio(struct backing_dev_info *bdi, unsigned int min_ra >> >> if (min_ratio > 100 * BDI_RATIO_SCALE) >> return -EINVAL; >> - min_ratio *= BDI_RATIO_SCALE; This indeed has visible runtime effect as follows: # cat /sys/class/bdi/253\:0/min_ratio 0 # cat /sys/class/bdi/253\:0/max_ratio 100 # echo 1 > /sys/class/bdi/253\:0/min_ratio -bash: echo: write error: Invalid argument Setting min_ratio will fail with -EINVAL, as the above code tries to set min_ratio with (min_ratio * BDI_RATIO_SCALE)%, i.e. 10000% in the above example. >> >> spin_lock_bh(&bdi_lock); >> if (min_ratio > bdi->max_ratio) { >> @@ -729,7 +728,8 @@ static int __bdi_set_max_ratio(struct backing_dev_info *bdi, unsigned int max_ra >> ret = -EINVAL; >> } 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, >> + 100UL * BDI_RATIO_SCALE); >> } >> spin_unlock_bh(&bdi_lock); This one has no visible runtime effect, but I believe this would affect the incrementing of writeout completion count when max_ratio is not 100%. -- Thanks, Jingbo