DAMOS access pattern supports selecting regions to apply a given
Subsystems (4)
SJ Park
maintainercover DAMOS access pattern supports selecting regions to apply a given
One straightforward solution is extending the DAMOS access pattern for specific deterministic time based age specification. However, DAMOS core filter is a better option. It is playing a similar role in a more flexible way. It can be used for both accepting and rejecting regions based on if they matched or unmatched to a given criteria. Multiple filters can also be combined for more flexible and detailed rules.
Extend DAMOS core filter to support milliseconds unit based age criteria.
Implement a new DAMOS core filter type, DAMOS_FILTER_TYPE_AGE_MS, in core layer and expose to DAMON API, via patch 1. Add the support of the feature on DAMON sysfs ABI with patch 2. Update the design and usage documents to explain the new features with patches 3 and 4, respectively.
SJ Park (4):
mm/damon/core: add DAMOS_FILTER_TYPE_AGE_MS mm/damon/sysfs-schemes: support DAMOS_FILTER_TYPE_AGE_MS Docs/mm/damon/design: update for age_ms damos core filter type Docs/admin-guide/mm/damon/usage: update for age_ms damos core filter
Documentation/admin-guide/mm/damon/usage.rst | 3 +++ Documentation/mm/damon/design.rst | 3 +++ include/linux/damon.h | 16 ++++++++++------ mm/damon/core.c | 9 ++++++++- mm/damon/sysfs-schemes.c | 5 +++++ 5 files changed, 29 insertions(+), 7 deletions(-)
base-commit: 32e967f279b24f952a5482e2c427894787848ee0
Signature · 1 line
2.47.3
SJ Park
maintainerRFC PATCH 1/4 mm/damon/core: add DAMOS_FILTER_TYPE_AGE_MS
There is no way to specify DAMOS target regions with a deterministic time based age range. Extend DAMOS core filter to specify target regions with age in milliseconds. Introduce new damos_filter_type, DAMOS_FILTER_TYPE_AGE_MS in DAMON API, and implement support of the type in the core layer.
Convert the age in aggregation intervals to milliseconds and use it when the filter is evaluated. Reuse damos_filter->range_{min,max} to save the age range.
--- include/linux/damon.h | 16 ++++++++++------ mm/damon/core.c | 9 ++++++++- 2 files changed, 18 insertions(+), 7 deletions(-)
include/linux/damon.h +10 -6
@@ -394,13 +394,16 @@ struct damos_stat {* @DAMOS_FILTER_TYPE_ADDR: Address range. * @DAMOS_FILTER_TYPE_TARGET: Data Access Monitoring target. * @DAMOS_FILTER_TYPE_PROBE_HITS_WSUM: probe_hits weighted sum range. +* @DAMOS_FILTER_TYPE_AGE_MS: Region age range in milliseconds. * -* All types except &DAMOS_FILTER_TYPE_ADDR, &DAMOS_FILTER_TYPE_TARGET and -* &DAMOS_FILTER_TYPE_PROBE_HITS_WSUM are handled by the underlying &struct -* damon_operations as a part of scheme action trying, and therefore accounted -* as 'tried'. In contrast, &DAMOS_FILTER_TYPE_ADDR, &DAMOS_FILTER_TYPE_TARGET -* and &DAMOS_FILTER_TYPE_PROBE_HITS_WSUM filters are handled by the core layer -* before trying of the action, and therefore not accounted as 'tried'. +* All types except &DAMOS_FILTER_TYPE_ADDR, &DAMOS_FILTER_TYPE_TARGET, +* &DAMOS_FILTER_TYPE_PROBE_HITS_WSUM and &DAMOS_FILTER_TYPE_AGE_MS are handled +* by the underlying &struct damon_operations as a part of scheme action +* trying, and therefore accounted as 'tried'. In contrast, +* &DAMOS_FILTER_TYPE_ADDR, &DAMOS_FILTER_TYPE_TARGET, +* &DAMOS_FILTER_TYPE_PROBE_HITS_WSUM and &DAMOS_FILTER_TYPE_AGE_MS filters are +* handled by the core layer before trying of the action, and therefore not +* accounted as 'tried'. * * Support for the operations-handled filters depends on the running * &struct damon_operations.
@@ -415,6 +418,7 @@ enum damos_filter_type {DAMOS_FILTER_TYPE_ADDR ,DAMOS_FILTER_TYPE_TARGET ,DAMOS_FILTER_TYPE_PROBE_HITS_WSUM , + DAMOS_FILTER_TYPE_AGE_MS, };/**
mm/damon/core.c +8 -1
@@ -659,6 +659,7 @@ bool damos_filter_for_ops(enum damos_filter_type type)case DAMOS_FILTER_TYPE_ADDR :case DAMOS_FILTER_TYPE_TARGET :case DAMOS_FILTER_TYPE_PROBE_HITS_WSUM : +case DAMOS_FILTER_TYPE_AGE_MS :return false;default :break ;
@@ -1336,6 +1337,7 @@ static int damos_commit_filter_arg( dst->sz_range = src->sz_range;break ;case DAMOS_FILTER_TYPE_PROBE_HITS_WSUM : +case DAMOS_FILTER_TYPE_AGE_MS :if (src->range_max < src->range_min)return -EINVAL ; dst->range_min = src->range_min;
@@ -2552,7 +2554,7 @@ static bool damos_filter_match(struct damon_ctx *ctx, struct damon_target *t,bool matched = false;struct damon_target *ti;int target_idx =0 ; -unsigned long start, end, wsum; +unsigned long start, end, wsum, age_ms; *err =0 ;switch (filter->type) {
@@ -2594,6 +2596,11 @@ static bool damos_filter_match(struct damon_ctx *ctx, struct damon_target *t, matched = filter->range_min <= wsum && wsum <= filter->range_max;break ; +case DAMOS_FILTER_TYPE_AGE_MS : + age_ms = r->age * ctx->attrs.aggr_interval /USEC_PER_MSEC ; + matched = filter->range_min <= age_ms && + age_ms <= filter->range_max; +break ;default :return false; }
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [RFC PATCH 1/4] mm/damon/core: add DAMOS_FILTER_TYPE_AGE_MS
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] mm/damon/core: 32-bit overflow calculating age_ms in damos_filter_match() --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] mm/damon/core: 32-bit overflow calculating age_ms in damos_filter_match() --
commit 8785e74923668744015c21ff7266b94722501bbc
Author: SJ Park <[email protected]>
mm/damon/core: add DAMOS_FILTER_TYPE_AGE_MS
This commit adds a new DAMOS core filter type, DAMOS_FILTER_TYPE_AGE_MS, allowing schemes to filter target regions by age in milliseconds using damos_filter->range_min and damos_filter->range_max.
Quoted 4 lines
mm/damon/core.c +0
-0
[ ... ]
Quoted 10 lines
mm/damon/core.c +1
-1@@ -2552,7 +2554,7 @@ static bool damos_filter_match(struct damon_ctx *ctx, struct damon_target *t,bool matched = false;struct damon_target *ti;int target_idx =0 ; -unsigned long start, end, wsum; +unsigned long start, end, wsum, age_ms; *err =0 ;switch (filter->type) {
mm/damon/core.c static bool damos_filter_match(struct damon_ctx *ctx, struct damon_target *t, · line 2603
Quoted 8 lines
mm/damon/core.c +5
-0@@ -2594,6 +2596,11 @@ static bool damos_filter_match(struct damon_ctx *ctx, struct damon_target *t, matched = filter->range_min <= wsum && wsum <= filter->range_max;break ; +case DAMOS_FILTER_TYPE_AGE_MS : + age_ms = r->age * ctx->attrs.aggr_interval /USEC_PER_MSEC ; + matched = filter->range_min <= age_ms && + age_ms <= filter->range_max; +break ;
[Severity: Medium]
Can the multiplication r->age * ctx->attrs.aggr_interval in damos_filter_match() overflow on 32-bit architectures?
Since r->age is unsigned int and ctx->attrs.aggr_interval is unsigned long (in microseconds), the multiplication is evaluated in 32-bit unsigned long on 32-bit platforms before dividing by USEC_PER_MSEC. Once a region's age exceeds ULONG_MAX microseconds (about 4,295 seconds, or r->age >= 42,950 at the default 100,000 us aggr_interval), the intermediate product wraps around and misclassifies old regions with a small age_ms value.
By comparison, damon_hot_score() in mm/damon/ops-common.c casts r->age to u64 and uses div_u64() to avoid this 32-bit overflow:
age_in_sec = div_u64((u64)r->age * c->attrs.aggr_interval, USEC_PER_SEC);
Should damos_filter_match() similarly use div_u64((u64)r->age * ctx->attrs.aggr_interval, USEC_PER_MSEC)?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
SJ Park
maintainerRe: [RFC PATCH 1/4] mm/damon/core: add DAMOS_FILTER_TYPE_AGE_MS
Quoted 50 lines · On Wed, 04 Nov 2026 15:44:08 +0000 [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium]mm/damon/core: 32-bit overflow calculatingage_msindamos_filter_match()--commit
8785e74923668744015c21ff7266b94722501bbc
Author: SJ Park <[email protected]>
mm/damon/core: addDAMOS_FILTER_TYPE_AGE_MSThis commit adds a new DAMOS core filter type,
DAMOS_FILTER_TYPE_AGE_MS, allowing schemes to filter target regions by age in milliseconds usingdamos_filter->range_minanddamos_filter->range_max.Quoted 4 lines
mm/damon/core.c +0
-0[ ... ]
Quoted 10 lines
mm/damon/core.c +1
-1@@ -2552,7 +2554,7 @@ static bool damos_filter_match(struct damon_ctx *ctx, struct damon_target *t,bool matched = false;struct damon_target *ti;int target_idx =0 ; -unsigned long start, end, wsum; +unsigned long start, end, wsum, age_ms; *err =0 ;switch (filter->type) {mm/damon/core.c static bool damos_filter_match(struct damon_ctx *ctx, struct damon_target *t, · line 2603
Quoted 8 lines
mm/damon/core.c +5
-0@@ -2594,6 +2596,11 @@ static bool damos_filter_match(struct damon_ctx *ctx, struct damon_target *t, matched = filter->range_min <= wsum && wsum <= filter->range_max;break ; +case DAMOS_FILTER_TYPE_AGE_MS : + age_ms = r->age * ctx->attrs.aggr_interval /USEC_PER_MSEC ; + matched = filter->range_min <= age_ms && + age_ms <= filter->range_max; +break ;[Severity: Medium]
Can the multiplicationr->age*ctx->attrs.aggr_intervalindamos_filter_match()overflow on 32-bit architectures?Since
r->ageis unsigned int andctx->attrs.aggr_intervalis unsigned long (in microseconds), the multiplication is evaluated in 32-bit unsigned long on 32-bit platforms before dividing byUSEC_PER_MSEC. Once a region's age exceedsULONG_MAXmicroseconds (about 4,295 seconds, orr->age>= 42,950 at the default 100,000 usaggr_interval), the intermediate product wraps around and misclassifies old regions with a smallage_msvalue.
Quoted 8 lines
By comparison,
damon_hot_score()inmm/damon/ops-common.ccastsr->ageto u64 and usesdiv_u64()to avoid this 32-bit overflow:age_in_sec = div_u64((u64)r->age * c->attrs.aggr_interval, USEC_PER_SEC);Should
damos_filter_match()similarly usediv_u64((u64)r->age * ctx->attrs.aggr_interval, USEC_PER_MSEC)?
Good finding. I will do so in the next spin.
Quoted 4 lines
Signature · 2 lines
-- Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Thanks,
SJ
SJ Park
maintainerRFC PATCH 2/4 mm/damon/sysfs-schemes: support DAMOS_FILTER_TYPE_AGE_MS
In reply to SJ ParkSupport use of DAMOS_FILTER_TYPE_AGE_MS via DAMON sysfs ABI. Add a user keyword "age_ms" for configuring a filter of the type using the existing filter configuration interface. Reuse existing 'min' and 'max' sysfs files in the filter configuration directory for storing the age range in milliseconds.
--- mm/damon/sysfs-schemes.c | 5 +++++ 1 file changed, 5 insertions(+)
mm/damon/sysfs-schemes.c +5 -0
@@ -593,6 +593,10 @@ damos_sysfs_filter_type_names[] = { .type = DAMOS_FILTER_TYPE_PROBE_HITS_WSUM, .name = "probe_hits_wsum", }, + { + .type = DAMOS_FILTER_TYPE_AGE_MS, + .name = "age_ms", + }, }; static ssize_t type_show(struct kobject *kobj,
@@ -2875,6 +2879,7 @@ static int damon_sysfs_add_scheme_filters(struct damos *scheme, filter->sz_range.max = sysfs_filter->range_max;break ;case DAMOS_FILTER_TYPE_PROBE_HITS_WSUM : +case DAMOS_FILTER_TYPE_AGE_MS : filter->range_min = sysfs_filter->range_min; filter->range_max = sysfs_filter->range_max;break ;
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [RFC PATCH 2/4] mm/damon/sysfs-schemes: support DAMOS_FILTER_TYPE_AGE_MS
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] mm/damon: 32-bit overflow calculating age_ms in damos_filter_match() --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] mm/damon: 32-bit overflow calculating age_ms in damos_filter_match() --
commit 9c78f1b31239922167bf213c5406c37c05fd310f
Author: SJ Park <[email protected]>
mm/damon/sysfs-schemes: support DAMOS_FILTER_TYPE_AGE_MS
This commit exposes DAMOS_FILTER_TYPE_AGE_MS to the DAMON sysfs interface using the "age_ms" filter type keyword and the existing min and max sysfs range files.
Quoted 4 lines
mm/damon/sysfs-schemes.c +0
-0
[ ... ]
mm/damon/sysfs-schemes.c static int damon_sysfs_add_scheme_filters(struct damos *scheme, · line 2885
Quoted 8 lines
mm/damon/sysfs-schemes.c +1
-0@@ -2875,6 +2879,7 @@ static int damon_sysfs_add_scheme_filters(struct damos *scheme, filter->sz_range.max = sysfs_filter->range_max;break ;case DAMOS_FILTER_TYPE_PROBE_HITS_WSUM : +case DAMOS_FILTER_TYPE_AGE_MS : filter->range_min = sysfs_filter->range_min; filter->range_max = sysfs_filter->range_max;break ;
[Severity: Medium]
When userspace configures an age_ms filter with range_min and range_max via damon_sysfs_add_scheme_filters() on a 32-bit system, can age_ms overflow in damos_filter_match()?
When kdamond evaluates the filter via kdamond_apply_schemes()->damon_do_apply_schemes()->damos_apply_scheme()->damos_core_filter_out()->damos_filter_match():
mm/damon/core.c:damos_filter_match() {
...
case DAMOS_FILTER_TYPE_AGE_MS:
age_ms = r->age * ctx->attrs.aggr_interval / USEC_PER_MSEC;
matched = filter->range_min <= age_ms &&
age_ms <= filter->range_max;
break;
...
}Here r->age is unsigned int and ctx->attrs.aggr_interval is unsigned long (in microseconds). On 32-bit architectures, multiplying r->age by ctx->attrs.aggr_interval is performed in 32-bit unsigned arithmetic before dividing by USEC_PER_MSEC, which wraps around once a region's age exceeds approximately 4,295 seconds (~71.6 minutes) even though the resulting millisecond value fits in a 32-bit unsigned long.
A similar 32-bit overflow on r->age * c->attrs.aggr_interval in damon_hot_score() in mm/damon/ops-common.c was fixed in commit 0284dff76e87 ("mm/damon/ops-common: fix age_in_sec overflow on 32-bit"). Should damos_filter_match() use div_u64((u64)r->age * ctx->attrs.aggr_interval, USEC_PER_MSEC) as well?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
SJ Park
maintainerRe: [RFC PATCH 2/4] mm/damon/sysfs-schemes: support DAMOS_FILTER_TYPE_AGE_MS
Quoted 54 lines · On Wed, 04 Nov 2026 15:50:23 +0000 [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] mm/damon: 32-bit overflow calculatingage_msindamos_filter_match()--commit
9c78f1b31239922167bf213c5406c37c05fd310f
Author: SJ Park <[email protected]>
mm/damon/sysfs-schemes: supportDAMOS_FILTER_TYPE_AGE_MSThis commit exposes
DAMOS_FILTER_TYPE_AGE_MSto the DAMON sysfs interface using the "age_ms" filter type keyword and the existing min and max sysfs range files.Quoted 4 lines
mm/damon/sysfs-schemes.c +0
-0[ ... ]
mm/damon/sysfs-schemes.c static int damon_sysfs_add_scheme_filters(struct damos *scheme, · line 2885
Quoted 8 lines
mm/damon/sysfs-schemes.c +1
-0@@ -2875,6 +2879,7 @@ static int damon_sysfs_add_scheme_filters(struct damos *scheme, filter->sz_range.max = sysfs_filter->range_max;break ;case DAMOS_FILTER_TYPE_PROBE_HITS_WSUM : +case DAMOS_FILTER_TYPE_AGE_MS : filter->range_min = sysfs_filter->range_min; filter->range_max = sysfs_filter->range_max;break ;[Severity: Medium]
When userspace configures anage_msfilter withrange_minandrange_maxviadamon_sysfs_add_scheme_filters()on a 32-bit system, canage_msoverflow indamos_filter_match()?When kdamond evaluates the filter via kdamond_apply_schemes()->damon_do_apply_schemes()->damos_apply_scheme()->damos_core_filter_out()->damos_filter_match():
mm/damon/core.c:damos_filter_match() { ... case DAMOS_FILTER_TYPE_AGE_MS: age_ms = r->age * ctx->attrs.aggr_interval / USEC_PER_MSEC; matched = filter->range_min <= age_ms && age_ms <= filter->range_max; break; ... }Here
r->ageis unsigned int andctx->attrs.aggr_intervalis unsigned long (in microseconds). On 32-bit architectures, multiplyingr->agebyctx->attrs.aggr_intervalis performed in 32-bit unsigned arithmetic before dividing byUSEC_PER_MSEC, which wraps around once a region's age exceeds approximately 4,295 seconds (~71.6 minutes) even though the resulting millisecond value fits in a 32-bit unsigned long.
Quoted 5 lines
A similar 32-bit overflow on
r->age*c->attrs.aggr_intervalindamon_hot_score()inmm/damon/ops-common.cwas fixed in commit0284dff76e87("mm/damon/ops-common: fixage_in_secoverflow on 32-bit"). Shoulddamos_filter_match()usediv_u64((u64)r->age * ctx->attrs.aggr_interval, USEC_PER_MSEC)as well?
I will fix [1] in the next version.
[1] https://lore.kernel.org/[email protected]
Quoted 4 lines
Signature · 2 lines
-- Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Thanks,
SJ
SJ Park
maintainerRFC PATCH 3/4 Docs/mm/damon/design: update for age_ms damos core filter type
In reply to SJ ParkUpdate DAMON design document for the newly added age_ms DAMOS core filter type.
--- Documentation/mm/damon/design.rst | 3 +++ 1 file changed, 3 insertions(+)
Documentation/mm/damon/design.rst +3 -0
@@ -838,6 +838,9 @@ Below ``type`` of filters are currently supported. - probe_hits_wsum - Matches to monitoring regions having a given range of :ref:`probe hits weighted sum <damon_design_attrs_only_monitoring>` value. + - age_ms + - Matces to monitoring regions having a given range of :ref:`age + <damon_design_age_tracking>` value in milliseconds. - Operations layer handled, supported by only ``paddr`` operations set. - anon - Applied to pages that contain data that are not stored in files.
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [RFC PATCH 3/4] Docs/mm/damon/design: update for age_ms damos core filter type
Sashiko has reviewed this patch and found no issues.
Quoted 4 lines
Update DAMON design document for the newly added
age_msDAMOS core filter type.Signed-off-by SJ Park <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
SJ Park
maintainerRFC PATCH 4/4 Docs/admin-guide/mm/damon/usage: update for age_ms damos core filter
In reply to SJ ParkUpdate DAMON usage document for the newly added age_ms DAMOS core filter type. Add an explanation of how the age range for the filter can be specified by the user.
--- Documentation/admin-guide/mm/damon/usage.rst | 3 +++ 1 file changed, 3 insertions(+)
Documentation/admin-guide/mm/damon/usage.rst +3 -0
@@ -559,6 +559,9 @@ For ``probe_hits_wsum`` type, you can specify the minimum and maximum probe hits weighted sum value for the filter to ``min`` and ``max`` files, respectively. +For ``age_ms`` type, you can specify the minimum and maximum age in +milliseconds for the filter to ``min`` and ``max`` files, respectively. + For ``memcg`` type, you can specify the memory cgroup of the interest by writing the path of the memory cgroup from the cgroups mount point to ``memcg_path`` file. For ``addr`` type, you can specify the start and end
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [RFC PATCH 4/4] Docs/admin-guide/mm/damon/usage: update for age_ms damos core filter
Sashiko has reviewed this patch and found no issues.
Quoted 5 lines
Update DAMON usage document for the newly added
age_msDAMOS core filter type. Add an explanation of how the age range for the filter can be specified by the user.Signed-off-by SJ Park <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
SJ Park
maintainerOn Wed, 4 Nov 2026 07:36:39 -0800 SJ Park <[email protected]> wrote:
I forgot adding a subject line. As a result, first part of below paragraph was added to the subject. Sorry for inconvenience. So, please read below paragraph before the quoted followup paragraph to read the full intentional cover letter message.
DAMOS access pattern supports selecting regions to apply a given operation to, based on their age (access frequency stability). The age is specified in the aggregation intervals unit. The aggregation interval can be changed by users or intervals auto-tuning features. If the intention is to specify the age in a deterministic way (e.g., 2 minutes), it should be updated for each aggregation interval update. Doing so is cumbersome and challenging, particularly in the interval auto-tuning case.
Quoted 30 lines
One straightforward solution is extending the DAMOS access pattern for specific deterministic time based age specification. However, DAMOS core filter is a better option. It is playing a similar role in a more flexible way. It can be used for both accepting and rejecting regions based on if they matched or unmatched to a given criteria. Multiple filters can also be combined for more flexible and detailed rules.
Extend DAMOS core filter to support milliseconds unit based age criteria.
Implement a new DAMOS core filter type,
DAMOS_FILTER_TYPE_AGE_MS, in core layer and expose to DAMON API, via patch 1. Add the support of the feature on DAMON sysfs ABI with patch 2. Update the design and usage documents to explain the new features with patches 3 and 4, respectively.SJ Park (4):
mm/damon/core: addDAMOS_FILTER_TYPE_AGE_MSmm/damon/sysfs-schemes: supportDAMOS_FILTER_TYPE_AGE_MSDocs/mm/damon/design: update forage_msdamos core filter type Docs/admin-guide/mm/damon/usage: update forage_msdamos core filterDocumentation/admin-guide/mm/damon/usage.rst | 3 +++ Documentation/mm/damon/design.rst | 3 +++ include/linux/damon.h | 16 ++++++++++------ mm/damon/core.c | 9 ++++++++- mm/damon/sysfs-schemes.c | 5 +++++ 5 files changed, 29 insertions(+), 7 deletions(-)
Quoted 5 lines
base-commit:
32e967f279b24f952a5482e2c427894787848ee0Signature · 1 line
2.47.3
Thanks,
SJ