DAMON_RECLAIM runs its scheme only while the free memory rate is in [wmarks_low, wmarks_mid]. Reclaiming cold pages raises the rate, so the scheme self-stops as soon as memory looks plentiful again, which is wrong for a VMM parking an idle sandbox that wants cold anonymous pages reclaimed immediately. So add an ignore_wmarks module parameter. When set, the scheme uses DAMOS_WMARK_NONE, so damos_wmark_wait_us() always returns zero and the scheme stays active, bounded only by min_age and the quota. Signed-off-by: Jinjie Ruan --- .../admin-guide/mm/damon/reclaim.rst | 17 ++++++++++++++++ mm/damon/reclaim.c | 20 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/Documentation/admin-guide/mm/damon/reclaim.rst b/Documentation/admin-guide/mm/damon/reclaim.rst index ec7e3e32b4ac..ef57f60a9105 100644 --- a/Documentation/admin-guide/mm/damon/reclaim.rst +++ b/Documentation/admin-guide/mm/damon/reclaim.rst @@ -159,6 +159,23 @@ this auto-tuning feature. Disabled by default. +ignore_wmarks +------------- + +Ignore the watermarks-based scheme activation condition. + +If set to ``Y``, DAMON_RECLAIM runs its scheme regardless of the system's +free memory rate, so the reclaim is bounded only by ``min_age`` and the +quota. This is useful when cold pages should be reclaimed even while the +system still has free memory, e.g. to squeeze the cold anonymous pages of a +just-parked virtual machine out immediately. + +By default, ``N``, so the scheme is activated based on the system's free +memory rate, as described for the watermarks below. + +Changes take effect when the scheme is rebuilt, i.e. on the next ``enabled`` +``0 -> 1`` transition, like the other DAMON_RECLAIM parameters. + wmarks_interval --------------- diff --git a/mm/damon/reclaim.c b/mm/damon/reclaim.c index 45d5557cc575..03b9a57694a6 100644 --- a/mm/damon/reclaim.c +++ b/mm/damon/reclaim.c @@ -112,6 +112,23 @@ static struct damos_watermarks damon_reclaim_wmarks = { }; DEFINE_DAMON_MODULES_WMARKS_PARAMS(damon_reclaim_wmarks); +/* + * Ignore the watermarks-based scheme activation condition. + * + * With the default ``N``, DAMON_RECLAIM runs its scheme only while the + * system's free memory rate is inside [wmarks_low, wmarks_mid]. + * Reclaiming cold pages itself raises the free rate, so the scheme + * deactivates as soon as memory looks plentiful again. For a VMM parking + * an idle sandbox, cold anonymous pages should be reclaimed immediately + * even while the host still has plenty of free memory; setting this ``Y`` + * makes the scheme ignore the watermarks, so the reclaim is bounded only + * by min_age and the quota. + */ +static bool ignore_wmarks __read_mostly; +module_param(ignore_wmarks, bool, 0600); +MODULE_PARM_DESC(ignore_wmarks, + "Ignore watermarks: reclaim cold pages even while free memory is plentiful (default: false)"); + static struct damon_attrs damon_reclaim_mon_attrs = { .sample_interval = 5000, /* 5 ms */ .aggr_interval = 100000, /* 100 ms */ @@ -226,6 +243,9 @@ static int damon_reclaim_apply_parameters(void) if (err) goto out; + damon_reclaim_wmarks.metric = ignore_wmarks ? + DAMOS_WMARK_NONE : DAMOS_WMARK_FREE_MEM_RATE; + err = -ENOMEM; scheme = damon_reclaim_new_scheme(attrs.aggr_interval); if (!scheme) -- 2.53.0