[PATCH v14-fix 11/11] mm: multi-gen LRU: refactor get_nr_evictable()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The previous commit made this refactor possible: 28 insertions and 36
deletions.

Signed-off-by: Yu Zhao <yuzhao@xxxxxxxxxx>
---
 mm/vmscan.c | 64 +++++++++++++++++++++++------------------------------
 1 file changed, 28 insertions(+), 36 deletions(-)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 50764b2d462f..a8fd6300fa7e 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -4418,14 +4418,15 @@ static bool try_to_inc_max_seq(struct lruvec *lruvec, unsigned long max_seq,
 	return true;
 }
 
-static unsigned long get_nr_evictable(struct lruvec *lruvec, unsigned long max_seq,
-				      unsigned long *min_seq, bool can_swap, bool *need_aging)
+static bool should_run_aging(struct lruvec *lruvec, unsigned long max_seq, unsigned long *min_seq,
+			     struct scan_control *sc, bool can_swap, unsigned long *nr_to_scan)
 {
 	int gen, type, zone;
 	unsigned long old = 0;
 	unsigned long young = 0;
 	unsigned long total = 0;
 	struct lru_gen_struct *lrugen = &lruvec->lrugen;
+	struct mem_cgroup *memcg = lruvec_memcg(lruvec);
 
 	for (type = !can_swap; type < ANON_AND_FILE; type++) {
 		unsigned long seq;
@@ -4441,35 +4442,37 @@ static unsigned long get_nr_evictable(struct lruvec *lruvec, unsigned long max_s
 			total += size;
 			if (seq == max_seq)
 				young += size;
-			if (seq + MIN_NR_GENS == max_seq)
+			else if (seq + MIN_NR_GENS == max_seq)
 				old += size;
 		}
 	}
 
+	/* try to scrape all its memory if this memcg was deleted */
+	*nr_to_scan = mem_cgroup_online(memcg) ? (total >> sc->priority) : total;
+
 	/*
-	 * The aging tries to be lazy to reduce the overhead. On the other hand,
-	 * the eviction stalls when the number of generations reaches
-	 * MIN_NR_GENS. So ideally, there should be MIN_NR_GENS+1 generations,
-	 * hence the first two if's.
-	 *
-	 * Also it's ideal to spread pages out evenly, meaning 1/(MIN_NR_GENS+1)
+	 * The aging tries to be lazy to reduce the overhead, while the eviction
+	 * stalls when the number of generations reaches MIN_NR_GENS. Hence, the
+	 * ideal number of generations is MIN_NR_GENS+1.
+	 */
+	if (min_seq[!can_swap] + MIN_NR_GENS > max_seq)
+		return true;
+	if (min_seq[!can_swap] + MIN_NR_GENS < max_seq)
+		return false;
+
+	/*
+	 * It's also ideal to spread pages out evenly, i.e., 1/(MIN_NR_GENS+1)
 	 * of the total number of pages for each generation. A reasonable range
 	 * for this average portion is [1/MIN_NR_GENS, 1/(MIN_NR_GENS+2)]. The
-	 * eviction cares about the lower bound of cold pages, whereas the aging
-	 * cares about the upper bound of hot pages.
+	 * aging cares about the upper bound of hot pages, while the eviction
+	 * cares about the lower bound of cold pages.
 	 */
-	if (min_seq[!can_swap] + MIN_NR_GENS > max_seq)
-		*need_aging = true;
-	else if (min_seq[!can_swap] + MIN_NR_GENS < max_seq)
-		*need_aging = false;
-	else if (young * MIN_NR_GENS > total)
-		*need_aging = true;
-	else if (old * (MIN_NR_GENS + 2) < total)
-		*need_aging = true;
-	else
-		*need_aging = false;
+	if (young * MIN_NR_GENS > total)
+		return true;
+	if (old * (MIN_NR_GENS + 2) < total)
+		return true;
 
-	return total;
+	return false;
 }
 
 static bool age_lruvec(struct lruvec *lruvec, struct scan_control *sc, unsigned long min_ttl)
@@ -4488,11 +4491,7 @@ static bool age_lruvec(struct lruvec *lruvec, struct scan_control *sc, unsigned
 	if (mem_cgroup_below_min(memcg))
 		return false;
 
-	nr_to_scan = get_nr_evictable(lruvec, max_seq, min_seq, swappiness, &need_aging);
-	if (!nr_to_scan)
-		return false;
-
-	nr_to_scan >>= mem_cgroup_online(memcg) ? sc->priority : 0;
+	need_aging = should_run_aging(lruvec, max_seq, min_seq, sc, swappiness, &nr_to_scan);
 
 	if (min_ttl) {
 		int gen = lru_gen_from_seq(min_seq[LRU_GEN_FILE]);
@@ -4506,7 +4505,7 @@ static bool age_lruvec(struct lruvec *lruvec, struct scan_control *sc, unsigned
 			return false;
 	}
 
-	if (nr_to_scan && need_aging)
+	if (need_aging)
 		try_to_inc_max_seq(lruvec, max_seq, sc, swappiness, false);
 
 	return true;
@@ -5054,14 +5053,7 @@ static unsigned long get_nr_to_scan(struct lruvec *lruvec, struct scan_control *
 	    (mem_cgroup_below_low(memcg) && !sc->memcg_low_reclaim))
 		return 0;
 
-	nr_to_scan = get_nr_evictable(lruvec, max_seq, min_seq, can_swap, need_aging);
-	if (!nr_to_scan)
-		return 0;
-
-	nr_to_scan >>= mem_cgroup_online(memcg) ? sc->priority : 0;
-	if (!nr_to_scan)
-		return 0;
-
+	*need_aging = should_run_aging(lruvec, max_seq, min_seq, sc, can_swap, &nr_to_scan);
 	if (!*need_aging)
 		return nr_to_scan;
 
-- 
2.37.3.968.ga6b4b080e4-goog





[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux