* [RFC PATCH 01/18] mm/damon: clarify trying vs applying on damos_stat kernel-doc comment
2024-12-19 4:03 [RFC PATCH 00/18] mm/damon: enable page level properties based access pattern monitoring SeongJae Park
@ 2024-12-19 4:03 ` SeongJae Park
2024-12-19 4:03 ` [RFC PATCH 02/18] Docs/mm/damon/design: document DAMOS regions walking SeongJae Park
` (17 subsequent siblings)
18 siblings, 0 replies; 22+ messages in thread
From: SeongJae Park @ 2024-12-19 4:03 UTC (permalink / raw)
Cc: kernel-team, SeongJae Park, damon, linux-mm, linux-kernel
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.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
include/linux/damon.h | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/include/linux/damon.h b/include/linux/damon.h
index b4165cc41d99..f66fa0ab9350 100644
--- a/include/linux/damon.h
+++ b/include/linux/damon.h
@@ -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;
--
2.39.5
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [RFC PATCH 02/18] Docs/mm/damon/design: document DAMOS regions walking
2024-12-19 4:03 [RFC PATCH 00/18] mm/damon: enable page level properties based access pattern monitoring SeongJae Park
2024-12-19 4:03 ` [RFC PATCH 01/18] mm/damon: clarify trying vs applying on damos_stat kernel-doc comment SeongJae Park
@ 2024-12-19 4:03 ` SeongJae Park
2024-12-19 4:03 ` [RFC PATCH 03/18] Docs/mm/damon/design: add 'statistics' section SeongJae Park
` (16 subsequent siblings)
18 siblings, 0 replies; 22+ messages in thread
From: SeongJae Park @ 2024-12-19 4:03 UTC (permalink / raw)
Cc: kernel-team, SeongJae Park, damon, linux-mm, linux-doc,
linux-kernel
DAMOS' regions walking feature is an important feature for efficiently
retrieving monitoring results or DAMOS-internal behavior. Document it
on the design document.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
Documentation/mm/damon/design.rst | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/Documentation/mm/damon/design.rst b/Documentation/mm/damon/design.rst
index f9c50525bdbf..a577ae40e71c 100644
--- a/Documentation/mm/damon/design.rst
+++ b/Documentation/mm/damon/design.rst
@@ -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
---------------------------------
--
2.39.5
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [RFC PATCH 03/18] Docs/mm/damon/design: add 'statistics' section
2024-12-19 4:03 [RFC PATCH 00/18] mm/damon: enable page level properties based access pattern monitoring SeongJae Park
2024-12-19 4:03 ` [RFC PATCH 01/18] mm/damon: clarify trying vs applying on damos_stat kernel-doc comment SeongJae Park
2024-12-19 4:03 ` [RFC PATCH 02/18] Docs/mm/damon/design: document DAMOS regions walking SeongJae Park
@ 2024-12-19 4:03 ` SeongJae Park
2024-12-19 4:03 ` [RFC PATCH 04/18] Docs/admin-guide/mm/damon/usage: link damos stat design doc SeongJae Park
` (15 subsequent siblings)
18 siblings, 0 replies; 22+ messages in thread
From: SeongJae Park @ 2024-12-19 4:03 UTC (permalink / raw)
Cc: kernel-team, SeongJae Park, damon, linux-mm, linux-doc,
linux-kernel
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.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
Documentation/mm/damon/design.rst | 37 +++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/Documentation/mm/damon/design.rst b/Documentation/mm/damon/design.rst
index a577ae40e71c..8710fa71ad71 100644
--- a/Documentation/mm/damon/design.rst
+++ b/Documentation/mm/damon/design.rst
@@ -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
~~~~~~~~~~~~~~~
--
2.39.5
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [RFC PATCH 04/18] Docs/admin-guide/mm/damon/usage: link damos stat design doc
2024-12-19 4:03 [RFC PATCH 00/18] mm/damon: enable page level properties based access pattern monitoring SeongJae Park
` (2 preceding siblings ...)
2024-12-19 4:03 ` [RFC PATCH 03/18] Docs/mm/damon/design: add 'statistics' section SeongJae Park
@ 2024-12-19 4:03 ` SeongJae Park
2024-12-19 4:03 ` [RFC PATCH 05/18] mm/damon: ask apply_scheme() to report filter-passed region-internal bytes SeongJae Park
` (14 subsequent siblings)
18 siblings, 0 replies; 22+ messages in thread
From: SeongJae Park @ 2024-12-19 4:03 UTC (permalink / raw)
Cc: kernel-team, SeongJae Park, damon, linux-mm, linux-doc,
linux-kernel
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.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
Documentation/admin-guide/mm/damon/usage.rst | 3 ++-
Documentation/mm/damon/design.rst | 2 ++
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/Documentation/admin-guide/mm/damon/usage.rst b/Documentation/admin-guide/mm/damon/usage.rst
index d9be9f7caa7d..af70f7244700 100644
--- a/Documentation/admin-guide/mm/damon/usage.rst
+++ b/Documentation/admin-guide/mm/damon/usage.rst
@@ -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
diff --git a/Documentation/mm/damon/design.rst b/Documentation/mm/damon/design.rst
index 8710fa71ad71..e2666124e382 100644
--- a/Documentation/mm/damon/design.rst
+++ b/Documentation/mm/damon/design.rst
@@ -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
~~~~~~~~~~
--
2.39.5
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [RFC PATCH 05/18] mm/damon: ask apply_scheme() to report filter-passed region-internal bytes
2024-12-19 4:03 [RFC PATCH 00/18] mm/damon: enable page level properties based access pattern monitoring SeongJae Park
` (3 preceding siblings ...)
2024-12-19 4:03 ` [RFC PATCH 04/18] Docs/admin-guide/mm/damon/usage: link damos stat design doc SeongJae Park
@ 2024-12-19 4:03 ` SeongJae Park
2024-12-19 4:03 ` [RFC PATCH 06/18] mm/damon/paddr: report filter-passed bytes back for normal actions SeongJae Park
` (13 subsequent siblings)
18 siblings, 0 replies; 22+ messages in thread
From: SeongJae Park @ 2024-12-19 4:03 UTC (permalink / raw)
Cc: kernel-team, SeongJae Park, damon, linux-mm, linux-kernel
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.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
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(-)
diff --git a/include/linux/damon.h b/include/linux/damon.h
index f66fa0ab9350..bff39c23f16e 100644
--- a/include/linux/damon.h
+++ b/include/linux/damon.h
@@ -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);
};
diff --git a/mm/damon/core.c b/mm/damon/core.c
index d8c223954996..c7ae95d6b7ba 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -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) -
diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
index a9ff35341d65..3530ef9c80bd 100644
--- a/mm/damon/paddr.c
+++ b/mm/damon/paddr.c
@@ -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:
diff --git a/mm/damon/vaddr.c b/mm/damon/vaddr.c
index b9eaa20b73b9..a6174f725bd7 100644
--- a/mm/damon/vaddr.c
+++ b/mm/damon/vaddr.c
@@ -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;
--
2.39.5
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [RFC PATCH 06/18] mm/damon/paddr: report filter-passed bytes back for normal actions
2024-12-19 4:03 [RFC PATCH 00/18] mm/damon: enable page level properties based access pattern monitoring SeongJae Park
` (4 preceding siblings ...)
2024-12-19 4:03 ` [RFC PATCH 05/18] mm/damon: ask apply_scheme() to report filter-passed region-internal bytes SeongJae Park
@ 2024-12-19 4:03 ` SeongJae Park
2024-12-19 4:03 ` [RFC PATCH 07/18] mm/damon/paddr: report filter-passed bytes back for DAMOS_STAT action SeongJae Park
` (12 subsequent siblings)
18 siblings, 0 replies; 22+ messages in thread
From: SeongJae Park @ 2024-12-19 4:03 UTC (permalink / raw)
Cc: kernel-team, SeongJae Park, damon, linux-mm, linux-kernel
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.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
mm/damon/paddr.c | 33 ++++++++++++++++++++++-----------
1 file changed, 22 insertions(+), 11 deletions(-)
diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
index 3530ef9c80bd..5944316a0b4c 100644
--- a/mm/damon/paddr.c
+++ b/mm/damon/paddr.c
@@ -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:
--
2.39.5
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [RFC PATCH 07/18] mm/damon/paddr: report filter-passed bytes back for DAMOS_STAT action
2024-12-19 4:03 [RFC PATCH 00/18] mm/damon: enable page level properties based access pattern monitoring SeongJae Park
` (5 preceding siblings ...)
2024-12-19 4:03 ` [RFC PATCH 06/18] mm/damon/paddr: report filter-passed bytes back for normal actions SeongJae Park
@ 2024-12-19 4:03 ` SeongJae Park
2025-01-13 19:49 ` Joshua Hahn
2024-12-19 4:03 ` [RFC PATCH 08/18] mm/damon/core: implement per-scheme filter-passed bytes stat SeongJae Park
` (11 subsequent siblings)
18 siblings, 1 reply; 22+ messages in thread
From: SeongJae Park @ 2024-12-19 4:03 UTC (permalink / raw)
Cc: kernel-team, SeongJae Park, damon, linux-mm, linux-kernel
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.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
mm/damon/paddr.c | 35 ++++++++++++++++++++++++++++++++++-
1 file changed, 34 insertions(+), 1 deletion(-)
diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
index 5944316a0b4c..b0c283808ba6 100644
--- a/mm/damon/paddr.c
+++ b/mm/damon/paddr.c
@@ -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;
--
2.39.5
^ permalink raw reply related [flat|nested] 22+ messages in thread
* Re: [RFC PATCH 07/18] mm/damon/paddr: report filter-passed bytes back for DAMOS_STAT action
2024-12-19 4:03 ` [RFC PATCH 07/18] mm/damon/paddr: report filter-passed bytes back for DAMOS_STAT action SeongJae Park
@ 2025-01-13 19:49 ` Joshua Hahn
2025-01-13 20:02 ` SeongJae Park
0 siblings, 1 reply; 22+ messages in thread
From: Joshua Hahn @ 2025-01-13 19:49 UTC (permalink / raw)
To: SeongJae Park; +Cc: kernel-team, damon, linux-mm, linux-kernel
On Wed, 18 Dec 2024 20:03:16 -0800 SeongJae Park <sj@kernel.org> 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...]
> +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;
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
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [RFC PATCH 07/18] mm/damon/paddr: report filter-passed bytes back for DAMOS_STAT action
2025-01-13 19:49 ` Joshua Hahn
@ 2025-01-13 20:02 ` SeongJae Park
0 siblings, 0 replies; 22+ messages in thread
From: SeongJae Park @ 2025-01-13 20:02 UTC (permalink / raw)
To: Joshua Hahn; +Cc: SeongJae Park, kernel-team, damon, linux-mm, linux-kernel
Hi Joshua,
On Mon, 13 Jan 2025 11:49:37 -0800 Joshua Hahn <joshua.hahnjy@gmail.com> wrote:
> On Wed, 18 Dec 2024 20:03:16 -0800 SeongJae Park <sj@kernel.org> 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...]
>
> > +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;
>
> 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.
> 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!
>
> [...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 :)
> Thank you for your time,
> I hope you have a great day!
You too!
Thanks,
SJ
[...]
^ permalink raw reply [flat|nested] 22+ messages in thread
* [RFC PATCH 08/18] mm/damon/core: implement per-scheme filter-passed bytes stat
2024-12-19 4:03 [RFC PATCH 00/18] mm/damon: enable page level properties based access pattern monitoring SeongJae Park
` (6 preceding siblings ...)
2024-12-19 4:03 ` [RFC PATCH 07/18] mm/damon/paddr: report filter-passed bytes back for DAMOS_STAT action SeongJae Park
@ 2024-12-19 4:03 ` SeongJae Park
2024-12-19 4:03 ` [RFC PATCH 09/18] mm/damon/syfs-schemes: " SeongJae Park
` (10 subsequent siblings)
18 siblings, 0 replies; 22+ messages in thread
From: SeongJae Park @ 2024-12-19 4:03 UTC (permalink / raw)
Cc: kernel-team, SeongJae Park, damon, linux-mm, linux-kernel
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().
Signed-off-by: SeongJae Park <sj@kernel.org>
---
include/linux/damon.h | 3 +++
mm/damon/core.c | 6 ++++--
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/include/linux/damon.h b/include/linux/damon.h
index bff39c23f16e..4a68bb38aad5 100644
--- a/include/linux/damon.h
+++ b/include/linux/damon.h
@@ -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;
};
diff --git a/mm/damon/core.c b/mm/damon/core.c
index c7ae95d6b7ba..8540e8f91260 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -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,
--
2.39.5
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [RFC PATCH 09/18] mm/damon/syfs-schemes: implement per-scheme filter-passed bytes stat
2024-12-19 4:03 [RFC PATCH 00/18] mm/damon: enable page level properties based access pattern monitoring SeongJae Park
` (7 preceding siblings ...)
2024-12-19 4:03 ` [RFC PATCH 08/18] mm/damon/core: implement per-scheme filter-passed bytes stat SeongJae Park
@ 2024-12-19 4:03 ` SeongJae Park
2024-12-19 4:03 ` [RFC PATCH 10/18] Docs/mm/damon/design: document sz_ops_filter_passed SeongJae Park
` (9 subsequent siblings)
18 siblings, 0 replies; 22+ messages in thread
From: SeongJae Park @ 2024-12-19 4:03 UTC (permalink / raw)
Cc: kernel-team, SeongJae Park, damon, linux-mm, linux-kernel
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.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
mm/damon/sysfs-schemes.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c
index 5c4490b97258..b447c412b02c 100644
--- a/mm/damon/sysfs-schemes.c
+++ b/mm/damon/sysfs-schemes.c
@@ -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;
}
}
--
2.39.5
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [RFC PATCH 10/18] Docs/mm/damon/design: document sz_ops_filter_passed
2024-12-19 4:03 [RFC PATCH 00/18] mm/damon: enable page level properties based access pattern monitoring SeongJae Park
` (8 preceding siblings ...)
2024-12-19 4:03 ` [RFC PATCH 09/18] mm/damon/syfs-schemes: " SeongJae Park
@ 2024-12-19 4:03 ` SeongJae Park
2024-12-19 4:03 ` [RFC PATCH 11/18] Docs/admin-guide/mm/damon/usage: " SeongJae Park
` (8 subsequent siblings)
18 siblings, 0 replies; 22+ messages in thread
From: SeongJae Park @ 2024-12-19 4:03 UTC (permalink / raw)
Cc: kernel-team, SeongJae Park, damon, linux-mm, linux-doc,
linux-kernel
Document the new per-scheme accumulated stat for total bytes that passed
the operations set layer-handled DAMOS filters on the design document.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
Documentation/mm/damon/design.rst | 2 ++
1 file changed, 2 insertions(+)
diff --git a/Documentation/mm/damon/design.rst b/Documentation/mm/damon/design.rst
index e2666124e382..0620675a1e8d 100644
--- a/Documentation/mm/damon/design.rst
+++ b/Documentation/mm/damon/design.rst
@@ -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.
--
2.39.5
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [RFC PATCH 11/18] Docs/admin-guide/mm/damon/usage: document sz_ops_filter_passed
2024-12-19 4:03 [RFC PATCH 00/18] mm/damon: enable page level properties based access pattern monitoring SeongJae Park
` (9 preceding siblings ...)
2024-12-19 4:03 ` [RFC PATCH 10/18] Docs/mm/damon/design: document sz_ops_filter_passed SeongJae Park
@ 2024-12-19 4:03 ` SeongJae Park
2024-12-19 4:03 ` [RFC PATCH 12/18] Docs/ABI/damon: document per-scheme filter-passed bytes stat file SeongJae Park
` (7 subsequent siblings)
18 siblings, 0 replies; 22+ messages in thread
From: SeongJae Park @ 2024-12-19 4:03 UTC (permalink / raw)
Cc: kernel-team, SeongJae Park, damon, linux-mm, linux-doc,
linux-kernel
Document the new per-scheme operations set layer-handled DAMOS filters
passed bytes statistic file on DAMON sysfs interface usage document.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
Documentation/admin-guide/mm/damon/usage.rst | 20 +++++++++-----------
1 file changed, 9 insertions(+), 11 deletions(-)
diff --git a/Documentation/admin-guide/mm/damon/usage.rst b/Documentation/admin-guide/mm/damon/usage.rst
index af70f7244700..179a9060a32e 100644
--- a/Documentation/admin-guide/mm/damon/usage.rst
+++ b/Documentation/admin-guide/mm/damon/usage.rst
@@ -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:
--
2.39.5
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [RFC PATCH 12/18] Docs/ABI/damon: document per-scheme filter-passed bytes stat file
2024-12-19 4:03 [RFC PATCH 00/18] mm/damon: enable page level properties based access pattern monitoring SeongJae Park
` (10 preceding siblings ...)
2024-12-19 4:03 ` [RFC PATCH 11/18] Docs/admin-guide/mm/damon/usage: " SeongJae Park
@ 2024-12-19 4:03 ` SeongJae Park
2024-12-19 4:03 ` [RFC PATCH 13/18] mm/damon/core: invoke damos_walk_control->walk_fn() after applying action SeongJae Park
` (6 subsequent siblings)
18 siblings, 0 replies; 22+ messages in thread
From: SeongJae Park @ 2024-12-19 4:03 UTC (permalink / raw)
Cc: kernel-team, SeongJae Park, damon, linux-mm, linux-kernel
Document the new ABI for per-scheme operations set layer-handled DAMOS
filters passed bytes statistic on the ABI document.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
Documentation/ABI/testing/sysfs-kernel-mm-damon | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/Documentation/ABI/testing/sysfs-kernel-mm-damon b/Documentation/ABI/testing/sysfs-kernel-mm-damon
index f1b90cf1249b..19cde386fd15 100644
--- a/Documentation/ABI/testing/sysfs-kernel-mm-damon
+++ b/Documentation/ABI/testing/sysfs-kernel-mm-damon
@@ -384,6 +384,12 @@ Contact: SeongJae Park <sj@kernel.org>
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 <sj@kernel.org>
+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 <sj@kernel.org>
--
2.39.5
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [RFC PATCH 13/18] mm/damon/core: invoke damos_walk_control->walk_fn() after applying action
2024-12-19 4:03 [RFC PATCH 00/18] mm/damon: enable page level properties based access pattern monitoring SeongJae Park
` (11 preceding siblings ...)
2024-12-19 4:03 ` [RFC PATCH 12/18] Docs/ABI/damon: document per-scheme filter-passed bytes stat file SeongJae Park
@ 2024-12-19 4:03 ` SeongJae Park
2024-12-19 4:03 ` [RFC PATCH 14/18] mm/damon/core: pass per-region filter-passed bytes to damos_walk_control->walk_fn() SeongJae Park
` (5 subsequent siblings)
18 siblings, 0 replies; 22+ messages in thread
From: SeongJae Park @ 2024-12-19 4:03 UTC (permalink / raw)
To: SeongJae Park; +Cc: kernel-team, damon, linux-mm, linux-kernel
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.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
mm/damon/core.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/mm/damon/core.c b/mm/damon/core.c
index 8540e8f91260..f7736df4f6c8 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -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);
--
2.39.5
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [RFC PATCH 14/18] mm/damon/core: pass per-region filter-passed bytes to damos_walk_control->walk_fn()
2024-12-19 4:03 [RFC PATCH 00/18] mm/damon: enable page level properties based access pattern monitoring SeongJae Park
` (12 preceding siblings ...)
2024-12-19 4:03 ` [RFC PATCH 13/18] mm/damon/core: invoke damos_walk_control->walk_fn() after applying action SeongJae Park
@ 2024-12-19 4:03 ` SeongJae Park
2024-12-19 4:03 ` [RFC PATCH 15/18] mm/damon/sysfs-schemes: expose per-region filter-passed bytes SeongJae Park
` (4 subsequent siblings)
18 siblings, 0 replies; 22+ messages in thread
From: SeongJae Park @ 2024-12-19 4:03 UTC (permalink / raw)
Cc: kernel-team, SeongJae Park, damon, linux-mm, linux-kernel
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().
Signed-off-by: SeongJae Park <sj@kernel.org>
---
include/linux/damon.h | 2 +-
mm/damon/core.c | 7 ++++---
mm/damon/sysfs.c | 2 +-
3 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/include/linux/damon.h b/include/linux/damon.h
index 4a68bb38aad5..b88f710297a9 100644
--- a/include/linux/damon.h
+++ b/include/linux/damon.h
@@ -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 */
diff --git a/mm/damon/core.c b/mm/damon/core.c
index f7736df4f6c8..f566cdcbb434 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -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);
diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c
index cf8fb5a963d6..224873ca8aa6 100644
--- a/mm/damon/sysfs.c
+++ b/mm/damon/sysfs.c
@@ -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;
--
2.39.5
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [RFC PATCH 15/18] mm/damon/sysfs-schemes: expose per-region filter-passed bytes
2024-12-19 4:03 [RFC PATCH 00/18] mm/damon: enable page level properties based access pattern monitoring SeongJae Park
` (13 preceding siblings ...)
2024-12-19 4:03 ` [RFC PATCH 14/18] mm/damon/core: pass per-region filter-passed bytes to damos_walk_control->walk_fn() SeongJae Park
@ 2024-12-19 4:03 ` SeongJae Park
2024-12-19 4:03 ` [RFC PATCH 16/18] Docs/mm/damon/design: document per-region sz_filter_passed stat SeongJae Park
` (3 subsequent siblings)
18 siblings, 0 replies; 22+ messages in thread
From: SeongJae Park @ 2024-12-19 4:03 UTC (permalink / raw)
Cc: kernel-team, SeongJae Park, damon, linux-mm, linux-kernel
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.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
mm/damon/sysfs-common.h | 2 +-
mm/damon/sysfs-schemes.c | 18 +++++++++++++++++-
mm/damon/sysfs.c | 3 ++-
3 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/mm/damon/sysfs-common.h b/mm/damon/sysfs-common.h
index b3f63bc658b7..70d84bdc9f5f 100644
--- a/mm/damon/sysfs-common.h
+++ b/mm/damon/sysfs-common.h
@@ -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);
diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c
index b447c412b02c..1da0594dde55 100644
--- a/mm/damon/sysfs-schemes.c
+++ b/mm/damon/sysfs-schemes.c
@@ -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(®ion->list, &sysfs_regions->regions_list);
sysfs_regions->nr_regions++;
if (kobject_init_and_add(®ion->kobj,
diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c
index 224873ca8aa6..deeab04d3b46 100644
--- a/mm/damon/sysfs.c
+++ b/mm/damon/sysfs.c
@@ -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(
--
2.39.5
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [RFC PATCH 16/18] Docs/mm/damon/design: document per-region sz_filter_passed stat
2024-12-19 4:03 [RFC PATCH 00/18] mm/damon: enable page level properties based access pattern monitoring SeongJae Park
` (14 preceding siblings ...)
2024-12-19 4:03 ` [RFC PATCH 15/18] mm/damon/sysfs-schemes: expose per-region filter-passed bytes SeongJae Park
@ 2024-12-19 4:03 ` SeongJae Park
2024-12-19 4:03 ` [RFC PATCH 17/18] Docs/admin-guide/mm/damon/usage: document sz_filtered_out of scheme tried region directories SeongJae Park
` (2 subsequent siblings)
18 siblings, 0 replies; 22+ messages in thread
From: SeongJae Park @ 2024-12-19 4:03 UTC (permalink / raw)
Cc: kernel-team, SeongJae Park, damon, linux-mm, linux-doc,
linux-kernel
Update 'Regions Walking' sectioin of design document for the newly added
per-region operations set handling DAMOS filters-passed bytes.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
Documentation/mm/damon/design.rst | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/Documentation/mm/damon/design.rst b/Documentation/mm/damon/design.rst
index 0620675a1e8d..ed3072dc8686 100644
--- a/Documentation/mm/damon/design.rst
+++ b/Documentation/mm/damon/design.rst
@@ -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>`.
--
2.39.5
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [RFC PATCH 17/18] Docs/admin-guide/mm/damon/usage: document sz_filtered_out of scheme tried region directories
2024-12-19 4:03 [RFC PATCH 00/18] mm/damon: enable page level properties based access pattern monitoring SeongJae Park
` (15 preceding siblings ...)
2024-12-19 4:03 ` [RFC PATCH 16/18] Docs/mm/damon/design: document per-region sz_filter_passed stat SeongJae Park
@ 2024-12-19 4:03 ` SeongJae Park
2024-12-19 4:03 ` [RFC PATCH 18/18] Docs/ABI/damon: document per-region DAMOS filter-passed bytes stat file SeongJae Park
2024-12-23 20:24 ` [RFC PATCH 00/18] mm/damon: enable page level properties based access pattern monitoring SeongJae Park
18 siblings, 0 replies; 22+ messages in thread
From: SeongJae Park @ 2024-12-19 4:03 UTC (permalink / raw)
Cc: kernel-team, SeongJae Park, damon, linux-mm, linux-doc,
linux-kernel
Document the newly added DAMON sysfs interface file for per-scheme-tried
region's bytes that passed the operations set handling DAMOS filters.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
Documentation/admin-guide/mm/damon/usage.rst | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/Documentation/admin-guide/mm/damon/usage.rst b/Documentation/admin-guide/mm/damon/usage.rst
index 179a9060a32e..a891e830c2a1 100644
--- a/Documentation/admin-guide/mm/damon/usage.rst
+++ b/Documentation/admin-guide/mm/damon/usage.rst
@@ -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
~~~~~~~
--
2.39.5
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [RFC PATCH 18/18] Docs/ABI/damon: document per-region DAMOS filter-passed bytes stat file
2024-12-19 4:03 [RFC PATCH 00/18] mm/damon: enable page level properties based access pattern monitoring SeongJae Park
` (16 preceding siblings ...)
2024-12-19 4:03 ` [RFC PATCH 17/18] Docs/admin-guide/mm/damon/usage: document sz_filtered_out of scheme tried region directories SeongJae Park
@ 2024-12-19 4:03 ` SeongJae Park
2024-12-23 20:24 ` [RFC PATCH 00/18] mm/damon: enable page level properties based access pattern monitoring SeongJae Park
18 siblings, 0 replies; 22+ messages in thread
From: SeongJae Park @ 2024-12-19 4:03 UTC (permalink / raw)
Cc: kernel-team, SeongJae Park, damon, linux-mm, linux-kernel
Document the new ABI for per-region operations set layer-handled DAMOS
filters passed bytes statistic.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
Documentation/ABI/testing/sysfs-kernel-mm-damon | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/Documentation/ABI/testing/sysfs-kernel-mm-damon b/Documentation/ABI/testing/sysfs-kernel-mm-damon
index 19cde386fd15..8c0acb31638b 100644
--- a/Documentation/ABI/testing/sysfs-kernel-mm-damon
+++ b/Documentation/ABI/testing/sysfs-kernel-mm-damon
@@ -430,3 +430,10 @@ Contact: SeongJae Park <sj@kernel.org>
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 <sj@kernel.org>
+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.
--
2.39.5
^ permalink raw reply related [flat|nested] 22+ messages in thread
* Re: [RFC PATCH 00/18] mm/damon: enable page level properties based access pattern monitoring
2024-12-19 4:03 [RFC PATCH 00/18] mm/damon: enable page level properties based access pattern monitoring SeongJae Park
` (17 preceding siblings ...)
2024-12-19 4:03 ` [RFC PATCH 18/18] Docs/ABI/damon: document per-region DAMOS filter-passed bytes stat file SeongJae Park
@ 2024-12-23 20:24 ` SeongJae Park
18 siblings, 0 replies; 22+ messages in thread
From: SeongJae Park @ 2024-12-23 20:24 UTC (permalink / raw)
To: SeongJae Park
Cc: kernel-team, Andrew Morton, Jonathan Corbet, damon, linux-mm,
linux-doc, linux-kernel
On Wed, 18 Dec 2024 20:03:09 -0800 SeongJae Park <sj@kernel.org> 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
[...]
^ permalink raw reply [flat|nested] 22+ messages in thread