Skip to contentSkip to conversation

mm/damon: add a DAMOS filter type for page granularity access recheck

RFC PATCH Superseded SeongJae Park 1 participant 5 messages Mar 7, 2024 – Mar 9, 2024

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

SeongJae Park

author maintainer
#0 lore raw

cover 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

Signature · 1 line
2.39.2
author maintainer
#1 lore raw

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.

---
 include/linux/damon.h    | 2 ++
 mm/damon/sysfs-schemes.c | 1 +
 2 files changed, 3 insertions(+)
include/linux/damon.h +2 -0
index 886d07294f4e..f7da65e1ac04 100644
@@ -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,
mm/damon/sysfs-schemes.c +1 -0
index 53a90ac678fb..bea5bc52846a 100644
@@ -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",
 };
Signature · 1 line
2.39.2
author maintainer
#2 lore raw

RFC PATCH 2/3 mm/damon/paddr: implement damon_folio_young()

In reply to SeongJae Park

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.

---
 mm/damon/paddr.c | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)
mm/damon/paddr.c +16 -10
index 5e6dc312072c..deee0fdf2e5b 100644
@@ -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;
Signature · 1 line
2.39.2
author maintainer
#3 lore raw

RFC PATCH 3/3 mm/damon/paddr: support DAMOS filter type YOUNG

In reply to SeongJae Park

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.

---
 mm/damon/paddr.c | 3 +++
 1 file changed, 3 insertions(+)
mm/damon/paddr.c +3 -0
index deee0fdf2e5b..52e4be7351cc 100644
@@ -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;
 	}
Signature · 1 line
2.39.2
author maintainer
#4 lore raw

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

Quoted 14 lines · 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.

---
 mm/damon/paddr.c | 3 +++
 1 file changed, 3 insertions(+)
mm/damon/paddr.c +0 -0
index deee0fdf2e5b..52e4be7351cc 100644

mm/damon/paddr.c static bool __damos_pa_filter_out(struct damos_filter *filter, · line 214

Quoted 6 lines
mm/damon/paddr.c +3 -0
@@ -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

Quoted 5 lines
mm/damon/paddr.c +0 -0
 	default:
 		break;
 	}
Signature · 1 line
2.39.2