From: Kaixu Xia <[email protected]>
This patchset simplify the operations when checking the damon
regions accesses.
v2:
-Update commit messages and fix the 80 characters warning.
-Add the check when damon target changed.
Kaixu Xia (2):
mm/damon: simplify the parameter passing for 'check_accesses'
mm/damon/vaddr: remove comparison between mm and last_mm when checking
region accesses
mm/damon/paddr.c | 5 ++---
mm/damon/vaddr.c | 13 +++++++------
2 files changed, 9 insertions(+), 9 deletions(-)
--
2.27.0
From: Kaixu Xia <[email protected]>
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.
Signed-off-by: Kaixu Xia <[email protected]>
---
mm/damon/vaddr.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/mm/damon/vaddr.c b/mm/damon/vaddr.c
index e481f81c3efb..5f66c826ee3a 100644
--- a/mm/damon/vaddr.c
+++ b/mm/damon/vaddr.c
@@ -533,15 +533,14 @@ static bool damon_va_young(struct mm_struct *mm, unsigned long addr,
* 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++;
@@ -552,7 +551,6 @@ static void __damon_va_check_access(struct mm_struct *mm,
if (last_accessed)
r->nr_accesses++;
- last_mm = mm;
last_addr = r->sampling_addr;
}
@@ -562,14 +560,17 @@ static unsigned int damon_va_check_accesses(struct damon_ctx *ctx)
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);
}
--
2.27.0
Hi Kaixu,
> From: Kaixu Xia <[email protected]>
>
> 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.
>
> Signed-off-by: Kaixu Xia <[email protected]>
Reviewed-by: SeongJae Park <[email protected]>
Thanks,
SJ
> ---
> mm/damon/vaddr.c | 11 ++++++-----
> 1 file changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/mm/damon/vaddr.c b/mm/damon/vaddr.c
> index e481f81c3efb..5f66c826ee3a 100644
> --- a/mm/damon/vaddr.c
> +++ b/mm/damon/vaddr.c
> @@ -533,15 +533,14 @@ static bool damon_va_young(struct mm_struct *mm, unsigned long addr,
> * 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++;
> @@ -552,7 +551,6 @@ static void __damon_va_check_access(struct mm_struct *mm,
> if (last_accessed)
> r->nr_accesses++;
>
> - last_mm = mm;
> last_addr = r->sampling_addr;
> }
>
> @@ -562,14 +560,17 @@ static unsigned int damon_va_check_accesses(struct damon_ctx *ctx)
> 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);
> }
> --
> 2.27.0