Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] mm/damon/paddr: skip non-LRU folios as a whole in pageout
@ 2026-11-17 16:24 Aveline Noir
  2026-11-18 14:16 ` Enze Li
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Aveline Noir @ 2026-11-17 16:24 UTC (permalink / raw)
  To: SJ Park
  Cc: Andrew Morton, damon, linux-mm, linux-kernel, sashiko-bot,
	sashiko-reviews

damon_pa_pageout() uses damon_get_folio(), which rejects folios that are
not on the LRU.  For a large non-LRU folio such as a hugetlb folio, the
loop then looks up the same folio once per base page even though
pageout cannot reclaim it.

Use damon_get_monitor_folio() and skip any returned non-LRU folio as a
whole by advancing to its end.  Do this before the filters, the
accounting and the last_applied check, so that adjacent regions within
the same non-LRU folio are not walked by base page either.

In an x86-64 KVM pageout microbenchmark, traversal time dropped by
about 99.7% for regions covering whole 2 MiB hugetlb folios. For
4 KiB regions within hugetlb folios, traversal took about 1 ns more
per region.

Signed-off-by: Aveline Noir <jm5905938@gmail.com>
---
Tested in x86-64 KVM guests.  DAMON KUnit tests all passed.  Ordinary-page
and THP controls passed the 3% non-inferiority bound in the microbenchmark.

Changes in v2:
- Drop the redundant hugetlb check and update the subject and description
  as suggested by SJ.
---
 mm/damon/paddr.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
index 5b773012a876..0a205fa8d468 100644
--- a/mm/damon/paddr.c
+++ b/mm/damon/paddr.c
@@ -268,7 +268,9 @@ static unsigned long damon_pa_pageout(struct damon_region *r,
 
 	addr = damon_pa_phys_addr(r->ar.start, addr_unit);
 	while (addr < damon_pa_phys_addr(r->ar.end, addr_unit)) {
-		folio = damon_get_folio(PHYS_PFN(addr));
+		folio = damon_get_monitor_folio(PHYS_PFN(addr));
+		if (folio && !folio_test_lru(folio))
+			goto put_folio;
 		if (damon_pa_invalid_damos_folio(folio, s)) {
 			addr += PAGE_SIZE;
 			continue;

---
base-commit: 67f3b04b277373438f17300e056306adbd9edf7b
change-id: 20261117-fix-damon-hugetlb-pageout-20261117-a4e03d9d5a5b

Best regards,
--  
Aveline Noir <jm5905938@gmail.com>



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

* Re: [PATCH v2] mm/damon/paddr: skip non-LRU folios as a whole in pageout
  2026-11-17 16:24 [PATCH v2] mm/damon/paddr: skip non-LRU folios as a whole in pageout Aveline Noir
@ 2026-11-18 14:16 ` Enze Li
  2026-11-18 14:33 ` SJ Park
  2026-11-18 14:36 ` SJ Park
  2 siblings, 0 replies; 4+ messages in thread
From: Enze Li @ 2026-11-18 14:16 UTC (permalink / raw)
  To: Aveline Noir, SJ Park
  Cc: Andrew Morton, damon, linux-mm, linux-kernel, sashiko-bot,
	sashiko-reviews

On 2026/11/18 00:24, Aveline Noir wrote:
> damon_pa_pageout() uses damon_get_folio(), which rejects folios that are
> not on the LRU.  For a large non-LRU folio such as a hugetlb folio, the
> loop then looks up the same folio once per base page even though
> pageout cannot reclaim it.
> 
> Use damon_get_monitor_folio() and skip any returned non-LRU folio as a
> whole by advancing to its end.  Do this before the filters, the
> accounting and the last_applied check, so that adjacent regions within
> the same non-LRU folio are not walked by base page either.
> 
> In an x86-64 KVM pageout microbenchmark, traversal time dropped by
> about 99.7% for regions covering whole 2 MiB hugetlb folios. For
> 4 KiB regions within hugetlb folios, traversal took about 1 ns more
> per region.

Good catch -- thanks for looking into this.

> 
> Signed-off-by: Aveline Noir <jm5905938@gmail.com>

Reviewed-by: Enze Li <lienze@kylinos.cn>

Thanks,
Enze

> ---
> Tested in x86-64 KVM guests.  DAMON KUnit tests all passed.  Ordinary-page
> and THP controls passed the 3% non-inferiority bound in the microbenchmark.
> 
> Changes in v2:
> - Drop the redundant hugetlb check and update the subject and description
>   as suggested by SJ.
> ---
>  mm/damon/paddr.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
> index 5b773012a876..0a205fa8d468 100644
> --- a/mm/damon/paddr.c
> +++ b/mm/damon/paddr.c
> @@ -268,7 +268,9 @@ static unsigned long damon_pa_pageout(struct damon_region *r,
>  
>  	addr = damon_pa_phys_addr(r->ar.start, addr_unit);
>  	while (addr < damon_pa_phys_addr(r->ar.end, addr_unit)) {
> -		folio = damon_get_folio(PHYS_PFN(addr));
> +		folio = damon_get_monitor_folio(PHYS_PFN(addr));
> +		if (folio && !folio_test_lru(folio))
> +			goto put_folio;
>  		if (damon_pa_invalid_damos_folio(folio, s)) {
>  			addr += PAGE_SIZE;
>  			continue;
> 
> ---
> base-commit: 67f3b04b277373438f17300e056306adbd9edf7b
> change-id: 20261117-fix-damon-hugetlb-pageout-20261117-a4e03d9d5a5b
> 
> Best regards,
> --  
> Aveline Noir <jm5905938@gmail.com>
> 



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

* Re: [PATCH v2] mm/damon/paddr: skip non-LRU folios as a whole in pageout
  2026-11-17 16:24 [PATCH v2] mm/damon/paddr: skip non-LRU folios as a whole in pageout Aveline Noir
  2026-11-18 14:16 ` Enze Li
@ 2026-11-18 14:33 ` SJ Park
  2026-11-18 14:36 ` SJ Park
  2 siblings, 0 replies; 4+ messages in thread
From: SJ Park @ 2026-11-18 14:33 UTC (permalink / raw)
  To: Aveline Noir
  Cc: SJ Park, Andrew Morton, damon, linux-mm, linux-kernel,
	sashiko-bot, sashiko-reviews

On Wed, 18 Nov 2026 03:24:28 +1100 Aveline Noir <jm5905938@gmail.com> wrote:

> damon_pa_pageout() uses damon_get_folio(), which rejects folios that are
> not on the LRU.  For a large non-LRU folio such as a hugetlb folio, the
> loop then looks up the same folio once per base page even though
> pageout cannot reclaim it.
> 
> Use damon_get_monitor_folio() and skip any returned non-LRU folio as a
> whole by advancing to its end.  Do this before the filters, the
> accounting and the last_applied check, so that adjacent regions within
> the same non-LRU folio are not walked by base page either.
> 
> In an x86-64 KVM pageout microbenchmark, traversal time dropped by
> about 99.7% for regions covering whole 2 MiB hugetlb folios. For
> 4 KiB regions within hugetlb folios, traversal took about 1 ns more
> per region.

Looks good to me.

> 
> Signed-off-by: Aveline Noir <jm5905938@gmail.com>

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

This patch is applied to damon/next [1] tree.  I will repost it soon (~1 week)
as an mm.git merge request.  So, no action from your side is needed for now.

[1] https://origin.kernel.org/doc/html/latest/mm/damon/maintainer-profile.html#scm-trees


Thanks,
SJ

[...]


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

* Re: [PATCH v2] mm/damon/paddr: skip non-LRU folios as a whole in pageout
  2026-11-17 16:24 [PATCH v2] mm/damon/paddr: skip non-LRU folios as a whole in pageout Aveline Noir
  2026-11-18 14:16 ` Enze Li
  2026-11-18 14:33 ` SJ Park
@ 2026-11-18 14:36 ` SJ Park
  2 siblings, 0 replies; 4+ messages in thread
From: SJ Park @ 2026-11-18 14:36 UTC (permalink / raw)
  To: Aveline Noir
  Cc: SJ Park, Andrew Morton, damon, linux-mm, linux-kernel,
	sashiko-bot, sashiko-reviews

On Wed, 18 Nov 2026 03:24:28 +1100 Aveline Noir <jm5905938@gmail.com> wrote:

> damon_pa_pageout() uses damon_get_folio(), which rejects folios that are
> not on the LRU.  For a large non-LRU folio such as a hugetlb folio, the
> loop then looks up the same folio once per base page even though
> pageout cannot reclaim it.
> 
> Use damon_get_monitor_folio() and skip any returned non-LRU folio as a
> whole by advancing to its end.  Do this before the filters, the
> accounting and the last_applied check, so that adjacent regions within
> the same non-LRU folio are not walked by base page either.
> 
> In an x86-64 KVM pageout microbenchmark, traversal time dropped by
> about 99.7% for regions covering whole 2 MiB hugetlb folios. For
> 4 KiB regions within hugetlb folios, traversal took about 1 ns more
> per region.
> 
> Signed-off-by: Aveline Noir <jm5905938@gmail.com>
> ---
> Tested in x86-64 KVM guests.  DAMON KUnit tests all passed.  Ordinary-page
> and THP controls passed the 3% non-inferiority bound in the microbenchmark.
> 
> Changes in v2:
> - Drop the redundant hugetlb check and update the subject and description
>   as suggested by SJ.

Nit.  Please add a link to the previious version from the next time.

For other readers, the previous version is available at
https://lore.kernel.org/20261117-fix-damon-hugetlb-pageout-20261117-v1-1-054ef8760a92@gmail.com


Thanks,
SJ

[...]


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

end of thread, other threads:[~2026-11-18 14:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17 16:24 [PATCH v2] mm/damon/paddr: skip non-LRU folios as a whole in pageout Aveline Noir
2026-11-18 14:16 ` Enze Li
2026-11-18 14:33 ` SJ Park
2026-11-18 14:36 ` SJ Park

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox