Skip to content

Commit bec976b

Browse files
sjp38torvalds
authored andcommitted
Documentation/admin-guide/mm/damon: add a document for DAMON_RECLAIM
This adds an admin-guide document for DAMON-based Reclamation. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: SeongJae Park <[email protected]> Cc: Amit Shah <[email protected]> Cc: Benjamin Herrenschmidt <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: David Rientjes <[email protected]> Cc: David Woodhouse <[email protected]> Cc: Greg Thelen <[email protected]> Cc: Jonathan Cameron <[email protected]> Cc: Jonathan Corbet <[email protected]> Cc: Leonard Foerster <[email protected]> Cc: Marco Elver <[email protected]> Cc: Markus Boehme <[email protected]> Cc: Shakeel Butt <[email protected]> Cc: Shuah Khan <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 43b0536 commit bec976b

File tree

2 files changed

+236
-0
lines changed

2 files changed

+236
-0
lines changed

Documentation/admin-guide/mm/damon/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ optimize those.
1313

1414
start
1515
usage
16+
reclaim
Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
.. SPDX-License-Identifier: GPL-2.0
2+
3+
=======================
4+
DAMON-based Reclamation
5+
=======================
6+
7+
DAMON-based Reclamation (DAMON_RECLAIM) is a static kernel module that aimed to
8+
be used for proactive and lightweight reclamation under light memory pressure.
9+
It doesn't aim to replace the LRU-list based page_granularity reclamation, but
10+
to be selectively used for different level of memory pressure and requirements.
11+
12+
Where Proactive Reclamation is Required?
13+
========================================
14+
15+
On general memory over-committed systems, proactively reclaiming cold pages
16+
helps saving memory and reducing latency spikes that incurred by the direct
17+
reclaim of the process or CPU consumption of kswapd, while incurring only
18+
minimal performance degradation [1]_ [2]_ .
19+
20+
Free Pages Reporting [3]_ based memory over-commit virtualization systems are
21+
good example of the cases. In such systems, the guest VMs reports their free
22+
memory to host, and the host reallocates the reported memory to other guests.
23+
As a result, the memory of the systems are fully utilized. However, the
24+
guests could be not so memory-frugal, mainly because some kernel subsystems and
25+
user-space applications are designed to use as much memory as available. Then,
26+
guests could report only small amount of memory as free to host, results in
27+
memory utilization drop of the systems. Running the proactive reclamation in
28+
guests could mitigate this problem.
29+
30+
How It Works?
31+
=============
32+
33+
DAMON_RECLAIM finds memory regions that didn't accessed for specific time
34+
duration and page out. To avoid it consuming too much CPU for the paging out
35+
operation, a speed limit can be configured. Under the speed limit, it pages
36+
out memory regions that didn't accessed longer time first. System
37+
administrators can also configure under what situation this scheme should
38+
automatically activated and deactivated with three memory pressure watermarks.
39+
40+
Interface: Module Parameters
41+
============================
42+
43+
To use this feature, you should first ensure your system is running on a kernel
44+
that is built with ``CONFIG_DAMON_RECLAIM=y``.
45+
46+
To let sysadmins enable or disable it and tune for the given system,
47+
DAMON_RECLAIM utilizes module parameters. That is, you can put
48+
``damon_reclaim.<parameter>=<value>`` on the kernel boot command line or write
49+
proper values to ``/sys/modules/damon_reclaim/parameters/<parameter>`` files.
50+
51+
Note that the parameter values except ``enabled`` are applied only when
52+
DAMON_RECLAIM starts. Therefore, if you want to apply new parameter values in
53+
runtime and DAMON_RECLAIM is already enabled, you should disable and re-enable
54+
it via ``enabled`` parameter file. Writing of the new values to proper
55+
parameter values should be done before the re-enablement.
56+
57+
Below are the description of each parameter.
58+
59+
enabled
60+
-------
61+
62+
Enable or disable DAMON_RECLAIM.
63+
64+
You can enable DAMON_RCLAIM by setting the value of this parameter as ``Y``.
65+
Setting it as ``N`` disables DAMON_RECLAIM. Note that DAMON_RECLAIM could do
66+
no real monitoring and reclamation due to the watermarks-based activation
67+
condition. Refer to below descriptions for the watermarks parameter for this.
68+
69+
min_age
70+
-------
71+
72+
Time threshold for cold memory regions identification in microseconds.
73+
74+
If a memory region is not accessed for this or longer time, DAMON_RECLAIM
75+
identifies the region as cold, and reclaims it.
76+
77+
120 seconds by default.
78+
79+
quota_ms
80+
--------
81+
82+
Limit of time for the reclamation in milliseconds.
83+
84+
DAMON_RECLAIM tries to use only up to this time within a time window
85+
(quota_reset_interval_ms) for trying reclamation of cold pages. This can be
86+
used for limiting CPU consumption of DAMON_RECLAIM. If the value is zero, the
87+
limit is disabled.
88+
89+
10 ms by default.
90+
91+
quota_sz
92+
--------
93+
94+
Limit of size of memory for the reclamation in bytes.
95+
96+
DAMON_RECLAIM charges amount of memory which it tried to reclaim within a time
97+
window (quota_reset_interval_ms) and makes no more than this limit is tried.
98+
This can be used for limiting consumption of CPU and IO. If this value is
99+
zero, the limit is disabled.
100+
101+
128 MiB by default.
102+
103+
quota_reset_interval_ms
104+
-----------------------
105+
106+
The time/size quota charge reset interval in milliseconds.
107+
108+
The charget reset interval for the quota of time (quota_ms) and size
109+
(quota_sz). That is, DAMON_RECLAIM does not try reclamation for more than
110+
quota_ms milliseconds or quota_sz bytes within quota_reset_interval_ms
111+
milliseconds.
112+
113+
1 second by default.
114+
115+
wmarks_interval
116+
---------------
117+
118+
Minimal time to wait before checking the watermarks, when DAMON_RECLAIM is
119+
enabled but inactive due to its watermarks rule.
120+
121+
wmarks_high
122+
-----------
123+
124+
Free memory rate (per thousand) for the high watermark.
125+
126+
If free memory of the system in bytes per thousand bytes is higher than this,
127+
DAMON_RECLAIM becomes inactive, so it does nothing but only periodically checks
128+
the watermarks.
129+
130+
wmarks_mid
131+
----------
132+
133+
Free memory rate (per thousand) for the middle watermark.
134+
135+
If free memory of the system in bytes per thousand bytes is between this and
136+
the low watermark, DAMON_RECLAIM becomes active, so starts the monitoring and
137+
the reclaiming.
138+
139+
wmarks_low
140+
----------
141+
142+
Free memory rate (per thousand) for the low watermark.
143+
144+
If free memory of the system in bytes per thousand bytes is lower than this,
145+
DAMON_RECLAIM becomes inactive, so it does nothing but periodically checks the
146+
watermarks. In the case, the system falls back to the LRU-list based page
147+
granularity reclamation logic.
148+
149+
sample_interval
150+
---------------
151+
152+
Sampling interval for the monitoring in microseconds.
153+
154+
The sampling interval of DAMON for the cold memory monitoring. Please refer to
155+
the DAMON documentation (:doc:`usage`) for more detail.
156+
157+
aggr_interval
158+
-------------
159+
160+
Aggregation interval for the monitoring in microseconds.
161+
162+
The aggregation interval of DAMON for the cold memory monitoring. Please
163+
refer to the DAMON documentation (:doc:`usage`) for more detail.
164+
165+
min_nr_regions
166+
--------------
167+
168+
Minimum number of monitoring regions.
169+
170+
The minimal number of monitoring regions of DAMON for the cold memory
171+
monitoring. This can be used to set lower-bound of the monitoring quality.
172+
But, setting this too high could result in increased monitoring overhead.
173+
Please refer to the DAMON documentation (:doc:`usage`) for more detail.
174+
175+
max_nr_regions
176+
--------------
177+
178+
Maximum number of monitoring regions.
179+
180+
The maximum number of monitoring regions of DAMON for the cold memory
181+
monitoring. This can be used to set upper-bound of the monitoring overhead.
182+
However, setting this too low could result in bad monitoring quality. Please
183+
refer to the DAMON documentation (:doc:`usage`) for more detail.
184+
185+
monitor_region_start
186+
--------------------
187+
188+
Start of target memory region in physical address.
189+
190+
The start physical address of memory region that DAMON_RECLAIM will do work
191+
against. That is, DAMON_RECLAIM will find cold memory regions in this region
192+
and reclaims. By default, biggest System RAM is used as the region.
193+
194+
monitor_region_end
195+
------------------
196+
197+
End of target memory region in physical address.
198+
199+
The end physical address of memory region that DAMON_RECLAIM will do work
200+
against. That is, DAMON_RECLAIM will find cold memory regions in this region
201+
and reclaims. By default, biggest System RAM is used as the region.
202+
203+
kdamond_pid
204+
-----------
205+
206+
PID of the DAMON thread.
207+
208+
If DAMON_RECLAIM is enabled, this becomes the PID of the worker thread. Else,
209+
-1.
210+
211+
Example
212+
=======
213+
214+
Below runtime example commands make DAMON_RECLAIM to find memory regions that
215+
not accessed for 30 seconds or more and pages out. The reclamation is limited
216+
to be done only up to 1 GiB per second to avoid DAMON_RECLAIM consuming too
217+
much CPU time for the paging out operation. It also asks DAMON_RECLAIM to do
218+
nothing if the system's free memory rate is more than 50%, but start the real
219+
works if it becomes lower than 40%. If DAMON_RECLAIM doesn't make progress and
220+
therefore the free memory rate becomes lower than 20%, it asks DAMON_RECLAIM to
221+
do nothing again, so that we can fall back to the LRU-list based page
222+
granularity reclamation. ::
223+
224+
# cd /sys/modules/damon_reclaim/parameters
225+
# echo 30000000 > min_age
226+
# echo $((1 * 1024 * 1024 * 1024)) > quota_sz
227+
# echo 1000 > quota_reset_interval_ms
228+
# echo 500 > wmarks_high
229+
# echo 400 > wmarks_mid
230+
# echo 200 > wmarks_low
231+
# echo Y > enabled
232+
233+
.. [1] https://research.google/pubs/pub48551/
234+
.. [2] https://lwn.net/Articles/787611/
235+
.. [3] https://www.kernel.org/doc/html/latest/vm/free_page_reporting.html

0 commit comments

Comments
 (0)