[PATCH] mm/vmscan: don't scan adjust too much if current is not kswapd

From: Hongchen Zhang
Date: Tue Sep 13 2022 - 22:33:47 EST


when a process falls into page fault and there is not enough free
memory,it will do direct reclaim. At the same time,it is holding
mmap_lock.So in case of multi-thread,it should exit from page fault
ASAP.
When reclaim memory,we do scan adjust between anon and file lru which
may cost too much time and trigger hung task for other thread.So for a
process which is not kswapd,it should just do a little scan adjust.

Signed-off-by: Hongchen Zhang <zhanghongchen@xxxxxxxxxxx>
---
mm/vmscan.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index b2b1431352dc..07fb58db812b 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -3042,11 +3042,17 @@ static void shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc)
nr[lru] = targets[lru] * (100 - percentage) / 100;
nr[lru] -= min(nr[lru], nr_scanned);

+ if (!current_is_kswapd())
+ nr[lru] = min(nr[lru], nr_to_reclaim);
+
lru += LRU_ACTIVE;
nr_scanned = targets[lru] - nr[lru];
nr[lru] = targets[lru] * (100 - percentage) / 100;
nr[lru] -= min(nr[lru], nr_scanned);

+ if (!current_is_kswapd())
+ nr[lru] = min(nr[lru], nr_to_reclaim);
+
scan_adjusted = true;
}
blk_finish_plug(&plug);
--
2.34.1