Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp484762rwb; Thu, 10 Nov 2022 03:43:01 -0800 (PST) X-Google-Smtp-Source: AMsMyM72ICqn+umZqb9GemGjJLwMwn2q+gAErL0jLQhR0S8iRDpGTxHLy5xV5vmeR4wO2lWkxjOn X-Received: by 2002:a05:6402:288c:b0:461:8f21:5f12 with SMTP id eg12-20020a056402288c00b004618f215f12mr2181487edb.54.1668080580767; Thu, 10 Nov 2022 03:43:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668080580; cv=none; d=google.com; s=arc-20160816; b=rwwtQ4nx9RAjkr7+UWMDcaKjZGvKT79eBTFYBoMFsDN/t2kPNldndhRF5b1jkK1Cvc 87Swk8gn2Oa9e+G8a3UMaFhFydelZZA/11Jb1T1yyfa+y0UWVOgaz/3hmqUekhf4HaQ5 W41Gr59vq9+bXk1iAmiS0PcG31fIm6uafXnO+wm3upH1SdfPHPFn3P7lcCYO/IS7puYs 2pLkgtStdW//dhtHk4LtIlF+/zATtyXT4VH2obQqT9GOeBJVcPRn+6ZR3pWorfueIwCf jD9Aaw2BAe2p7ZNYtcu9Nj4Wpfkj2c3g2TJcd82A/rm1fn2mczaOu2Gin8cMxhartXyW HmHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=Pzfo2COKuQMunTGeb4PhEUp6IKXwGgGtyosnQ14pUIg=; b=hOff0aAsxOE0nduQQ0jPDSzkKY5EXxttdoDNxv4EJtQ35V6ow6bYxg+ZJcwXxhAtu0 BhUKpxa77zlGJ5Kn8t2/DzpfwT9xbzh2H2/aTWla/TgsmbivuXcVIBcCqA5Cj8xs6aSf H6pA/Kqh6EhLcpY6LrY04tGU7ztQoKi9NpxsE2P2b/V9s6zHr7FTNHdxvSsWgG1t/Yuu j04w8lImj8dRbyoGXW+frS2nDeCWmqihozz6s/BMn0+AxjPy+RPdEC5v8RJ3XJkayybC 2hhr+jCOLJN9QuvtC+a1U8AiKk1KW/Rb3WzI444B1g83A4Je4zqXMzuU5o8+1d5p4bCT i9hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=XIUBsLhH; 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 rv14-20020a17090710ce00b007ad9f041c3bsi13276305ejb.27.2022.11.10.03.42.11; Thu, 10 Nov 2022 03:43:00 -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=XIUBsLhH; 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 S229984AbiKJLbu (ORCPT + 92 others); Thu, 10 Nov 2022 06:31:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229560AbiKJLbs (ORCPT ); Thu, 10 Nov 2022 06:31:48 -0500 Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC26E716C0 for ; Thu, 10 Nov 2022 03:31:47 -0800 (PST) Received: by mail-pl1-x644.google.com with SMTP id b21so1172142plc.9 for ; Thu, 10 Nov 2022 03:31:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Pzfo2COKuQMunTGeb4PhEUp6IKXwGgGtyosnQ14pUIg=; b=XIUBsLhHEkyqVyhMi4qLVUwFKwPhOYMpXqMRU4YNe83FqVQvAz9iMze2c4WvHoHvqP qBcEsMujHT+uNwn/Q4hT8XVwrQL7pTMHAyE8StE/uGtrdVkKgvmyNectYC1G5vk6/Z79 GdqEPzmsa0OyTF5Xf/Cye6674DeeGOjtpvIfjFCiQ5UTLkJ8IOkCwF8B1GdGgqrSOZjV zfc7bvcSOgZoInMc7spCKFyoGKBFFc9TYZYfGEv2qv4ySkm+Q/M/mnHuI0ha/XUObKeo aRe1A0ZIuKTv/QzpmsOKD/tpgGtkMOWhz6vHO+5BiqdKu3J6/aty6K8S4yjcMxFeE9R5 5llg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Pzfo2COKuQMunTGeb4PhEUp6IKXwGgGtyosnQ14pUIg=; b=7lDa79bC8a98OVQ6FdYcW0KSRXMoq3iVjh6JlGAcHjIwj12MgU25Gj5L0OG6feTYFf IUEeHT2mIiIsTMbk6TQy9/66hf/pm2lFxdp+Ss08k4w6KnBJYSegiMwZFL0/XFmg+S/O phGi/n0zVm8WaIz7AxiFha1cyy1Ghf6V2t7vETL3QEsVlLtogSl038vAi9EH4QQ0ggp/ +NrttXvVYem9GwKc1hEtQ1pAXnFmYf+Px17OG3fSzyzlUtl0Vj6XvtokOA8UbhYUNnb9 MD1PNvh7Ly3XycQ5czdXgDRwgXWpfb5Fvx1FIW8zg9AR+D410bNSN2RyFEUA3grYY0GC vf7g== X-Gm-Message-State: ACrzQf0wgmIIay0XGp/eXasdP7L5IEFvnMap3wSS+vnl6fEGvsYvucx0 WfGmc/hmSB8cy8EwA+eok54= X-Received: by 2002:a17:90a:b792:b0:214:2a4a:4bbc with SMTP id m18-20020a17090ab79200b002142a4a4bbcmr44693944pjr.81.1668079907310; Thu, 10 Nov 2022 03:31:47 -0800 (PST) Received: from xuchao.Geely.Auto ([129.227.152.6]) by smtp.gmail.com with ESMTPSA id w21-20020aa79555000000b0056bcb102e7bsm9959929pfq.68.2022.11.10.03.31.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Nov 2022 03:31:46 -0800 (PST) From: Chao Xu X-Google-Original-From: Chao Xu To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Chao Xu Subject: [PATCH v1] mm/vmscan: simplify the nr assignment logic for pages to scan Date: Thu, 10 Nov 2022 19:31:30 +0800 Message-Id: <20221110113130.284290-1-Chao.Xu9@zeekrlife.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 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, 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 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. Signed-off-by: Chao Xu --- mm/vmscan.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 04d8b88e5216..69e458e51c81 100644 --- 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 += LRU_ACTIVE) { + nr_scanned = targets[lru] - nr[lru]; + nr[lru] = targets[lru] * (100 - percentage) / 100; + nr[lru] -= min(nr[lru], nr_scanned); + } scan_adjusted = true; } -- 2.34.1