2022-09-13 19:03:18

by SeongJae Park

[permalink] [raw]
Subject: [PATCH 00/22] mm/damon: cleanup code

DAMON code was not so clean from the beginning, but it has been too much
nowadays, especially due to the duplicates in DAMON_RECLAIM and
DAMON_LRU_SORT. This patchset cleans some of the mess.

SeongJae Park (22):
mm/damon/paddr: make supported DAMOS actions of paddr clear
mm/damon/paddr: deduplicate
damon_pa_{mark_accessed,deactivate_pages}()
mm/damon/core: copy struct-to-struct instead of field-to-field in
damon_new_scheme()
mm/damon/core: factor out 'damos_quota' private fileds initialization
mm/damon/core: use a dedicated struct for monitoring attributes
mm/damon/core: reduce parameters for damon_set_attrs()
mm/damon/reclaim: use 'struct damon_attrs' for storing parameters for
it
mm/damon/lru_sort: use 'struct damon_attrs' for storing parameters for
it
mm/damon: implement a monitoring attributes module parameters
generator macro
mm/damon/lru_sort: use monitoring attributes parameters generaotr
macro
mm/damon/reclaim: use monitoring attributes parameters generator macro
mm/damon/modules-common: implement a watermarks module parameters
generator macro
mm/damon/lru_sort: use watermarks parameters generator macro
mm/damon/reclaim: use watermarks parameters generator macro
mm/damon/modules-common: implement a stats parameters generator macro
mm/damon/reclaim: use stat parameters generator
mm/damon/lru_sort: use stat generator
mm/damon/modules-common: implement a damos quota params generator
mm/damon/modules-common: implement damos time quota params generator
mm/damon/reclaim: use the quota params generator macro
mm/damon/lru_sort: use quotas param generator
mm/damon/lru_sort: deduplicate hot/cold schemes generators

include/linux/damon.h | 34 +++--
mm/damon/core.c | 87 +++++------
mm/damon/dbgfs.c | 15 +-
mm/damon/lru_sort.c | 303 +++++++++-----------------------------
mm/damon/modules-common.h | 46 ++++++
mm/damon/ops-common.c | 4 +-
mm/damon/paddr.c | 29 ++--
mm/damon/reclaim.c | 220 ++++++---------------------
mm/damon/sysfs.c | 12 +-
mm/damon/vaddr.c | 4 +-
10 files changed, 246 insertions(+), 508 deletions(-)
create mode 100644 mm/damon/modules-common.h

--
2.25.1


2022-09-13 19:04:42

by SeongJae Park

[permalink] [raw]
Subject: [PATCH 15/22] mm/damon/modules-common: implement a stats parameters generator macro

DAMON_RECLAIM and DAMON_LRU_SORT have module parameters for DAMOS
statistics that having same names. This commit implements a macro for
generating such module parameters so that we can reuse later.

Signed-off-by: SeongJae Park <[email protected]>
---
mm/damon/modules-common.h | 12 ++++++++++++
1 file changed, 12 insertions(+)

diff --git a/mm/damon/modules-common.h b/mm/damon/modules-common.h
index 4c2ce84869d5..ed973e0770ae 100644
--- a/mm/damon/modules-common.h
+++ b/mm/damon/modules-common.h
@@ -23,3 +23,15 @@
module_param_named(wmarks_high, wmarks.high, ulong, 0600); \
module_param_named(wmarks_mid, wmarks.mid, ulong, 0600); \
module_param_named(wmarks_low, wmarks.low, ulong, 0600);
+
+#define DEFINE_DAMON_MODULES_DAMOS_STATS_PARAMS(stat, try_name, \
+ succ_name, qt_exceed_name) \
+ module_param_named(nr_##try_name, stat.nr_tried, ulong, 0400); \
+ module_param_named(bytes_##try_name, stat.sz_tried, ulong, \
+ 0400); \
+ module_param_named(nr_##succ_name, stat.nr_applied, ulong, \
+ 0400); \
+ module_param_named(bytes_##succ_name, stat.sz_applied, ulong, \
+ 0400); \
+ module_param_named(qt_exceed_name, stat.qt_exceeds, ulong, \
+ 0400);
--
2.25.1

2022-09-13 19:05:04

by SeongJae Park

[permalink] [raw]
Subject: [PATCH 12/22] mm/damon/modules-common: implement a watermarks module parameters generator macro

DAMON_RECLAIM and DAMON_LRU_SORT have module parameters for watermarks
that having same names. This commit implements a macro for generating
such module parameters so that we can reuse later.

Signed-off-by: SeongJae Park <[email protected]>
---
mm/damon/modules-common.h | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/mm/damon/modules-common.h b/mm/damon/modules-common.h
index 0abd0636bc64..1370590a37d1 100644
--- a/mm/damon/modules-common.h
+++ b/mm/damon/modules-common.h
@@ -16,3 +16,10 @@
0600); \
module_param_named(max_nr_regions, attrs.max_nr_regions, ulong, \
0600);
+
+#define DEFINE_DAMON_MODULES_WMARKS_PARAMS(wmarks) \
+ module_param_named(wmarks_interval, wmarks->interval, ulong, \
+ 0600); \
+ module_param_named(wmarks_high, wmarks.high, ulong, 0600); \
+ module_param_named(wmarks_mid, wmarks.mid, ulong, 0600); \
+ module_param_named(wmarks_low, wmarks.lowulong, 0600);
--
2.25.1

2022-09-13 19:08:31

by SeongJae Park

[permalink] [raw]
Subject: [PATCH 16/22] mm/damon/reclaim: use stat parameters generator

This commit makes DAMON_RECLAIM to generate the module parameters for
DAMOS statistics using the generator macro to simplify the code and
reduce duplicates.

Signed-off-by: SeongJae Park <[email protected]>
---
mm/damon/reclaim.c | 41 +++++------------------------------------
1 file changed, 5 insertions(+), 36 deletions(-)

diff --git a/mm/damon/reclaim.c b/mm/damon/reclaim.c
index 7f845f617dc5..1ef8353ac15a 100644
--- a/mm/damon/reclaim.c
+++ b/mm/damon/reclaim.c
@@ -136,35 +136,9 @@ module_param(monitor_region_end, ulong, 0600);
static int kdamond_pid __read_mostly = -1;
module_param(kdamond_pid, int, 0400);

-/*
- * Number of memory regions that tried to be reclaimed.
- */
-static unsigned long nr_reclaim_tried_regions __read_mostly;
-module_param(nr_reclaim_tried_regions, ulong, 0400);
-
-/*
- * Total bytes of memory regions that tried to be reclaimed.
- */
-static unsigned long bytes_reclaim_tried_regions __read_mostly;
-module_param(bytes_reclaim_tried_regions, ulong, 0400);
-
-/*
- * Number of memory regions that successfully be reclaimed.
- */
-static unsigned long nr_reclaimed_regions __read_mostly;
-module_param(nr_reclaimed_regions, ulong, 0400);
-
-/*
- * Total bytes of memory regions that successfully be reclaimed.
- */
-static unsigned long bytes_reclaimed_regions __read_mostly;
-module_param(bytes_reclaimed_regions, ulong, 0400);
-
-/*
- * Number of times that the time/space quota limits have exceeded
- */
-static unsigned long nr_quota_exceeds __read_mostly;
-module_param(nr_quota_exceeds, ulong, 0400);
+static struct damos_stat damon_reclaim_stat;
+DEFINE_DAMON_MODULES_DAMOS_STATS_PARAMS(damon_reclaim_stat,
+ reclaim_tried_regions, reclaimed_regions, quota_exceeds);

static struct damon_ctx *ctx;
static struct damon_target *target;
@@ -318,13 +292,8 @@ static int damon_reclaim_after_aggregation(struct damon_ctx *c)
struct damos *s;

/* update the stats parameter */
- damon_for_each_scheme(s, c) {
- nr_reclaim_tried_regions = s->stat.nr_tried;
- bytes_reclaim_tried_regions = s->stat.sz_tried;
- nr_reclaimed_regions = s->stat.nr_applied;
- bytes_reclaimed_regions = s->stat.sz_applied;
- nr_quota_exceeds = s->stat.qt_exceeds;
- }
+ damon_for_each_scheme(s, c)
+ damon_reclaim_stat = s->stat;

return damon_reclaim_handle_commit_inputs();
}
--
2.25.1

2022-09-13 19:11:44

by SeongJae Park

[permalink] [raw]
Subject: [PATCH 03/22] mm/damon/core: copy struct-to-struct instead of field-to-field in damon_new_scheme()

The function for new 'struct damos' creation, 'damon_new_scheme()',
copies each field of the struct one by one, though it could simply
copied via struct to struct. This commit replaces the unnecessarily
verbose field-to-field copies with struct-to-struct copies to make code
simple and short.

Signed-off-by: SeongJae Park <[email protected]>
---
mm/damon/core.c | 21 ++++-----------------
1 file changed, 4 insertions(+), 17 deletions(-)

diff --git a/mm/damon/core.c b/mm/damon/core.c
index c21f5fe5928a..27e0c312f7a5 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -276,22 +276,13 @@ struct damos *damon_new_scheme(struct damos_access_pattern *pattern,
scheme = kmalloc(sizeof(*scheme), GFP_KERNEL);
if (!scheme)
return NULL;
- scheme->pattern.min_sz_region = pattern->min_sz_region;
- scheme->pattern.max_sz_region = pattern->max_sz_region;
- scheme->pattern.min_nr_accesses = pattern->min_nr_accesses;
- scheme->pattern.max_nr_accesses = pattern->max_nr_accesses;
- scheme->pattern.min_age_region = pattern->min_age_region;
- scheme->pattern.max_age_region = pattern->max_age_region;
+ scheme->pattern = *pattern;
scheme->action = action;
scheme->stat = (struct damos_stat){};
INIT_LIST_HEAD(&scheme->list);

- scheme->quota.ms = quota->ms;
- scheme->quota.sz = quota->sz;
- scheme->quota.reset_interval = quota->reset_interval;
- scheme->quota.weight_sz = quota->weight_sz;
- scheme->quota.weight_nr_accesses = quota->weight_nr_accesses;
- scheme->quota.weight_age = quota->weight_age;
+ scheme->quota = *quota;
+ /* caller might not zero-initialized the private fileds */
scheme->quota.total_charged_sz = 0;
scheme->quota.total_charged_ns = 0;
scheme->quota.esz = 0;
@@ -300,11 +291,7 @@ struct damos *damon_new_scheme(struct damos_access_pattern *pattern,
scheme->quota.charge_target_from = NULL;
scheme->quota.charge_addr_from = 0;

- scheme->wmarks.metric = wmarks->metric;
- scheme->wmarks.interval = wmarks->interval;
- scheme->wmarks.high = wmarks->high;
- scheme->wmarks.mid = wmarks->mid;
- scheme->wmarks.low = wmarks->low;
+ scheme->wmarks = *wmarks;
scheme->wmarks.activated = true;

return scheme;
--
2.25.1

2022-09-13 19:28:28

by SeongJae Park

[permalink] [raw]
Subject: [PATCH 11/22] mm/damon/reclaim: use monitoring attributes parameters generator macro

This commit makes DAMON_RECLAIM to generate the module parameters for
DAMON monitoring attributes using the generator macro to simplify the
code and reduce duplicates.

Signed-off-by: SeongJae Park <[email protected]>
---
mm/damon/reclaim.c | 47 +++++-----------------------------------------
1 file changed, 5 insertions(+), 42 deletions(-)

diff --git a/mm/damon/reclaim.c b/mm/damon/reclaim.c
index d35a00d8dde2..48326bef20f5 100644
--- a/mm/damon/reclaim.c
+++ b/mm/damon/reclaim.c
@@ -13,6 +13,8 @@
#include <linux/sched.h>
#include <linux/workqueue.h>

+#include "modules-common.h"
+
#ifdef MODULE_PARAM_PREFIX
#undef MODULE_PARAM_PREFIX
#endif
@@ -130,52 +132,13 @@ static unsigned long wmarks_low __read_mostly = 200;
module_param(wmarks_low, ulong, 0600);

static struct damon_attrs damon_reclaim_mon_attrs = {
- .sample_interval = 5000,
- .aggr_interval = 100000,
+ .sample_interval = 5000, /* 5 ms */
+ .aggr_interval = 100000, /* 100 ms */
.ops_update_interval = 0,
.min_nr_regions = 10,
.max_nr_regions = 1000,
};
-
-/*
- * Sampling interval for the monitoring in microseconds.
- *
- * The sampling interval of DAMON for the cold memory monitoring. Please refer
- * to the DAMON documentation for more detail. 5 ms by default.
- */
-module_param_named(sample_interval, damon_reclaim_mon_attrs.sample_interval,
- ulong, 0600);
-
-/*
- * Aggregation interval for the monitoring in microseconds.
- *
- * The aggregation interval of DAMON for the cold memory monitoring. Please
- * refer to the DAMON documentation for more detail. 100 ms by default.
- */
-module_param_named(aggr_interval, damon_reclaim_mon_attrs.aggr_interval, ulong,
- 0600);
-
-/*
- * Minimum number of monitoring regions.
- *
- * The minimal number of monitoring regions of DAMON for the cold memory
- * monitoring. This can be used to set lower-bound of the monitoring quality.
- * But, setting this too high could result in increased monitoring overhead.
- * Please refer to the DAMON documentation for more detail. 10 by default.
- */
-module_param_named(min_nr_regions, damon_reclaim_mon_attrs.min_nr_regions,
- ulong, 0600);
-
-/*
- * Maximum number of monitoring regions.
- *
- * The maximum number of monitoring regions of DAMON for the cold memory
- * monitoring. This can be used to set upper-bound of the monitoring overhead.
- * However, setting this too low could result in bad monitoring quality.
- * Please refer to the DAMON documentation for more detail. 1000 by default.
- */
-module_param_named(max_nr_regions, damon_reclaim_mon_attrs.max_nr_regions,
- ulong, 0600);
+DEFINE_DAMON_MODULES_MON_ATTRS_PARAMS(damon_reclaim_mon_attrs);

/*
* Start of the target memory region in physical address.
--
2.25.1

2022-09-13 19:28:53

by SeongJae Park

[permalink] [raw]
Subject: [PATCH 09/22] mm/damon: implement a monitoring attributes module parameters generator macro

DAMON_RECLAIM and DAMON_LRU_SORT have module parameters for monitoring
attributes that having same names. This commot implements a macro for
generating such module parameters so that we can reuse later.

Signed-off-by: SeongJae Park <[email protected]>
---
mm/damon/modules-common.h | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
create mode 100644 mm/damon/modules-common.h

diff --git a/mm/damon/modules-common.h b/mm/damon/modules-common.h
new file mode 100644
index 000000000000..0abd0636bc64
--- /dev/null
+++ b/mm/damon/modules-common.h
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Common Primitives for DAMON Modules
+ *
+ * Author: SeongJae Park <[email protected]>
+ */
+
+#include <linux/moduleparam.h>
+
+#define DEFINE_DAMON_MODULES_MON_ATTRS_PARAMS(attrs) \
+ module_param_named(sample_interval, attrs.sample_interval, \
+ ulong, 0600); \
+ module_param_named(aggr_interval, attrs.aggr_interval, ulong, \
+ 0600); \
+ module_param_named(min_nr_regions, attrs.min_nr_regions, ulong, \
+ 0600); \
+ module_param_named(max_nr_regions, attrs.max_nr_regions, ulong, \
+ 0600);
--
2.25.1

2022-09-13 19:29:11

by SeongJae Park

[permalink] [raw]
Subject: [PATCH 20/22] mm/damon/reclaim: use the quota params generator macro

This commit makes DAMON_RECLAIM to generate the module parameters for
DAMOS quotas using the generator macro to simplify the code and reduce
duplicates.

Signed-off-by: SeongJae Park <[email protected]>
---
mm/damon/reclaim.c | 64 +++++++++-------------------------------------
1 file changed, 12 insertions(+), 52 deletions(-)

diff --git a/mm/damon/reclaim.c b/mm/damon/reclaim.c
index 1ef8353ac15a..1acf808e1624 100644
--- a/mm/damon/reclaim.c
+++ b/mm/damon/reclaim.c
@@ -52,44 +52,17 @@ module_param(commit_inputs, bool, 0600);
static unsigned long min_age __read_mostly = 120000000;
module_param(min_age, ulong, 0600);

-/*
- * Limit of time for trying the reclamation in milliseconds.
- *
- * DAMON_RECLAIM tries to use only up to this time within a time window
- * (quota_reset_interval_ms) for trying reclamation of cold pages. This can be
- * used for limiting CPU consumption of DAMON_RECLAIM. If the value is zero,
- * the limit is disabled.
- *
- * 10 ms by default.
- */
-static unsigned long quota_ms __read_mostly = 10;
-module_param(quota_ms, ulong, 0600);
-
-/*
- * Limit of size of memory for the reclamation in bytes.
- *
- * DAMON_RECLAIM charges amount of memory which it tried to reclaim within a
- * time window (quota_reset_interval_ms) and makes no more than this limit is
- * tried. This can be used for limiting consumption of CPU and IO. If this
- * value is zero, the limit is disabled.
- *
- * 128 MiB by default.
- */
-static unsigned long quota_sz __read_mostly = 128 * 1024 * 1024;
-module_param(quota_sz, ulong, 0600);
-
-/*
- * The time/size quota charge reset interval in milliseconds.
- *
- * The charge reset interval for the quota of time (quota_ms) and size
- * (quota_sz). That is, DAMON_RECLAIM does not try reclamation for more than
- * quota_ms milliseconds or quota_sz bytes within quota_reset_interval_ms
- * milliseconds.
- *
- * 1 second by default.
- */
-static unsigned long quota_reset_interval_ms __read_mostly = 1000;
-module_param(quota_reset_interval_ms, ulong, 0600);
+static struct damos_quota damon_reclaim_quota = {
+ /* use up to 10 ms time, reclaim up to 128 MiB per 1 sec by default */
+ .ms = 10,
+ .sz = 128 * 1024 * 1024,
+ .reset_interval = 1000,
+ /* Within the quota, page out older regions first. */
+ .weight_sz = 0,
+ .weight_nr_accesses = 0,
+ .weight_age = 1
+};
+DEFINE_DAMON_MODULES_DAMOS_QUOTAS(damon_reclaim_quota);

struct damos_watermarks damon_reclaim_wmarks = {
.metric = DAMOS_WMARK_FREE_MEM_RATE,
@@ -157,26 +130,13 @@ static struct damos *damon_reclaim_new_scheme(void)
damon_reclaim_mon_attrs.aggr_interval,
.max_age_region = UINT_MAX,
};
- struct damos_quota quota = {
- /*
- * Do not try reclamation for more than quota_ms milliseconds
- * or quota_sz bytes within quota_reset_interval_ms.
- */
- .ms = quota_ms,
- .sz = quota_sz,
- .reset_interval = quota_reset_interval_ms,
- /* Within the quota, page out older regions first. */
- .weight_sz = 0,
- .weight_nr_accesses = 0,
- .weight_age = 1
- };

return damon_new_scheme(
&pattern,
/* page out those, as soon as found */
DAMOS_PAGEOUT,
/* under the quota. */
- &quota,
+ &damon_reclaim_quota,
/* (De)activate this according to the watermarks. */
&damon_reclaim_wmarks);
}
--
2.25.1

2022-09-13 19:29:46

by SeongJae Park

[permalink] [raw]
Subject: [PATCH 22/22] mm/damon/lru_sort: deduplicate hot/cold schemes generators

damon_lru_sort_new_{hot,cold}_scheme() have quite a lot of duplicates.
This commit factors out the duplicate to a separate function and use it
for reducing the duplicate.

Signed-off-by: SeongJae Park <[email protected]>
---
mm/damon/lru_sort.c | 45 +++++++++++++++++++++------------------------
1 file changed, 21 insertions(+), 24 deletions(-)

diff --git a/mm/damon/lru_sort.c b/mm/damon/lru_sort.c
index 8d9c3d1fd6be..07a0908963fd 100644
--- a/mm/damon/lru_sort.c
+++ b/mm/damon/lru_sort.c
@@ -135,6 +135,25 @@ DEFINE_DAMON_MODULES_DAMOS_STATS_PARAMS(damon_lru_sort_cold_stat,
static struct damon_ctx *ctx;
static struct damon_target *target;

+static struct damos *damon_lru_sort_new_scheme(
+ struct damos_access_pattern *pattern, enum damos_action action)
+{
+ struct damos_quota quota = damon_lru_sort_quota;
+
+ /* Use half of total quota for hot/cold pages sorting */
+ quota.ms = quota.ms / 2;
+
+ return damon_new_scheme(
+ /* find the pattern, and */
+ pattern,
+ /* (de)prioritize on LRU-lists */
+ action,
+ /* under the quota. */
+ &quota,
+ /* (De)activate this according to the watermarks. */
+ &damon_lru_sort_wmarks);
+}
+
/* Create a DAMON-based operation scheme for hot memory regions */
static struct damos *damon_lru_sort_new_hot_scheme(unsigned int hot_thres)
{
@@ -149,19 +168,8 @@ static struct damos *damon_lru_sort_new_hot_scheme(unsigned int hot_thres)
.min_age_region = 0,
.max_age_region = UINT_MAX,
};
- struct damos_quota quota = damon_lru_sort_quota;
-
- /* Use half of total quota for hot pages sorting */
- quota.ms = quota.ms / 2;

- return damon_new_scheme(
- &pattern,
- /* prioritize those on LRU lists, as soon as found */
- DAMOS_LRU_PRIO,
- /* under the quota. */
- &quota,
- /* (De)activate this according to the watermarks. */
- &damon_lru_sort_wmarks);
+ return damon_lru_sort_new_scheme(&pattern, DAMOS_LRU_PRIO);
}

/* Create a DAMON-based operation scheme for cold memory regions */
@@ -178,19 +186,8 @@ static struct damos *damon_lru_sort_new_cold_scheme(unsigned int cold_thres)
.min_age_region = cold_thres,
.max_age_region = UINT_MAX,
};
- struct damos_quota quota = damon_lru_sort_quota;

- /* Use half of total quota for cold pages sorting */
- quota.ms = quota.ms / 2;
-
- return damon_new_scheme(
- &pattern,
- /* mark those as not accessed, as soon as found */
- DAMOS_LRU_DEPRIO,
- /* under the quota. */
- &quota,
- /* (De)activate this according to the watermarks. */
- &damon_lru_sort_wmarks);
+ return damon_lru_sort_new_scheme(&pattern, DAMOS_LRU_DEPRIO);
}

static int damon_lru_sort_apply_parameters(void)
--
2.25.1

2022-09-13 19:29:56

by SeongJae Park

[permalink] [raw]
Subject: [PATCH 14/22] mm/damon/reclaim: use watermarks parameters generator macro

This commit makes DAMON_RECLAIM to generate the module parameters for
DAMOS watermarks using the generator macro to simplify the code and
reduce duplicates.

Signed-off-by: SeongJae Park <[email protected]>
---
mm/damon/reclaim.c | 56 ++++++++--------------------------------------
1 file changed, 9 insertions(+), 47 deletions(-)

diff --git a/mm/damon/reclaim.c b/mm/damon/reclaim.c
index 48326bef20f5..7f845f617dc5 100644
--- a/mm/damon/reclaim.c
+++ b/mm/damon/reclaim.c
@@ -91,45 +91,14 @@ module_param(quota_sz, ulong, 0600);
static unsigned long quota_reset_interval_ms __read_mostly = 1000;
module_param(quota_reset_interval_ms, ulong, 0600);

-/*
- * The watermarks check time interval in microseconds.
- *
- * Minimal time to wait before checking the watermarks, when DAMON_RECLAIM is
- * enabled but inactive due to its watermarks rule. 5 seconds by default.
- */
-static unsigned long wmarks_interval __read_mostly = 5000000;
-module_param(wmarks_interval, ulong, 0600);
-
-/*
- * Free memory rate (per thousand) for the high watermark.
- *
- * If free memory of the system in bytes per thousand bytes is higher than
- * this, DAMON_RECLAIM becomes inactive, so it does nothing but periodically
- * checks the watermarks. 500 (50%) by default.
- */
-static unsigned long wmarks_high __read_mostly = 500;
-module_param(wmarks_high, ulong, 0600);
-
-/*
- * Free memory rate (per thousand) for the middle watermark.
- *
- * If free memory of the system in bytes per thousand bytes is between this and
- * the low watermark, DAMON_RECLAIM becomes active, so starts the monitoring
- * and the reclaiming. 400 (40%) by default.
- */
-static unsigned long wmarks_mid __read_mostly = 400;
-module_param(wmarks_mid, ulong, 0600);
-
-/*
- * Free memory rate (per thousand) for the low watermark.
- *
- * If free memory of the system in bytes per thousand bytes is lower than this,
- * DAMON_RECLAIM becomes inactive, so it does nothing but periodically checks
- * the watermarks. In the case, the system falls back to the LRU-based page
- * granularity reclamation logic. 200 (20%) by default.
- */
-static unsigned long wmarks_low __read_mostly = 200;
-module_param(wmarks_low, ulong, 0600);
+struct damos_watermarks damon_reclaim_wmarks = {
+ .metric = DAMOS_WMARK_FREE_MEM_RATE,
+ .interval = 5000000, /* 5 seconds */
+ .high = 500, /* 50 percent */
+ .mid = 400, /* 40 percent */
+ .low = 200, /* 20 percent */
+};
+DEFINE_DAMON_MODULES_WMARKS_PARAMS(damon_reclaim_wmarks);

static struct damon_attrs damon_reclaim_mon_attrs = {
.sample_interval = 5000, /* 5 ms */
@@ -214,13 +183,6 @@ static struct damos *damon_reclaim_new_scheme(void)
damon_reclaim_mon_attrs.aggr_interval,
.max_age_region = UINT_MAX,
};
- struct damos_watermarks wmarks = {
- .metric = DAMOS_WMARK_FREE_MEM_RATE,
- .interval = wmarks_interval,
- .high = wmarks_high,
- .mid = wmarks_mid,
- .low = wmarks_low,
- };
struct damos_quota quota = {
/*
* Do not try reclamation for more than quota_ms milliseconds
@@ -242,7 +204,7 @@ static struct damos *damon_reclaim_new_scheme(void)
/* under the quota. */
&quota,
/* (De)activate this according to the watermarks. */
- &wmarks);
+ &damon_reclaim_wmarks);
}

static int damon_reclaim_apply_parameters(void)
--
2.25.1