Subject: [PATCH 2376/2944] mm/memory: fix IO cost for anonymous page

From: Joonsoo Kim <[email-masked]>
Date: Thu, 25 Jun 2020 20:30:37 -0700

task #31256938

commit 0076f029cb2906d32baf3bf4401ef09663071d16 upstream

With synchronous IO swap device, swap-in is directly handled in fault
code.  Since IO cost notation isn't added there, with synchronous IO
swap device, LRU balancing could be wrongly biased.  Fix it to count it
in fault code.

Link: http://lkml.kernel.org/r/[email-masked]
Fixes: 314b57fb0460001 ("mm: balance LRU lists based on relative thrashing cache sizing")
Signed-off-by: Joonsoo Kim <[email-masked]>
Acked-by: Johannes Weiner <[email-masked]>
Cc: Joonsoo Kim <[email-masked]>
Cc: Michal Hocko <[email-masked]>
Cc: Minchan Kim <[email-masked]>
Cc: Rik van Riel <[email-masked]>
Signed-off-by: Andrew Morton <[email-masked]>
Signed-off-by: Linus Torvalds <[email-masked]>
Signed-off-by: zhongjiang-ali <[email-masked]>
Reviewed-by: Xunlei Pang <[email-masked]>
---
 mm/memory.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/mm/memory.c b/mm/memory.c
index dde0e79..7e6107b 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -2980,6 +2980,14 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)
 					goto out_page;
 				}
 
+				/*
+				 * XXX: Move to lru_cache_add() when it
+				 * supports new vs putback
+				 */
+				spin_lock_irq(&page_pgdat(page)->lru_lock);
+				lru_note_cost_page(page);
+				spin_unlock_irq(&page_pgdat(page)->lru_lock);
+
 				lru_cache_add(page);
 				swap_readpage(page, true);
 			}
-- 
1.8.3.1