mm/damos/stat: introduce nr_snapshots, max_nr_snapshots and tracepoint
Subsystems (5)
SeongJae Park
maintainercover mm/damos/stat: introduce nr_snapshots, max_nr_snapshots and tracepoint
Introduce three changes for improving DAMOS stat's provided information, deterministic control, and reading usability.
DAMOS provides stats that are important for understanding its behavior. It lacks information about how many DAMON-generated monitoring output snapshots it has worked on. Add a new stat, nr_snapshots, to show the information.
Users can control DAMOS schemes in multiple ways. Using the online parameters commit feature, they can install and uninstall DAMOS schemes whenever they want while keeping DAMON runs. DAMOS quotas and watermarks can be used for manually or automatically turning on/off or adjusting the aggressiveness of the scheme. DAMOS filters can be used for applying the scheme to specific memory entities based on their types and locations. Some users want their DAMOS scheme to be applied to only specific number of DAMON snapshots, for more deterministic control. One example use case is tracepoint based snapshot reading. Add a new knob, max_nr_snapshots, to support this. If the nr_snapshots parameter becomes same to or greater than the value of this parameter, the scheme is deactivated.
Users can read DAMOS stats via DAMON's sysfs interface. For deep level investigations on environments having advanced tools like perf and bpftrace, exposing the stats via a tracepoint can be useful. Implement a new tracepoint, namely damon:damos_stat_after_apply_interval.
First five patches (patches 1-5) of this series implement the new stat, nr_snapshots, on the core layer (patch 1), expose on DAMON sysfs user interface (patch 2), and update documents (patches 3-5).
Following six patches (patches 6-11) are for the new stat based DAMOS deactivation (max_nr_snapshots). The first one (patch 6) of this group updates a kernel-doc comment before making further changes. Then an implementation of it on the core layer (patch 7), an introduction of a new DAMON sysfs interface file for users of the feature (patch 8), and three updates of the documents (patches 9-11) follow.
The final one (patch 12) introduces the new tracepoint that exposes the DAMOS stat values for each scheme apply interval.
SeongJae Park (12):
mm/damon/core: introduce nr_snapshots damos stat mm/damon/sysfs-schemes: introduce nr_snapshots damos stat file Docs/mm/damon/design: update for nr_snapshots damos stat Docs/admin-guide/mm/damon/usage: update for nr_snapshots damos stat Docs/ABI/damon: update for nr_snapshots damos stat mm/damon: update damos kerneldoc for stat field mm/damon/core: implement max_nr_snapshots mm/damon/sysfs-schemes: implement max_nr_snapshots file Docs/mm/damon/design: update for max_nr_snapshots Docs/admin-guide/mm/damon/usage: update for max_nr_snapshots Docs/ABI/damon: update for max_nr_snapshots mm/damon/core: add trace point for damos stat per apply interval
.../ABI/testing/sysfs-kernel-mm-damon | 13 ++++++ Documentation/admin-guide/mm/damon/usage.rst | 11 ++--- Documentation/mm/damon/design.rst | 7 +++ include/linux/damon.h | 12 ++++-- include/trace/events/damon.h | 41 ++++++++++++++++++ mm/damon/core.c | 37 ++++++++++++++-- mm/damon/sysfs-schemes.c | 43 +++++++++++++++++++ 7 files changed, 153 insertions(+), 11 deletions(-)
base-commit: 522f1a9fc5f1f0a11af39ba5bedae446322ca0a2
Signature · 1 line
2.47.3
SeongJae Park
maintainerRFC PATCH 1/12 mm/damon/core: introduce nr_snapshots damos stat
DAMON generates monitoring results snapshots for every sampling interval. DAMOS applies given schemes on the regions of the snapshots, for every apply interval of the scheme.
DAMOS stat informs a given scheme has tried to how many memory entities and applied, in the region and byte level. In some use cases including user-space oriented tuning and investigations, it is useful to know that in the DAMON-snapshot level. Introduce a new stat, namely nr_snapshots for DAMON core API callers.
--- include/linux/damon.h | 3 +++ mm/damon/core.c | 13 ++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-)
include/linux/damon.h +3 -0
@@ -330,6 +330,8 @@ struct damos_watermarks {* @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. +* @nr_snapshots: +* Total number of DAMON snapshots that the scheme has tried. * * "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
@@ -355,6 +357,7 @@ struct damos_stat {unsigned long sz_applied;unsigned long sz_ops_filter_passed;unsigned long qt_exceeds; +unsigned long nr_snapshots; };/**
mm/damon/core.c +10 -3
@@ -157,6 +157,12 @@ void damon_destroy_region(struct damon_region *r, struct damon_target *t)damon_free_region (r); } +static bool damon_is_last_region (struct damon_region *r, +struct damon_target *t) +{ +return list_is_last (&t->regions_list, &r->list); +} +/* * Check whether a region is intersecting an address range *
@@ -1949,10 +1955,11 @@ static void damon_do_apply_schemes(struct damon_ctx *c,if (damos_skip_charged_region (t, &r, s, c->min_sz_region))continue ; -if (!damos_valid_target (c, t, r, s)) -continue ; +if (damos_valid_target (c, t, r, s)) +damos_apply_scheme (c, t, r, s); -damos_apply_scheme (c, t, r, s); +if (damon_is_last_region (r, t)) + s->stat.nr_snapshots++; } }
Signature · 1 line
2.47.3
SeongJae Park
maintainerRFC PATCH 2/12 mm/damon/sysfs-schemes: introduce nr_snapshots damos stat file
In reply to SeongJae ParkIntroduce a new DAMON sysfs interface file for exposing the newly added DAMOS stat, nr_snapshots. The file has the name same to the stat name (nr_snapshots) and placed under the damos stat sysfs directory.
--- mm/damon/sysfs-schemes.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
mm/damon/sysfs-schemes.c +15 -0
@@ -204,6 +204,7 @@ struct damon_sysfs_stats {unsigned long sz_applied;unsigned long sz_ops_filter_passed;unsigned long qt_exceeds; +unsigned long nr_snapshots; };static struct damon_sysfs_stats *damon_sysfs_stats_alloc (void )
@@ -265,6 +266,15 @@ static ssize_t qt_exceeds_show(struct kobject *kobj,return sysfs_emit (buf,"%lu\n" , stats->qt_exceeds); } +static ssize_t nr_snapshots_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->nr_snapshots); +} +static void damon_sysfs_stats_release (struct kobject *kobj) {kfree (container_of(kobj ,struct damon_sysfs_stats ,kobj ));
@@ -288,6 +298,9 @@ static struct kobj_attribute damon_sysfs_stats_sz_ops_filter_passed_attr =static struct kobj_attribute damon_sysfs_stats_qt_exceeds_attr =__ATTR_RO_MODE (qt_exceeds,0400 ); +static struct kobj_attribute damon_sysfs_stats_nr_snapshots_attr = +__ATTR_RO_MODE (nr_snapshots,0400 ); +static struct attribute *damon_sysfs_stats_attrs[] = { &damon_sysfs_stats_nr_tried_attr.attr, &damon_sysfs_stats_sz_tried_attr.attr,
@@ -295,6 +308,7 @@ static struct attribute *damon_sysfs_stats_attrs[] = { &damon_sysfs_stats_sz_applied_attr.attr, &damon_sysfs_stats_sz_ops_filter_passed_attr.attr, &damon_sysfs_stats_qt_exceeds_attr.attr, + &damon_sysfs_stats_nr_snapshots_attr.attr,NULL , };ATTRIBUTE_GROUPS (damon_sysfs_stats);
@@ -2761,6 +2775,7 @@ void damon_sysfs_schemes_update_stats( sysfs_stats->sz_ops_filter_passed = scheme->stat.sz_ops_filter_passed; sysfs_stats->qt_exceeds = scheme->stat.qt_exceeds; + sysfs_stats->nr_snapshots = scheme->stat.nr_snapshots; } }
Signature · 1 line
2.47.3
SeongJae Park
maintainerRFC PATCH 3/12 Docs/mm/damon/design: update for nr_snapshots damos stat
In reply to SeongJae ParkUpdate DAMON design document for the newly added damos stat, nr_snapshots.
--- Documentation/mm/damon/design.rst | 2 ++ 1 file changed, 2 insertions(+)
Documentation/mm/damon/design.rst +2 -0
@@ -718,6 +718,8 @@ scheme's execution. - ``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. +- ``nr_snapshots``: Total number of DAMON snapshots that the scheme is tried to + be applied. "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
Signature · 1 line
2.47.3
SeongJae Park
maintainerRFC PATCH 4/12 Docs/admin-guide/mm/damon/usage: update for nr_snapshots damos stat
In reply to SeongJae ParkUpdate DAMON usage document for the newly added damos stat, nr_snapshots.
--- Documentation/admin-guide/mm/damon/usage.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
Documentation/admin-guide/mm/damon/usage.rst +4 -4
@@ -87,7 +87,7 @@ comma (","). │ │ │ │ │ │ │ │ 0/type,matching,allow,memcg_path,addr_start,addr_end,target_idx,min,max │ │ │ │ │ │ │ :ref:`dests <damon_sysfs_dests>`/nr_dests │ │ │ │ │ │ │ │ 0/id,weight - │ │ │ │ │ │ │ :ref:`stats <sysfs_schemes_stats>`/nr_tried,sz_tried,nr_applied,sz_applied,sz_ops_filter_passed,qt_exceeds + │ │ │ │ │ │ │ :ref:`stats <sysfs_schemes_stats>`/nr_tried,sz_tried,nr_applied,sz_applied,sz_ops_filter_passed,qt_exceeds,nr_snapshots │ │ │ │ │ │ │ :ref:`tried_regions <sysfs_schemes_tried_regions>`/total_bytes │ │ │ │ │ │ │ │ 0/start,end,nr_accesses,age,sz_filter_passed │ │ │ │ │ │ │ │ ...
@@ -543,9 +543,9 @@ online analysis or tuning of the schemes. Refer to :ref:`design doc The statistics can be retrieved by reading the files under ``stats`` directory (``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, +``sz_ops_filter_passed``, ``qt_exceeds`` and ``nr_snapshots``), 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.47.3
SeongJae Park
maintainerRFC PATCH 5/12 Docs/ABI/damon: update for nr_snapshots damos stat
In reply to SeongJae ParkUpdate DAMON ABI document for the newly added damos stat, nr_snapshots.
--- Documentation/ABI/testing/sysfs-kernel-mm-damon | 6 ++++++ 1 file changed, 6 insertions(+)
Documentation/ABI/testing/sysfs-kernel-mm-damon +6 -0
@@ -516,6 +516,12 @@ Contact: SeongJae Park <[email protected]> Description: Reading this file returns the number of the exceed events of the scheme's quotas. +What: /sys/kernel/mm/damon/admin/kdamonds/<K>/contexts/<C>/schemes/<S>/stats/nr_snapshots +Date: Nov 2025 +Contact: SeongJae Park <[email protected]> +Description: Reading this file returns the total number of DAMON snapshots + that the scheme has tried to be applied. + What: /sys/kernel/mm/damon/admin/kdamonds/<K>/contexts/<C>/schemes/<S>/tried_regions/total_bytes Date: Jul 2023 Contact: SeongJae Park <[email protected]>
Signature · 1 line
2.47.3
SeongJae Park
maintainerRFC PATCH 6/12 mm/damon: update damos kerneldoc for stat field
In reply to SeongJae ParkCommit 0e92c2ee9f45 ("mm/damon/schemes: account scheme actions that successfully applied") has replaced ->stat_count and ->stat_sz of 'struct damos' with ->stat. The commit mistakenly did not update the related kernel doc comment, though. Update the comment.
--- include/linux/damon.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
include/linux/damon.h +1 -3
@@ -532,9 +532,7 @@ struct damos_migrate_dests {* unsets @last_applied when each regions walking for applying the scheme is * finished. * -* After applying the &action to each region, &stat_count and &stat_sz is -* updated to reflect the number of regions and total size of regions that the -* &action is applied. +* After applying the &action to each region, &stat is updated. */ struct damos {struct damos_access_pattern pattern;
Signature · 1 line
2.47.3
SeongJae Park
maintainerRFC PATCH 7/12 mm/damon/core: implement max_nr_snapshots
In reply to SeongJae ParkThere are DAMOS use cases that require user-space centric control of its activation and deactivation. Having the control plane on the user-space, or using DAMOS as a way for monitoring results collection are such examples.
DAMON parameters online commit, DAMOS quotas and watermarks can be useful for this purpose. However, those features work only at the sub-DAMON-snapshot level. In some use cases, the DAMON-snapshot level control is required. For example, in DAMOS-based monitoring results collection use case, the user online-installs a DAMOS scheme with DAMOS_STAT action, wait it be applied to whole regions of a single DAMON-snapshot, retrieves the stats and tried regions information, and online-uninstall the scheme. It is efficient to ensure the lifetime of the scheme as no more no less one snapshot consumption.
To support such use cases, introduce a new DAMOS core API per-scheme parameter, namely max_nr_snapshots. As the name implies, it is the upper limit of nr_snapshots, which is a DAMOS stat that represents the number of DAMON-snapshots that the scheme has fully applied. If the limit is set with a non-zero value and nr_snapshots reaches or exceeds the limit, the scheme is deactivated.
--- include/linux/damon.h | 5 +++++ mm/damon/core.c | 11 ++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-)
include/linux/damon.h +5 -0
@@ -499,6 +499,7 @@ struct damos_migrate_dests {* @ops_filters: ops layer handling &struct damos_filter objects list. * @last_applied: Last @action applied ops-managing entity. * @stat: Statistics of this scheme. +* @max_nr_snapshots: Upper limit of nr_snapshots stat. * @list: List head for siblings. * * For each @apply_interval_us, DAMON finds regions which fit in the
@@ -533,6 +534,9 @@ struct damos_migrate_dests {* finished. * * After applying the &action to each region, &stat is updated. +* +* If &max_nr_snapshots is set as non-zero and &stat.nr_snapshots be same to or +* greater than it, the scheme is deactivated. */ struct damos {struct damos_access_pattern pattern;
@@ -567,6 +571,7 @@ struct damos {struct list_head ops_filters;void *last_applied;struct damos_stat stat; +unsigned long max_nr_snapshots;struct list_head list; };
mm/damon/core.c +10 -1
@@ -401,6 +401,7 @@ struct damos *damon_new_scheme(struct damos_access_pattern *pattern,INIT_LIST_HEAD (&scheme->core_filters);INIT_LIST_HEAD (&scheme->ops_filters); scheme->stat = (struct damos_stat ){}; + scheme->max_nr_snapshots =0 ;INIT_LIST_HEAD (&scheme->list); scheme->quota = *(damos_quota_init (quota));
@@ -1078,7 +1079,11 @@ static int damos_commit(struct damos *dst, struct damos *src)return err; err =damos_commit_filters (dst, src); -return err; +if (err) +return err; + + dst->max_nr_snapshots = src->max_nr_snapshots; +return 0 ; }static int damon_commit_schemes (struct damon_ctx *dst,struct damon_ctx *src)
@@ -1955,6 +1960,10 @@ static void damon_do_apply_schemes(struct damon_ctx *c,if (damos_skip_charged_region (t, &r, s, c->min_sz_region))continue ; +if (s->max_nr_snapshots && + s->max_nr_snapshots <= s->stat.nr_snapshots) +continue ; +if (damos_valid_target (c, t, r, s))damos_apply_scheme (c, t, r, s);
Signature · 1 line
2.47.3
SeongJae Park
maintainerRFC PATCH 8/12 mm/damon/sysfs-schemes: implement max_nr_snapshots file
In reply to SeongJae ParkAdd a new DAMON sysfs file for setting and getting the newly introduced per-DAMON-snapshot level DAMOS deactivation control parameter, max_nr_snapshots. The file has a name same to the parameter and placed under the damos stat directory.
--- mm/damon/sysfs-schemes.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
mm/damon/sysfs-schemes.c +28 -0
@@ -205,6 +205,7 @@ struct damon_sysfs_stats {unsigned long sz_ops_filter_passed;unsigned long qt_exceeds;unsigned long nr_snapshots; +unsigned long max_nr_snapshots; };static struct damon_sysfs_stats *damon_sysfs_stats_alloc (void )
@@ -275,6 +276,28 @@ static ssize_t nr_snapshots_show(struct kobject *kobj,return sysfs_emit (buf,"%lu\n" , stats->nr_snapshots); } +static ssize_t max_nr_snapshots_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->max_nr_snapshots); +} + +static ssize_t max_nr_snapshots_store (struct kobject *kobj, +struct kobj_attribute *attr,const char *buf,size_t count) +{ +struct damon_sysfs_stats *stats =container_of (kobj, + struct damon_sysfs_stats, kobj); +unsigned long max_nr_snapshots, err =kstrtoul (buf,0 , &max_nr_snapshots); + +if (err) +return err; + stats->max_nr_snapshots = max_nr_snapshots; +return count; +} +static void damon_sysfs_stats_release (struct kobject *kobj) {kfree (container_of(kobj ,struct damon_sysfs_stats ,kobj ));
@@ -301,6 +324,9 @@ static struct kobj_attribute damon_sysfs_stats_qt_exceeds_attr =static struct kobj_attribute damon_sysfs_stats_nr_snapshots_attr =__ATTR_RO_MODE (nr_snapshots,0400 ); +static struct kobj_attribute damon_sysfs_stats_max_nr_snapshots_attr = +__ATTR_RW_MODE (max_nr_snapshots,0600 ); +static struct attribute *damon_sysfs_stats_attrs[] = { &damon_sysfs_stats_nr_tried_attr.attr, &damon_sysfs_stats_sz_tried_attr.attr,
@@ -309,6 +335,7 @@ static struct attribute *damon_sysfs_stats_attrs[] = { &damon_sysfs_stats_sz_ops_filter_passed_attr.attr, &damon_sysfs_stats_qt_exceeds_attr.attr, &damon_sysfs_stats_nr_snapshots_attr.attr, + &damon_sysfs_stats_max_nr_snapshots_attr.attr,NULL , };ATTRIBUTE_GROUPS (damon_sysfs_stats);
@@ -2731,6 +2758,7 @@ static struct damos *damon_sysfs_mk_scheme(damon_destroy_scheme (scheme);return NULL ; } + scheme->max_nr_snapshots = sysfs_scheme->stats->max_nr_snapshots;return scheme; }
Signature · 1 line
2.47.3
SeongJae Park
maintainerRFC PATCH 9/12 Docs/mm/damon/design: update for max_nr_snapshots
In reply to SeongJae ParkUpdate DAMON design document for the newly added snapshot level DAMOS deactivation feature, max_nr_snapshots.
--- Documentation/mm/damon/design.rst | 5 +++++ 1 file changed, 5 insertions(+)
Documentation/mm/damon/design.rst +5 -0
@@ -720,6 +720,7 @@ scheme's execution. - ``qt_exceeds``: Total number of times the quota of the scheme has exceeded. - ``nr_snapshots``: Total number of DAMON snapshots that the scheme is tried to be applied. +- ``max_nr_snapshots``: Upper limit of ``nr_snapshots``. "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
@@ -741,6 +742,10 @@ 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. +Unlike normal stats, ``max_nr_snapshots`` is set by users. If it is set as +non-zero and ``nr_snapshots`` be same to or greater than ``nr_snapshots``, the +scheme is deactivated. + 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.
Signature · 1 line
2.47.3
SeongJae Park
maintainerRFC PATCH 10/12 Docs/admin-guide/mm/damon/usage: update for max_nr_snapshots
In reply to SeongJae ParkUpdate DAMON usage document for the newly added DAMON sysfs interface file, max_nr_snapshots.
--- Documentation/admin-guide/mm/damon/usage.rst | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
Documentation/admin-guide/mm/damon/usage.rst +6 -5
@@ -87,7 +87,7 @@ comma (","). │ │ │ │ │ │ │ │ 0/type,matching,allow,memcg_path,addr_start,addr_end,target_idx,min,max │ │ │ │ │ │ │ :ref:`dests <damon_sysfs_dests>`/nr_dests │ │ │ │ │ │ │ │ 0/id,weight - │ │ │ │ │ │ │ :ref:`stats <sysfs_schemes_stats>`/nr_tried,sz_tried,nr_applied,sz_applied,sz_ops_filter_passed,qt_exceeds,nr_snapshots + │ │ │ │ │ │ │ :ref:`stats <sysfs_schemes_stats>`/nr_tried,sz_tried,nr_applied,sz_applied,sz_ops_filter_passed,qt_exceeds,nr_snapshots,max_nr_snapshots │ │ │ │ │ │ │ :ref:`tried_regions <sysfs_schemes_tried_regions>`/total_bytes │ │ │ │ │ │ │ │ 0/start,end,nr_accesses,age,sz_filter_passed │ │ │ │ │ │ │ │ ...
@@ -543,10 +543,11 @@ online analysis or tuning of the schemes. Refer to :ref:`design doc The statistics can be retrieved by reading the files under ``stats`` directory (``nr_tried``, ``sz_tried``, ``nr_applied``, ``sz_applied``, -``sz_ops_filter_passed``, ``qt_exceeds`` and ``nr_snapshots``), 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. +``sz_ops_filter_passed``, ``qt_exceeds``, ``nr_snapshots`` and +``max_nr_snapshots``), 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.47.3
SeongJae Park
maintainerRFC PATCH 11/12 Docs/ABI/damon: update for max_nr_snapshots
In reply to SeongJae ParkUpdate DAMON ABI document for the newly added DAMON sysfs interface file, max_nr_snapshots.
--- Documentation/ABI/testing/sysfs-kernel-mm-damon | 7 +++++++ 1 file changed, 7 insertions(+)
Documentation/ABI/testing/sysfs-kernel-mm-damon +7 -0
@@ -522,6 +522,13 @@ Contact: SeongJae Park <[email protected]> Description: Reading this file returns the total number of DAMON snapshots that the scheme has tried to be applied. +What: /sys/kernel/mm/damon/admin/kdamonds/<K>/contexts/<C>/schemes/<S>/stats/max_nr_snapshots +Date: Nov 2025 +Contact: SeongJae Park <[email protected]> +Description: Writing a number to this file sets the upper limit of + nr_snapshots that deactivates the scheme when the limit is + reached or exceeded. + What: /sys/kernel/mm/damon/admin/kdamonds/<K>/contexts/<C>/schemes/<S>/tried_regions/total_bytes Date: Jul 2023 Contact: SeongJae Park <[email protected]>
Signature · 1 line
2.47.3
SeongJae Park
maintainerRFC PATCH 12/12 mm/damon/core: add trace point for damos stat per apply interval
In reply to SeongJae ParkDAMON users can read DAMOS stats via DAMON sysfs interface. It enables efficient, simple and flexible usages of the stats. Especially for systems not having advanced tools like perf or bpftrace, that can be useful. But if the advanced tools are available, exposing the stats via tracepoint can reduce unnecessary reimplementation of the wheels. Add a new tracepoint for DAMOS stats, namely damos_stat_after_apply_interval. The tracepoint is triggered for each scheme's apply interval and exposes the whole stat values. If the user needs sub-apply interval information for any chance, damos_before_apply tracepoint could be used.
--- include/trace/events/damon.h | 41 ++++++++++++++++++++++++++++++++++++ mm/damon/core.c | 15 +++++++++++++ 2 files changed, 56 insertions(+)
include/trace/events/damon.h +41 -0
@@ -9,6 +9,47 @@#include <linux/types.h> #include <linux/tracepoint.h> +TRACE_EVENT (damos_stat_after_apply_interval, + + TP_PROTO(unsigned int context_idx, unsigned int scheme_idx, + struct damos_stat *stat), + +TP_ARGS (context_idx, scheme_idx, stat), + +TP_STRUCT__entry ( + __field(unsigned int, context_idx) + __field(unsigned int, scheme_idx) + __field(unsigned long, nr_tried) + __field(unsigned long, sz_tried) + __field(unsigned long, nr_applied) + __field(unsigned long, sz_applied) + __field(unsigned long, sz_ops_filter_passed) + __field(unsigned long, qt_exceeds) + __field(unsigned long, nr_snapshots) + ), + +TP_fast_assign ( + __entry->context_idx = context_idx; + __entry->scheme_idx = scheme_idx; + __entry->nr_tried = stat->nr_tried; + __entry->sz_tried = stat->sz_tried; + __entry->nr_applied = stat->nr_applied; + __entry->sz_applied = stat->sz_applied; + __entry->sz_ops_filter_passed = stat->sz_ops_filter_passed; + __entry->qt_exceeds = stat->qt_exceeds; + __entry->nr_snapshots = stat->nr_snapshots; + ), + +TP_printk ("ctx_idx=%u scheme_idx=%u nr_tried=%lu sz_tried=%lu " +"nr_applied=%lu sz_tried=%lu sz_ops_filter_passed=%lu " +"qt_exceeds=%lu nr_snapshots=%lu" , + __entry->context_idx, __entry->scheme_idx, + __entry->nr_tried, __entry->sz_tried, + __entry->nr_applied, __entry->sz_applied, + __entry->sz_ops_filter_passed, __entry->qt_exceeds, + __entry->nr_snapshots) +); + TRACE_EVENT(damos_esz, TP_PROTO(unsigned int context_idx, unsigned int scheme_idx,
mm/damon/core.c +15 -0
@@ -2256,6 +2256,19 @@ static void damos_adjust_quota(struct damon_ctx *c, struct damos *s) quota->min_score = score; } +static void damos_trace_stat (struct damon_ctx *c,struct damos *s) +{ +unsigned int cidx =0 , sidx =0 ; +struct damos *siter; + +damon_for_each_scheme (siter, c) { +if (siter == s) +break ; + sidx++; + } +trace_damos_stat_after_apply_interval (cidx, sidx, &s->stat); +} +static void kdamond_apply_schemes (struct damon_ctx *c) {struct damon_target *t;
@@ -2294,6 +2307,8 @@ static void kdamond_apply_schemes(struct damon_ctx *c) (s->apply_interval_us ? s->apply_interval_us : c->attrs.aggr_interval) / sample_interval; s->last_applied =NULL ; +if (trace_damos_stat_after_apply_interval_enabled ()) +damos_trace_stat (c, s); }mutex_unlock (&c->walk_control_lock); }
Signature · 1 line
2.47.3
SeongJae Park
maintainerQuoted 2 lines · On Sun, 23 Nov 2025 10:43:14 -0800 SeongJae Park <[email protected]> wrote:
Introduce three changes for improving DAMOS stat's provided information, deterministic control, and reading usability.
FYI, I'm not aiming to make this be merged in 6.19-rc1.
Thanks,
SJ
[...]
Steven Rostedt
maintainerRe: [RFC PATCH 12/12] mm/damon/core: add trace point for damos stat per apply interval
In reply to SeongJae ParkQuoted 23 lines · On Sun, 23 Nov 2025 10:43:26 -0800 SeongJae Park <[email protected]> wrote:
mm/damon/core.c +13
-0@@ -2256,6 +2256,19 @@ static void damos_adjust_quota(struct damon_ctx *c, struct damos *s) quota->min_score = score; } +static void damos_trace_stat (struct damon_ctx *c,struct damos *s) +{ +unsigned int cidx =0 , sidx =0 ; +struct damos *siter; + +damon_for_each_scheme (siter, c) { +if (siter == s) +break ; + sidx++; + } +trace_damos_stat_after_apply_interval (cidx, sidx, &s->stat); +} +static void kdamond_apply_schemes (struct damon_ctx *c) {struct damon_target *t;
mm/damon/core.c static void kdamond_apply_schemes(struct damon_ctx *c) · line 2314
Quoted 8 lines
mm/damon/core.c +2
-0@@ -2294,6 +2307,8 @@ static void kdamond_apply_schemes(struct damon_ctx *c) (s->apply_interval_us ? s->apply_interval_us : c->attrs.aggr_interval) / sample_interval; s->last_applied =NULL ; +if (trace_damos_stat_after_apply_interval_enabled ()) +damos_trace_stat (c, s); }mutex_unlock (&c->walk_control_lock); }
I wonder if the above would look better (and still produce good assembly) if it was:
static inline void damos_trace_stat(struct damon_ctx *c, struct damos *s)
{
unsigned int cidx = 0, sidx = 0;
struct damos *siter;
if (!trace_damos_stat_after_apply_interval_enabled())
return;
damon_for_each_scheme(siter, c) {
if (siter == s)
break;
sidx++;
}
trace_damos_stat_after_apply_interval(cidx, sidx, &s->stat);
}static void kdamond_apply_schemes(struct damon_ctx *c)
{
struct damon_target *t;mm/damon/core.c static void kdamond_apply_schemes(struct damon_ctx *c)
Quoted 1 line
mm/damon/core.c +0
-0@@ -2294,6 +2307,8 @@ static void kdamond_apply_schemes(struct damon_ctx *c)
(s->apply_interval_us ? s->apply_interval_us : c->attrs.aggr_interval) / sample_interval; s->last_applied = NULL; damos_trace_stat(c, s); } mutex_unlock(&c->walk_control_lock); }
I have no real preference. I just think keeping the "if ()" statement out of the main code as a more aesthetic look. But the above should be equivalent in actual functionality.
-- Steve
SeongJae Park
maintainerRe: [RFC PATCH 12/12] mm/damon/core: add trace point for damos stat per apply interval
Quoted 5 lines · On Mon, 24 Nov 2025 10:15:45 -0500 Steven Rostedt <[email protected]> wrote:
Quoted 2 lines · On Sun, 23 Nov 2025 10:43:26 -0800 SeongJae Park <[email protected]> wrote:
mm/damon/core.c +0
-0
[...]
Quoted 2 lines
I wonder if the above would look better (and still produce good assembly) if it was:
[...]
Quoted 3 lines
I have no real preference. I just think keeping the "if ()" statement out of the main code as a more aesthetic look. But the above should be equivalent in actual functionality.
Thank you for this suggestion, Steve! I'll update this patch as you suggested in the next version.
Thanks,
SJ
[...]