@@ -108,6 +108,9 @@ struct scan_control {
/* Can folios be swapped as part of reclaim? */
unsigned int may_swap:1;
+ /* Can cache_trim_mode be turned on as part of reclaim? */
+ unsigned int may_cache_trim_mode:1;
+
/* Proactive reclaim invoked by userspace through memory.reclaim */
unsigned int proactive:1;
@@ -2268,7 +2271,8 @@ static void prepare_scan_control(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) &&
+ sc->may_cache_trim_mode)
sc->cache_trim_mode = 1;
else
sc->cache_trim_mode = 0;
@@ -6744,6 +6748,7 @@ static int balance_pgdat(pg_data_t *pgdat, int order, int highest_zoneidx)
.gfp_mask = GFP_KERNEL,
.order = order,
.may_unmap = 1,
+ .may_cache_trim_mode = 1,
};
set_task_reclaim_state(current, &sc.reclaim_state);
@@ -6898,8 +6903,14 @@ static int balance_pgdat(pg_data_t *pgdat, int order, int highest_zoneidx)
sc.priority--;
} while (sc.priority >= 1);
- if (!sc.nr_reclaimed)
+ if (!sc.nr_reclaimed) {
+ if (sc.may_cache_trim_mode) {
+ sc.may_cache_trim_mode = 0;
+ goto restart;
+ }
+
pgdat->kswapd_failures++;
+ }
out:
clear_reclaim_active(pgdat, highest_zoneidx);