* [RFC PATCH 1/3] mm/damon: add DAMOS filter type YOUNG
2024-03-07 3:00 [RFC PATCH 0/3] mm/damon: add a DAMOS filter type for page granularity access recheck SeongJae Park
@ 2024-03-07 3:00 ` SeongJae Park
2024-03-07 3:00 ` [RFC PATCH 2/3] mm/damon/paddr: implement damon_folio_young() SeongJae Park
2024-03-07 3:00 ` [RFC PATCH 3/3] mm/damon/paddr: support DAMOS filter type YOUNG SeongJae Park
2 siblings, 0 replies; 5+ messages in thread
From: SeongJae Park @ 2024-03-07 3:00 UTC (permalink / raw)
Cc: SeongJae Park, Andrew Morton, honggyu.kim, hyeongtak.ji,
kernel_team, damon, linux-mm, linux-kernel
Define yet another DAMOS filter type, YOUNG. Like anon and memcg, the
type of filter will be applied to each page in the memory region, and
check if the page is accessed since the last check.
Note that this commit is only defining the type. Implementation of it
should be made on DAMON operations sets. A couple of commits for the
implementation on 'paddr' DAMON operations set will follow.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
include/linux/damon.h | 2 ++
mm/damon/sysfs-schemes.c | 1 +
2 files changed, 3 insertions(+)
diff --git a/include/linux/damon.h b/include/linux/damon.h
index 886d07294f4e..f7da65e1ac04 100644
--- a/include/linux/damon.h
+++ b/include/linux/damon.h
@@ -297,6 +297,7 @@ struct damos_stat {
* enum damos_filter_type - Type of memory for &struct damos_filter
* @DAMOS_FILTER_TYPE_ANON: Anonymous pages.
* @DAMOS_FILTER_TYPE_MEMCG: Specific memcg's pages.
+ * @DAMOS_FILTER_TYPE_YOUNG: Recently accessed pages.
* @DAMOS_FILTER_TYPE_ADDR: Address range.
* @DAMOS_FILTER_TYPE_TARGET: Data Access Monitoring target.
* @NR_DAMOS_FILTER_TYPES: Number of filter types.
@@ -315,6 +316,7 @@ struct damos_stat {
enum damos_filter_type {
DAMOS_FILTER_TYPE_ANON,
DAMOS_FILTER_TYPE_MEMCG,
+ DAMOS_FILTER_TYPE_YOUNG,
DAMOS_FILTER_TYPE_ADDR,
DAMOS_FILTER_TYPE_TARGET,
NR_DAMOS_FILTER_TYPES,
diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c
index 53a90ac678fb..bea5bc52846a 100644
--- a/mm/damon/sysfs-schemes.c
+++ b/mm/damon/sysfs-schemes.c
@@ -343,6 +343,7 @@ static struct damon_sysfs_scheme_filter *damon_sysfs_scheme_filter_alloc(void)
static const char * const damon_sysfs_scheme_filter_type_strs[] = {
"anon",
"memcg",
+ "young",
"addr",
"target",
};
--
2.39.2
^ permalink raw reply related [flat|nested] 5+ messages in thread* [RFC PATCH 2/3] mm/damon/paddr: implement damon_folio_young()
2024-03-07 3:00 [RFC PATCH 0/3] mm/damon: add a DAMOS filter type for page granularity access recheck SeongJae Park
2024-03-07 3:00 ` [RFC PATCH 1/3] mm/damon: add DAMOS filter type YOUNG SeongJae Park
@ 2024-03-07 3:00 ` SeongJae Park
2024-03-07 3:00 ` [RFC PATCH 3/3] mm/damon/paddr: support DAMOS filter type YOUNG SeongJae Park
2 siblings, 0 replies; 5+ messages in thread
From: SeongJae Park @ 2024-03-07 3:00 UTC (permalink / raw)
Cc: SeongJae Park, Andrew Morton, honggyu.kim, hyeongtak.ji,
kernel_team, damon, linux-mm, linux-kernel
damon_pa_young() receives physical address, get the folio covering the
address, and return if the folio is accessed since the last check.
Split the internal logic for checking access to given folio, for future
reuse of the logic from code that already got the folio of the address
of the question.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
mm/damon/paddr.c | 26 ++++++++++++++++----------
1 file changed, 16 insertions(+), 10 deletions(-)
diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
index 5e6dc312072c..deee0fdf2e5b 100644
--- a/mm/damon/paddr.c
+++ b/mm/damon/paddr.c
@@ -111,9 +111,8 @@ static bool __damon_pa_young(struct folio *folio, struct vm_area_struct *vma,
return *accessed == false;
}
-static bool damon_pa_young(unsigned long paddr, unsigned long *folio_sz)
+static bool damon_folio_young(struct folio *folio)
{
- struct folio *folio = damon_get_folio(PHYS_PFN(paddr));
bool accessed = false;
struct rmap_walk_control rwc = {
.arg = &accessed,
@@ -122,27 +121,34 @@ static bool damon_pa_young(unsigned long paddr, unsigned long *folio_sz)
};
bool need_lock;
- if (!folio)
- return false;
-
if (!folio_mapped(folio) || !folio_raw_mapping(folio)) {
if (folio_test_idle(folio))
- accessed = false;
+ return false;
else
- accessed = true;
- goto out;
+ return true;
}
need_lock = !folio_test_anon(folio) || folio_test_ksm(folio);
if (need_lock && !folio_trylock(folio))
- goto out;
+ return false;
rmap_walk(folio, &rwc);
if (need_lock)
folio_unlock(folio);
-out:
+ return accessed;
+}
+
+static bool damon_pa_young(unsigned long paddr, unsigned long *folio_sz)
+{
+ struct folio *folio = damon_get_folio(PHYS_PFN(paddr));
+ bool accessed;
+
+ if (!folio)
+ return false;
+
+ accessed = damon_folio_young(folio);
*folio_sz = folio_size(folio);
folio_put(folio);
return accessed;
--
2.39.2
^ permalink raw reply related [flat|nested] 5+ messages in thread* [RFC PATCH 3/3] mm/damon/paddr: support DAMOS filter type YOUNG
2024-03-07 3:00 [RFC PATCH 0/3] mm/damon: add a DAMOS filter type for page granularity access recheck SeongJae Park
2024-03-07 3:00 ` [RFC PATCH 1/3] mm/damon: add DAMOS filter type YOUNG SeongJae Park
2024-03-07 3:00 ` [RFC PATCH 2/3] mm/damon/paddr: implement damon_folio_young() SeongJae Park
@ 2024-03-07 3:00 ` SeongJae Park
2024-03-09 1:53 ` SeongJae Park
2 siblings, 1 reply; 5+ messages in thread
From: SeongJae Park @ 2024-03-07 3:00 UTC (permalink / raw)
Cc: SeongJae Park, Andrew Morton, honggyu.kim, hyeongtak.ji,
kernel_team, damon, linux-mm, linux-kernel
DAMOS filter of type YOUNG is defined, but not yet implemented by any
DAMON operations set. Add the implementation to the DAMON operations
set for the physical address space, paddr.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
mm/damon/paddr.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
index deee0fdf2e5b..52e4be7351cc 100644
--- a/mm/damon/paddr.c
+++ b/mm/damon/paddr.c
@@ -209,6 +209,9 @@ static bool __damos_pa_filter_out(struct damos_filter *filter,
matched = filter->memcg_id == mem_cgroup_id(memcg);
rcu_read_unlock();
break;
+ case DAMOS_FILTER_TYPE_YOUNG:
+ matched = damon_folio_young(folio);
+ break;
default:
break;
}
--
2.39.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [RFC PATCH 3/3] mm/damon/paddr: support DAMOS filter type YOUNG
2024-03-07 3:00 ` [RFC PATCH 3/3] mm/damon/paddr: support DAMOS filter type YOUNG SeongJae Park
@ 2024-03-09 1:53 ` SeongJae Park
0 siblings, 0 replies; 5+ messages in thread
From: SeongJae Park @ 2024-03-09 1:53 UTC (permalink / raw)
To: SeongJae Park
Cc: Andrew Morton, honggyu.kim, hyeongtak.ji, kernel_team, damon,
linux-mm, linux-kernel
On Wed, 6 Mar 2024 19:00:13 -0800 SeongJae Park <sj@kernel.org> wrote:
> DAMOS filter of type YOUNG is defined, but not yet implemented by any
> DAMON operations set. Add the implementation to the DAMON operations
> set for the physical address space, paddr.
>
> Signed-off-by: SeongJae Park <sj@kernel.org>
> ---
> mm/damon/paddr.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
> index deee0fdf2e5b..52e4be7351cc 100644
> --- a/mm/damon/paddr.c
> +++ b/mm/damon/paddr.c
> @@ -209,6 +209,9 @@ static bool __damos_pa_filter_out(struct damos_filter *filter,
> matched = filter->memcg_id == mem_cgroup_id(memcg);
> rcu_read_unlock();
> break;
> + case DAMOS_FILTER_TYPE_YOUNG:
> + matched = damon_folio_young(folio);
> + break;
damon_folio_young() doesn't reset the Accessed bit of the folio. Hence, unless
something is resetting the bit, this damon_folio_young() call will repeatedly
return true even if there was no access to the folio since last check. We
should implement Accessed bit test-and-reset variant of this function and
replace this, or call damon_pa_mkold() when 'matched' is 'true'.
I will fix this in the next spin.
Thanks,
SJ
> default:
> break;
> }
> --
> 2.39.2
^ permalink raw reply [flat|nested] 5+ messages in thread