[PATCH -V8 09/10] mm/vmscan: never demote for memcg reclaim

From: Huang Ying
Date: Fri Jun 18 2021 - 02:21:20 EST


From: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>

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 <dave.hansen@xxxxxxxxxxxxxxx>
Signed-off-by: "Huang, Ying" <ying.huang@xxxxxxxxx>
Suggested-by: Yang Shi <yang.shi@xxxxxxxxxxxxxxxxx>
Reviewed-by: Yang Shi <shy828301@xxxxxxxxx>
Cc: Michal Hocko <mhocko@xxxxxxxx>
Cc: Wei Xu <weixugc@xxxxxxxxxx>
Cc: David Rientjes <rientjes@xxxxxxxxxx>
Cc: Dan Williams <dan.j.williams@xxxxxxxxx>
Cc: David Hildenbrand <david@xxxxxxxxxx>
Cc: osalvador <osalvador@xxxxxxx>
---
mm/vmscan.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index bf52329f29dd..13a60426c12f 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -517,7 +517,8 @@ static long add_nr_deferred(long nr, struct shrinker *shrinker,
}

static inline bool can_reclaim_anon_pages(struct mem_cgroup *memcg,
- int node_id)
+ int node_id,
+ struct scan_control *sc)
{
if (memcg == NULL) {
/*
@@ -555,7 +556,7 @@ unsigned long zone_reclaimable_pages(struct zone *zone)

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);

@@ -1260,7 +1261,8 @@ static enum page_references page_check_references(struct page *page,
return PAGEREF_RECLAIM;
}

-static bool migrate_demote_page_ok(struct page *page)
+static bool migrate_demote_page_ok(struct page *page,
+ struct scan_control *sc)
{
int next_nid = next_demotion_node(page_to_nid(page));

@@ -1268,6 +1270,10 @@ static bool migrate_demote_page_ok(struct page *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())
@@ -1525,7 +1531,7 @@ static unsigned int shrink_page_list(struct list_head *page_list,
* Before reclaiming the page, try to relocate
* its contents to another node.
*/
- if (do_demote_pass && migrate_demote_page_ok(page)) {
+ if (do_demote_pass && migrate_demote_page_ok(page, sc)) {
list_add(&page->lru, &demote_pages);
unlock_page(page);
continue;
@@ -2560,7 +2566,7 @@ static void get_scan_count(struct lruvec *lruvec, struct scan_control *sc,
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;
}
@@ -2935,7 +2941,7 @@ static inline bool should_continue_reclaim(struct pglist_data *pgdat,
*/
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;
--
2.30.2