Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp3312601pxa; Tue, 18 Aug 2020 11:53:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyy55LHr3IGntpDfEfhYVBQBKGOQZNucJL4oG11FTQh1FsHlc+2UO8kw2FefCFU12imR0ji X-Received: by 2002:a05:6402:748:: with SMTP id p8mr22082466edy.305.1597776781226; Tue, 18 Aug 2020 11:53:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597776781; cv=none; d=google.com; s=arc-20160816; b=C+qAbrcM0w3A+OnOVaqxCxl08tMd9u8U0OweONKI5KdYy2+WC/ycb38z8AtlqXme+Z TUQdyju7S2tvu3ubOs1+ivYbHNMrOsb14Ll2JmqOwsI8d3HcdGf9sVaR5w+ya1UVIXTE YL8aH6z2yf8LSC6kTX61guICJKREaUmok2i+bitM5xplCMZROUWy2Jn48CKgb1Pl5BWS IZrAvksnYg51N9OKmsiExrn6uEja3nw4ZCSxjpxmaboog5DI/sTPs1DZbFzkHlu4AdI7 N8UJOQLblKh1+2EdoP4SYhzKEScveXB5U4PSPtnd71IvDsyBxlZ/HZFt7v3gucuoViBZ L+bA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:in-reply-to:references:date :from:cc:to:subject:ironport-sdr:ironport-sdr; bh=YEhx47XakATGR7fNfxLezRK6KCUXdu4cM91Mg7mgMts=; b=QTG2UZFXKS3vXNNdygmlLNhg307f3rHyRid7emVQjDtYIFe3EINVoskWgSDZFVg4mB wj4pEEFlykuuB1kq9h07ntTnl0VQRuZLdZ7WExBK5IxYM9JbfeWG29Dq4fEXRGoF7/aR bVqZDcnpX5YEafrboAJyMqSxaNGeuqvmxmo58YPfsnrDBaSGnxufoX8qO0uGmwYsJK3c M1UccIOYo6JN2I9QSg3V8RZx7DdVDJCak8CYbuPXHaAAK9kGSm4qdesmFVeSAHUyN/Yz hTpQmxee9O9gbSsARQ2lZHQZYdmXUyWXEj6FCkNo8tyVlr66EQMDykN9icvkLYhrVP4O 0ywA== 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 eb8si17979626edb.246.2020.08.18.11.52.37; Tue, 18 Aug 2020 11:53:01 -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 S1726885AbgHRSss (ORCPT + 99 others); Tue, 18 Aug 2020 14:48:48 -0400 Received: from mga09.intel.com ([134.134.136.24]:57761 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726786AbgHRSsR (ORCPT ); Tue, 18 Aug 2020 14:48:17 -0400 IronPort-SDR: uDcTOeZIRJa421Z+CAwjLuhYA6eQvXCs5SBz7ZG244eIcE5Q9opagzpKA3x4vByJdn9PJOdLTK WDwpp1ghJO+w== X-IronPort-AV: E=McAfee;i="6000,8403,9717"; a="156062851" X-IronPort-AV: E=Sophos;i="5.76,328,1592895600"; d="scan'208";a="156062851" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Aug 2020 11:48:15 -0700 IronPort-SDR: cWBVF1DfDv7ERzpS3Zg6X7K51sFh/SKk6VbTnQra1Pb9Bv3lvDG4v6KtVL5Ky32JBKc6XLW8Sh EmysAwh/ehDw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,328,1592895600"; d="scan'208";a="320191197" Received: from viggo.jf.intel.com (HELO localhost.localdomain) ([10.54.77.144]) by fmsmga004.fm.intel.com with ESMTP; 18 Aug 2020 11:48:15 -0700 Subject: [RFC][PATCH 8/9] mm/vmscan: never demote for memcg reclaim To: linux-kernel@vger.kernel.org Cc: Dave Hansen , yang.shi@linux.alibaba.com, rientjes@google.com, ying.huang@intel.com, dan.j.williams@intel.com From: Dave Hansen Date: Tue, 18 Aug 2020 11:41:36 -0700 References: <20200818184122.29C415DF@viggo.jf.intel.com> In-Reply-To: <20200818184122.29C415DF@viggo.jf.intel.com> Message-Id: <20200818184136.7FD537AA@viggo.jf.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dave Hansen Global reclaim aims to reduce the amount of memory used on a given node or set of nodes. Migrating pages to another node serves this purpose. memcg reclaim is different. Its goal is to reduce the total memory consumption of the entire memcg, across all nodes. Migration does not assist memcg reclaim because it just moves page contents between nodes rather than actually reducing memory consumption. Signed-off-by: Dave Hansen Suggested-by: Yang Shi Cc: David Rientjes Cc: Huang Ying Cc: Dan Williams --- b/mm/vmscan.c | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff -puN mm/vmscan.c~never-demote-for-memcg-reclaim mm/vmscan.c --- a/mm/vmscan.c~never-demote-for-memcg-reclaim 2020-08-18 11:36:56.442583170 -0700 +++ b/mm/vmscan.c 2020-08-18 11:36:56.447583170 -0700 @@ -296,8 +296,11 @@ static bool writeback_throttling_sane(st #endif static inline bool can_reclaim_anon_pages(struct mem_cgroup *memcg, - int node_id) + int node_id, + struct scan_control *sc) { + bool in_cgroup_reclaim = false; + /* Always age anon pages when we have swap */ if (memcg == NULL) { if (get_nr_swap_pages() > 0) @@ -307,8 +310,18 @@ static inline bool can_reclaim_anon_page return true; } - /* Also age anon pages if we can auto-migrate them */ - if (next_demotion_node(node_id) >= 0) + /* Can only be in memcg reclaim in paths with valid 'sc': */ + if (sc && cgroup_reclaim(sc)) + in_cgroup_reclaim = true; + + /* + * Also age anon pages if we can auto-migrate them. + * + * Migrating a page does not reduce comsumption of a + * memcg so should not be performed when in memcg + * reclaim. + */ + if (!in_cgroup_reclaim && (next_demotion_node(node_id) >= 0)) return true; /* No way to reclaim anon pages */ @@ -326,7 +339,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 (can_reclaim_anon_pages(NULL, zone_to_nid(zone))) + if (can_reclaim_anon_pages(NULL, zone_to_nid(zone), NULL)) nr += zone_page_state_snapshot(zone, NR_ZONE_INACTIVE_ANON) + zone_page_state_snapshot(zone, NR_ZONE_ACTIVE_ANON); @@ -1070,6 +1083,10 @@ bool migrate_demote_page_ok(struct page VM_BUG_ON_PAGE(PageHuge(page), page); VM_BUG_ON_PAGE(PageLRU(page), page); + /* It is pointless to do demotion in memcg reclaim */ + if (cgroup_reclaim(sc)) + return false; + if (next_nid == NUMA_NO_NODE) return false; if (PageTransHuge(page) && !thp_migration_supported()) @@ -2369,7 +2386,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 || !can_reclaim_anon_pages(memcg, pgdat->node_id)) { + if (!sc->may_swap || !can_reclaim_anon_pages(memcg, pgdat->node_id, sc)) { scan_balance = SCAN_FILE; goto out; } @@ -2653,7 +2670,7 @@ static void shrink_lruvec(struct lruvec * rebalance the anon lru active/inactive ratio. */ if (can_reclaim_anon_pages(lruvec_memcg(lruvec), - lruvec_pgdat(lruvec)->node_id) && + lruvec_pgdat(lruvec)->node_id, sc) && inactive_is_low(lruvec, LRU_INACTIVE_ANON)) shrink_active_list(SWAP_CLUSTER_MAX, lruvec, sc, LRU_ACTIVE_ANON); @@ -2724,7 +2741,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 (can_reclaim_anon_pages(NULL, pgdat->node_id)) + if (can_reclaim_anon_pages(NULL, pgdat->node_id, sc)) inactive_lru_pages += node_page_state(pgdat, NR_INACTIVE_ANON); return inactive_lru_pages > pages_for_compaction; @@ -3485,7 +3502,7 @@ static void age_active_anon(struct pglis struct mem_cgroup *memcg; struct lruvec *lruvec; - if (!can_reclaim_anon_pages(NULL, pgdat->node_id)) + if (!can_reclaim_anon_pages(NULL, pgdat->node_id, sc)) return; lruvec = mem_cgroup_lruvec(NULL, pgdat); _