← Documents Documentation/admin-guide/mm/damon/reclaim.rst GitHub 원문 ↗

Linux 6.18.37 · Administration / Memory Management / DAMON

DAMON-based Reclamation

가벼운 memory pressure에서 cold memory를 선제적으로 page out하는 DAMON_RECLAIM의 quota, watermark, 자동 조정, 통계를 설명합니다.

Source pathDocumentation/admin-guide/mm/damon/reclaim.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

DAMON_RECLAIM 운용 지도

reclaim.rst:1-305

DAMON_RECLAIM은 cold region을 먼저 찾아 제한된 속도로 reclaim하고, pressure가 너무 낮거나 너무 높을 때는 물러납니다. 시간·크기 quota와 PSI·feedback 자동 조정, 세 watermark를 조합해 기존 LRU reclaim을 보완합니다.

단계핵심 설정결과
Cold 감지`min_age` 이상 접근 없음해당 memory region을 page out
속도 제한`quota_ms`, `quota_sz`, reset intervalCPU 시간과 처리 byte 상한 적용
압력 자동 조정`quota_mem_pressure_us`system-wide `some` memory PSI 목표 사용
사용자 feedback`quota_autotune_feedback`10,000을 목표로 유효 quota 조정
자동 활성화high / mid / low watermarkfree memory 비율에 따라 reclaim 시작·중지
범위와 통계monitor region, `skip_anon`, counter대상·anonymous page 포함 여부·성과 확인

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
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/module/damon_reclaim/parameters/<parameter>`` files.
50
51 Below are the description of each parameter.
52
53 enabled
54 -------
55
56 Enable or disable DAMON_RECLAIM.
57
58 You can enable DAMON_RCLAIM by setting the value of this parameter as ``Y``.
59 Setting it as ``N`` disables DAMON_RECLAIM. Note that DAMON_RECLAIM could do
60 no real monitoring and reclamation due to the watermarks-based activation
61 condition. Refer to below descriptions for the watermarks parameter for this.
62
63 commit_inputs
64 -------------
65
66 Make DAMON_RECLAIM reads the input parameters again, except ``enabled``.
67
68 Input parameters that updated while DAMON_RECLAIM is running are not applied
69 by default. Once this parameter is set as ``Y``, DAMON_RECLAIM reads values
70 of parametrs except ``enabled`` again. Once the re-reading is done, this
71 parameter is set as ``N``. If invalid parameters are found while the
72 re-reading, DAMON_RECLAIM will be disabled.
73
74 Once ``Y`` is written to this parameter, the user must not write to any
75 parameters until reading ``commit_inputs`` again returns ``N``. If users
76 violate this rule, the kernel may exhibit undefined behavior.
77
78 min_age
79 -------
80
81 Time threshold for cold memory regions identification in microseconds.
82
83 If a memory region is not accessed for this or longer time, DAMON_RECLAIM
84 identifies the region as cold, and reclaims it.
85
86 120 seconds by default.
87
88 quota_ms
89 --------
90
91 Limit of time for the reclamation in milliseconds.
92
93 DAMON_RECLAIM tries to use only up to this time within a time window
94 (quota_reset_interval_ms) for trying reclamation of cold pages. This can be
95 used for limiting CPU consumption of DAMON_RECLAIM. If the value is zero, the
96 limit is disabled.
97
98 10 ms by default.
99
100 quota_sz
101 --------
102
103 Limit of size of memory for the reclamation in bytes.
104
105 DAMON_RECLAIM charges amount of memory which it tried to reclaim within a time
106 window (quota_reset_interval_ms) and makes no more than this limit is tried.
107 This can be used for limiting consumption of CPU and IO. If this value is
108 zero, the limit is disabled.
109
110 128 MiB by default.
111
112 quota_reset_interval_ms
113 -----------------------
114
115 The time/size quota charge reset interval in milliseconds.
116
117 The charget reset interval for the quota of time (quota_ms) and size
118 (quota_sz). That is, DAMON_RECLAIM does not try reclamation for more than
119 quota_ms milliseconds or quota_sz bytes within quota_reset_interval_ms
120 milliseconds.
121
122 1 second by default.
123
124 quota_mem_pressure_us
125 ---------------------
126
127 Desired level of memory pressure-stall time in microseconds.
128
129 While keeping the caps that set by other quotas, DAMON_RECLAIM automatically
130 increases and decreases the effective level of the quota aiming this level of
131 memory pressure is incurred. System-wide ``some`` memory PSI in microseconds
132 per quota reset interval (``quota_reset_interval_ms``) is collected and
133 compared to this value to see if the aim is satisfied. Value zero means
134 disabling this auto-tuning feature.
135
136 Disabled by default.
137
138 quota_autotune_feedback
139 -----------------------
140
141 User-specifiable feedback for auto-tuning of the effective quota.
142
143 While keeping the caps that set by other quotas, DAMON_RECLAIM automatically
144 increases and decreases the effective level of the quota aiming receiving this
145 feedback of value ``10,000`` from the user. DAMON_RECLAIM assumes the feedback
146 value and the quota are positively proportional. Value zero means disabling
147 this auto-tuning feature.
148
149 Disabled by default.
150
151 wmarks_interval
152 ---------------
153
154 Minimal time to wait before checking the watermarks, when DAMON_RECLAIM is
155 enabled but inactive due to its watermarks rule.
156
157 wmarks_high
158 -----------
159
160 Free memory rate (per thousand) for the high watermark.
161
162 If free memory of the system in bytes per thousand bytes is higher than this,
163 DAMON_RECLAIM becomes inactive, so it does nothing but only periodically checks
164 the watermarks.
165
166 wmarks_mid
167 ----------
168
169 Free memory rate (per thousand) for the middle watermark.
170
171 If free memory of the system in bytes per thousand bytes is between this and
172 the low watermark, DAMON_RECLAIM becomes active, so starts the monitoring and
173 the reclaiming.
174
175 wmarks_low
176 ----------
177
178 Free memory rate (per thousand) for the low watermark.
179
180 If free memory of the system in bytes per thousand bytes is lower than this,
181 DAMON_RECLAIM becomes inactive, so it does nothing but periodically checks the
182 watermarks. In the case, the system falls back to the LRU-list based page
183 granularity reclamation logic.
184
185 sample_interval
186 ---------------
187
188 Sampling interval for the monitoring in microseconds.
189
190 The sampling interval of DAMON for the cold memory monitoring. Please refer to
191 the DAMON documentation (:doc:`usage`) for more detail.
192
193 aggr_interval
194 -------------
195
196 Aggregation interval for the monitoring in microseconds.
197
198 The aggregation interval of DAMON for the cold memory monitoring. Please
199 refer to the DAMON documentation (:doc:`usage`) for more detail.
200
201 min_nr_regions
202 --------------
203
204 Minimum number of monitoring regions.
205
206 The minimal number of monitoring regions of DAMON for the cold memory
207 monitoring. This can be used to set lower-bound of the monitoring quality.
208 But, setting this too high could result in increased monitoring overhead.
209 Please refer to the DAMON documentation (:doc:`usage`) for more detail.
210
211 max_nr_regions
212 --------------
213
214 Maximum number of monitoring regions.
215
216 The maximum number of monitoring regions of DAMON for the cold memory
217 monitoring. This can be used to set upper-bound of the monitoring overhead.
218 However, setting this too low could result in bad monitoring quality. Please
219 refer to the DAMON documentation (:doc:`usage`) for more detail.
220
221 monitor_region_start
222 --------------------
223
224 Start of target memory region in physical address.
225
226 The start physical address of memory region that DAMON_RECLAIM will do work
227 against. That is, DAMON_RECLAIM will find cold memory regions in this region
228 and reclaims. By default, biggest System RAM is used as the region.
229
230 monitor_region_end
231 ------------------
232
233 End of target memory region in physical address.
234
235 The end physical address of memory region that DAMON_RECLAIM will do work
236 against. That is, DAMON_RECLAIM will find cold memory regions in this region
237 and reclaims. By default, biggest System RAM is used as the region.
238
239 skip_anon
240 ---------
241
242 Skip anonymous pages reclamation.
243
244 If this parameter is set as ``Y``, DAMON_RECLAIM does not reclaim anonymous
245 pages. By default, ``N``.
246
247
248 kdamond_pid
249 -----------
250
251 PID of the DAMON thread.
252
253 If DAMON_RECLAIM is enabled, this becomes the PID of the worker thread. Else,
254 -1.
255
256 nr_reclaim_tried_regions
257 ------------------------
258
259 Number of memory regions that tried to be reclaimed by DAMON_RECLAIM.
260
261 bytes_reclaim_tried_regions
262 ---------------------------
263
264 Total bytes of memory regions that tried to be reclaimed by DAMON_RECLAIM.
265
266 nr_reclaimed_regions
267 --------------------
268
269 Number of memory regions that successfully be reclaimed by DAMON_RECLAIM.
270
271 bytes_reclaimed_regions
272 -----------------------
273
274 Total bytes of memory regions that successfully be reclaimed by DAMON_RECLAIM.
275
276 nr_quota_exceeds
277 ----------------
278
279 Number of times that the time/space quota limits have exceeded.
280
281 Example
282 =======
283
284 Below runtime example commands make DAMON_RECLAIM to find memory regions that
285 not accessed for 30 seconds or more and pages out. The reclamation is limited
286 to be done only up to 1 GiB per second to avoid DAMON_RECLAIM consuming too
287 much CPU time for the paging out operation. It also asks DAMON_RECLAIM to do
288 nothing if the system's free memory rate is more than 50%, but start the real
289 works if it becomes lower than 40%. If DAMON_RECLAIM doesn't make progress and
290 therefore the free memory rate becomes lower than 20%, it asks DAMON_RECLAIM to
291 do nothing again, so that we can fall back to the LRU-list based page
292 granularity reclamation. ::
293
294 # cd /sys/module/damon_reclaim/parameters
295 # echo 30000000 > min_age
296 # echo $((1 * 1024 * 1024 * 1024)) > quota_sz
297 # echo 1000 > quota_reset_interval_ms
298 # echo 500 > wmarks_high
299 # echo 400 > wmarks_mid
300 # echo 200 > wmarks_low
301 # echo Y > enabled
302
303 .. [1] https://research.google/pubs/pub48551/
304 .. [2] https://lwn.net/Articles/787611/
305 .. [3] https://www.kernel.org/doc/html/latest/mm/free_page_reporting.html
306

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

DAMON 기반 proactive reclaim

1-11

이 문서는 GPL-2.0 라이선스를 따릅니다. DAMON-based Reclamation(`DAMON_RECLAIM`)은 가벼운 memory pressure에서 선제적이고 가볍게 reclaim하도록 만든 정적 kernel module입니다. LRU 목록 기반 `page_granularity` reclaim을 대체하려는 기능이 아니라, 서로 다른 pressure 수준과 요구에 맞춰 선택적으로 사용합니다.

선제적 reclaim이 필요한 이유

12-29

일반적인 memory over-commit 시스템에서 cold page를 미리 reclaim하면 성능 저하는 작게 유지하면서 memory를 절약하고, process의 direct reclaim이 만드는 latency spike와 `kswapd`의 CPU 소비를 줄일 수 있습니다 [1] [2].

Free Pages Reporting [3] 기반의 memory over-commit virtualization이 좋은 예입니다. guest VM이 free memory를 host에 보고하면 host는 그 memory를 다른 guest에 다시 할당해 전체 memory를 활용합니다. 그러나 일부 kernel subsystem과 user-space application은 가능한 memory를 많이 쓰도록 설계되어 있어 guest가 충분히 절약하지 못할 수 있습니다. host에 보고되는 free memory가 적어져 전체 활용도가 떨어질 때, guest에서 proactive reclaim을 실행하면 이 문제를 완화할 수 있습니다.

작동 방식

30-39

DAMON_RECLAIM은 지정한 시간 동안 접근되지 않은 memory region을 찾아 page out합니다. paging out 작업이 CPU를 지나치게 쓰지 않도록 속도 제한을 설정할 수 있으며, 그 한도 안에서는 더 오래 접근되지 않은 region부터 처리합니다. 관리자는 세 개의 memory pressure watermark로 이 scheme의 자동 활성화·비활성화 조건도 정할 수 있습니다.

Module parameter interface

40-52

이 기능을 쓰려면 먼저 `CONFIG_DAMON_RECLAIM=y`로 빌드한 kernel을 실행하고 있는지 확인해야 합니다.

관리자는 kernel boot command line에 `damon_reclaim.<parameter>=<value>`를 넣거나 `/sys/module/damon_reclaim/parameters/<parameter>` 파일에 값을 써서 DAMON_RECLAIM을 켜고 끄며 조정할 수 있습니다. 아래에서 각 parameter를 설명합니다.

활성화와 입력값 반영

53-77
Parameter동작기본값
enabledY / NDAMON_RECLAIM을 활성화하거나 비활성화합니다. 활성화되어도 watermark 조건 때문에 실제 작업은 멈춰 있을 수 있습니다.-
commit_inputsY -> N실행 중 바뀐 입력값을 `enabled`를 제외하고 다시 읽습니다. Y를 쓴 뒤 N을 읽을 때까지 다른 매개변수에 쓰면 안 됩니다.-

`enabled=Y`는 기능을 켜고 `enabled=N`은 끕니다. 원문 58행의 `DAMON_RCLAIM`은 `DAMON_RECLAIM`의 표기 오류이지만 그대로 보존해 둡니다. watermark 활성화 조건을 만족하지 않으면 켜진 상태에서도 실제 모니터링과 reclaim은 일어나지 않을 수 있습니다.

실행 중 수정한 값은 기본적으로 즉시 적용되지 않습니다. `commit_inputs=Y`를 쓰면 `enabled`를 제외한 parameter를 다시 읽고 완료 뒤 N으로 돌아갑니다. 잘못된 값이 발견되면 DAMON_RECLAIM이 비활성화됩니다.

`commit_inputs`에 Y를 쓴 뒤 다시 읽어서 N이 반환될 때까지 어떤 parameter에도 쓰면 안 됩니다. 이 규칙을 어기면 kernel이 undefined behavior를 보일 수 있습니다.

Cold 기준과 시간·크기 quota

78-123
Parameter단위의미기본값
min_agemicroseconds이 시간 이상 접근되지 않은 영역을 cold로 판단해 reclaim합니다.120 seconds
quota_msmilliseconds`quota_reset_interval_ms` 창마다 reclaim에 쓸 수 있는 CPU 시간을 제한합니다. 0이면 제한하지 않습니다.10 ms
quota_szbytes한 quota 창에서 reclaim을 시도할 memory 양을 제한해 CPU와 I/O 소비를 제어합니다. 0이면 제한하지 않습니다.128 MiB
quota_reset_interval_msmilliseconds시간 quota와 크기 quota의 charge를 초기화하는 간격입니다.1 second

`min_age` 이상 접근되지 않은 region을 cold로 식별해 reclaim합니다. 한 `quota_reset_interval_ms` 안에서 `quota_ms`보다 긴 시간 또는 `quota_sz`보다 많은 byte를 시도하지 않습니다. 각 quota 값이 0이면 해당 제한을 비활성화합니다.

Quota 자동 조정

124-150
Parameter단위동작기본값
quota_mem_pressure_usmicrosecondsquota 창마다 system-wide `some` memory PSI가 이 목표에 가깝도록 유효 quota를 자동 조정합니다. 0이면 비활성화합니다.disabled
quota_autotune_feedbackfeedback사용자 feedback이 10,000에 가까워지도록 quota를 양의 비례 관계로 자동 조정합니다. 0이면 비활성화합니다.disabled

`quota_mem_pressure_us`는 다른 quota의 상한을 지키면서 quota reset 간격마다 system-wide `some` memory PSI를 수집해 목표와 비교하고 유효 quota를 늘리거나 줄입니다. `quota_autotune_feedback`은 사용자 feedback과 quota가 양의 비례 관계라고 가정하고 feedback 10,000을 목표로 같은 조정을 수행합니다. 두 값 모두 0이면 해당 자동 조정 기능을 끕니다.

Memory pressure watermark

151-184
Parameter단위동작기본값
wmarks_intervalmicrosecondswatermark 규칙으로 비활성 상태일 때 다음 watermark 확인까지 기다릴 최소 시간입니다.not specified
wmarks_highpermilfree memory 비율이 이 값보다 높으면 비활성화하고 watermark만 주기적으로 확인합니다.not specified
wmarks_midpermilfree memory 비율이 이 값과 low watermark 사이이면 모니터링과 reclaim을 활성화합니다.not specified
wmarks_lowpermilfree memory 비율이 이 값보다 낮으면 비활성화하고 LRU 기반 page-granularity reclaim으로 되돌아갑니다.not specified

free memory 비율이 high watermark보다 높으면 DAMON_RECLAIM은 비활성화하고 watermark만 주기적으로 확인합니다. mid와 low 사이에서는 모니터링과 reclaim을 시작합니다. low보다 낮으면 다시 멈추고 기존 LRU 목록 기반 page-granularity reclaim logic으로 되돌아갑니다.

이 문서의 151-184행은 네 watermark parameter의 기본값을 따로 제시하지 않습니다.

모니터링·대상 영역·anonymous page

185-247
Parameter단위의미기본값
sample_intervalmicrosecondscold memory 모니터링을 위한 DAMON sampling 간격입니다.not specified
aggr_intervalmicrosecondscold memory 모니터링을 위한 DAMON aggregation 간격입니다.not specified
min_nr_regionsregions모니터링 품질의 하한을 정하는 최소 영역 수입니다. 지나치게 높으면 오버헤드가 늘 수 있습니다.not specified
max_nr_regionsregions모니터링 오버헤드의 상한을 정하는 최대 영역 수입니다. 지나치게 낮으면 품질이 나빠질 수 있습니다.not specified
monitor_region_startphysical addresscold region을 찾아 reclaim할 physical memory 영역의 시작 주소입니다.biggest System RAM
monitor_region_endphysical addresscold region을 찾아 reclaim할 physical memory 영역의 끝 주소입니다.biggest System RAM
skip_anonY / NY이면 anonymous page를 reclaim하지 않습니다.N

sampling·aggregation 간격과 monitoring region의 최소·최대 수는 DAMON 관측의 품질과 오버헤드를 조절합니다. 자세한 의미는 DAMON `usage` 문서를 참조합니다. physical address 범위를 따로 지정하지 않으면 가장 큰 System RAM에서 cold region을 찾아 reclaim합니다. `skip_anon=Y`이면 anonymous page는 대상에서 제외합니다.

Worker 상태와 reclaim 통계

248-280
항목의미
kdamond_pidDAMON_RECLAIM이 활성화되면 worker thread의 PID이며, 아니면 -1입니다.
nr_reclaim_tried_regionsDAMON_RECLAIM이 reclaim을 시도한 memory region 수입니다.
bytes_reclaim_tried_regionsreclaim을 시도한 memory region의 총 byte 수입니다.
nr_reclaimed_regionsDAMON_RECLAIM이 reclaim에 성공한 memory region 수입니다.
bytes_reclaimed_regionsreclaim에 성공한 memory region의 총 byte 수입니다.
nr_quota_exceeds시간 또는 공간 quota를 초과한 횟수입니다.

worker PID와 함께 reclaim을 시도한 region 수·byte, 성공한 region 수·byte, 시간 또는 공간 quota를 초과한 횟수를 확인할 수 있습니다.

Runtime 설정 예

281-302

다음 명령은 30초 이상 접근되지 않은 memory region을 찾아 page out하고, 처리량을 초당 최대 1 GiB로 제한합니다. 이 제한은 paging out에 CPU 시간을 지나치게 쓰지 않도록 합니다.

free memory가 50%보다 많으면 아무 작업도 하지 않고, 40% 아래로 떨어지면 실제 reclaim을 시작합니다. 진행이 없어 free memory가 20% 아래로 내려가면 다시 멈춰 LRU 목록 기반 page-granularity reclaim으로 되돌아갑니다.

# cd /sys/module/damon_reclaim/parameters
# echo 30000000 > min_age
# echo $((1 * 1024 * 1024 * 1024)) > quota_sz
# echo 1000 > quota_reset_interval_ms
# echo 500 > wmarks_high
# echo 400 > wmarks_mid
# echo 200 > wmarks_low
# echo Y > enabled

참고 자료

303-305