Skip to contentSkip to conversation

mm/damon: enable page level properties based access pattern monitoring

RFC PATCH In review SeongJae Park 2 participants 22 messages Dec 19, 2024 – Jan 13, 2025

Subsystems (4)
lore
Share & tools
lore

SeongJae Park

author maintainer
#0 lore raw

cover mm/damon: enable page level properties based access pattern monitoring

TL; DR
======

This patch series eanble access monitoring based on page level properties including their anonymousness, belonging cgroups and pg-young-ness, by extending DAMOS stats and regions walk features with region-internal DAMOS filters.

Background
==========

DAMON fundametally provides only access pattern information in region granularity. For some use cases, fixed and fine granularity information based on non access pattern properties can be useful, though. For example, on systems having fast swap devices and slow storage devices, DAMOS-based proactive reclaim need to be applied differently for anonymous pages and file-backed pages.

DAMOS makes it possible via DAMOS filters that work in page level properties including anonymousness, belonging cgroups, and pg-young-ness. Having only the fine-grained inforamtion without making system operation behavior changes can be useful for tuning or monitoring purposes. But currently DAMON provides no way for that.

Idea
====

DAMOS has initially developed for only access-aware system operations. But, efficient acces monitoring results querying is yet another major usage of today's DAMOS. DAMOS stats and regions walk, which exposes accumulated counts and per-region monitoring results that filtered by DAMOS parameters including target access pattern and quotas, are the key features for that usage. Special DAMOS action, DAMOS_STAT, was also introduced to support doing only monitoring without making any system operation behavioral changes.

Hence, the fine-grained information that already available for access-aware system operation can be passed to users by connecting the region-internal DAMOS filters with stats and regions walk features.

Design
======

Update the interface of DAMON operations set layer, which contains region-internal DAMOS filters implementation, to report back the amount of memory that passed the region-internal DAMOS filters to the core layer. On the core layer, account the operations set layer reported stat with a per-scheme accumulated stat. Also, pass the stat to regions walk. In this way, DAMON API users can efficiently get the fine-grained information.

For the user-space, make DAMON sysfs interface collects the information using DAMON core API, and expose those to new per-scheme stats file and per-DAMOS-tried region properties file.

Practical Usages
================

With this patch series, DAMON users can query how many bytes of regions of specific access temperature is backed by pages of specific type. The type can be any of DAMOS filter-supporting one, including anonymousness, belonging cgroups, and pg-young-ness. For example, users can visualize access hotness-based page granulairty histogram for different cgroups, backing content type, or youngness. In future, it could be extended to more types such as whether it is THP, position on LRU lists, etc. This can be useful for estimating benefits of a new or an existing access-aware system optimizations without really committing the changes.

Patches Sequence
================

The patches are separated in four sequences.

First four patches add adding documentation of background knowledge.

Following three patches change the operations set layer interface to report back the region-internal filter passed memory size, and make the operations set implementations support the changed symantic.

Following five patches implement per-scheme accumulated stat for region-internal filter-passed memory size on core API, DAMON sysfs interface. First two patches of those are for code change, and following three patches are for documentation.

Finally, six patches implementing per-region region-internal filter-passed memory size follows. First three patches of these are for code change of preparation, API, and DAMON sysfs interface parts. The final three patches are for documentation.

Misc Notes
==========

This patch series depend on another RFC patch series[1] that introduced damos_call(). Some of patches here, particularly the one that adds Documentation for damos_call() and changing damos_call_control->walk_fn() invocation sequence, may be moved and folded into the patch series when it drops RFC tag.

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

SeongJae Park (18):
mm/damon: clarify trying vs applying on damos_stat kernel-doc comment Docs/mm/damon/design: document DAMOS regions walking Docs/mm/damon/design: add 'statistics' section Docs/admin-guide/mm/damon/usage: link damos stat design doc mm/damon: ask apply_scheme() to report filter-passed region-internal
bytes
mm/damon/paddr: report filter-passed bytes back for normal actions mm/damon/paddr: report filter-passed bytes back for DAMOS_STAT action mm/damon/core: implement per-scheme filter-passed bytes stat mm/damon/syfs-schemes: implement per-scheme filter-passed bytes stat Docs/mm/damon/design: document sz_ops_filter_passed Docs/admin-guide/mm/damon/usage: document sz_ops_filter_passed Docs/ABI/damon: document per-scheme filter-passed bytes stat file mm/damon/core: invoke damos_walk_control->walk_fn() after applying
action
mm/damon/core: pass per-region filter-passed bytes to

    damos_walk_control->walk_fn()

mm/damon/sysfs-schemes: expose per-region filter-passed bytes Docs/mm/damon/design: document per-region sz_filter_passed stat Docs/admin-guide/mm/damon/usage: document sz_filtered_out of scheme
tried region directories
Docs/ABI/damon: document per-region DAMOS filter-passed bytes stat
file

 .../ABI/testing/sysfs-kernel-mm-damon         | 13 ++++
 Documentation/admin-guide/mm/damon/usage.rst  | 29 ++++----
 Documentation/mm/damon/design.rst             | 53 ++++++++++++++
 include/linux/damon.h                         | 27 ++++++-
 mm/damon/core.c                               | 31 ++++----
 mm/damon/paddr.c                              | 70 +++++++++++++++----
 mm/damon/sysfs-common.h                       |  2 +-
 mm/damon/sysfs-schemes.c                      | 34 ++++++++-
 mm/damon/sysfs.c                              |  5 +-
 mm/damon/vaddr.c                              |  2 +-
 10 files changed, 216 insertions(+), 50 deletions(-)

base-commit: af113b0c56e321562fb85ef5da57f323c34b616b

Signature · 1 line
2.39.5
author maintainer
#1 lore raw

RFC PATCH 1/18 mm/damon: clarify trying vs applying on damos_stat kernel-doc comment

DAMOS stat kernel-doc documentation is using somewhat implicit terms. Without reading the code, understanding it correctly is not that easy. Add the clarification on the kernel-doc comment.

---
 include/linux/damon.h | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
include/linux/damon.h +17 -0
index b4165cc41d99..f66fa0ab9350 100644
@@ -292,6 +292,23 @@ struct damos_watermarks {
  * @nr_applied:	Total number of regions that the scheme is applied.
  * @sz_applied:	Total size of regions that the scheme is applied.
  * @qt_exceeds: Total number of times the quota of the scheme has exceeded.
+ *
+ * "Tried an action to a region" in this context means the DAMOS core logic
+ * determined the region as eligible to apply the action.  The access pattern
+ * (&struct damos_access_pattern), quotas (&struct damos_quota), watermarks
+ * (&struct damos_watermarks) and filters (&struct damos_filter) that handled
+ * on core logic can affect this.  The core logic asks the operation set
+ * (&struct damon_operations) to apply the action to the region.
+ *
+ * "Applied an action to a region" in this context means the operation set
+ * (&struct damon_operations) successfully applied the action to the region, at
+ * least to a part of the region.  The filters (&struct damos_filter) that
+ * handled on operation set layer and type of the action and pages of the
+ * region can affect this.  For example, if a filter is set to exclude
+ * anonymous pages and the region has only anonymous pages, the region will be
+ * failed at applying the action.  If the action is &DAMOS_PAGEOUT and all
+ * pages of the region are already paged out, the region will be failed at
+ * applying the action.
  */
 struct damos_stat {
 	unsigned long nr_tried;
Signature · 1 line
2.39.5
author maintainer
#2 lore raw

RFC PATCH 2/18 Docs/mm/damon/design: document DAMOS regions walking

In reply to SeongJae Park

DAMOS' regions walking feature is an important feature for efficiently retrieving monitoring results or DAMOS-internal behavior. Document it on the design document.

---
 Documentation/mm/damon/design.rst | 11 +++++++++++
 1 file changed, 11 insertions(+)
Documentation/mm/damon/design.rst +11 -0
index f9c50525bdbf..a577ae40e71c 100644
@@ -540,6 +540,17 @@ To know how user-space can set the watermarks via :ref:`DAMON sysfs interface
 documentation.
 
 
+Regions Walking
+~~~~~~~~~~~~~~~
+
+DAMOS feature allowing users access each region that a DAMOS action has just
+applied.  Using this feature, DAMON :ref:`API <damon_design_api>` allows users
+access full properties of the regions including the access monitoring results.
+:ref:`DAMON sysfs interface <sysfs_interface>` also allows users read the data
+via special :ref:`files <sysfs_schemes_tried_regions>`.
+
+.. _damon_design_api:
+
 Application Programming Interface
 ---------------------------------
 
Signature · 1 line
2.39.5
author maintainer
#3 lore raw

RFC PATCH 3/18 Docs/mm/damon/design: add 'statistics' section

In reply to SeongJae Park

DAMOS stats are important feature for tuning of DAMOS-based access-aware system operation, and efficient access pattern monitoring. But not well documented on the design document. Add a section on the document.

---
 Documentation/mm/damon/design.rst | 37 +++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
Documentation/mm/damon/design.rst +37 -0
index a577ae40e71c..8710fa71ad71 100644
@@ -539,6 +539,43 @@ To know how user-space can set the watermarks via :ref:`DAMON sysfs interface
 <sysfs_interface>`, refer to :ref:`filters <sysfs_filters>` part of the
 documentation.
 
+Statistics
+~~~~~~~~~~
+
+The statistics of DAMOS behaviors that designed to help monitoring, tuning and
+debugging of DAMOS.
+
+DAMOS accounts below statistics for each scheme, from the beginning of the
+scheme's execution.
+
+- ``nr_tried``: Total number of regions that the scheme is tried to be applied.
+- ``sz_trtied``: Total size of regions that the scheme is tried to be applied.
+- ``nr_applied``: Total number of regions that the scheme is applied.
+- ``sz_applied``: Total size of regions that the scheme is applied.
+- ``qt_exceeds``: Total number of times the quota of the scheme has exceeded.
+
+"A scheme is tried to be applied to a region" means DAMOS core logic determined
+the region is eligible to apply the scheme's :ref:`action
+<damon_design_damos_action>`.  The :ref:`access pattern
+<damon_design_damos_access_patter>`, :ref:`quotas <damon_design_damos_quotas>`,
+:ref:`watermarks <damon_design_damos_watermarks>`, and :ref:`filters
+<damon_design_damos_filters>` that handled on core logic could affect this.
+The core logic will only ask the underlying :ref:`operation set
+<damon_operations_set>` to do apply the action to the region, so whether the
+action is really applied or not is unclear.  That's why it is called "tried".
+
+"A scheme is applied to a region" means the :ref:`operation set
+<damon_operations_set>` has applied the action to at least a part of the
+region.  The :ref:`filters <damon_design_damos_filters>` that handled by the
+operation set, and the types of the :ref:`action <damon_design_damos_action>`
+and the pages of the region can affect this.  For example, if a filter is set
+to exclude anonymous pages and the region has only anonymous pages, or if the
+action is ``pageout`` while all pages of the region are unreclaimable, applying
+the action to the region will fail.
+
+To know how user-space can read the stats via :ref:`DAMON sysfs interface
+<sysfs_interface>`, refer to :ref:s`stats <sysfs_stats>` part of the
+documentation.
 
 Regions Walking
 ~~~~~~~~~~~~~~~
Signature · 1 line
2.39.5
author maintainer
#4 lore raw

RFC PATCH 4/18 Docs/admin-guide/mm/damon/usage: link damos stat design doc

In reply to SeongJae Park

DAMON sysfs usage document should focus on usage, rather than the detail of the stat metric itself. Add a link to the design document on usage section for DAMOS stat.

---
 Documentation/admin-guide/mm/damon/usage.rst | 3 ++-
 Documentation/mm/damon/design.rst            | 2 ++
 2 files changed, 4 insertions(+), 1 deletion(-)
Documentation/admin-guide/mm/damon/usage.rst +2 -1
index d9be9f7caa7d..af70f7244700 100644
@@ -457,7 +457,8 @@ schemes/<N>/stats/
 DAMON counts the total number and bytes of regions that each scheme is tried to
 be applied, the two numbers for the regions that each scheme is successfully
 applied, and the total number of the quota limit exceeds.  This statistics can
-be used for online analysis or tuning of the schemes.
+be used for online analysis or tuning of the schemes.  Refer to :ref:`design
+doc <damon_design_damos_stat>` for more details about the stats.
 
 The statistics can be retrieved by reading the files under ``stats`` directory
 (``nr_tried``, ``sz_tried``, ``nr_applied``, ``sz_applied``, and
Documentation/mm/damon/design.rst +2 -0
index 8710fa71ad71..e2666124e382 100644
@@ -539,6 +539,8 @@ To know how user-space can set the watermarks via :ref:`DAMON sysfs interface
 <sysfs_interface>`, refer to :ref:`filters <sysfs_filters>` part of the
 documentation.
 
+.. _damon_design_damos_stat:
+
 Statistics
 ~~~~~~~~~~
 
Signature · 1 line
2.39.5
author maintainer
#5 lore raw

RFC PATCH 5/18 mm/damon: ask apply_scheme() to report filter-passed region-internal bytes

In reply to SeongJae Park

Some DAMOS filter types including those for young page, anon page, and belonging memcg are handled by underlying DAMON operations set implementation, via damon_operations->apply_scheme() interface. How many bytes of the region have passed the filter can be useful for DAMOS scheme tuning and access pattern monitoring. Modify the interface to let the callback implementation reports back the number if possible.

---
 include/linux/damon.h | 5 +++--
 mm/damon/core.c       | 4 +++-
 mm/damon/paddr.c      | 2 +-
 mm/damon/vaddr.c      | 2 +-
 4 files changed, 8 insertions(+), 5 deletions(-)
include/linux/damon.h +3 -2
index f66fa0ab9350..bff39c23f16e 100644
@@ -534,7 +534,8 @@ enum damon_ops_id {
  * @apply_scheme is called from @kdamond when a region for user provided
  * DAMON-based operation scheme is found.  It should apply the scheme's action
  * to the region and return bytes of the region that the action is successfully
- * applied.
+ * applied.  It should also report how many bytes of the region has passed
+ * filters (&struct damos_filter) that handled by itself.
  * @target_valid should check whether the target is still valid for the
  * monitoring.
  * @cleanup is called from @kdamond just before its termination.
@@ -551,7 +552,7 @@ struct damon_operations {
 			struct damos *scheme);
 	unsigned long (*apply_scheme)(struct damon_ctx *context,
 			struct damon_target *t, struct damon_region *r,
-			struct damos *scheme);
+			struct damos *scheme, unsigned long *sz_filter_passed);
 	bool (*target_valid)(struct damon_target *t);
 	void (*cleanup)(struct damon_ctx *context);
 };
mm/damon/core.c +3 -1
index d8c223954996..c7ae95d6b7ba 100644
@@ -1517,6 +1517,7 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t,
 	unsigned long sz = damon_sz_region(r);
 	struct timespec64 begin, end;
 	unsigned long sz_applied = 0;
+	unsigned long sz_ops_filter_passed = 0;
 	int err = 0;
 	/*
 	 * We plan to support multiple context per kdamond, as DAMON sysfs
@@ -1563,7 +1564,8 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t,
 		if (!err) {
 			trace_damos_before_apply(cidx, sidx, tidx, r,
 					damon_nr_regions(t), do_trace);
-			sz_applied = c->ops.apply_scheme(c, t, r, s);
+			sz_applied = c->ops.apply_scheme(c, t, r, s,
+					&sz_ops_filter_passed);
 		}
 		ktime_get_coarse_ts64(&end);
 		quota->total_charged_ns += timespec64_to_ns(&end) -
mm/damon/paddr.c +1 -1
index a9ff35341d65..3530ef9c80bd 100644
@@ -477,7 +477,7 @@ static unsigned long damon_pa_migrate(struct damon_region *r, struct damos *s)
 
 static unsigned long damon_pa_apply_scheme(struct damon_ctx *ctx,
 		struct damon_target *t, struct damon_region *r,
-		struct damos *scheme)
+		struct damos *scheme, unsigned long *sz_filter_passed)
 {
 	switch (scheme->action) {
 	case DAMOS_PAGEOUT:
mm/damon/vaddr.c +1 -1
index b9eaa20b73b9..a6174f725bd7 100644
@@ -655,7 +655,7 @@ static unsigned long damos_madvise(struct damon_target *target,
 
 static unsigned long damon_va_apply_scheme(struct damon_ctx *ctx,
 		struct damon_target *t, struct damon_region *r,
-		struct damos *scheme)
+		struct damos *scheme, unsigned long *sz_filter_passed)
 {
 	int madv_action;
 
Signature · 1 line
2.39.5
author maintainer
#6 lore raw

RFC PATCH 6/18 mm/damon/paddr: report filter-passed bytes back for normal actions

In reply to SeongJae Park

damon_operations->apply_scheme() implementations are requested to report back how many bytes of the given region has passed DAMOS filter. 'paddr' operations set implementation supports some of region-internal DAMOS filter handling for normal DAMOS actions except DAMOS_STAT action. But, those are not respecting the request. Report the region-internal DAMOS filter-passed bytes back for the actions.

---
 mm/damon/paddr.c | 33 ++++++++++++++++++++++-----------
 1 file changed, 22 insertions(+), 11 deletions(-)
mm/damon/paddr.c +22 -11
index 3530ef9c80bd..5944316a0b4c 100644
@@ -243,7 +243,8 @@ static bool damos_pa_filter_out(struct damos *scheme, struct folio *folio)
 	return false;
 }
 
-static unsigned long damon_pa_pageout(struct damon_region *r, struct damos *s)
+static unsigned long damon_pa_pageout(struct damon_region *r, struct damos *s,
+		unsigned long *sz_filter_passed)
 {
 	unsigned long addr, applied;
 	LIST_HEAD(folio_list);
@@ -272,6 +273,8 @@ static unsigned long damon_pa_pageout(struct damon_region *r, struct damos *s)
 
 		if (damos_pa_filter_out(s, folio))
 			goto put_folio;
+		else
+			*sz_filter_passed += folio_size(folio);
 
 		folio_clear_referenced(folio);
 		folio_test_clear_young(folio);
@@ -292,7 +295,8 @@ static unsigned long damon_pa_pageout(struct damon_region *r, struct damos *s)
 }
 
 static inline unsigned long damon_pa_mark_accessed_or_deactivate(
-		struct damon_region *r, struct damos *s, bool mark_accessed)
+		struct damon_region *r, struct damos *s, bool mark_accessed,
+		unsigned long *sz_filter_passed)
 {
 	unsigned long addr, applied = 0;
 
@@ -304,6 +308,8 @@ static inline unsigned long damon_pa_mark_accessed_or_deactivate(
 
 		if (damos_pa_filter_out(s, folio))
 			goto put_folio;
+		else
+			*sz_filter_passed += folio_size(folio);
 
 		if (mark_accessed)
 			folio_mark_accessed(folio);
@@ -317,15 +323,17 @@ static inline unsigned long damon_pa_mark_accessed_or_deactivate(
 }
 
 static unsigned long damon_pa_mark_accessed(struct damon_region *r,
-	struct damos *s)
+	struct damos *s, unsigned long *sz_filter_passed)
 {
-	return damon_pa_mark_accessed_or_deactivate(r, s, true);
+	return damon_pa_mark_accessed_or_deactivate(r, s, true,
+			sz_filter_passed);
 }
 
 static unsigned long damon_pa_deactivate_pages(struct damon_region *r,
-	struct damos *s)
+	struct damos *s, unsigned long *sz_filter_passed)
 {
-	return damon_pa_mark_accessed_or_deactivate(r, s, false);
+	return damon_pa_mark_accessed_or_deactivate(r, s, false,
+			sz_filter_passed);
 }
 
 static unsigned int __damon_pa_migrate_folio_list(
@@ -449,7 +457,8 @@ static unsigned long damon_pa_migrate_pages(struct list_head *folio_list,
 	return nr_migrated;
 }
 
-static unsigned long damon_pa_migrate(struct damon_region *r, struct damos *s)
+static unsigned long damon_pa_migrate(struct damon_region *r, struct damos *s,
+		unsigned long *sz_filter_passed)
 {
 	unsigned long addr, applied;
 	LIST_HEAD(folio_list);
@@ -462,6 +471,8 @@ static unsigned long damon_pa_migrate(struct damon_region *r, struct damos *s)
 
 		if (damos_pa_filter_out(s, folio))
 			goto put_folio;
+		else
+			*sz_filter_passed += folio_size(folio);
 
 		if (!folio_isolate_lru(folio))
 			goto put_folio;
@@ -481,14 +492,14 @@ static unsigned long damon_pa_apply_scheme(struct damon_ctx *ctx,
 {
 	switch (scheme->action) {
 	case DAMOS_PAGEOUT:
-		return damon_pa_pageout(r, scheme);
+		return damon_pa_pageout(r, scheme, sz_filter_passed);
 	case DAMOS_LRU_PRIO:
-		return damon_pa_mark_accessed(r, scheme);
+		return damon_pa_mark_accessed(r, scheme, sz_filter_passed);
 	case DAMOS_LRU_DEPRIO:
-		return damon_pa_deactivate_pages(r, scheme);
+		return damon_pa_deactivate_pages(r, scheme, sz_filter_passed);
 	case DAMOS_MIGRATE_HOT:
 	case DAMOS_MIGRATE_COLD:
-		return damon_pa_migrate(r, scheme);
+		return damon_pa_migrate(r, scheme, sz_filter_passed);
 	case DAMOS_STAT:
 		break;
 	default:
Signature · 1 line
2.39.5
author maintainer
#7 lore raw

RFC PATCH 7/18 mm/damon/paddr: report filter-passed bytes back for DAMOS_STAT action

In reply to SeongJae Park

DAMOS_STAT action handling of paddr DAMON operations set implementation is simply ignoring the filters, and therefore not reporting back the filter-passed bytes. Apply the filtrs and report back the information.

Before this change, DAMOS_STAT was doing nothing for DAMOS filters. Hence users might see some performance regressions. Such regression for use cases where no filter is added to the scheme will be negligible, since this change implementation avoid unnecessary filtering works if no filter is installed.

For old users who were using DAMOS_STAT with filters, the regression could be visible depending on the size of the region and the overhead of the installed DAMOS filters. But, because the filters were completely ignored before in the use case, no real users would really depend on such use case that makes no point.

---
 mm/damon/paddr.c | 35 ++++++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)
mm/damon/paddr.c +34 -1
index 5944316a0b4c..b0c283808ba6 100644
@@ -485,6 +485,39 @@ static unsigned long damon_pa_migrate(struct damon_region *r, struct damos *s,
 	return applied * PAGE_SIZE;
 }
 
+static bool damon_pa_scheme_has_filter(struct damos *s)
+{
+	struct damos_filter *f;
+
+	damos_for_each_filter(f, s)
+		return true;
+	return false;
+}
+
+static unsigned long damon_pa_stat(struct damon_region *r, struct damos *s,
+		unsigned long *sz_filter_passed)
+{
+	unsigned long addr;
+	LIST_HEAD(folio_list);
+
+	if (!damon_pa_scheme_has_filter(s))
+		return 0;
+
+	for (addr = r->ar.start; addr < r->ar.end; addr += PAGE_SIZE) {
+		struct folio *folio = damon_get_folio(PHYS_PFN(addr));
+
+		if (!folio)
+			continue;
+
+		if (damos_pa_filter_out(s, folio))
+			goto put_folio;
+		else
+			*sz_filter_passed += folio_size(folio);
+put_folio:
+		folio_put(folio);
+	}
+	return 0;
+}
 
 static unsigned long damon_pa_apply_scheme(struct damon_ctx *ctx,
 		struct damon_target *t, struct damon_region *r,
@@ -501,7 +534,7 @@ static unsigned long damon_pa_apply_scheme(struct damon_ctx *ctx,
 	case DAMOS_MIGRATE_COLD:
 		return damon_pa_migrate(r, scheme, sz_filter_passed);
 	case DAMOS_STAT:
-		break;
+		return damon_pa_stat(r, scheme, sz_filter_passed);
 	default:
 		/* DAMOS actions that not yet supported by 'paddr'. */
 		break;
Signature · 1 line
2.39.5
author maintainer
#10 lore raw

RFC PATCH 8/18 mm/damon/core: implement per-scheme filter-passed bytes stat

In reply to SeongJae Park

Implement a new per-DAMOS scheme statistic field, namely sz_ops_filter_passed, using the changed damon_operations->apply_scheme() interface. It counts total bytes of memory that given DAMOS action tried to be applied, and passed the filters of the scheme. DAMON API users can access it using DAMON-internal safe access features such as damon_call() and/or damos_walk().

---
 include/linux/damon.h | 3 +++
 mm/damon/core.c       | 6 ++++--
 2 files changed, 7 insertions(+), 2 deletions(-)
include/linux/damon.h +3 -0
index bff39c23f16e..4a68bb38aad5 100644
@@ -291,6 +291,8 @@ struct damos_watermarks {
  * @sz_tried:	Total size of regions that the scheme is tried to be applied.
  * @nr_applied:	Total number of regions that the scheme is applied.
  * @sz_applied:	Total size of regions that the scheme is applied.
+ * @sz_ops_filter_passed:
+ * 		Total bytes that passed ops layer-handled DAMOS filters.
  * @qt_exceeds: Total number of times the quota of the scheme has exceeded.
  *
  * "Tried an action to a region" in this context means the DAMOS core logic
@@ -315,6 +317,7 @@ struct damos_stat {
 	unsigned long sz_tried;
 	unsigned long nr_applied;
 	unsigned long sz_applied;
+	unsigned long sz_ops_filter_passed;
 	unsigned long qt_exceeds;
 };
 
mm/damon/core.c +4 -2
index c7ae95d6b7ba..8540e8f91260 100644
@@ -1354,13 +1354,15 @@ static bool damos_skip_charged_region(struct damon_target *t,
 }
 
 static void damos_update_stat(struct damos *s,
-		unsigned long sz_tried, unsigned long sz_applied)
+		unsigned long sz_tried, unsigned long sz_applied,
+		unsigned long sz_ops_filter_passed)
 {
 	s->stat.nr_tried++;
 	s->stat.sz_tried += sz_tried;
 	if (sz_applied)
 		s->stat.nr_applied++;
 	s->stat.sz_applied += sz_applied;
+	s->stat.sz_ops_filter_passed += sz_ops_filter_passed;
 }
 
 static bool __damos_filter_out(struct damon_ctx *ctx, struct damon_target *t,
@@ -1580,7 +1582,7 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t,
 		r->age = 0;
 
 update_stat:
-	damos_update_stat(s, sz, sz_applied);
+	damos_update_stat(s, sz, sz_applied, sz_ops_filter_passed);
 }
 
 static void damon_do_apply_schemes(struct damon_ctx *c,
Signature · 1 line
2.39.5
author maintainer
#11 lore raw

RFC PATCH 9/18 mm/damon/syfs-schemes: implement per-scheme filter-passed bytes stat

In reply to SeongJae Park

Add a new DAMON sysfs interface file under scheme stat directory, namely 'sz_ops_filter_passed'. It represents total bytes that passed region-internal DAMOS filters of the scheme that handled by the DAMON operations set layer.

---
 mm/damon/sysfs-schemes.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
mm/damon/sysfs-schemes.c +16 -0
index 5c4490b97258..b447c412b02c 100644
@@ -188,6 +188,7 @@ struct damon_sysfs_stats {
 	unsigned long sz_tried;
 	unsigned long nr_applied;
 	unsigned long sz_applied;
+	unsigned long sz_ops_filter_passed;
 	unsigned long qt_exceeds;
 };
 
@@ -232,6 +233,15 @@ static ssize_t sz_applied_show(struct kobject *kobj,
 	return sysfs_emit(buf, "%lu\n", stats->sz_applied);
 }
 
+static ssize_t sz_ops_filter_passed_show(struct kobject *kobj,
+		struct kobj_attribute *attr, char *buf)
+{
+	struct damon_sysfs_stats *stats = container_of(kobj,
+			struct damon_sysfs_stats, kobj);
+
+	return sysfs_emit(buf, "%lu\n", stats->sz_ops_filter_passed);
+}
+
 static ssize_t qt_exceeds_show(struct kobject *kobj,
 		struct kobj_attribute *attr, char *buf)
 {
@@ -258,6 +268,9 @@ static struct kobj_attribute damon_sysfs_stats_nr_applied_attr =
 static struct kobj_attribute damon_sysfs_stats_sz_applied_attr =
 		__ATTR_RO_MODE(sz_applied, 0400);
 
+static struct kobj_attribute damon_sysfs_stats_sz_ops_filter_passed_attr =
+		__ATTR_RO_MODE(sz_ops_filter_passed, 0400);
+
 static struct kobj_attribute damon_sysfs_stats_qt_exceeds_attr =
 		__ATTR_RO_MODE(qt_exceeds, 0400);
 
@@ -266,6 +279,7 @@ static struct attribute *damon_sysfs_stats_attrs[] = {
 	&damon_sysfs_stats_sz_tried_attr.attr,
 	&damon_sysfs_stats_nr_applied_attr.attr,
 	&damon_sysfs_stats_sz_applied_attr.attr,
+	&damon_sysfs_stats_sz_ops_filter_passed_attr.attr,
 	&damon_sysfs_stats_qt_exceeds_attr.attr,
 	NULL,
 };
@@ -2077,6 +2091,8 @@ void damon_sysfs_schemes_update_stats(
 		sysfs_stats->sz_tried = scheme->stat.sz_tried;
 		sysfs_stats->nr_applied = scheme->stat.nr_applied;
 		sysfs_stats->sz_applied = scheme->stat.sz_applied;
+		sysfs_stats->sz_ops_filter_passed =
+			scheme->stat.sz_ops_filter_passed;
 		sysfs_stats->qt_exceeds = scheme->stat.qt_exceeds;
 	}
 }
Signature · 1 line
2.39.5
author maintainer
#12 lore raw

RFC PATCH 10/18 Docs/mm/damon/design: document sz_ops_filter_passed

In reply to SeongJae Park

Document the new per-scheme accumulated stat for total bytes that passed the operations set layer-handled DAMOS filters on the design document.

---
 Documentation/mm/damon/design.rst | 2 ++
 1 file changed, 2 insertions(+)
Documentation/mm/damon/design.rst +2 -0
index e2666124e382..0620675a1e8d 100644
@@ -552,6 +552,8 @@ scheme's execution.
 
 - ``nr_tried``: Total number of regions that the scheme is tried to be applied.
 - ``sz_trtied``: Total size of regions that the scheme is tried to be applied.
+- ``sz_ops_filter_passed``: Total bytes that passed operations set
+  layer-handled DAMOS filters.
 - ``nr_applied``: Total number of regions that the scheme is applied.
 - ``sz_applied``: Total size of regions that the scheme is applied.
 - ``qt_exceeds``: Total number of times the quota of the scheme has exceeded.
Signature · 1 line
2.39.5
author maintainer
#13 lore raw

RFC PATCH 11/18 Docs/admin-guide/mm/damon/usage: document sz_ops_filter_passed

In reply to SeongJae Park

Document the new per-scheme operations set layer-handled DAMOS filters passed bytes statistic file on DAMON sysfs interface usage document.

---
 Documentation/admin-guide/mm/damon/usage.rst | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)
Documentation/admin-guide/mm/damon/usage.rst +9 -11
index af70f7244700..179a9060a32e 100644
@@ -90,7 +90,7 @@ comma (",").
     │ │ │ │ │ │ │ :ref:`watermarks <sysfs_watermarks>`/metric,interval_us,high,mid,low
     │ │ │ │ │ │ │ :ref:`filters <sysfs_filters>`/nr_filters
     │ │ │ │ │ │ │ │ 0/type,matching,memcg_id
-    │ │ │ │ │ │ │ :ref:`stats <sysfs_schemes_stats>`/nr_tried,sz_tried,nr_applied,sz_applied,qt_exceeds
+    │ │ │ │ │ │ │ :ref:`stats <sysfs_schemes_stats>`/nr_tried,sz_tried,nr_applied,sz_applied,sz_ops_filter_passed,qt_exceeds
     │ │ │ │ │ │ │ :ref:`tried_regions <sysfs_schemes_tried_regions>`/total_bytes
     │ │ │ │ │ │ │ │ 0/start,end,nr_accesses,age
     │ │ │ │ │ │ │ │ ...
@@ -454,18 +454,16 @@ difference is applied to :ref:`stats <damos_stats>` and
 schemes/<N>/stats/
 ------------------
 
-DAMON counts the total number and bytes of regions that each scheme is tried to
-be applied, the two numbers for the regions that each scheme is successfully
-applied, and the total number of the quota limit exceeds.  This statistics can
-be used for online analysis or tuning of the schemes.  Refer to :ref:`design
-doc <damon_design_damos_stat>` for more details about the stats.
+DAMON counts statistics for each scheme.  This statistics can be used for
+online analysis or tuning of the schemes.  Refer to :ref:`design doc
+<damon_design_damos_stat>` for more details about the stats.
 
 The statistics can be retrieved by reading the files under ``stats`` directory
-(``nr_tried``, ``sz_tried``, ``nr_applied``, ``sz_applied``, and
-``qt_exceeds``), respectively.  The files are not updated in real time, so you
-should ask DAMON sysfs interface to update the content of the files for the
-stats by writing a special keyword, ``update_schemes_stats`` to the relevant
-``kdamonds/<N>/state`` file.
+(``nr_tried``, ``sz_tried``, ``nr_applied``, ``sz_applied``,
+``sz_ops_filter_passed``, and ``qt_exceeds``), respectively.  The files are not
+updated in real time, so you should ask DAMON sysfs interface to update the
+content of the files for the stats by writing a special keyword,
+``update_schemes_stats`` to the relevant ``kdamonds/<N>/state`` file.
 
 .. _sysfs_schemes_tried_regions:
 
Signature · 1 line
2.39.5
author maintainer
#14 lore raw

RFC PATCH 12/18 Docs/ABI/damon: document per-scheme filter-passed bytes stat file

In reply to SeongJae Park

Document the new ABI for per-scheme operations set layer-handled DAMOS filters passed bytes statistic on the ABI document.

---
 Documentation/ABI/testing/sysfs-kernel-mm-damon | 6 ++++++
 1 file changed, 6 insertions(+)
Documentation/ABI/testing/sysfs-kernel-mm-damon +6 -0
index f1b90cf1249b..19cde386fd15 100644
@@ -384,6 +384,12 @@ Contact:	SeongJae Park <[email protected]>
 Description:	Reading this file returns the total size of regions that the
 		action of the scheme has successfully applied in bytes.
 
+What:		/sys/kernel/mm/damon/admin/kdamonds/<K>/contexts/<C>/schemes/<S>/stats/sz_ops_filter_passed
+Date:		Dec 2024
+Contact:	SeongJae Park <[email protected]>
+Description:	Reading this file returns the total size of memory that passed
+		DAMON operations layer-handled filters of the scheme in bytes.
+
 What:		/sys/kernel/mm/damon/admin/kdamonds/<K>/contexts/<C>/schemes/<S>/stats/qt_exceeds
 Date:		Mar 2022
 Contact:	SeongJae Park <[email protected]>
Signature · 1 line
2.39.5
author maintainer
#15 lore raw

RFC PATCH 13/18 mm/damon/core: invoke damos_walk_control->walk_fn() after applying action

In reply to SeongJae Park

damos_walk_control->walk_fn() is called just before a DAMOS action is applied to a region. It can be useful if some users want to make some changes to the region before the scheme's action is applied, but there is no such real usages.

On the other hand, calling it after the DAMOS action is applied can give a chance to investigate what happened during applying the action to the region. Actually, followup commits will make and pass such information to walk_fn(). Invoke walk_fn() after applying the action.

---
 mm/damon/core.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
mm/damon/core.c +7 -9
index 8540e8f91260..f7736df4f6c8 100644
@@ -1214,7 +1214,7 @@ int damon_call(struct damon_ctx *ctx, struct damon_call_control *control)
  * finishes handling of the request.
  *
  * The kdamond executes the given function in the main loop, for each region
- * just before it applies any DAMOS actions of @ctx to it.  The invocation is
+ * just after it applied any DAMOS actions of @ctx to it.  The invocation is
  * made only within one &damos->apply_interval_us since damos_walk()
  * invocation, for each scheme.  The given callback function can hence safely
  * access the internal data of &struct damon_ctx and &struct damon_region that
@@ -1432,11 +1432,9 @@ static bool damos_filter_out(struct damon_ctx *ctx, struct damon_target *t,
  * @r:		The region of @t that @s will be applied.
  * @s:		The scheme of @ctx that will be applied to @r.
  *
- * This function is called from kdamond whenever it found a region that
- * eligible to apply a DAMOS scheme's action.  If a DAMOS walk request is
- * installed by damos_walk() and its &damos_walk_control->walk_fn has not
- * invoked for the region for the last &damos->apply_interval_us interval,
- * invoke it.
+ * This function is called from kdamond whenever it asked the operation set to
+ * apply a DAMOS scheme action to a region.  If a DAMOS walk request is
+ * installed by damos_walk() and not yet uninstalled, invoke it.
  */
 static void damos_walk_call_walk(struct damon_ctx *ctx, struct damon_target *t,
 		struct damon_region *r, struct damos *s)
@@ -1457,8 +1455,8 @@ static void damos_walk_call_walk(struct damon_ctx *ctx, struct damon_target *t,
  * @s:		A scheme of @ctx that all walks are now done.
  *
  * This function is called when kdamond finished applying the action of a DAMOS
- * scheme to regions that eligible for the given &damos->apply_interval_us.  If
- * every scheme of @ctx including @s now finished walking for at least one
+ * scheme to all regions that eligible for the given &damos->apply_interval_us.
+ * If every scheme of @ctx including @s now finished walking for at least one
  * &damos->apply_interval_us, this function makrs the handling of the given
  * DAMOS walk request is done, so that damos_walk() can wake up and return.
  */
@@ -1560,7 +1558,6 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t,
 		if (damos_filter_out(c, t, r, s))
 			return;
 		ktime_get_coarse_ts64(&begin);
-		damos_walk_call_walk(c, t, r, s);
 		if (c->callback.before_damos_apply)
 			err = c->callback.before_damos_apply(c, t, r, s);
 		if (!err) {
@@ -1569,6 +1566,7 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t,
 			sz_applied = c->ops.apply_scheme(c, t, r, s,
 					&sz_ops_filter_passed);
 		}
+		damos_walk_call_walk(c, t, r, s);
 		ktime_get_coarse_ts64(&end);
 		quota->total_charged_ns += timespec64_to_ns(&end) -
 			timespec64_to_ns(&begin);
Signature · 1 line
2.39.5
author maintainer
#16 lore raw

RFC PATCH 14/18 mm/damon/core: pass per-region filter-passed bytes to damos_walk_control->walk_fn()

In reply to SeongJae Park

Total size of memory that passed DAMON operations set layer-handled DAMOS filters per scheme is provided to DAMON core API and ABI (sysfs interface) users. It is useful, but that for each region can be more fine-grained information. Provide it to users of DAMON core API, specifically damos_walk() users, by passing the data to damos_walk_control->walk_fn().

---
 include/linux/damon.h | 2 +-
 mm/damon/core.c       | 7 ++++---
 mm/damon/sysfs.c      | 2 +-
 3 files changed, 6 insertions(+), 5 deletions(-)
include/linux/damon.h +1 -1
index 4a68bb38aad5..b88f710297a9 100644
@@ -393,7 +393,7 @@ struct damos;
 struct damos_walk_control {
 	void (*walk_fn)(void *data, struct damon_ctx *ctx,
 			struct damon_target *t, struct damon_region *r,
-			struct damos *s);
+			struct damos *s, unsigned long sz_filter_passed);
 	void *data;
 /* private: internal use only */
 	/* informs if the kdamond finished handling of the walk request */
mm/damon/core.c +4 -3
index f7736df4f6c8..f566cdcbb434 100644
@@ -1437,7 +1437,8 @@ static bool damos_filter_out(struct damon_ctx *ctx, struct damon_target *t,
  * installed by damos_walk() and not yet uninstalled, invoke it.
  */
 static void damos_walk_call_walk(struct damon_ctx *ctx, struct damon_target *t,
-		struct damon_region *r, struct damos *s)
+		struct damon_region *r, struct damos *s,
+		unsigned long sz_filter_passed)
 {
 	struct damos_walk_control *control;
 
@@ -1446,7 +1447,7 @@ static void damos_walk_call_walk(struct damon_ctx *ctx, struct damon_target *t,
 	mutex_unlock(&ctx->walk_control_lock);
 	if (!control)
 		return;
-	control->walk_fn(control->data, ctx, t, r, s);
+	control->walk_fn(control->data, ctx, t, r, s, sz_filter_passed);
 }
 
 /*
@@ -1566,7 +1567,7 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t,
 			sz_applied = c->ops.apply_scheme(c, t, r, s,
 					&sz_ops_filter_passed);
 		}
-		damos_walk_call_walk(c, t, r, s);
+		damos_walk_call_walk(c, t, r, s, sz_ops_filter_passed);
 		ktime_get_coarse_ts64(&end);
 		quota->total_charged_ns += timespec64_to_ns(&end) -
 			timespec64_to_ns(&begin);
mm/damon/sysfs.c +1 -1
index cf8fb5a963d6..224873ca8aa6 100644
@@ -1454,7 +1454,7 @@ struct damon_sysfs_schemes_walk_data {
 /* populate the region directory */
 static void damon_sysfs_schemes_tried_regions_upd_one(void *data, struct damon_ctx *ctx,
 		struct damon_target *t, struct damon_region *r,
-		struct damos *s)
+		struct damos *s, unsigned long sz_filter_passed)
 {
 	struct damon_sysfs_schemes_walk_data *walk_data = data;
 	struct damon_sysfs_kdamond *sysfs_kdamond = walk_data->sysfs_kdamond;
Signature · 1 line
2.39.5
author maintainer
#17 lore raw

RFC PATCH 15/18 mm/damon/sysfs-schemes: expose per-region filter-passed bytes

In reply to SeongJae Park

Per-region operations set-handled DAMOS filters passed memory size information is provided to only DAMON core API users. Further expose it to the user space by adding a new DAMON sysfs interface file under each scheme tried region directory.

---
 mm/damon/sysfs-common.h  |  2 +-
 mm/damon/sysfs-schemes.c | 18 +++++++++++++++++-
 mm/damon/sysfs.c         |  3 ++-
 3 files changed, 20 insertions(+), 3 deletions(-)
mm/damon/sysfs-common.h +1 -1
index b3f63bc658b7..70d84bdc9f5f 100644
@@ -48,7 +48,7 @@ void damon_sysfs_schemes_update_stats(
 void damos_sysfs_populate_region_dir(struct damon_sysfs_schemes *sysfs_schemes,
 		struct damon_ctx *ctx, struct damon_target *t,
 		struct damon_region *r, struct damos *s,
-		bool total_bytes_only);
+		bool total_bytes_only, unsigned long sz_filter_passed);
 
 int damon_sysfs_schemes_clear_regions(
 		struct damon_sysfs_schemes *sysfs_schemes);
mm/damon/sysfs-schemes.c +17 -1
index b447c412b02c..1da0594dde55 100644
@@ -19,6 +19,7 @@ struct damon_sysfs_scheme_region {
 	struct damon_addr_range ar;
 	unsigned int nr_accesses;
 	unsigned int age;
+	unsigned long sz_filter_passed;
 	struct list_head list;
 };
 
@@ -74,6 +75,15 @@ static ssize_t age_show(struct kobject *kobj, struct kobj_attribute *attr,
 	return sysfs_emit(buf, "%u\n", region->age);
 }
 
+static ssize_t sz_filter_passed_show(struct kobject *kobj,
+		struct kobj_attribute *attr, char *buf)
+{
+	struct damon_sysfs_scheme_region *region = container_of(kobj,
+			struct damon_sysfs_scheme_region, kobj);
+
+	return sysfs_emit(buf, "%lu\n", region->sz_filter_passed);
+}
+
 static void damon_sysfs_scheme_region_release(struct kobject *kobj)
 {
 	struct damon_sysfs_scheme_region *region = container_of(kobj,
@@ -95,11 +105,15 @@ static struct kobj_attribute damon_sysfs_scheme_region_nr_accesses_attr =
 static struct kobj_attribute damon_sysfs_scheme_region_age_attr =
 		__ATTR_RO_MODE(age, 0400);
 
+static struct kobj_attribute damon_sysfs_scheme_region_sz_filter_passed_attr =
+		__ATTR_RO_MODE(sz_filter_passed, 0400);
+
 static struct attribute *damon_sysfs_scheme_region_attrs[] = {
 	&damon_sysfs_scheme_region_start_attr.attr,
 	&damon_sysfs_scheme_region_end_attr.attr,
 	&damon_sysfs_scheme_region_nr_accesses_attr.attr,
 	&damon_sysfs_scheme_region_age_attr.attr,
+	&damon_sysfs_scheme_region_sz_filter_passed_attr.attr,
 	NULL,
 };
 ATTRIBUTE_GROUPS(damon_sysfs_scheme_region);
@@ -2110,7 +2124,8 @@ void damon_sysfs_schemes_update_stats(
  */
 void damos_sysfs_populate_region_dir(struct damon_sysfs_schemes *sysfs_schemes,
 		struct damon_ctx *ctx, struct damon_target *t,
-		struct damon_region *r, struct damos *s, bool total_bytes_only)
+		struct damon_region *r, struct damos *s, bool total_bytes_only,
+		unsigned long sz_filter_passed)
 {
 	struct damos *scheme;
 	struct damon_sysfs_scheme_regions *sysfs_regions;
@@ -2135,6 +2150,7 @@ void damos_sysfs_populate_region_dir(struct damon_sysfs_schemes *sysfs_schemes,
 	region = damon_sysfs_scheme_region_alloc(r);
 	if (!region)
 		return;
+	region->sz_filter_passed = sz_filter_passed;
 	list_add_tail(&region->list, &sysfs_regions->regions_list);
 	sysfs_regions->nr_regions++;
 	if (kobject_init_and_add(&region->kobj,
mm/damon/sysfs.c +2 -1
index 224873ca8aa6..deeab04d3b46 100644
@@ -1461,7 +1461,8 @@ static void damon_sysfs_schemes_tried_regions_upd_one(void *data, struct damon_c
 
 	damos_sysfs_populate_region_dir(
 			sysfs_kdamond->contexts->contexts_arr[0]->schemes,
-			ctx, t, r, s, walk_data->total_bytes_only);
+			ctx, t, r, s, walk_data->total_bytes_only,
+			sz_filter_passed);
 }
 
 static int damon_sysfs_update_schemes_tried_regions(
Signature · 1 line
2.39.5
author maintainer
#18 lore raw

RFC PATCH 16/18 Docs/mm/damon/design: document per-region sz_filter_passed stat

In reply to SeongJae Park

Update 'Regions Walking' sectioin of design document for the newly added per-region operations set handling DAMOS filters-passed bytes.

---
 Documentation/mm/damon/design.rst | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Documentation/mm/damon/design.rst +2 -1
index 0620675a1e8d..ed3072dc8686 100644
@@ -586,7 +586,8 @@ Regions Walking
 
 DAMOS feature allowing users access each region that a DAMOS action has just
 applied.  Using this feature, DAMON :ref:`API <damon_design_api>` allows users
-access full properties of the regions including the access monitoring results.
+access full properties of the regions including the access monitoring results
+and amount of the region's internal memory that passed the DAMOS filters.
 :ref:`DAMON sysfs interface <sysfs_interface>` also allows users read the data
 via special :ref:`files <sysfs_schemes_tried_regions>`.
 
Signature · 1 line
2.39.5
author maintainer
#19 lore raw

RFC PATCH 17/18 Docs/admin-guide/mm/damon/usage: document sz_filtered_out of scheme tried region directories

In reply to SeongJae Park

Document the newly added DAMON sysfs interface file for per-scheme-tried region's bytes that passed the operations set handling DAMOS filters.

---
 Documentation/admin-guide/mm/damon/usage.rst | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
Documentation/admin-guide/mm/damon/usage.rst +5 -5
index 179a9060a32e..a891e830c2a1 100644
@@ -92,7 +92,7 @@ comma (",").
     │ │ │ │ │ │ │ │ 0/type,matching,memcg_id
     │ │ │ │ │ │ │ :ref:`stats <sysfs_schemes_stats>`/nr_tried,sz_tried,nr_applied,sz_applied,sz_ops_filter_passed,qt_exceeds
     │ │ │ │ │ │ │ :ref:`tried_regions <sysfs_schemes_tried_regions>`/total_bytes
-    │ │ │ │ │ │ │ │ 0/start,end,nr_accesses,age
+    │ │ │ │ │ │ │ │ 0/start,end,nr_accesses,age,sz_filter_passed
     │ │ │ │ │ │ │ │ ...
     │ │ │ │ │ │ ...
     │ │ │ │ ...
@@ -500,10 +500,10 @@ set the ``access pattern`` as their interested pattern that they want to query.
 tried_regions/<N>/
 ------------------
 
-In each region directory, you will find four files (``start``, ``end``,
-``nr_accesses``, and ``age``).  Reading the files will show the start and end
-addresses, ``nr_accesses``, and ``age`` of the region that corresponding
-DAMON-based operation scheme ``action`` has tried to be applied.
+In each region directory, you will find five files (``start``, ``end``,
+``nr_accesses``, ``age``, and ``sz_filter_passed``).  Reading the files will
+show the properties of the region that corresponding DAMON-based operation
+scheme ``action`` has tried to be applied.
 
 Example
 ~~~~~~~
Signature · 1 line
2.39.5
author maintainer
#20 lore raw

RFC PATCH 18/18 Docs/ABI/damon: document per-region DAMOS filter-passed bytes stat file

In reply to SeongJae Park

Document the new ABI for per-region operations set layer-handled DAMOS filters passed bytes statistic.

---
 Documentation/ABI/testing/sysfs-kernel-mm-damon | 7 +++++++
 1 file changed, 7 insertions(+)
Documentation/ABI/testing/sysfs-kernel-mm-damon +7 -0
index 19cde386fd15..8c0acb31638b 100644
@@ -430,3 +430,10 @@ Contact:	SeongJae Park <[email protected]>
 Description:	Reading this file returns the 'age' of a memory region that
 		corresponding DAMON-based Operation Scheme's action has tried
 		to be applied.
+
+What:		/sys/kernel/mm/damon/admin/kdamonds/<K>/contexts/<C>/schemes/<S>/tried_regions/<R>/sz_filter_passed
+Date:		Dec 2024
+Contact:	SeongJae Park <[email protected]>
+Description:	Reading this file returns the size of the memory in the region
+		that passed DAMON operations layer-handled filters of the
+		scheme in bytes.
Signature · 1 line
2.39.5
author maintainer
#21 lore raw
In reply to SeongJae Park
Quoted 7 lines · On Wed, 18 Dec 2024 20:03:09 -0800 SeongJae Park <[email protected]> wrote:

TL; DR
======

This patch series eanble access monitoring based on page level properties including their anonymousness, belonging cgroups and pg-young-ness, by extending DAMOS stats and regions walk features with region-internal DAMOS filters.

I just released DAMON user-space tool, damo, of v2.6.1. It includes support of this feature. Using the user-space tool, I took and shared a simple screenshot[1] that might help you better understand what users can do with this.

[1] https://social.kernel.org/notice/ApLdd6IaUEHk3WhgTA

Thanks,
SJ

[...]

#8 lore raw

Re: [RFC PATCH 07/18] mm/damon/paddr: report filter-passed bytes back for DAMOS_STAT action

In reply to SeongJae Park

On Wed, 18 Dec 2024 20:03:16 -0800 SeongJae Park <[email protected]> wrote:

Hello SJ,
I hope you are doing well! Sorry to add noise to an old mail, but I recently saw Usama's patch that improves this function, and it brought my attention to this series, so I have been reading it today.

I was unsure if I should send this mail because I had a nit / naive question about the patch:

[...snip...]

Quoted 13 lines
mm/damon/paddr.c +13 -0
+static unsigned long damon_pa_stat(struct damon_region *r, struct damos *s,
+		unsigned long *sz_filter_passed)
+{
+	unsigned long addr;
+	LIST_HEAD(folio_list);
+
+	if (!damon_pa_scheme_has_filter(s))
+		return 0;
+
+	for (addr = r->ar.start; addr < r->ar.end; addr += PAGE_SIZE) {
+		struct folio *folio = damon_get_folio(PHYS_PFN(addr));
+
+		if (!folio)

mm/damon/paddr.c static unsigned long damon_pa_migrate(struct damon_region *r, struct damos *s, · line 519

Quoted 10 lines
mm/damon/paddr.c +10 -0
+			continue;
+
+		if (damos_pa_filter_out(s, folio))
+			goto put_folio;
+		else
+			*sz_filter_passed += folio_size(folio);
+put_folio:
+		folio_put(folio);
+	}
+	return 0;

Is there a reason that we decide to use a goto statement here? As far as I can tell, this is the only place this goto statement is used, and the else case bleeds into it as well. That is, I believe that the following could be more readable:

		if (!damos_pa_filter_out(s, folio))
			*sz_filter_passed += folio_size(folio);

		folio_put(folio);
	}
	return 0;

[...snip...]

Again, I am sorry if this is a naive question. Thank you for your time, I hope you have a great day!
Joshua

author maintainer
#9 lore raw

Re: [RFC PATCH 07/18] mm/damon/paddr: report filter-passed bytes back for DAMOS_STAT action

Hi Joshua,

Quoted 29 lines · On Mon, 13 Jan 2025 11:49:37 -0800 Joshua Hahn <[email protected]> wrote:

On Wed, 18 Dec 2024 20:03:16 -0800 SeongJae Park <[email protected]> wrote:

Hello SJ,
I hope you are doing well! Sorry to add noise to an old mail, but I recently saw Usama's patch that improves this function, and it brought my attention to this series, so I have been reading it today.

I was unsure if I should send this mail because I had a nit / naive question about the patch:

[...snip...]

Quoted 17 lines
mm/damon/paddr.c +17 -0
+static unsigned long damon_pa_stat(struct damon_region *r, struct damos *s,
+		unsigned long *sz_filter_passed)
+{
+	unsigned long addr;
+	LIST_HEAD(folio_list);
+
+	if (!damon_pa_scheme_has_filter(s))
+		return 0;
+
+	for (addr = r->ar.start; addr < r->ar.end; addr += PAGE_SIZE) {
+		struct folio *folio = damon_get_folio(PHYS_PFN(addr));
+
+		if (!folio)
+			continue;
+
+		if (damos_pa_filter_out(s, folio))
+			goto put_folio;
Quoted 8 lines

mm/damon/paddr.c static unsigned long damon_pa_migrate(struct damon_region *r, struct damos *s, · line 519

Quoted 6 lines
mm/damon/paddr.c +6 -0
+		else
+			*sz_filter_passed += folio_size(folio);
+put_folio:
+		folio_put(folio);
+	}
+	return 0;

Is there a reason that we decide to use a goto statement here?

There was no special reason. I wrote this function by copying damon_pa_migrate() and removing parts that not necessary. As a result, the weird 'goto' has remained.

Quoted 11 lines

As far as I
can tell, this is the only place this goto statement is used, and the else case bleeds into it as well. That is, I believe that the following could be more readable:

		if (!damos_pa_filter_out(s, folio))
			*sz_filter_passed += folio_size(folio);

		folio_put(folio);
	}
	return 0;

I agree. This looks much better! If you don't mind, pleae send a patch!

Quoted 4 lines

[...snip...]

Again, I am sorry if this is a naive question.

No worry, thank you for this nice and important question! I believe readability matters and DAMON code needs many helps for that :)

Quoted 2 lines

Thank you for your time,
I hope you have a great day!

You too!

Thanks,
SJ

[...]