All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 6.1.y] mm/damon/paddr: drop last same folio access check reuse optimization
       [not found] <2026090853-handoff-bootlace-9e07@gregkh>
@ 2026-09-09  5:42 ` SJ Park
  2026-09-09  5:52   ` sashiko-bot
  2026-09-09 20:26   ` Sasha Levin
  0 siblings, 2 replies; 4+ messages in thread
From: SJ Park @ 2026-09-09  5:42 UTC (permalink / raw)
  To: stable; +Cc: damon, SJ Park, Andrew Morton

It can race when multiple kdamonds are being used.  The problem from the
race is doubtful, but the gain from the optimization is also doubtful.
Simply drop the optimization in favor of code simplicity.

The user impact is doubtfully trivial.  After all, this kind of
interference can happen only by intentional user setup.  Even if it
happens, it will be rare, and the consequence is degradation of the
best-effort monitoring results.  No critical consequences like kernel
panic or memory corruption happen.

The race was discovered [1] by Sashiko.

Link: https://lore.kernel.org/20260715031002.108504-5-sj@kernel.org
Link: https://lore.kernel.org/20260621204050.10993-1-sj@kernel.org [1]
Fixes: a28397beb55b ("mm/damon: implement primitives for physical address space monitoring")
Signed-off-by: SJ Park <sj@kernel.org>
Cc: <stable@vger.kernel.org> # 5.16.x
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
(cherry picked from commit f23f0aa62b2f32c2b12f95959fc4603ef81678b2)
Signed-off-by: SJ Park <sj@kernel.org>
---
 mm/damon/paddr.c | 21 ++++-----------------
 1 file changed, 4 insertions(+), 17 deletions(-)

diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
index 7bc8d79c7fa07..d1d047f494aed 100644
--- a/mm/damon/paddr.c
+++ b/mm/damon/paddr.c
@@ -120,7 +120,7 @@ static bool __damon_pa_young(struct folio *folio, struct vm_area_struct *vma,
 	return !result->accessed;
 }
 
-static bool damon_pa_young(unsigned long paddr, unsigned long *page_sz)
+static bool damon_pa_young(unsigned long paddr)
 {
 	struct folio *folio;
 	struct page *page = damon_get_page(PHYS_PFN(paddr));
@@ -161,29 +161,16 @@ static bool damon_pa_young(unsigned long paddr, unsigned long *page_sz)
 	folio_put(folio);
 
 out:
-	*page_sz = result.page_sz;
 	return result.accessed;
 }
 
 static void __damon_pa_check_access(struct damon_region *r)
 {
-	static unsigned long last_addr;
-	static unsigned long last_page_sz = PAGE_SIZE;
-	static bool last_accessed;
-
-	/* If the region is in the last checked page, reuse the result */
-	if (ALIGN_DOWN(last_addr, last_page_sz) ==
-				ALIGN_DOWN(r->sampling_addr, last_page_sz)) {
-		if (last_accessed)
-			r->nr_accesses++;
-		return;
-	}
+	bool accessed;
 
-	last_accessed = damon_pa_young(r->sampling_addr, &last_page_sz);
-	if (last_accessed)
+	accessed = damon_pa_young(r->sampling_addr);
+	if (accessed)
 		r->nr_accesses++;
-
-	last_addr = r->sampling_addr;
 }
 
 static unsigned int damon_pa_check_accesses(struct damon_ctx *ctx)
-- 
2.47.3


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

* Re: [PATCH 6.1.y] mm/damon/paddr: drop last same folio access check reuse optimization
  2026-09-09  5:42 ` [PATCH 6.1.y] mm/damon/paddr: drop last same folio access check reuse optimization SJ Park
@ 2026-09-09  5:52   ` sashiko-bot
  2026-09-09  6:40     ` SJ Park
  2026-09-09 20:26   ` Sasha Levin
  1 sibling, 1 reply; 4+ messages in thread
From: sashiko-bot @ 2026-09-09  5:52 UTC (permalink / raw)
  To: SJ Park; +Cc: damon

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Unused field `page_sz` left in `struct damon_pa_access_chk_result` after dropping the optimization.
--

commit 9b0877a60d53720420f674776094bf4134b4f6d7
Author: SJ Park <sj@kernel.org>

mm/damon/paddr: drop last same folio access check reuse optimization

This commit drops the optimization that reuses the last access check result
if the region is in the same page. This removes the race condition when
multiple kdamonds are used and favors code simplicity.

Link: https://lore.kernel.org/20260715031002.108504-5-sj@kernel.org
Link: https://lore.kernel.org/20260621204050.10993-1-sj@kernel.org [1]

> diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
> index 7bc8d79c7fa07..d1d047f494aed 100644
> --- a/mm/damon/paddr.c
> +++ b/mm/damon/paddr.c

[ ... ]

> @@ -161,29 +161,16 @@ static bool damon_pa_young(unsigned long paddr, unsigned long *page_sz)
>  	folio_put(folio);
>  
>  out:
> -	*page_sz = result.page_sz;

[Severity: Low]
Since the optimization was removed and page_sz is no longer returned, is it
necessary to keep the page_sz field in struct damon_pa_access_chk_result?

It looks like result.page_sz is still being assigned in __damon_pa_young()
and initialized in damon_pa_young(), but the value is never used by any
caller after this patch. Can the field and its assignments be removed
entirely to clean up the remaining dead stores?

>  	return result.accessed;
>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260909054255.253652-1-sj@kernel.org?part=1

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

* Re: [PATCH 6.1.y] mm/damon/paddr: drop last same folio access check reuse optimization
  2026-09-09  5:52   ` sashiko-bot
@ 2026-09-09  6:40     ` SJ Park
  0 siblings, 0 replies; 4+ messages in thread
From: SJ Park @ 2026-09-09  6:40 UTC (permalink / raw)
  To: sashiko-bot; +Cc: SJ Park, damon

On Wed, 09 Sep 2026 05:52:15 +0000 sashiko-bot@kernel.org wrote:

> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Low] Unused field `page_sz` left in `struct damon_pa_access_chk_result` after dropping the optimization.
> --
> 
> commit 9b0877a60d53720420f674776094bf4134b4f6d7
> Author: SJ Park <sj@kernel.org>
> 
> mm/damon/paddr: drop last same folio access check reuse optimization
> 
> This commit drops the optimization that reuses the last access check result
> if the region is in the same page. This removes the race condition when
> multiple kdamonds are used and favors code simplicity.
> 
> Link: https://lore.kernel.org/20260715031002.108504-5-sj@kernel.org
> Link: https://lore.kernel.org/20260621204050.10993-1-sj@kernel.org [1]
> 
> > diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
> > index 7bc8d79c7fa07..d1d047f494aed 100644
> > --- a/mm/damon/paddr.c
> > +++ b/mm/damon/paddr.c
> 
> [ ... ]
> 
> > @@ -161,29 +161,16 @@ static bool damon_pa_young(unsigned long paddr, unsigned long *page_sz)
> >  	folio_put(folio);
> >  
> >  out:
> > -	*page_sz = result.page_sz;
> 
> [Severity: Low]
> Since the optimization was removed and page_sz is no longer returned, is it
> necessary to keep the page_sz field in struct damon_pa_access_chk_result?
> 
> It looks like result.page_sz is still being assigned in __damon_pa_young()
> and initialized in damon_pa_young(), but the value is never used by any
> caller after this patch. Can the field and its assignments be removed
> entirely to clean up the remaining dead stores?

Apparently the upstream fix is not making such change.  Let's keep it as-is to
reduce unnecessary changes.

> 
> >  	return result.accessed;
> >  }
> 
> -- 
> Sashiko AI review · https://sashiko.dev/#/patchset/20260909054255.253652-1-sj@kernel.org?part=1
> 


Thanks,
SJ

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

* Re: [PATCH 6.1.y] mm/damon/paddr: drop last same folio access check reuse optimization
  2026-09-09  5:42 ` [PATCH 6.1.y] mm/damon/paddr: drop last same folio access check reuse optimization SJ Park
  2026-09-09  5:52   ` sashiko-bot
@ 2026-09-09 20:26   ` Sasha Levin
  1 sibling, 0 replies; 4+ messages in thread
From: Sasha Levin @ 2026-09-09 20:26 UTC (permalink / raw)
  To: stable; +Cc: Sasha Levin, damon, SJ Park, Andrew Morton

> It can race when multiple kdamonds are being used.  The problem from the
> race is doubtful, but the gain from the optimization is also doubtful.
> Simply drop the optimization in favor of code simplicity.

Queued for 6.1, thanks.

-- 
Thanks,
Sasha

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

end of thread, other threads:[~2026-09-09 20:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <2026090853-handoff-bootlace-9e07@gregkh>
2026-09-09  5:42 ` [PATCH 6.1.y] mm/damon/paddr: drop last same folio access check reuse optimization SJ Park
2026-09-09  5:52   ` sashiko-bot
2026-09-09  6:40     ` SJ Park
2026-09-09 20:26   ` Sasha Levin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.