Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1633871pxb; Thu, 4 Mar 2021 17:03:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJwG011rg8oY8A24Loc+hS6ytmGdCI/5iSsmZL4eAp+eDWxxcBzVwH907Ja2+PhwWuYrUqDU X-Received: by 2002:a05:6e02:4a4:: with SMTP id e4mr6016026ils.114.1614906225289; Thu, 04 Mar 2021 17:03:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614906225; cv=none; d=google.com; s=arc-20160816; b=eyWnQO9yC5Y3kELKCu5uxEAfLIg1p6A3fuNPW9v1Qk4pXfHic8OlF5wAUqj3wQWS5U 7pstYTSfMKPnPphDN5CRtnMDmOcUPnrPpzAcLgHyIlIEQhttuUEg76NT9Le5Bo8BNbe9 s8uoiEaZCVhtT1J1SKVmoxuKb12X27YYo6cgMhQR+M4MqHqtGKhcchvDnLD13JsPgBnN X5QRvsQzcytqZkFOhW1GHP34T3BEnBo7PURSm5uSTg6CsBSHtmXEJ8O+lKLQVnJtzT10 ZtQlrnof/SXeR9XBBy7TMkz0UcBnWbM4w9URd6PhfesY5IZ2MjLL4VndaBWVuNy6BS9Z ei6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:in-reply-to:references:date:from:cc :to:subject:ironport-sdr:ironport-sdr; bh=ndlx14cdbPxmvpclr+OqiyN7YCZ5m/kuGmibMc3+1h4=; b=0taZTNZxyrgun68jAFeqCHEZfvmpfLQfGxuZyp07th6lqNmujIk+0DL4UgEkbF27np ZbbjILVykKmQ5ZtLBDr/mLLl1GWAVcVxqpV8F4WP8BiRdFJk4jAGPqDUPMF3AVJF8yQT Dg5txI/vGe7WxHwIbh3ZccQM47V66OYVHUC4/RIb3cDPEzMxIgGe5ZvGo3t1Rw0Qk+TD 9AlLcoDnqKjqT5NcXZzvZ2iu5WjoxO0oljDgSQa2R5kbWRSwDl9VGqnimV7T1dFbz/R+ AFvP6FIQg3jHGz/I/vauBJNgyMgEbmJ4/fmBjZRelwtB8D3+kKcB4vNmQinG9NYaIPW+ 4nlg== 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 k31si917033jav.116.2021.03.04.17.03.31; Thu, 04 Mar 2021 17:03:45 -0800 (PST) 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 S230477AbhCEABE (ORCPT + 99 others); Thu, 4 Mar 2021 19:01:04 -0500 Received: from mga14.intel.com ([192.55.52.115]:31689 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230475AbhCEAA6 (ORCPT ); Thu, 4 Mar 2021 19:00:58 -0500 IronPort-SDR: p5sVtzHI9OGXAJEbw+krNlkjlC8K6jwQ0RraygJMpVezYCUw/oHztIxtdj1HGwQ7q7svOZSZmT eapzGlzMkjRw== X-IronPort-AV: E=McAfee;i="6000,8403,9913"; a="186882996" X-IronPort-AV: E=Sophos;i="5.81,223,1610438400"; d="scan'208";a="186882996" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Mar 2021 16:00:56 -0800 IronPort-SDR: ZF7TP6u0e8Rj9aS3WwuoWDC8vt2zn91PkvW9spyEVeVPGNZnBVRI0jeznH/SUH5m8C4dVfUYDP CZL/9mwaCdPg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,223,1610438400"; d="scan'208";a="407034832" Received: from viggo.jf.intel.com (HELO localhost.localdomain) ([10.54.77.144]) by orsmga007.jf.intel.com with ESMTP; 04 Mar 2021 16:00:56 -0800 Subject: [PATCH 08/10] mm/vmscan: Consider anonymous pages without swap To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, Dave Hansen , kbusch@kernel.org, yang.shi@linux.alibaba.com, rientjes@google.com, ying.huang@intel.com, dan.j.williams@intel.com, david@redhat.com, osalvador@suse.de From: Dave Hansen Date: Thu, 04 Mar 2021 16:00:04 -0800 References: <20210304235949.7922C1C3@viggo.jf.intel.com> In-Reply-To: <20210304235949.7922C1C3@viggo.jf.intel.com> Message-Id: <20210305000004.20A8D23F@viggo.jf.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Keith Busch Reclaim anonymous pages if a migration path is available now that demotion provides a non-swap recourse for reclaiming anon pages. Note that this check is subtly different from the anon_should_be_aged() checks. This mechanism checks whether a specific page in a specific context *can* actually be reclaimed, given current swap space and cgroup limits anon_should_be_aged() is a much simpler and more prelimiary check which just says whether there is a possibility of future reclaim. #Signed-off-by: Keith Busch Cc: Keith Busch Signed-off-by: Dave Hansen Cc: Yang Shi Cc: David Rientjes Cc: Huang Ying Cc: Dan Williams Cc: David Hildenbrand Cc: osalvador -- Changes from Dave 10/2020: * remove 'total_swap_pages' modification Changes from Dave 06/2020: * rename reclaim_anon_pages()->can_reclaim_anon_pages() Note: Keith's Intel SoB is commented out because he is no longer at Intel and his @intel.com mail will bounce. --- b/mm/vmscan.c | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff -puN mm/vmscan.c~0009-mm-vmscan-Consider-anonymous-pages-without-swap mm/vmscan.c --- a/mm/vmscan.c~0009-mm-vmscan-Consider-anonymous-pages-without-swap 2021-03-04 15:35:59.994806420 -0800 +++ b/mm/vmscan.c 2021-03-04 15:36:00.001806420 -0800 @@ -287,6 +287,34 @@ static bool writeback_throttling_sane(st } #endif +static inline bool can_reclaim_anon_pages(struct mem_cgroup *memcg, + int node_id) +{ + if (memcg == NULL) { + /* + * For non-memcg reclaim, is there + * space in any swap device? + */ + if (get_nr_swap_pages() > 0) + return true; + } else { + /* Is the memcg below its swap limit? */ + if (mem_cgroup_get_nr_swap_pages(memcg) > 0) + return true; + } + + /* + * The page can not be swapped. + * + * Can it be reclaimed from this node via demotion? + */ + if (next_demotion_node(node_id) >= 0) + return true; + + /* No way to reclaim anon pages */ + return false; +} + /* * This misses isolated pages which are not accounted for to save counters. * As the data only determines if reclaim or compaction continues, it is @@ -298,7 +326,7 @@ unsigned long zone_reclaimable_pages(str nr = zone_page_state_snapshot(zone, NR_ZONE_INACTIVE_FILE) + zone_page_state_snapshot(zone, NR_ZONE_ACTIVE_FILE); - if (get_nr_swap_pages() > 0) + if (can_reclaim_anon_pages(NULL, zone_to_nid(zone))) nr += zone_page_state_snapshot(zone, NR_ZONE_INACTIVE_ANON) + zone_page_state_snapshot(zone, NR_ZONE_ACTIVE_ANON); @@ -2332,6 +2360,7 @@ enum scan_balance { static void get_scan_count(struct lruvec *lruvec, struct scan_control *sc, unsigned long *nr) { + struct pglist_data *pgdat = lruvec_pgdat(lruvec); struct mem_cgroup *memcg = lruvec_memcg(lruvec); unsigned long anon_cost, file_cost, total_cost; int swappiness = mem_cgroup_swappiness(memcg); @@ -2342,7 +2371,7 @@ static void get_scan_count(struct lruvec enum lru_list lru; /* If we have no swap space, do not bother scanning anon pages. */ - if (!sc->may_swap || mem_cgroup_get_nr_swap_pages(memcg) <= 0) { + if (!sc->may_swap || !can_reclaim_anon_pages(memcg, pgdat->node_id)) { scan_balance = SCAN_FILE; goto out; } @@ -2717,7 +2746,7 @@ static inline bool should_continue_recla */ pages_for_compaction = compact_gap(sc->order); inactive_lru_pages = node_page_state(pgdat, NR_INACTIVE_FILE); - if (get_nr_swap_pages() > 0) + if (can_reclaim_anon_pages(NULL, pgdat->node_id)) inactive_lru_pages += node_page_state(pgdat, NR_INACTIVE_ANON); return inactive_lru_pages > pages_for_compaction; _