diff mbox series

[RFC] mm: set cache_trim_mode when inactive ratio is undesired

Message ID 1658387208-20065-1-git-send-email-zhaoyang.huang@unisoc.com (mailing list archive)
State New
Headers show
Series [RFC] mm: set cache_trim_mode when inactive ratio is undesired | expand

Commit Message

zhaoyang.huang July 21, 2022, 7:06 a.m. UTC
From: Zhaoyang Huang <zhaoyang.huang@unisoc.com>

Undesirable inactive file ratio could be observed under some scenarios(such as
large number of mapped file access) and hardly recover during a certain period
of time, which could be a result of tight criteria judgement of cache_trim_mode,
which demand both of none-thrashing and inactive_is_low simutaneously and lead
to the mode as SCAN_FRAC or SCAN_EQUAL when scanning lru.

Signed-off-by: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
---
 mm/vmscan.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

Comments

Matthew Wilcox (Oracle) July 21, 2022, 2:20 p.m. UTC | #1
On Thu, Jul 21, 2022 at 03:06:48PM +0800, zhaoyang.huang wrote:
> @@ -3198,7 +3215,8 @@ static void shrink_node(pg_data_t *pgdat, struct scan_control *sc)
>  	 * anonymous pages.
>  	 */
>  	file = lruvec_page_state(target_lruvec, NR_INACTIVE_FILE);
> -	if (file >> sc->priority && !(sc->may_deactivate & DEACTIVATE_FILE))
> +	if (file >> sc->priority && (!(sc->may_deactivate & DEACTIVATE_FILE)
> +		|| inactive_is_high(target_lruvec, LRU_INACTIVE_FILE)))

Indentation is weird here.  When splitting a line, put the operator at
the end, and then indent the rest by something *other* than a single
tab, so it doesn't look like it's part of the following statement.  ie
either:

	if (file >> sc->priority && (!(sc->may_deactivate & DEACTIVATE_FILE) ||
	    inactive_is_high(target_lruvec, LRU_INACTIVE_FILE)))

or:

	if (file >> sc->priority && (!(sc->may_deactivate & DEACTIVATE_FILE) ||
			inactive_is_high(target_lruvec, LRU_INACTIVE_FILE)))

Some people like to use the indentation to illustrate the precendence.
That would look like this:

	if (file >> sc->priority &&
	    (!(sc->may_deactivate & DEACTIVATE_FILE) ||
	     inactive_is_high(target_lruvec, LRU_INACTIVE_FILE)))

(I have a mild preference for the third option in this instance)

>  		sc->cache_trim_mode = 1;
>  	else
>  		sc->cache_trim_mode = 0;
> -- 
> 1.9.1
> 
>
diff mbox series

Patch

diff --git a/mm/vmscan.c b/mm/vmscan.c
index f7d9a68..8e84fe6 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -2663,6 +2663,23 @@  static bool inactive_is_low(struct lruvec *lruvec, enum lru_list inactive_lru)
 	return inactive * inactive_ratio < active;
 }
 
+static bool inactive_is_high(struct lruvec *lruvec, enum lru_list inactive_lru)
+{
+	enum lru_list active_lru = inactive_lru + LRU_ACTIVE;
+	unsigned long inactive, active;
+	unsigned long active_ratio = 2;
+	unsigned long gb;
+
+	inactive = lruvec_page_state(lruvec, NR_LRU_BASE + inactive_lru);
+	active = lruvec_page_state(lruvec, NR_LRU_BASE + active_lru);
+
+	gb = (inactive + active) >> (30 - PAGE_SHIFT);
+	if (gb)
+		active_ratio = 1;
+
+	return inactive > active_ratio * active;
+}
+
 enum scan_balance {
 	SCAN_EQUAL,
 	SCAN_FRACT,
@@ -3198,7 +3215,8 @@  static void shrink_node(pg_data_t *pgdat, struct scan_control *sc)
 	 * anonymous pages.
 	 */
 	file = lruvec_page_state(target_lruvec, NR_INACTIVE_FILE);
-	if (file >> sc->priority && !(sc->may_deactivate & DEACTIVATE_FILE))
+	if (file >> sc->priority && (!(sc->may_deactivate & DEACTIVATE_FILE)
+		|| inactive_is_high(target_lruvec, LRU_INACTIVE_FILE)))
 		sc->cache_trim_mode = 1;
 	else
 		sc->cache_trim_mode = 0;