The patch titled Subject: mm/damon/vaddr: remove comparison between mm and last_mm when checking region accesses has been added to the -mm mm-unstable branch. Its filename is mm-damon-vaddr-remove-comparison-between-mm-and-last_mm-when-checking-region-accesses.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-damon-vaddr-remove-comparison-between-mm-and-last_mm-when-checking-region-accesses.patch This patch will later appear in the mm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: Kaixu Xia <kaixuxia@xxxxxxxxxxx> Subject: mm/damon/vaddr: remove comparison between mm and last_mm when checking region accesses Date: Sat, 27 Aug 2022 17:02:51 +0800 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. But the check is necessary when the target changed in '__damon_va_check_accesses()', so we can simplify the whole operation by using the bool 'same_target' to indicate whether the target changed. Link: https://lkml.kernel.org/r/1661590971-20893-3-git-send-email-kaixuxia@xxxxxxxxxxx Signed-off-by: Kaixu Xia <kaixuxia@xxxxxxxxxxx> Reviewed-by: SeongJae Park <sj@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- mm/damon/vaddr.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) --- a/mm/damon/vaddr.c~mm-damon-vaddr-remove-comparison-between-mm-and-last_mm-when-checking-region-accesses +++ a/mm/damon/vaddr.c @@ -544,15 +544,14 @@ static bool damon_va_young(struct mm_str * r the region to be checked */ static void __damon_va_check_access(struct mm_struct *mm, - struct damon_region *r) + struct damon_region *r, bool same_target) { - 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) == + if (same_target && (ALIGN_DOWN(last_addr, last_page_sz) == ALIGN_DOWN(r->sampling_addr, last_page_sz))) { if (last_accessed) r->nr_accesses++; @@ -563,7 +562,6 @@ static void __damon_va_check_access(stru if (last_accessed) r->nr_accesses++; - last_mm = mm; last_addr = r->sampling_addr; } @@ -573,14 +571,17 @@ static unsigned int damon_va_check_acces struct mm_struct *mm; struct damon_region *r; unsigned int max_nr_accesses = 0; + bool same_target; damon_for_each_target(t, ctx) { mm = damon_get_mm(t); if (!mm) continue; + same_target = false; damon_for_each_region(r, t) { - __damon_va_check_access(mm, r); + __damon_va_check_access(mm, r, same_target); max_nr_accesses = max(r->nr_accesses, max_nr_accesses); + same_target = true; } mmput(mm); } _ Patches currently in -mm which might be from kaixuxia@xxxxxxxxxxx are mm-damon-core-simplify-the-parameter-passing-for-region-split-operation.patch mm-damon-simplify-the-parameter-passing-for-check_accesses.patch mm-damon-vaddr-remove-comparison-between-mm-and-last_mm-when-checking-region-accesses.patch