[v3 PATCH 6/9] mm: vmscan: don't demote for memcg reclaim

From: Yang Shi
Date: Thu Jun 13 2019 - 19:35:13 EST


The memcg reclaim happens when the limit is breached, but demotion just
migrate pages to the other node instead of reclaiming them. This sounds
pointless to memcg reclaim since the usage is not reduced at all.

Signed-off-by: Yang Shi <yang.shi@xxxxxxxxxxxxxxxxx>
---
mm/vmscan.c | 38 +++++++++++++++++++++-----------------
1 file changed, 21 insertions(+), 17 deletions(-)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 428a83b..fb931ded 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -1126,12 +1126,16 @@ static inline struct page *alloc_demote_page(struct page *page,
}
#endif

-static inline bool is_demote_ok(int nid)
+static inline bool is_demote_ok(int nid, struct scan_control *sc)
{
/* Just do demotion with migrate mode of node reclaim */
if (!(node_reclaim_mode & RECLAIM_MIGRATE))
return false;

+ /* It is pointless to do demotion in memcg reclaim */
+ if (!global_reclaim(sc))
+ return false;
+
/* Current node is cpuless node */
if (!node_state(nid, N_CPU_MEM))
return false;
@@ -1326,7 +1330,7 @@ static unsigned long shrink_page_list(struct list_head *page_list,
* Demotion only happen from primary nodes
* to cpuless nodes.
*/
- if (is_demote_ok(page_to_nid(page))) {
+ if (is_demote_ok(page_to_nid(page), sc)) {
list_add(&page->lru, &demote_pages);
unlock_page(page);
continue;
@@ -2226,7 +2230,7 @@ static bool inactive_list_is_low(struct lruvec *lruvec, bool file,
* anonymous page deactivation is pointless.
*/
if (!file && !total_swap_pages &&
- !is_demote_ok(pgdat->node_id))
+ !is_demote_ok(pgdat->node_id, sc))
return false;

inactive = lruvec_lru_size(lruvec, inactive_lru, sc->reclaim_idx);
@@ -2307,7 +2311,7 @@ static void get_scan_count(struct lruvec *lruvec, struct mem_cgroup *memcg,
*
* If current node is already PMEM node, demotion is not applicable.
*/
- if (!is_demote_ok(pgdat->node_id)) {
+ if (!is_demote_ok(pgdat->node_id, sc)) {
/*
* If we have no swap space, do not bother scanning
* anon pages.
@@ -2316,18 +2320,18 @@ static void get_scan_count(struct lruvec *lruvec, struct mem_cgroup *memcg,
scan_balance = SCAN_FILE;
goto out;
}
+ }

- /*
- * Global reclaim will swap to prevent OOM even with no
- * swappiness, but memcg users want to use this knob to
- * disable swapping for individual groups completely when
- * using the memory controller's swap limit feature would be
- * too expensive.
- */
- if (!global_reclaim(sc) && !swappiness) {
- scan_balance = SCAN_FILE;
- goto out;
- }
+ /*
+ * Global reclaim will swap to prevent OOM even with no
+ * swappiness, but memcg users want to use this knob to
+ * disable swapping for individual groups completely when
+ * using the memory controller's swap limit feature would be
+ * too expensive.
+ */
+ if (!global_reclaim(sc) && !swappiness) {
+ scan_balance = SCAN_FILE;
+ goto out;
}

/*
@@ -2676,7 +2680,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 (get_nr_swap_pages() > 0 || is_demote_ok(pgdat->node_id))
+ if (get_nr_swap_pages() > 0 || is_demote_ok(pgdat->node_id, sc))
inactive_lru_pages += node_page_state(pgdat, NR_INACTIVE_ANON);
if (sc->nr_reclaimed < pages_for_compaction &&
inactive_lru_pages > pages_for_compaction)
@@ -3362,7 +3366,7 @@ static void age_active_anon(struct pglist_data *pgdat,
struct mem_cgroup *memcg;

/* Aging anon page as long as demotion is fine */
- if (!total_swap_pages && !is_demote_ok(pgdat->node_id))
+ if (!total_swap_pages && !is_demote_ok(pgdat->node_id, sc))
return;

memcg = mem_cgroup_iter(NULL, NULL, NULL);
--
1.8.3.1