DAMON development mailing list
 help / color / mirror / Atom feed
From: SJ Park <sj@kernel.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Arijit Desai <arijit.desai@crusoe.ai>, SJ Park <sj@kernel.org>,
	damon@lists.linux.dev, linux-mm@kvack.org
Subject: [PATCH 2/2] mm/damon/reclaim: use age_ms filter for min_age
Date: Thu,  3 Dec 2026 07:32:14 -0800	[thread overview]
Message-ID: <20261203153215.733163-3-sj@kernel.org> (raw)
In-Reply-To: <20261203153215.733163-1-sj@kernel.org>

From: Arijit Desai <arijit.desai@crusoe.ai>

DAMON_RECLAIM converts its min_age parameter (in microseconds) into
DAMOS min_age_region, which is in aggregation intervals, once when the
parameters are applied.  When autotune_monitoring_intervals is enabled,
the conversion uses the initial 100 ms aggregation interval, but the
auto-tuning soon grows the interval.  The region age threshold therefore
stays at the same number of aggregation intervals while each interval
becomes much longer.  For the default min_age of 120 seconds, the
threshold becomes 1,200 aggregation intervals, which is about 2.5 hours
once the aggregation interval grows to about 7.5 seconds.  As a result,
DAMON_RECLAIM reclaims almost nothing [1] in that setup.

Use a DAMOS_FILTER_TYPE_AGE_MS filter that rejects regions younger than
min_age instead, and set min_age_region to zero.  The filter compares
the region age converted with the current aggregation interval, so it
stays correct while the intervals change.  For fixed intervals, the
behavior is unchanged.  Regions rejected by the filter are not charged
to the quota and do not count as tried regions.

Keep accepting any min_age, as before.  If min_age is smaller than a
millisecond, add no filter, so every region is old enough.

Tested on a 16 vCPU / 62 GiB VM with a cold anonymous buffer plus 1 GiB
of hot anonymous memory, autotune_monitoring_intervals=Y, min_age=120 s
and watermarks forced active:

  kernel     cold buffer  10 min result
  unpatched  8 GiB        no region tried, nothing paged out
  unpatched  48 GiB       no region tried, nothing paged out
  patched    48 GiB       nothing paged out before 181 s, then
                          steady pageout (~1 GiB swapped out by
                          600 s, limited by the time quota)

The same age_ms filter based min_age was also tested with a DAMOS
pageout scheme set up via the DAMON sysfs interface, on a vLLM CPU
inference workload (3B model, 32 concurrent users, intervals
auto-tuning, min_age 120 s, 4 runs per setup).  Compared to no DAMON,
it reduced the vLLM worker's resident memory by about 1.8 GiB (of
18.4 GiB), at a cost of 0.2% output throughput and 0.3% inter-token
latency.  With the classic LRU instead of MGLRU, it reduced 1.55 GiB at
0.1% throughput and 0.1% latency cost.  The same scheme with min_age
converted to aggregation intervals once, as DAMON_RECLAIM does now,
reduced only 0.06 GiB.

[1] https://lore.kernel.org/20261121015324.83753-1-sj@kernel.org

Signed-off-by: Arijit Desai <arijit.desai@crusoe.ai>
Reviewed-by: SJ Park <sj@kernel.org>
Signed-off-by: SJ Park <sj@kernel.org>
---
Changes from v1
- v1: https://lore.kernel.org/20261130-damon-reclaim-age-ms-v1-1-595659163211@crusoe.ai
- Add a context to the initial issue sharing link.
- Drop verbose comment.
- Collect R-b: from SJ.
- Rebase to the latet mm-new.

 mm/damon/reclaim.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/mm/damon/reclaim.c b/mm/damon/reclaim.c
index a84cea070ec7..cb259391cd49 100644
--- a/mm/damon/reclaim.c
+++ b/mm/damon/reclaim.c
@@ -164,7 +164,7 @@ DEFINE_DAMON_MODULES_DAMOS_STATS_PARAMS(damon_reclaim_stat,
 static struct damon_ctx *ctx;
 static struct damon_target *target;
 
-static struct damos *damon_reclaim_new_scheme(unsigned long aggr_interval)
+static struct damos *damon_reclaim_new_scheme(void)
 {
 	struct damos_access_pattern pattern = {
 		/* Find regions having PAGE_SIZE or larger size */
@@ -173,8 +173,8 @@ static struct damos *damon_reclaim_new_scheme(unsigned long aggr_interval)
 		/* and not accessed at all */
 		.min_nr_accesses = 0,
 		.max_nr_accesses = 0,
-		/* for min_age or more micro-seconds */
-		.min_age_region = min_age / aggr_interval,
+		/* min_age is applied via a DAMOS_FILTER_TYPE_AGE_MS filter */
+		.min_age_region = 0,
 		.max_age_region = UINT_MAX,
 	};
 
@@ -227,7 +227,7 @@ static int damon_reclaim_apply_parameters(void)
 		goto out;
 
 	err = -ENOMEM;
-	scheme = damon_reclaim_new_scheme(attrs.aggr_interval);
+	scheme = damon_reclaim_new_scheme();
 	if (!scheme)
 		goto out;
 	damon_set_schemes(param_ctx, &scheme, 1);
@@ -249,6 +249,16 @@ static int damon_reclaim_apply_parameters(void)
 		damos_add_quota_goal(&scheme->quota, goal);
 	}
 
+	if (min_age >= USEC_PER_MSEC) {
+		filter = damos_new_filter(DAMOS_FILTER_TYPE_AGE_MS, true,
+				false);
+		if (!filter)
+			goto out;
+		filter->range_min = 0;
+		filter->range_max = min_age / USEC_PER_MSEC - 1;
+		damos_add_filter(scheme, filter);
+	}
+
 	if (skip_anon) {
 		filter = damos_new_filter(DAMOS_FILTER_TYPE_ANON, true, false);
 		if (!filter)
-- 
2.47.3

  parent reply	other threads:[~2026-12-03 15:32 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 15:32 [PATCH 0/2] mm/damon: cleanup memcg_path_leak selftest and fix DAMON_RECLAIM age_ms SJ Park
2026-12-03 15:32 ` [PATCH 1/2] selftests/damon/sysfs_memcg_path_leak: use common check_dependencies() SJ Park
2026-12-03 15:32 ` SJ Park [this message]
2026-12-03 15:52 ` [PATCH 0/2] mm/damon: cleanup memcg_path_leak selftest and fix DAMON_RECLAIM age_ms sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261203153215.733163-3-sj@kernel.org \
    --to=sj@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=arijit.desai@crusoe.ai \
    --cc=damon@lists.linux.dev \
    --cc=linux-mm@kvack.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox