Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp17925rwb; Wed, 9 Nov 2022 19:08:41 -0800 (PST) X-Google-Smtp-Source: AMsMyM5ytj8rdqtmXr+2PYNXGzwrR4lFXF3S9Wetel3PLJmaskUr+iZT+34Clo49JpkLXH6JRDFL X-Received: by 2002:a17:906:d10d:b0:7ad:b7c2:a2f7 with SMTP id b13-20020a170906d10d00b007adb7c2a2f7mr2206887ejz.227.1668049720816; Wed, 09 Nov 2022 19:08:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668049720; cv=none; d=google.com; s=arc-20160816; b=S4P3hAHElr8SuXSlXpRmKifryUS7JTvSdFK1DoYjdFtYu1X95m4nKkbzM/j8Tzhr9m a6b7RlnPVyZF2H9hz32gw2qfjt2e+8BlqcTxFABdJFBJfSfVtOfO3aL5z05yD17izov/ PbUti7L3yAz6DRftqfPCCL/iZY4d3PCMh8N+tUEJhSBBfv6D7zLmG7ISQeNirOfJq8Li AWqj56IkslrX+DDRRzHtpqf9k1sYewV29+X1nTvzuRct19pPV2CWgs3Acyobegs3uUX4 FXUXcB4EIE3EMNST8BwP42cj7Iar2iRCDvEzqXLtRYMB5EJUeyfTHbE0tMZOFXOx1H4V Rg+Q== 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:from :references:cc:to:subject:user-agent:mime-version:date:message-id :dkim-signature; bh=e7eUyiQ6IzU2+8YpPxlxYGEz6hnrs4cMH/uVBORMyPA=; b=xm/Ry4BoizEUizANwWIBeK6916pdG1IuVUkgwP03F0b1DFkfHIPyW0QJh0TzBOK4YX o0sCB/f42oJlfZhL2bhdR3R3YqBwktyNVTh0Ei6RXlYoMxdLnDQU2tT4ejb29Sp8yo5k BFoYMmzvIKlkqPXIiySfmuaqrxy92/fjbAtxK07vZ8Gq39TCZwRbIjntDv9s44xTyRg6 FegGssH+Oom5qWrQZK0B0nvCA7i0S0q/N0PoKTc6pdWlo/MVyog6xXcFgsIbQNPyGJpv VvUA3AQc4GAvkxss2Dgkrg06S4mtglH47AGSOpFQ8V0lv7E5fj0/k6NLP+CTwhW0zonZ VwOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=hJj2r8CB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q19-20020a056402519300b004637e16cfa3si19728267edd.598.2022.11.09.19.07.54; Wed, 09 Nov 2022 19:08:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=hJj2r8CB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232559AbiKJCsd (ORCPT + 92 others); Wed, 9 Nov 2022 21:48:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232549AbiKJCs2 (ORCPT ); Wed, 9 Nov 2022 21:48:28 -0500 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E192BE3D for ; Wed, 9 Nov 2022 18:48:27 -0800 (PST) Received: by mail-pg1-x544.google.com with SMTP id h193so442500pgc.10 for ; Wed, 09 Nov 2022 18:48:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=e7eUyiQ6IzU2+8YpPxlxYGEz6hnrs4cMH/uVBORMyPA=; b=hJj2r8CBurme6Ps/PCRGDQ3Ut2BotHl6PwfMBtsW7ln7DRdh0pA3cM5hiaEWBSqlVP SY66mlbXOKxsctjgeY4XX4nHLI2vM3O2SKr6OqdnrVRYFEdos4rJ9QHklqnYLqaHG5aN /WJeRVBHALT+4aBNRJ8FpvYsP2q+OydgmEW3BojR3++p3aWiGlb8agop3By+kFGHXJo2 oEsKLhzBRhbwc0fFfqJWkjRMUS1jm4kP+P/WCLgCaEpSyMurjI1dK61vyWeybyzTsmP7 80cfVi/G89288QVex5RaQ/VzondOZ4PCka2oSB8tOAWBYGu71bOhMV85fxIUh4Od3Oyo YnnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=e7eUyiQ6IzU2+8YpPxlxYGEz6hnrs4cMH/uVBORMyPA=; b=kGrymT7c9Nu4ODvd/Mk8EDIW/eP9GCBrHG1JuULqBEPbRSnifbyTBHcszwTuuGQ5Al rT6DmdBr5JKtaUNdZPKPIJ/mC3WO0R6TqJHgg5uNYNvOV7Q1PPOPDdiIKXgZjrcl1RML RB+vhnDtqHaCYwpLQL25RCxgdO1QyWBnDjbAztpl5+rSW/4r3D/PJT14araZiOQrwRUI T/1F5zLjSwktEibVn1JksML++xjLwLPwR0O7cweVFn+oXhBS9XMg+aD6cb7JODsc6wiB e+Qv9GQybMiLmVHHmxISsAqm4ypcw2enRRKtcVg1hAldXrR9FJ9ajPCjWpQk1npcOgNZ XGYA== X-Gm-Message-State: ACrzQf1HQ3yZvmvkej6Swe5JPyWFB1l4aU0unl+LMVlg9uaUuBnDiqhY aH4RcsLwR6vwCEQtY44o0kI= X-Received: by 2002:a65:4b88:0:b0:44e:74d0:e843 with SMTP id t8-20020a654b88000000b0044e74d0e843mr1616131pgq.95.1668048506995; Wed, 09 Nov 2022 18:48:26 -0800 (PST) Received: from [10.114.96.16] ([129.227.152.6]) by smtp.gmail.com with ESMTPSA id ij26-20020a170902ab5a00b0017f6c9622b9sm9744756plb.183.2022.11.09.18.48.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 09 Nov 2022 18:48:26 -0800 (PST) Message-ID: <7113d66a-9792-b026-cece-5c1b21dd989d@gmail.com> Date: Thu, 10 Nov 2022 10:48:24 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: [PATCH] mm/vmscan: simplify the nr assignment logic for pages to scan To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Chao Xu References: <20221109070416.620887-1-Chao.Xu9@zeekrlife.com> <20221109171952.826d991327e07319c5eb8cd3@linux-foundation.org> From: Chao Xu In-Reply-To: <20221109171952.826d991327e07319c5eb8cd3@linux-foundation.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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 在 2022/11/10 9:19, Andrew Morton 写道: > On Wed, 9 Nov 2022 15:04:16 +0800 Chao Xu wrote: > >> By default the assignment logic of anonymouns or file inactive >> pages and active pages to scan using the same duplicated code >> snippet. To simplify the logic, merge the same part. >> >> --- a/mm/vmscan.c >> +++ b/mm/vmscan.c >> @@ -5932,14 +5932,11 @@ static void shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc) >> * scan target and the percentage scanning already complete >> */ >> lru = (lru == LRU_FILE) ? LRU_BASE : LRU_FILE; >> - nr_scanned = targets[lru] - nr[lru]; >> - nr[lru] = targets[lru] * (100 - percentage) / 100; >> - nr[lru] -= min(nr[lru], nr_scanned); >> - >> - lru += LRU_ACTIVE; >> - nr_scanned = targets[lru] - nr[lru]; >> - nr[lru] = targets[lru] * (100 - percentage) / 100; >> - nr[lru] -= min(nr[lru], nr_scanned); >> + for ( ; lru <= lru + LRU_ACTIVE; lru++) { > The "lru++" implicitly assumes that LRU_ACTIVE=1. That happens to be > the case, but a more accurate translation of the existing code would > use "lru += LRU_ACTIVE" here, yes? By default the value of LRU_ACTIVE is 1,but if someone change it one day, I use "lru++" maybe facing some exceptions, which is not robust. So I agree with that "lru += LRU_ACTIVE" is appropriate instead of "lru++". I will send a new patch. >> + nr_scanned = targets[lru] - nr[lru]; >> + nr[lru] = targets[lru] * (100 - percentage) / 100; >> + nr[lru] -= min(nr[lru], nr_scanned); >> + } >> >> scan_adjusted = true; >> }