damon.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] mm/damon/paddr: fix missing folio_put()
@ 2023-02-22  6:42 Andrew Yang
  2023-02-22 18:26 ` SeongJae Park
  0 siblings, 1 reply; 2+ messages in thread
From: Andrew Yang @ 2023-02-22  6:42 UTC (permalink / raw)
  To: SeongJae Park, Andrew Morton, Matthias Brugger,
	AngeloGioacchino Del Regno
  Cc: wsd_upstream, casper.li, andrew.yang, stable, damon, linux-mm,
	linux-kernel, linux-arm-kernel, linux-mediatek

From: "andrew.yang" <andrew.yang@mediatek.com>

damon_get_folio() would always increase folio _refcount and
folio_isolate_lru() would increase folio _refcount if the folio's lru
flag is set.

If an unevictable folio isolated successfully, there will be two more
_refcount. The one from folio_isolate_lru() will be decreased in
folio_puback_lru(), but the other one from damon_get_folio() will be
left behind. This causes a pin page.

Whatever the case, the _refcount from damon_get_folio() should be
decreased.

Signed-off-by: andrew.yang <andrew.yang@mediatek.com>
Fixes: 57223ac29584 ("mm/damon/paddr: support the pageout scheme")
Cc: <stable@vger.kernel.org> # 5.16.x
---
v3:
  add fixes tag and cc stable
v2:
  according to David's suggestion
    1. revise subject
  according to SeongJae's suggestions
    1. rebase to mm-unstable tree 
    2. remove braces for th single statements
---
 mm/damon/paddr.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
index 607bb69e526c..6c655d9b5639 100644
--- a/mm/damon/paddr.c
+++ b/mm/damon/paddr.c
@@ -250,12 +250,11 @@ static unsigned long damon_pa_pageout(struct damon_region *r, struct damos *s)
 			folio_put(folio);
 			continue;
 		}
-		if (folio_test_unevictable(folio)) {
+		if (folio_test_unevictable(folio))
 			folio_putback_lru(folio);
-		} else {
+		else
 			list_add(&folio->lru, &folio_list);
-			folio_put(folio);
-		}
+		folio_put(folio);
 	}
 	applied = reclaim_pages(&folio_list);
 	cond_resched();
-- 
2.18.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v3] mm/damon/paddr: fix missing folio_put()
  2023-02-22  6:42 [PATCH v3] mm/damon/paddr: fix missing folio_put() Andrew Yang
@ 2023-02-22 18:26 ` SeongJae Park
  0 siblings, 0 replies; 2+ messages in thread
From: SeongJae Park @ 2023-02-22 18:26 UTC (permalink / raw)
  Cc: SeongJae Park, Andrew Morton, Matthias Brugger,
	AngeloGioacchino Del Regno, wsd_upstream, casper.li,
	andrew . yang, stable, damon, linux-mm, linux-kernel,
	linux-arm-kernel, linux-mediatek

Hi Andrew,


Thank you for revising this patch!

> From: "andrew.yang" <andrew.yang@mediatek.com>
> 
> damon_get_folio() would always increase folio _refcount and
> folio_isolate_lru() would increase folio _refcount if the folio's lru
> flag is set.
> 
> If an unevictable folio isolated successfully, there will be two more
> _refcount. The one from folio_isolate_lru() will be decreased in
> folio_puback_lru(), but the other one from damon_get_folio() will be
> left behind. This causes a pin page.
> 
> Whatever the case, the _refcount from damon_get_folio() should be
> decreased.
> 
> Signed-off-by: andrew.yang <andrew.yang@mediatek.com>
> Fixes: 57223ac29584 ("mm/damon/paddr: support the pageout scheme")
> Cc: <stable@vger.kernel.org> # 5.16.x

Reviewed-by: SeongJae Park <sj@kernel.org>

This may not cleanly applicable on 6.1.y and 6.2.y.  I would post backports
once this is merged in the mainline, unless others do earlier than me.


Thanks,
SJ

> ---
> v3:
>   add fixes tag and cc stable
> v2:
>   according to David's suggestion
>     1. revise subject
>   according to SeongJae's suggestions
>     1. rebase to mm-unstable tree 
>     2. remove braces for th single statements
> ---
>  mm/damon/paddr.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
> index 607bb69e526c..6c655d9b5639 100644
> --- a/mm/damon/paddr.c
> +++ b/mm/damon/paddr.c
> @@ -250,12 +250,11 @@ static unsigned long damon_pa_pageout(struct damon_region *r, struct damos *s)
>  			folio_put(folio);
>  			continue;
>  		}
> -		if (folio_test_unevictable(folio)) {
> +		if (folio_test_unevictable(folio))
>  			folio_putback_lru(folio);
> -		} else {
> +		else
>  			list_add(&folio->lru, &folio_list);
> -			folio_put(folio);
> -		}
> +		folio_put(folio);
>  	}
>  	applied = reclaim_pages(&folio_list);
>  	cond_resched();
> -- 
> 2.18.0
> 
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-02-22 18:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-22  6:42 [PATCH v3] mm/damon/paddr: fix missing folio_put() Andrew Yang
2023-02-22 18:26 ` SeongJae Park

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).