damon.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH 0/3] mm/damon: add a DAMOS filter type for page granularity access recheck
@ 2024-03-07  3:00 SeongJae Park
  2024-03-07  3:00 ` [RFC PATCH 1/3] mm/damon: add DAMOS filter type YOUNG SeongJae Park
                   ` (2 more replies)
  0 siblings, 3 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 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/20240227235121.153277-1-sj@kernel.org

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [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

end of thread, other threads:[~2024-03-09  1:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [RFC PATCH 3/3] mm/damon/paddr: support DAMOS filter type YOUNG SeongJae Park
2024-03-09  1:53   ` SeongJae Park

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).