Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp123905rwb; Tue, 8 Nov 2022 23:29:29 -0800 (PST) X-Google-Smtp-Source: AMsMyM4wCNf7+cmtGBz6G3K7RKgB2J7nem0T15JGLWPC8jaN/0dRCNjmyFOovX25UwNwMXEIjWSI X-Received: by 2002:a17:902:e952:b0:17c:7aaa:c679 with SMTP id b18-20020a170902e95200b0017c7aaac679mr60263228pll.74.1667978969615; Tue, 08 Nov 2022 23:29:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667978969; cv=none; d=google.com; s=arc-20160816; b=HcIEyr1ktoRm/HYTYGPKqOnQoGp6uKPj4slWCe89bvSzEqkicOrh/xKKn3v2Y6+Z0b zBr86trOcYZC4hQHRHgLQ7UeDJt6kxmmlf3P5EVFcuyIO4kalB3UCRdVaFflpEJOLEaQ QanRvw3P/8xOflilaRTTKOvpxwYXIgb76zA6Cmdlq4aJKJ5xSYmZaW7s8nyVea92TFJV xrLbQpy7GPnMBm98LcnlTKOynAa+P3Wh0M5OYttSr38VAtxXKsUuZnaGbOetbpyJfZVc scALYBBJq83zezdw+cQPQ/EsvTv7BYAH0nPIUB864Lrm3KdERO6+FOzoEUslISTiCUzr uhPw== 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=zSRw6nfdCPaMCQzx3jE+HEvjxFnji+/pTOoyXTdquzQ=; b=bEcXhoLnZaN6k6++DqY/43YoyUY1r5jPvCm1ckGqM1XIWKSd5GVF8muF6OGHqyNldP 00F4j0dGEAhwsQPyhC5yLS1O8e1wxcFELByhvLSLBYDttY29U1SAgxpI5s5tdDt1EmMP NEbTdy0U209pd8hKguxeJIZxYiRE14bhnCJFyfDgDAzcc3ZlxtBoe2r5wODZlFJnRnPH 6fkPrwdCuCxILszPqmTCt6J1hilmQgw6XzNBf4b/vgzKEE8qO6o2Mpmb6F2HP7khZL3j TeZO2vzajxU9zUfFfd2VOrpAQatB0IXZ5t72lF1kcviQ04R8I+DRdhFuiOyodPPwuHgL JPGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=K1QccXq8; 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 rm2-20020a17090b3ec200b001fdb95c743bsi689688pjb.83.2022.11.08.23.29.17; Tue, 08 Nov 2022 23:29:29 -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=K1QccXq8; 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 S229562AbiKIHE0 (ORCPT + 94 others); Wed, 9 Nov 2022 02:04:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229485AbiKIHEZ (ORCPT ); Wed, 9 Nov 2022 02:04:25 -0500 Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A3E11DDFF for ; Tue, 8 Nov 2022 23:04:22 -0800 (PST) Received: by mail-pl1-x643.google.com with SMTP id j12so16276345plj.5 for ; Tue, 08 Nov 2022 23:04:22 -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=zSRw6nfdCPaMCQzx3jE+HEvjxFnji+/pTOoyXTdquzQ=; b=K1QccXq8zGYDQPCT01fpavRZS+3GR2LdhwmxeSruUTnDnGDZJVASHd65B4QgmtE0aF 4giOK3TrfRJWZTQRYUpBAqE3zxCJj1t45z5MDUvPYFY+GJGY/qOvlnwo4sByTsSaqIMk E+1wQYCdJm1XCWoA7I/VtEs1Nvv7XKuj6lgdxQoLTq7d2COGG9+Z4aIKwpSmb/kbJ8im HfejMODT3G4QL2GWSCFSWYvkPqDetayUE9cca77CR8PMz9JeREcBM/6lvsfNV4LznYsV XnQXD4zPWtYkF37R4NYV0CY6xYh/sZNDMGRQ+7HtLQxqliQIDlpOgzBpXyProExchux+ F48g== 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=zSRw6nfdCPaMCQzx3jE+HEvjxFnji+/pTOoyXTdquzQ=; b=Vod1EZ6jmY5QSITJdvlBH/ilNu3tu5WZEBEnuCxZOVMYQmrtTZZs78miWxTm2sBkrN KWn8RfKKY58TXwp9bCRoWrXvUGW68Hug+KSYFwyksbpryHT91yStwxcTkyMUz2cIdNd0 aM/3GQqdvqwGwmCAB09nZAIpdnpSNfLbSCl1d8+Ky4R1KkDfdfBGeK5LwddS7ZE1sFer ULJK3Jymp14jGjypgA9tFeRB/6g+2SUePel0UUSHxppmqFD5TSKBgav+6Ht17iTm4J/X tzW834iNMSBPqyvGRF2dvyESevFo5aKGYmHAhMBPTZZ4hMCwnbgE+zVmrtVFM+XRAuGg t/og== X-Gm-Message-State: ACrzQf0qbLj1I/KegIrkWxX5jNO0vWvJoe+QEUdKiQUL8d53EzVSsSix TUzA7FFZhyJYie/w3FBNxoNnleROe8lUPxD3 X-Received: by 2002:a17:902:db12:b0:187:4736:f780 with SMTP id m18-20020a170902db1200b001874736f780mr37864396plx.145.1667977461892; Tue, 08 Nov 2022 23:04:21 -0800 (PST) Received: from xuchao.. ([129.227.152.6]) by smtp.gmail.com with ESMTPSA id x11-20020aa7940b000000b0056bf29c9ba3sm7788696pfo.146.2022.11.08.23.04.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Nov 2022 23:04:21 -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] mm/vmscan: simplify the nr assignment logic for pages to scan Date: Wed, 9 Nov 2022 15:04:16 +0800 Message-Id: <20221109070416.620887-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..df3c0cbe381f 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++) { + 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