Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm/damon/core: introduce [in]active memory ratio damos quota goal metric

Patch series "mm/damon: advance DAMOS-based LRU sorting".

DAMOS_LRU_[DE]PRIO actions were added to DAMOS for more access-aware LRU
lists sorting. For simple usage, a specialized kernel module, namely
DAMON_LRU_SORT, has also been introduced. After the introduction of the
module, DAMON got a few important new features, including the aim-based
quota auto-tuning, age tracking, young page filter, and monitoring
intervals auto-tuning. Meanwhile, DAMOS-based LRU sorting had no direct
updates. Now we show some rooms to advance for DAMOS-based LRU sorting.

Firstly, the aim-oriented quota auto-tuning can simplify the LRU sorting
parameters tuning. But there is no good auto-tuning target metric for LRU
sorting use case. Secondly, the behavior of DAMOS_LRU_[DE]PRIO are not
very symmetric. DAMOS_LRU_DEPRIO directly moves the pages to inactive LRU
list, while DAMOS_LRU_PRIO only marks the page as accessed, so that the
page can not directly but only eventually moved to the active LRU list.
Finally, DAMON_LRU_SORT users cannot utilize the modern features that can
be useful for them, too.

Improve the situation with the following changes. First, introduce a new
DAMOS quota auto-tuning target metric for active:inactive memory size
ratio. Since LRU sorting is a kind of balancing of active and inactive
pages, the active:inactive memory size ratio can be intuitively set.
Second, update DAMOS_LRU_[DE]PRIO behaviors to be more intuitive and
symmetric, by letting them directly move the pages to [in]active LRU list.
Third, update the DAMON_LRU_SORT module user interface to be able to
fully utilize the modern features including the [in]active memory size
ratio-based quota auto-tuning, young page filter, and monitoring intervals
auto-tuning.

With these changes, for example, users can now ask DAMON to "find hot/cold
memory regions with auto-tuned monitoring intervals, do one more page
level access check for found hot/cold memory, and move pages of those to
active or inactive LRU lists accordingly, aiming X:Y active to inactive
memory ratio." For example, if they know 30% of the memory is better to be
protected from reclamation, 30:70 can be set as the target ratio.

Test Results
------------

I ran DAMON_LRU_SORT with the features introduced by this series, on a
real world server workload. For the active:inactive ratio goal, I set
50:50. I confirmed it achieves the target active:inactive ratio, without
manual tuning of the monitoring intervals and the hot/coldness thresholds.
The baseline system that was not running the DAMON_LRU_SORT was keeping
active:inactive ratio of about 1:10.

Note that the test didn't show a clear performance difference, though. I
believe that was mainly because the workload was not very memory
intensive. Also, whether the 50:50 target ratio was optimum is unclear.
Nonetheless, the positive performance impact of the basic LRU sorting idea
is already confirmed with the initial DAMON_LRU_SORT introduction patch
series. The goal of this patch series is simplifying the parameters
tuning of DAMOS-based LRU sorting, and the test confirmed the aimed goals
are achieved.

Patches Sequence
----------------

First three patches extend DAMOS quota auto-tuning to support [in]active
memory ratio target metric type. Those (patches 1-3) introduce new
metrics, implement DAMON sysfs support, and update the documentation,
respectively.

Following patch (patch 4) makes DAMOS_LRU_PRIO action to directly move
target pages to active LRU list, instead of only marking them accessed.

Following seven patches (patches 5-11) updates DAMON_LRU_SORT to support
modern DAMON features. Patch 5 makes it uses not only access frequency
but also age at under-quota regions prioritization. Patches 6-11 add the
support for young page filtering, active:inactive memory ratio based quota
auto-tuning, and monitoring intervals auto-tuning, with appropriate
document updates.


This patch (of 11):

DAMOS_LRU_[DE]PRIO are DAMOS actions for making balance of active and
inactive memory size. There is no appropriate DAMOS quota auto-tuning
target metric for the use case. Add two new DAMOS quota goal metrics for
the purpose, namely DAMOS_QUOTA_[IN]ACTIVE_MEM_BP. Those will represent
the ratio of [in]active memory to total (inactive + active) memory.
Hence, users will be able to ask DAMON to, for example, "find hot and cold
memory, and move pages of those to active and inactive LRU lists,
adjusting the hot/cold thresholds aiming 50:50 active:inactive memory
ratio."

Link: https://lkml.kernel.org/r/20260113152717.70459-1-sj@kernel.org
Link: https://lkml.kernel.org/r/20260113152717.70459-2-sj@kernel.org
Signed-off-by: SeongJae Park <sj@kernel.org>
Cc: David Hildenbrand <david@kernel.org>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

SeongJae Park and committed by
Andrew Morton
4835e287 b19cb086

+26
+4
include/linux/damon.h
··· 155 155 * @DAMOS_QUOTA_NODE_MEM_FREE_BP: MemFree ratio of a node. 156 156 * @DAMOS_QUOTA_NODE_MEMCG_USED_BP: MemUsed ratio of a node for a cgroup. 157 157 * @DAMOS_QUOTA_NODE_MEMCG_FREE_BP: MemFree ratio of a node for a cgroup. 158 + * @DAMOS_QUOTA_ACTIVE_MEM_BP: Active to total LRU memory ratio. 159 + * @DAMOS_QUOTA_INACTIVE_MEM_BP: Inactive to total LRU memory ratio. 158 160 * @NR_DAMOS_QUOTA_GOAL_METRICS: Number of DAMOS quota goal metrics. 159 161 * 160 162 * Metrics equal to larger than @NR_DAMOS_QUOTA_GOAL_METRICS are unsupported. ··· 168 166 DAMOS_QUOTA_NODE_MEM_FREE_BP, 169 167 DAMOS_QUOTA_NODE_MEMCG_USED_BP, 170 168 DAMOS_QUOTA_NODE_MEMCG_FREE_BP, 169 + DAMOS_QUOTA_ACTIVE_MEM_BP, 170 + DAMOS_QUOTA_INACTIVE_MEM_BP, 171 171 NR_DAMOS_QUOTA_GOAL_METRICS, 172 172 }; 173 173
+22
mm/damon/core.c
··· 2132 2132 } 2133 2133 #endif 2134 2134 2135 + /* 2136 + * Returns LRU-active or inactive memory to total LRU memory size ratio. 2137 + */ 2138 + static unsigned int damos_get_in_active_mem_bp(bool active_ratio) 2139 + { 2140 + unsigned long active, inactive, total; 2141 + 2142 + /* This should align with /proc/meminfo output */ 2143 + active = global_node_page_state(NR_LRU_BASE + LRU_ACTIVE_ANON) + 2144 + global_node_page_state(NR_LRU_BASE + LRU_ACTIVE_FILE); 2145 + inactive = global_node_page_state(NR_LRU_BASE + LRU_INACTIVE_ANON) + 2146 + global_node_page_state(NR_LRU_BASE + LRU_INACTIVE_FILE); 2147 + total = active + inactive; 2148 + if (active_ratio) 2149 + return active * 10000 / total; 2150 + return inactive * 10000 / total; 2151 + } 2135 2152 2136 2153 static void damos_set_quota_goal_current_value(struct damos_quota_goal *goal) 2137 2154 { ··· 2170 2153 case DAMOS_QUOTA_NODE_MEMCG_USED_BP: 2171 2154 case DAMOS_QUOTA_NODE_MEMCG_FREE_BP: 2172 2155 goal->current_value = damos_get_node_memcg_used_bp(goal); 2156 + break; 2157 + case DAMOS_QUOTA_ACTIVE_MEM_BP: 2158 + case DAMOS_QUOTA_INACTIVE_MEM_BP: 2159 + goal->current_value = damos_get_in_active_mem_bp( 2160 + goal->metric == DAMOS_QUOTA_ACTIVE_MEM_BP); 2173 2161 break; 2174 2162 default: 2175 2163 break;