2024-03-07 03:00:28

by SeongJae Park

[permalink] [raw]
Subject: [RFC PATCH 0/3] mm/damon: add a DAMOS filter type for page granularity access recheck

DAMON allows users to specify desired ranges of overhead and accuracy of
the monitoring, and do its best effort to make most lightweight and
accurate results. A recent discussion for tiered memory management
support from DAMON[1] revealed that the best effort accuracy may not
suffice in some use cases, while increasing the minimum accuracy can
incur too high overhead. The discussion further concluded finding
memory regions of specific access pattern via DAMON first, and then
double checking the access of the region again in finer granularity
could help increasing the accuracy while keeping the low overhead.

Add a new type of DAMOS filter, namely YOUNG for such a case. Like anon
and memcg, the type of filter is applied to each page of the memory
region of DAMOS target memory region, and check if the page is accessed
since the last check. Because this is a filter type that applied in
page granularity, the support depends on DAMON operations set. Because
there are expected usages of this filter for physical address space
based DAMOS usage[1], implement the support for only DAMON operations
set for the physical address space, paddr.

[1] https://lore.kernel.org/r/[email protected]

SeongJae Park (3):
mm/damon: add DAMOS filter type YOUNG
mm/damon/paddr: implement damon_folio_young()
mm/damon/paddr: support DAMOS filter type YOUNG

include/linux/damon.h | 2 ++
mm/damon/paddr.c | 29 +++++++++++++++++++----------
mm/damon/sysfs-schemes.c | 1 +
3 files changed, 22 insertions(+), 10 deletions(-)


base-commit: 78a854de1f605e99ccc20df1775f237120cca47c
--
2.39.2



2024-03-07 03:00:34

by SeongJae Park

[permalink] [raw]
Subject: [RFC PATCH 1/3] mm/damon: add DAMOS filter type YOUNG

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 <[email protected]>
---
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


2024-03-07 03:00:46

by SeongJae Park

[permalink] [raw]
Subject: [RFC PATCH 2/3] mm/damon/paddr: implement damon_folio_young()

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 <[email protected]>
---
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


2024-03-07 03:02:07

by SeongJae Park

[permalink] [raw]
Subject: [RFC PATCH 3/3] mm/damon/paddr: support DAMOS filter type YOUNG

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 <[email protected]>
---
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


2024-03-09 01:53:20

by SeongJae Park

[permalink] [raw]
Subject: Re: [RFC PATCH 3/3] mm/damon/paddr: support DAMOS filter type YOUNG

On Wed, 6 Mar 2024 19:00:13 -0800 SeongJae Park <[email protected]> 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 <[email protected]>
> ---
> 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