mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-08-30 07:39:12 -04:00
Pull MM updates from Andrew Morton:
- "selftests/mm: clean up build output and verbosity" (Li Wang)
Remove some noise from the MM selftests build
- "mm: Free contiguous order-0 pages efficiently" (Ryan Roberts)
Speed up the freeing of a batch of 0-order pages by first scanning
them for coalescing opportunities. This is applicable to vfree() and
to the releasing of frozen pages
- "mm/damon: introduce DAMOS failed region quota charge ratio"
(SeongJae Park)
Address a DAMOS usability issue: The DAMOS quota often exhausts
prematurely because it charges for all memory attempted, causing slow
and inconsistent performance when actions fail on unreclaimable
memory.
To fix this, a new feature lets users set a smaller, flexible quota
charge ratio (via a numerator and denominator) for failed regions.
Since failed actions cause less overhead, reducing their quota cost
ensures more predictable and efficient DAMOS processing
- "selftests/cgroup: improve zswap tests robustness and support large
page sizes" (Li Wang)
Fix various spurious failures and improves the overall robustness of
the cgroup zswap selftests
- "fix MAP_DROPPABLE not supported errno" (Anthony Yznaga)
Fix an issue in the mlock selftests on arm32
- "mm: huge_memory: clean up defrag sysfs with shared" (Breno Leitao)
Some maintenance work in the huge_memory code
- "treewide: fixup gfp_t printks" (Brendan Jackman)
Use the special vprintf() gfp_t conversion in various places
- "mm: Fix vmemmap optimization accounting and initialization" (Muchun
Song)
Fix several bugs in the vmemmap optimization, mainly around incorrect
page accounting and memmap initialization in the DAX and memory
hotplug paths. It also fixes pageblock migratetype initialization and
struct page initialization for ZONE_DEVICE compound pages
- "mm/damon: repost non-hotfix reviewed patches in damon/next tree"
A sprinkle of unrelated minor bugfixes for DAMON
- "mm: remove page_mapped()" (David Hildenbrand)
Remove this function from the tree, replacing it with folio_mapped()
- "mm/damon: let DAMON be paused and resumed" (SeongJae Park)
Allow DAMON to be paused and resumed without losing its current state
- "kasan: hw_tags: Disable tagging for stack and page-tables" (Muhammad
Usama Anjum)
Simplify and speed up kasan by removing its ineffective tagging of
stacks and page tables
- "mm/damon/reclaim,lru_sort: monitor all system rams by default"
(SeongJae Park)
Simplify deployment on diverse hardware like NUMA systems by updating
DAMON_RECLAIM and DAMON_LRU_SORT to automatically monitor the
physical address range covering all System RAM areas by default,
replacing the overly restrictive behavior that only targeted the
single largest memory block to save on negligible overhead
- "mm/damon/sysfs: document filters/ directory as deprecated" (SeongJae
Park)
Update some DAMON docs
- "mm: use spinlock guards for zone lock" (Dmitry Ilvokhin)
Switch zone->lock handling over to using the guard() mechanisms
- "mm/filemap: tighten mmap_miss hit accounting" (fujunjie)
Fix a flaw where the mmap_miss counter over-credited page cache hits
during fault-arounds and page-fault retries. This results in
significant reduction of redundant synchronous mmap readahead I/O,
drastically cutting down execution time and gigabytes read for sparse
random or strided memory access workloads
- "selftests/cgroup: Fix false positive failures in test_percpu_basic"
(Li Wang)
Fix a couple of false-positives in the cgroup kmem selftests
- "mm/damon/reclaim: support monitoring intervals auto-tuning"
(SeongJae Park)
Add a new parameter to DAMON permitting DAMON_RECLAIM to
automatically tune DAMON's sampling and aggregation intervals
- "mm/damon/stat: add kdamond_pid parameter" (SeongJae Park)
Change DAMON_STAT to provide the pid of its kdamond
- "mm/kmemleak: dedupe verbose scan output" (Breno Leitao)
Remove large amounts of duplicated backtraces from the verbose-mode
kmemleak output
- "mm: remove CONFIG_HAVE_BOOTMEM_INFO_NODE (Part 1)" (David
Hildenbrand)
Reduce our use of CONFIG_HAVE_BOOTMEM_INFO_NODE, with a view to
removing it entirely in a later series
- "mm/damon: validate min_region_size to be power of 2" (Liew Rui Yan)
Prevent users from passing a non-power-of-2 value of `addr_unit', as
this later results in undesirable behavior
- "mm: document read_pages and simplify usage" (Frederick Mayle)
- "tools/mm/page-types: Fix misc bugs" (Ye Liu)
Fix three issues in tools/mm/page-types.c
- "mm: misc cleanups from __GFP_UNMAPPED series" (Brendan Jackman)
Implement several cleanups in the page allocator and related code
- "mm, swap: swap table phase IV: unify allocation" (Kairui Song)
Unify the allocation and charging of anon and shmem swap in folios,
provides better synchronization, consolidates the metadata
management, hence dropping the static array and map, and improves
performance
- "mm/damon: introduce data attributes monitoring" (SeongJae Park(
Extend DAMON to monitor general data attributes other than accesses
- "mm/vmalloc: free unused pages on vrealloc() shrink" (Shivam Kalra)
Implement the TODO in vrealloc() to unmap and free unused pages when
shrinking across a page boundary
- "mm/damon: documentation and comment fixes" (niecheng)
- "remove mmap_action success, error hooks" (Lorenzo Stoakes)
Eliminate custom hooks from mmap_action by removing the problematic
success_hook which allowed drivers to improperly access uninitialized
VMAs. It replaces the error_hook with a simple error-code field and
updates the memory char driver accordingly
- "mm/damon: minor improvements for code readability and tests"
(SeongJae Park)
- "mm/damon: fix macro arguments and clarify quota goals doc" (Maksym
Shcherba)
- "userfaultfd: merge fs/userfaultfd.c into mm/userfaultfd.c" (Mike
Rapoport)
- "mm/mglru: improve reclaim loop and dirty folio" (Kairui Song and
others)
Clean up and slightly improves MGLRU's reclaim loop and dirty
writeback handling. Large performance improvements are measured
- "use vma locks for proc/pid/{smaps|numa_maps} reads" (Suren
Baghdasaryan)
Use per-vma locks when reading /proc/pid/smaps and numa_maps similar
to reduce contention on central mmap_lock
- "refactors thpsize_shmem_enabled_store() and thpsize_shmem_enabled_show()"
(Ran Xiaokai)
Some cleanup work in the THP code
- "selftests/memfd: fix compilation warnings" (Konstantin Khorenko)
Fix a few build glitches in the memfd selftest code.
- "memcg: shrink obj_stock_pcp and cache multiple objcgs" (Shakeel
Butt)
Resolve a 68% performance regression caused by NUMA-node cache
thrashing around struct obj_stock_pcp by shrinking its existing
fields and expanding it into a multi-slot array that caches up to
five obj_cgroup pointers per CPU, allowing per-node variants of the
same memcg to coexist within a single 64-byte cache line.
- "zram: writeback fixes" (Sergey Senozhatsky)
address a couple of unrelated zram writeback issues
- "mm: switch THP shrinker to list_lru" (Johannes Weiner)
Resolve NUMA-awareness issues and streamlines callsite interaction by
refactoring and extending the list_lru API to completely replace the
complex, open-coded deferred split queue for Transparent Huge Pages
- "mm: improve large folio readahead for exec memory" (Usama Arif)
Improve large-folio readahead on systems like 64K-page arm64 by
preventing the mmap_miss check from permanently disabling
target-oriented VM_EXEC readahead, and by generalizing the
force_thp_readahead gate to support mappings with any usefully large
maximum folio order under the cache cap.
- "userfaultfd/pagemap: pre-existing fixes" (Kiryl Shutsemau)
Fix a bunch of minor issues in the userfaultfd/pagemap, all of which
were flagged by Sashiko review of proposed new material
- "mm/sparse-vmemmap: Provide generic vmemmap_set_pmd() and
vmemmap_check_pmd()" (Muchun Song)
Provide generic versions of these two functions so the four
arch-specific implementations can be removed.
- "mm/swap, PM: hibernate: fix swapoff race in uswsusp by pinning swap
device" (Youngjun Park)
Address a uswsusp-vs-swapoff race and reduces the swap device
reference taking/releasing frequency.
- "mm/hmm: A fix and a selftest" (Dev Jain)
* tag 'mm-stable-2026-06-18-09-26' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm: (321 commits)
selftests/mm/hmm-tests: test pagemap reads of PMD device-private entries
fs/proc/task_mmu: do not warn on seeing non-migration pmd entry
lib/test_hmm: check alloc_page_vma() return value and handle OOM
mm/compaction: cap compact_gap() at COMPACT_CLUSTER_MAX
mm/swap: remove redundant swap device reference in alloc/free
mm/swap, PM: hibernate: fix swapoff race in uswsusp by pinning swap device
mm/filemap: use folio_next_index() for start
vmalloc: fix NULL pointer dereference in is_vm_area_hugepages()
sparc/mm: drop vmemmap_check_pmd helper and use generic code
loongarch/mm: drop vmemmap_check_pmd helper and use generic code
riscv/mm: drop vmemmap_pmd helpers and use generic code
arm64/mm: drop vmemmap_pmd helpers and use generic code
mm/sparse-vmemmap: provide generic vmemmap_set_pmd() and vmemmap_check_pmd()
rust: page: mark Page::nid as inline
userfaultfd: build __VMA_UFFD_FLAGS from config-gated masks
userfaultfd: gate must_wait writability check on pte_present()
mm/huge_memory: preserve pmd_swp_uffd_wp on device-private PMD downgrade
fs/proc/task_mmu: fix hugetlb self-deadlock in pagemap_scan_pte_hole()
fs/proc/task_mmu: use huge_page_size() in pagemap_scan_hugetlb_entry()
fs/proc/task_mmu: fix make_uffd_wp_huge_pte() prot-update race
...
562 lines
15 KiB
C
562 lines
15 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* DAMON-based LRU-lists Sorting
|
|
*
|
|
* Author: SeongJae Park <sj@kernel.org>
|
|
*/
|
|
|
|
#define pr_fmt(fmt) "damon-lru-sort: " 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 "damon_lru_sort."
|
|
|
|
/*
|
|
* Enable or disable DAMON_LRU_SORT.
|
|
*
|
|
* You can enable DAMON_LRU_SORT by setting the value of this parameter as
|
|
* ``Y``. Setting it as ``N`` disables DAMON_LRU_SORT. Note that
|
|
* DAMON_LRU_SORT could do no real monitoring and LRU-lists sorting due to the
|
|
* watermarks-based activation condition. Refer to below descriptions for the
|
|
* watermarks parameter for this.
|
|
*/
|
|
static bool enabled __read_mostly;
|
|
|
|
/*
|
|
* Make DAMON_LRU_SORT reads the input parameters again, except ``enabled``.
|
|
*
|
|
* Input parameters that updated while DAMON_LRU_SORT is running are not
|
|
* applied by default. Once this parameter is set as ``Y``, DAMON_LRU_SORT
|
|
* reads values of parameters 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_LRU_SORT will be disabled.
|
|
*/
|
|
static bool commit_inputs __read_mostly;
|
|
|
|
/*
|
|
* Desired active to [in]active memory ratio in bp (1/10,000).
|
|
*
|
|
* While keeping the caps that set by other quotas, DAMON_LRU_SORT
|
|
* automatically increases and decreases the effective level of the quota
|
|
* aiming the LRU [de]prioritizations of the hot and cold memory resulting in
|
|
* this active to [in]active memory ratio. Value zero means disabling this
|
|
* auto-tuning feature.
|
|
*
|
|
* Disabled by default.
|
|
*/
|
|
static unsigned long active_mem_bp __read_mostly;
|
|
module_param(active_mem_bp, ulong, 0600);
|
|
|
|
/*
|
|
* Auto-tune monitoring intervals.
|
|
*
|
|
* If this parameter is set as ``Y``, DAMON_LRU_SORT automatically tunes
|
|
* DAMON's sampling and aggregation intervals. The auto-tuning aims to capture
|
|
* meaningful amount of access events in each DAMON-snapshot, while keeping the
|
|
* sampling interval 5 milliseconds in minimum, and 10 seconds in maximum.
|
|
* Setting this as ``N`` disables the auto-tuning.
|
|
*
|
|
* Disabled by default.
|
|
*/
|
|
static bool autotune_monitoring_intervals __read_mostly;
|
|
module_param(autotune_monitoring_intervals, bool, 0600);
|
|
|
|
/*
|
|
* Filter [non-]young pages accordingly for LRU [de]prioritizations.
|
|
*
|
|
* If this is set, check page level access (youngness) once again before each
|
|
* LRU [de]prioritization operation. LRU prioritization operation is skipped
|
|
* if the page has not accessed since the last check (not young). LRU
|
|
* deprioritization operation is skipped if the page has accessed since the
|
|
* last check (young). The feature is enabled or disabled if this parameter is
|
|
* set as ``Y`` or ``N``, respectively.
|
|
*
|
|
* Disabled by default.
|
|
*/
|
|
static bool filter_young_pages __read_mostly;
|
|
module_param(filter_young_pages, bool, 0600);
|
|
|
|
/*
|
|
* Access frequency threshold for hot memory regions identification in permil.
|
|
*
|
|
* If a memory region is accessed in frequency of this or higher,
|
|
* DAMON_LRU_SORT identifies the region as hot, and mark it as accessed on the
|
|
* LRU list, so that it could not be reclaimed under memory pressure. 50% by
|
|
* default.
|
|
*/
|
|
static unsigned long hot_thres_access_freq = 500;
|
|
module_param(hot_thres_access_freq, ulong, 0600);
|
|
|
|
/*
|
|
* Time threshold for cold memory regions identification in microseconds.
|
|
*
|
|
* If a memory region is not accessed for this or longer time, DAMON_LRU_SORT
|
|
* identifies the region as cold, and mark it as unaccessed on the LRU list, so
|
|
* that it could be reclaimed first under memory pressure. 120 seconds by
|
|
* default.
|
|
*/
|
|
static unsigned long cold_min_age __read_mostly = 120000000;
|
|
module_param(cold_min_age, ulong, 0600);
|
|
|
|
static struct damos_quota damon_lru_sort_quota = {
|
|
/* Use up to 10 ms per 1 sec, by default */
|
|
.ms = 10,
|
|
.sz = 0,
|
|
.reset_interval = 1000,
|
|
/* Within the quota, mark hotter regions accessed first. */
|
|
.weight_sz = 0,
|
|
.weight_nr_accesses = 1,
|
|
.weight_age = 1,
|
|
};
|
|
DEFINE_DAMON_MODULES_DAMOS_TIME_QUOTA(damon_lru_sort_quota);
|
|
|
|
static struct damos_watermarks damon_lru_sort_wmarks = {
|
|
.metric = DAMOS_WMARK_FREE_MEM_RATE,
|
|
.interval = 5000000, /* 5 seconds */
|
|
.high = 200, /* 20 percent */
|
|
.mid = 150, /* 15 percent */
|
|
.low = 50, /* 5 percent */
|
|
};
|
|
DEFINE_DAMON_MODULES_WMARKS_PARAMS(damon_lru_sort_wmarks);
|
|
|
|
static struct damon_attrs damon_lru_sort_mon_attrs = {
|
|
.sample_interval = 5000, /* 5 ms */
|
|
.aggr_interval = 100000, /* 100 ms */
|
|
.ops_update_interval = 0,
|
|
.min_nr_regions = 10,
|
|
.max_nr_regions = 1000,
|
|
};
|
|
DEFINE_DAMON_MODULES_MON_ATTRS_PARAMS(damon_lru_sort_mon_attrs);
|
|
|
|
/*
|
|
* Start of the target memory region in physical address.
|
|
*
|
|
* The start physical address of memory region that DAMON_LRU_SORT will do work
|
|
* against. By default, the system's entire physical memory 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_LRU_SORT will do work
|
|
* against. By default, the system's entire physical memory is used as the
|
|
* region.
|
|
*/
|
|
static unsigned long monitor_region_end __read_mostly;
|
|
module_param(monitor_region_end, ulong, 0600);
|
|
|
|
/*
|
|
* Scale factor for DAMON_LRU_SORT to ops address conversion.
|
|
*
|
|
* This parameter must not be set to 0.
|
|
*/
|
|
static unsigned long addr_unit __read_mostly = 1;
|
|
|
|
static struct damos_stat damon_lru_sort_hot_stat;
|
|
DEFINE_DAMON_MODULES_DAMOS_STATS_PARAMS(damon_lru_sort_hot_stat,
|
|
lru_sort_tried_hot_regions, lru_sorted_hot_regions,
|
|
hot_quota_exceeds);
|
|
|
|
static struct damos_stat damon_lru_sort_cold_stat;
|
|
DEFINE_DAMON_MODULES_DAMOS_STATS_PARAMS(damon_lru_sort_cold_stat,
|
|
lru_sort_tried_cold_regions, lru_sorted_cold_regions,
|
|
cold_quota_exceeds);
|
|
|
|
static struct damos_access_pattern damon_lru_sort_stub_pattern = {
|
|
/* Find regions having PAGE_SIZE or larger size */
|
|
.min_sz_region = PAGE_SIZE,
|
|
.max_sz_region = ULONG_MAX,
|
|
/* no matter its access frequency */
|
|
.min_nr_accesses = 0,
|
|
.max_nr_accesses = UINT_MAX,
|
|
/* no matter its age */
|
|
.min_age_region = 0,
|
|
.max_age_region = UINT_MAX,
|
|
};
|
|
|
|
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,
|
|
/* for each aggregation interval */
|
|
0,
|
|
/* under the quota. */
|
|
"a,
|
|
/* (De)activate this according to the watermarks. */
|
|
&damon_lru_sort_wmarks,
|
|
NUMA_NO_NODE);
|
|
}
|
|
|
|
/* Create a DAMON-based operation scheme for hot memory regions */
|
|
static struct damos *damon_lru_sort_new_hot_scheme(unsigned int hot_thres)
|
|
{
|
|
struct damos_access_pattern pattern = damon_lru_sort_stub_pattern;
|
|
|
|
pattern.min_nr_accesses = hot_thres;
|
|
return damon_lru_sort_new_scheme(&pattern, DAMOS_LRU_PRIO);
|
|
}
|
|
|
|
/* Create a DAMON-based operation scheme for cold memory regions */
|
|
static struct damos *damon_lru_sort_new_cold_scheme(unsigned int cold_thres)
|
|
{
|
|
struct damos_access_pattern pattern = damon_lru_sort_stub_pattern;
|
|
|
|
pattern.max_nr_accesses = 0;
|
|
pattern.min_age_region = cold_thres;
|
|
return damon_lru_sort_new_scheme(&pattern, DAMOS_LRU_DEPRIO);
|
|
}
|
|
|
|
static int damon_lru_sort_add_quota_goals(struct damos *hot_scheme,
|
|
struct damos *cold_scheme)
|
|
{
|
|
struct damos_quota_goal *goal;
|
|
|
|
if (!active_mem_bp)
|
|
return 0;
|
|
goal = damos_new_quota_goal(DAMOS_QUOTA_ACTIVE_MEM_BP, active_mem_bp);
|
|
if (!goal)
|
|
return -ENOMEM;
|
|
damos_add_quota_goal(&hot_scheme->quota, goal);
|
|
/* aim 0.2 % goal conflict, to keep little ping pong */
|
|
goal = damos_new_quota_goal(DAMOS_QUOTA_INACTIVE_MEM_BP,
|
|
10000 - active_mem_bp + 2);
|
|
if (!goal)
|
|
return -ENOMEM;
|
|
damos_add_quota_goal(&cold_scheme->quota, goal);
|
|
return 0;
|
|
}
|
|
|
|
static int damon_lru_sort_add_filters(struct damos *hot_scheme,
|
|
struct damos *cold_scheme)
|
|
{
|
|
struct damos_filter *filter;
|
|
|
|
if (!filter_young_pages)
|
|
return 0;
|
|
|
|
/* disallow prioritizing not-young pages */
|
|
filter = damos_new_filter(DAMOS_FILTER_TYPE_YOUNG, false, false);
|
|
if (!filter)
|
|
return -ENOMEM;
|
|
damos_add_filter(hot_scheme, filter);
|
|
|
|
/* disabllow de-prioritizing young pages */
|
|
filter = damos_new_filter(DAMOS_FILTER_TYPE_YOUNG, true, false);
|
|
if (!filter)
|
|
return -ENOMEM;
|
|
damos_add_filter(cold_scheme, filter);
|
|
return 0;
|
|
}
|
|
|
|
static int damon_lru_sort_apply_parameters(void)
|
|
{
|
|
struct damon_ctx *param_ctx;
|
|
struct damon_target *param_target;
|
|
struct damon_attrs attrs;
|
|
struct damos *hot_scheme, *cold_scheme;
|
|
unsigned int hot_thres, cold_thres;
|
|
int err;
|
|
|
|
err = damon_modules_new_paddr_ctx_target(¶m_ctx, ¶m_target);
|
|
if (err)
|
|
return err;
|
|
|
|
param_ctx->addr_unit = addr_unit;
|
|
param_ctx->min_region_sz = max(DAMON_MIN_REGION_SZ / addr_unit, 1);
|
|
|
|
if (!is_power_of_2(param_ctx->min_region_sz)) {
|
|
err = -EINVAL;
|
|
goto out;
|
|
}
|
|
|
|
if (!damon_lru_sort_mon_attrs.sample_interval) {
|
|
err = -EINVAL;
|
|
goto out;
|
|
}
|
|
|
|
attrs = damon_lru_sort_mon_attrs;
|
|
if (autotune_monitoring_intervals) {
|
|
attrs.sample_interval = 5000;
|
|
attrs.aggr_interval = 100000;
|
|
attrs.intervals_goal.access_bp = 40;
|
|
attrs.intervals_goal.aggrs = 3;
|
|
attrs.intervals_goal.min_sample_us = 5000;
|
|
attrs.intervals_goal.max_sample_us = 10 * 1000 * 1000;
|
|
}
|
|
err = damon_set_attrs(param_ctx, &attrs);
|
|
if (err)
|
|
goto out;
|
|
|
|
err = -ENOMEM;
|
|
hot_thres = damon_max_nr_accesses(&attrs) *
|
|
hot_thres_access_freq / 1000;
|
|
hot_scheme = damon_lru_sort_new_hot_scheme(hot_thres);
|
|
if (!hot_scheme)
|
|
goto out;
|
|
|
|
cold_thres = cold_min_age / attrs.aggr_interval;
|
|
cold_scheme = damon_lru_sort_new_cold_scheme(cold_thres);
|
|
if (!cold_scheme) {
|
|
damon_destroy_scheme(hot_scheme);
|
|
goto out;
|
|
}
|
|
|
|
damon_set_schemes(param_ctx, &hot_scheme, 1);
|
|
damon_add_scheme(param_ctx, cold_scheme);
|
|
|
|
err = damon_lru_sort_add_quota_goals(hot_scheme, cold_scheme);
|
|
if (err)
|
|
goto out;
|
|
err = damon_lru_sort_add_filters(hot_scheme, cold_scheme);
|
|
if (err)
|
|
goto out;
|
|
|
|
err = damon_set_region_system_rams_default(param_target,
|
|
&monitor_region_start,
|
|
&monitor_region_end,
|
|
param_ctx->addr_unit,
|
|
param_ctx->min_region_sz);
|
|
if (err)
|
|
goto out;
|
|
err = damon_commit_ctx(ctx, param_ctx);
|
|
out:
|
|
damon_destroy_ctx(param_ctx);
|
|
return err;
|
|
}
|
|
|
|
static int damon_lru_sort_commit_inputs_fn(void *arg)
|
|
{
|
|
return damon_lru_sort_apply_parameters();
|
|
}
|
|
|
|
static int damon_lru_sort_commit_inputs_store(const char *val,
|
|
const struct kernel_param *kp)
|
|
{
|
|
bool commit_inputs_request;
|
|
int err;
|
|
struct damon_call_control control = {
|
|
.fn = damon_lru_sort_commit_inputs_fn,
|
|
};
|
|
|
|
if (!val) {
|
|
commit_inputs_request = true;
|
|
} else {
|
|
err = kstrtobool(val, &commit_inputs_request);
|
|
if (err)
|
|
return err;
|
|
}
|
|
|
|
if (!commit_inputs_request)
|
|
return 0;
|
|
|
|
/*
|
|
* Skip damon_call() if ctx is not initialized to avoid
|
|
* NULL pointer dereference.
|
|
*/
|
|
if (!ctx)
|
|
return -EINVAL;
|
|
|
|
err = damon_call(ctx, &control);
|
|
|
|
return err ? err : control.return_code;
|
|
}
|
|
|
|
static const struct kernel_param_ops commit_inputs_param_ops = {
|
|
.flags = KERNEL_PARAM_OPS_FL_NOARG,
|
|
.set = damon_lru_sort_commit_inputs_store,
|
|
.get = param_get_bool,
|
|
};
|
|
|
|
module_param_cb(commit_inputs, &commit_inputs_param_ops, &commit_inputs, 0600);
|
|
|
|
static int damon_lru_sort_damon_call_fn(void *arg)
|
|
{
|
|
struct damon_ctx *c = arg;
|
|
struct damos *s;
|
|
|
|
/* update the stats parameter */
|
|
damon_for_each_scheme(s, c) {
|
|
if (s->action == DAMOS_LRU_PRIO)
|
|
damon_lru_sort_hot_stat = s->stat;
|
|
else if (s->action == DAMOS_LRU_DEPRIO)
|
|
damon_lru_sort_cold_stat = s->stat;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static struct damon_call_control call_control = {
|
|
.fn = damon_lru_sort_damon_call_fn,
|
|
.repeat = true,
|
|
};
|
|
|
|
static int damon_lru_sort_turn(bool on)
|
|
{
|
|
int err;
|
|
|
|
if (!on)
|
|
return damon_stop(&ctx, 1);
|
|
|
|
err = damon_lru_sort_apply_parameters();
|
|
if (err)
|
|
return err;
|
|
|
|
err = damon_start(&ctx, 1, true);
|
|
if (err)
|
|
return err;
|
|
return damon_call(ctx, &call_control);
|
|
}
|
|
|
|
static int damon_lru_sort_addr_unit_store(const char *val,
|
|
const struct kernel_param *kp)
|
|
{
|
|
unsigned long input_addr_unit;
|
|
int err = kstrtoul(val, 0, &input_addr_unit);
|
|
|
|
if (err)
|
|
return err;
|
|
if (!input_addr_unit)
|
|
return -EINVAL;
|
|
|
|
addr_unit = input_addr_unit;
|
|
return 0;
|
|
}
|
|
|
|
static const struct kernel_param_ops addr_unit_param_ops = {
|
|
.set = damon_lru_sort_addr_unit_store,
|
|
.get = param_get_ulong,
|
|
};
|
|
|
|
module_param_cb(addr_unit, &addr_unit_param_ops, &addr_unit, 0600);
|
|
MODULE_PARM_DESC(addr_unit,
|
|
"Scale factor for DAMON_LRU_SORT to ops address conversion (default: 1)");
|
|
|
|
static bool damon_lru_sort_enabled(void)
|
|
{
|
|
if (!ctx)
|
|
return false;
|
|
return damon_is_running(ctx);
|
|
}
|
|
|
|
static int damon_lru_sort_enabled_store(const char *val,
|
|
const struct kernel_param *kp)
|
|
{
|
|
int err;
|
|
|
|
err = kstrtobool(val, &enabled);
|
|
if (err)
|
|
return err;
|
|
|
|
if (damon_lru_sort_enabled() == enabled)
|
|
return 0;
|
|
|
|
/* Called before init function. The function will handle this. */
|
|
if (!damon_initialized())
|
|
return 0;
|
|
|
|
/* damon_modules_new_paddr_ctx_target() in the init function failed. */
|
|
if (!ctx)
|
|
return -ENOMEM;
|
|
|
|
return damon_lru_sort_turn(enabled);
|
|
}
|
|
|
|
static int damon_lru_sort_enabled_load(char *buffer,
|
|
const struct kernel_param *kp)
|
|
{
|
|
return sprintf(buffer, "%c\n", damon_lru_sort_enabled() ? 'Y' : 'N');
|
|
}
|
|
|
|
static const struct kernel_param_ops enabled_param_ops = {
|
|
.set = damon_lru_sort_enabled_store,
|
|
.get = damon_lru_sort_enabled_load,
|
|
};
|
|
|
|
module_param_cb(enabled, &enabled_param_ops, &enabled, 0600);
|
|
MODULE_PARM_DESC(enabled,
|
|
"Enable or disable DAMON_LRU_SORT (default: disabled)");
|
|
|
|
static int damon_lru_sort_kdamond_pid_store(const char *val,
|
|
const struct kernel_param *kp)
|
|
{
|
|
/*
|
|
* kdamond_pid is read-only, but kernel command line could write it.
|
|
* Do nothing here.
|
|
*/
|
|
return 0;
|
|
}
|
|
|
|
static int damon_lru_sort_kdamond_pid_load(char *buffer,
|
|
const struct kernel_param *kp)
|
|
{
|
|
int kdamond_pid = -1;
|
|
|
|
if (ctx) {
|
|
kdamond_pid = damon_kdamond_pid(ctx);
|
|
if (kdamond_pid < 0)
|
|
kdamond_pid = -1;
|
|
}
|
|
return sprintf(buffer, "%d\n", kdamond_pid);
|
|
}
|
|
|
|
static const struct kernel_param_ops kdamond_pid_param_ops = {
|
|
.set = damon_lru_sort_kdamond_pid_store,
|
|
.get = damon_lru_sort_kdamond_pid_load,
|
|
};
|
|
|
|
/*
|
|
* PID of the DAMON thread
|
|
*
|
|
* If DAMON_LRU_SORT is enabled, this becomes the PID of the worker thread.
|
|
* Else, -1.
|
|
*/
|
|
module_param_cb(kdamond_pid, &kdamond_pid_param_ops, NULL, 0400);
|
|
|
|
static int __init damon_lru_sort_init(void)
|
|
{
|
|
int err;
|
|
|
|
if (!damon_initialized()) {
|
|
err = -ENOMEM;
|
|
goto out;
|
|
}
|
|
err = damon_modules_new_paddr_ctx_target(&ctx, &target);
|
|
if (err)
|
|
goto out;
|
|
|
|
call_control.data = ctx;
|
|
|
|
/* 'enabled' has set before this function, probably via command line */
|
|
if (enabled)
|
|
err = damon_lru_sort_turn(true);
|
|
|
|
out:
|
|
if (err && enabled)
|
|
enabled = false;
|
|
return err;
|
|
}
|
|
|
|
module_init(damon_lru_sort_init);
|