// SPDX-License-Identifier: GPL-2.0 /* * DAMON-based page reclamation * * Author: SeongJae Park <[email protected]> */ #define pr_fmt(fmt) … #include <linux/damon.h> #include <linux/kstrtox.h> #include <linux/module.h> #include "modules-common.h" #ifdef MODULE_PARAM_PREFIX #undef MODULE_PARAM_PREFIX #endif #define MODULE_PARAM_PREFIX … /* * Enable or disable DAMON_RECLAIM. * * You can enable DAMON_RCLAIM by setting the value of this parameter as ``Y``. * Setting it as ``N`` disables DAMON_RECLAIM. Note that DAMON_RECLAIM could * do no real monitoring and reclamation due to the watermarks-based activation * condition. Refer to below descriptions for the watermarks parameter for * this. */ static bool enabled __read_mostly; /* * Make DAMON_RECLAIM reads the input parameters again, except ``enabled``. * * Input parameters that updated while DAMON_RECLAIM is running are not applied * by default. Once this parameter is set as ``Y``, DAMON_RECLAIM reads values * of parametrs except ``enabled`` again. Once the re-reading is done, this * parameter is set as ``N``. If invalid parameters are found while the * re-reading, DAMON_RECLAIM will be disabled. */ static bool commit_inputs __read_mostly; module_param(commit_inputs, bool, 0600); /* * Time threshold for cold memory regions identification in microseconds. * * If a memory region is not accessed for this or longer time, DAMON_RECLAIM * identifies the region as cold, and reclaims. 120 seconds by default. */ static unsigned long min_age __read_mostly = …; module_param(min_age, ulong, 0600); static struct damos_quota damon_reclaim_quota = …; DEFINE_DAMON_MODULES_DAMOS_QUOTAS(damon_reclaim_quota); /* * Desired level of memory pressure-stall time in microseconds. * * While keeping the caps that set by other quotas, DAMON_RECLAIM automatically * increases and decreases the effective level of the quota aiming this level of * memory pressure is incurred. System-wide ``some`` memory PSI in microseconds * per quota reset interval (``quota_reset_interval_ms``) is collected and * compared to this value to see if the aim is satisfied. Value zero means * disabling this auto-tuning feature. * * Disabled by default. */ static unsigned long quota_mem_pressure_us __read_mostly; module_param(quota_mem_pressure_us, ulong, 0600); /* * User-specifiable feedback for auto-tuning of the effective quota. * * While keeping the caps that set by other quotas, DAMON_RECLAIM automatically * increases and decreases the effective level of the quota aiming receiving this * feedback of value ``10,000`` from the user. DAMON_RECLAIM assumes the feedback * value and the quota are positively proportional. Value zero means disabling * this auto-tuning feature. * * Disabled by default. * */ static unsigned long quota_autotune_feedback __read_mostly; module_param(quota_autotune_feedback, ulong, 0600); static struct damos_watermarks damon_reclaim_wmarks = …; DEFINE_DAMON_MODULES_WMARKS_PARAMS(damon_reclaim_wmarks); static struct damon_attrs damon_reclaim_mon_attrs = …; DEFINE_DAMON_MODULES_MON_ATTRS_PARAMS(damon_reclaim_mon_attrs); /* * Start of the target memory region in physical address. * * The start physical address of memory region that DAMON_RECLAIM will do work * against. By default, biggest System RAM is used as the region. */ static unsigned long monitor_region_start __read_mostly; module_param(monitor_region_start, ulong, 0600); /* * End of the target memory region in physical address. * * The end physical address of memory region that DAMON_RECLAIM will do work * against. By default, biggest System RAM is used as the region. */ static unsigned long monitor_region_end __read_mostly; module_param(monitor_region_end, ulong, 0600); /* * Skip anonymous pages reclamation. * * If this parameter is set as ``Y``, DAMON_RECLAIM does not reclaim anonymous * pages. By default, ``N``. */ static bool skip_anon __read_mostly; module_param(skip_anon, bool, 0600); /* * PID of the DAMON thread * * If DAMON_RECLAIM is enabled, this becomes the PID of the worker thread. * Else, -1. */ static int kdamond_pid __read_mostly = …; module_param(kdamond_pid, int, 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; static struct damos *damon_reclaim_new_scheme(void) { … } static int damon_reclaim_apply_parameters(void) { … } static int damon_reclaim_turn(bool on) { … } static int damon_reclaim_enabled_store(const char *val, const struct kernel_param *kp) { … } static const struct kernel_param_ops enabled_param_ops = …; module_param_cb(…); MODULE_PARM_DESC(…) …; static int damon_reclaim_handle_commit_inputs(void) { … } static int damon_reclaim_after_aggregation(struct damon_ctx *c) { … } static int damon_reclaim_after_wmarks_check(struct damon_ctx *c) { … } static int __init damon_reclaim_init(void) { … } module_init(…) …;