[RFC,v1,3/4] mm: Fix demotion-only scanning anon pages

Message ID 20221122203850.2765015-3-almasrymina@google.com
State New
Headers
Series [RFC,v1] mm: Add memory.demote for proactive demotion only |

Commit Message

Mina Almasry Nov. 22, 2022, 8:38 p.m. UTC
  This is likely a missed change from commit a2a36488a61c ("mm/vmscan: Consider
anonymous pages without swap"). Current logic is if !may_swap _or_
!can_reclaim_anon_pages() then we don't scan anon memory.

This should be an 'and'. We would like to scan anon memory if we may swap
or if we can_reclaim_anon_pages().

Fixes: commit a2a36488a61c ("mm/vmscan: Consider anonymous pages without swap")

Signed-off-by: Mina Almasry <almasrymina@google.com>
---
 mm/vmscan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--
2.38.1.584.g0f3c55d4c2-goog
  

Comments

Huang, Ying Nov. 24, 2022, 5:27 a.m. UTC | #1
Mina Almasry <almasrymina@google.com> writes:

> This is likely a missed change from commit a2a36488a61c ("mm/vmscan: Consider
> anonymous pages without swap"). Current logic is if !may_swap _or_
> !can_reclaim_anon_pages() then we don't scan anon memory.
>
> This should be an 'and'. We would like to scan anon memory if we may swap
> or if we can_reclaim_anon_pages().
>
> Fixes: commit a2a36488a61c ("mm/vmscan: Consider anonymous pages without swap")
>
> Signed-off-by: Mina Almasry <almasrymina@google.com>
> ---
>  mm/vmscan.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/vmscan.c b/mm/vmscan.c
> index 8c1f5416d789..d7e509b3f07f 100644
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -2931,7 +2931,7 @@ static void get_scan_count(struct lruvec *lruvec, struct scan_control *sc,
>  	enum lru_list lru;
>
>  	/* If we have no swap space, do not bother scanning anon folios. */
> -	if (!sc->may_swap || !can_reclaim_anon_pages(memcg, pgdat->node_id, sc)) {
> +	if (!sc->may_swap && !can_reclaim_anon_pages(memcg, pgdat->node_id, sc)) {

If there is only DRAM but swap device is enabled, sc->may_swap will not
work as expected.  So we should check can_demote() instead if
sc->may_swap.

Best Regards,
Huang, Ying

>  		scan_balance = SCAN_FILE;
>  		goto out;
>  	}
> --
> 2.38.1.584.g0f3c55d4c2-goog
  

Patch

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 8c1f5416d789..d7e509b3f07f 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -2931,7 +2931,7 @@  static void get_scan_count(struct lruvec *lruvec, struct scan_control *sc,
 	enum lru_list lru;

 	/* If we have no swap space, do not bother scanning anon folios. */
-	if (!sc->may_swap || !can_reclaim_anon_pages(memcg, pgdat->node_id, sc)) {
+	if (!sc->may_swap && !can_reclaim_anon_pages(memcg, pgdat->node_id, sc)) {
 		scan_balance = SCAN_FILE;
 		goto out;
 	}