diff mbox series

[2/2] mm/damon/vaddr: remove comparison between mm and last_mm when checking region accesses

Message ID 1661502678-19336-3-git-send-email-kaixuxia@tencent.com (mailing list archive)
State New
Headers show
Series Simplify the damon regions access check | expand

Commit Message

Kaixu Xia Aug. 26, 2022, 8:31 a.m. UTC
From: Kaixu Xia <kaixuxia@tencent.com>

The damon regions that belong to the same damon target have the same
'struct mm_struct *mm', so it's unnecessary to compare the mm and last_mm
objects among the damon regions in one damon target when checking accesses.

Signed-off-by: Kaixu Xia <kaixuxia@tencent.com>
---
 mm/damon/vaddr.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Comments

SeongJae Park Aug. 26, 2022, 5:16 p.m. UTC | #1
Hi Kaixu,

On Fri, 26 Aug 2022 16:31:18 +0800 xiakaixu1987@gmail.com wrote:

> From: Kaixu Xia <kaixuxia@tencent.com>
> 
> The damon regions that belong to the same damon target have the same
> 'struct mm_struct *mm', so it's unnecessary to compare the mm and last_mm
> objects among the damon regions in one damon target when checking accesses.

There could be multiple targets, and 'damon_va_check_accesses()' calls
'__damon_va_check_accesses()' for all the targets.  However,
'damon_va_check_accesses()' doesn't note if '__damon_va_check_accesses()' is
called with a target that same to the target it was called with for the last
time.  Hence the check is necessary.

If I'm missing something, please let me know.


Thanks,
SJ

[...]
Kaixu Xia Aug. 26, 2022, 9:06 p.m. UTC | #2
On Sat, Aug 27, 2022 at 1:16 AM SeongJae Park <sj@kernel.org> wrote:
>
> Hi Kaixu,
>
> On Fri, 26 Aug 2022 16:31:18 +0800 xiakaixu1987@gmail.com wrote:
>
> > From: Kaixu Xia <kaixuxia@tencent.com>
> >
> > The damon regions that belong to the same damon target have the same
> > 'struct mm_struct *mm', so it's unnecessary to compare the mm and last_mm
> > objects among the damon regions in one damon target when checking accesses.
>
> There could be multiple targets, and 'damon_va_check_accesses()' calls
> '__damon_va_check_accesses()' for all the targets.  However,
> 'damon_va_check_accesses()' doesn't note if '__damon_va_check_accesses()' is
> called with a target that same to the target it was called with for the last
> time.  Hence the check is necessary.

There could be many regions(1000 max limit) in one target and the mm
is same within
the target, maybe we don't need to maintain the 'last_mm' and do the
check every time
when the target is same.
But yes, the check is necessary when the target changed in
'__damon_va_check_accesses()',
this RFC patch missed this case :)  will fix it.

>
> If I'm missing something, please let me know.
>
>
> Thanks,
> SJ
>
> [...]
diff mbox series

Patch

diff --git a/mm/damon/vaddr.c b/mm/damon/vaddr.c
index c8c2f306bb6d..db9d0ab37a52 100644
--- a/mm/damon/vaddr.c
+++ b/mm/damon/vaddr.c
@@ -534,14 +534,13 @@  static bool damon_va_young(struct mm_struct *mm, unsigned long addr,
  */
 static void __damon_va_check_access(struct mm_struct *mm, struct damon_region *r)
 {
-	static struct mm_struct *last_mm;
 	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 (mm == last_mm && (ALIGN_DOWN(last_addr, last_page_sz) ==
-				ALIGN_DOWN(r->sampling_addr, last_page_sz))) {
+	if (ALIGN_DOWN(last_addr, last_page_sz) ==
+				ALIGN_DOWN(r->sampling_addr, last_page_sz)) {
 		if (last_accessed)
 			r->nr_accesses++;
 		return;
@@ -551,7 +550,6 @@  static void __damon_va_check_access(struct mm_struct *mm, struct damon_region *r
 	if (last_accessed)
 		r->nr_accesses++;
 
-	last_mm = mm;
 	last_addr = r->sampling_addr;
 }