Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp5226204pxv; Tue, 20 Jul 2021 23:49:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyIXtrbJ5cXsYNlEQSntaYtxgcX+FdRvBoDRX2jtVxrQT4MK7wcAgl8ex1d3XelP/xAqrPF X-Received: by 2002:a17:906:d045:: with SMTP id bo5mr37366030ejb.461.1626850175194; Tue, 20 Jul 2021 23:49:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626850175; cv=none; d=google.com; s=arc-20160816; b=ruPIoHrtxQj14/or8tdZ8TYkuXFxQhQKMU0HAhtXeqlCkSKMqWPlsPrLaT9WfbM3+A vFadlHEvX2VCvczm6J/rNdEndX+wVC6YcpfP0cZ7uhjq2sCyh7X+uZZClN5tGaoFMP+K 8ECMqC2nsmfQoIIrODiQ+/Ea4Lctw1QpklNgvVMvapApU2ORmmfC8HYDVb7reeoDJJaL 7WmWBc5HfnCqe5oZ6Lr69IIuBEgok1DzQVQpZd9mT1e77IiGSE+5D6nd1EPqOxkOHKHo HxzSd7xphdRcJeD3OT+KHdcNXr6MQvtoPe9R/unknfUQM/a4ugaMgX4yA3pp/hB5aihj /Deg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=aSNVJi5Kt2Ww7lpTGnzDUGdyCRFNWUNYzOpVHCiC31M=; b=xev6OV3TGnRUzCZ8aI9HXzg4wYPtT0PB0CzRVpMJSUa+z+sA868C/ganT64lXKnFns 3ZxS3ole67sj/In7dmo8hvwuO9GLbgcYzVVrsGhuIJ7wDZcbqmJ5ETwO2ePwB4ZdRrcv Beamf5OMxkLKqDh5Vser2nDDU/f8ys6xXZGpTOsyPaZu8ShW96O/wbGBIAOusChxP0kz BlyOq703VylesThO+cq62WEF6yVMtyJyU9KUce+fYQ4rfSdKkA/7ikbVx+tLQchdlIxy UOXFaF095cJ49ozn6yHGx0SxnUZMHLndgPr4TSb1cs1zyykWF6PlmSt5gBbK9gRlDL1l Mpww== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p26si26792505ejf.481.2021.07.20.23.49.12; Tue, 20 Jul 2021 23:49:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233923AbhGUGDM (ORCPT + 99 others); Wed, 21 Jul 2021 02:03:12 -0400 Received: from mga06.intel.com ([134.134.136.31]:44379 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234243AbhGUF7Q (ORCPT ); Wed, 21 Jul 2021 01:59:16 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10051"; a="272496391" X-IronPort-AV: E=Sophos;i="5.84,257,1620716400"; d="scan'208";a="272496391" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jul 2021 23:39:53 -0700 X-IronPort-AV: E=Sophos;i="5.84,257,1620716400"; d="scan'208";a="511390027" Received: from yhuang6-desk2.sh.intel.com ([10.239.159.119]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jul 2021 23:39:50 -0700 From: Huang Ying To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Dave Hansen , "Huang, Ying" , Yang Shi , Greg Thelen , Michal Hocko , Wei Xu , Oscar Salvador , Zi Yan , David Rientjes , Dan Williams , David Hildenbrand , Keith Busch , Yang Shi Subject: [PATCH -V11 6/9] mm/vmscan: add helper for querying ability to age anonymous pages Date: Wed, 21 Jul 2021 14:39:23 +0800 Message-Id: <20210721063926.3024591-6-ying.huang@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210721063926.3024591-1-ying.huang@intel.com> References: <20210721063926.3024591-1-ying.huang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dave Hansen Anonymous pages are kept on their own LRU(s). These lists could theoretically always be scanned and maintained. But, without swap, there is currently nothing the kernel can *do* with the results of a scanned, sorted LRU for anonymous pages. A check for '!total_swap_pages' currently serves as a valid check as to whether anonymous LRUs should be maintained. However, another method will be added shortly: page demotion. Abstract out the 'total_swap_pages' checks into a helper, give it a logically significant name, and check for the possibility of page demotion. Link: https://lkml.kernel.org/r/20210715055145.195411-7-ying.huang@intel.com Signed-off-by: Dave Hansen Signed-off-by: "Huang, Ying" Reviewed-by: Yang Shi Reviewed-by: Greg Thelen Cc: Michal Hocko Cc: Wei Xu Cc: Oscar Salvador Cc: Zi Yan Cc: David Rientjes Cc: Dan Williams Cc: David Hildenbrand Cc: Keith Busch Cc: Yang Shi Signed-off-by: Andrew Morton --- mm/vmscan.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 90fa026cfa29..d79bf91700de 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -2729,6 +2729,21 @@ static void get_scan_count(struct lruvec *lruvec, struct scan_control *sc, } } +/* + * Anonymous LRU management is a waste if there is + * ultimately no way to reclaim the memory. + */ +static bool can_age_anon_pages(struct pglist_data *pgdat, + struct scan_control *sc) +{ + /* Aging the anon LRU is valuable if swap is present: */ + if (total_swap_pages > 0) + return true; + + /* Also valuable if anon pages can be demoted: */ + return can_demote(pgdat->node_id, sc); +} + static void shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc) { unsigned long nr[NR_LRU_LISTS]; @@ -2838,7 +2853,8 @@ static void shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc) * Even if we did not try to evict anon pages at all, we want to * rebalance the anon lru active/inactive ratio. */ - if (total_swap_pages && inactive_is_low(lruvec, LRU_INACTIVE_ANON)) + if (can_age_anon_pages(lruvec_pgdat(lruvec), sc) && + inactive_is_low(lruvec, LRU_INACTIVE_ANON)) shrink_active_list(SWAP_CLUSTER_MAX, lruvec, sc, LRU_ACTIVE_ANON); } @@ -3669,7 +3685,7 @@ static void age_active_anon(struct pglist_data *pgdat, struct mem_cgroup *memcg; struct lruvec *lruvec; - if (!total_swap_pages) + if (!can_age_anon_pages(pgdat, sc)) return; lruvec = mem_cgroup_lruvec(NULL, pgdat); -- 2.30.2