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

Linux 6.18.37 · Administration / Memory Management / DAMON

DAMON-based LRU-lists Sorting

DAMON 접근 패턴으로 hot page의 LRU 우선순위를 높이고 cold page의 우선순위를 낮추는 DAMON_LRU_SORT의 동작과 module parameter를 설명합니다.

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

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

1. 요약·해설

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

DAMON_LRU_SORT 운용 지도

lru_sort.rst:1-294

DAMON_LRU_SORT는 page 단위 접근 검사의 큰 비용 없이 LRU 목록을 접근 패턴에 더 가깝게 정돈합니다. threshold, CPU quota, 세 watermark, monitoring 범위를 함께 설정하고 hot/cold 통계로 효과를 확인합니다.

단계핵심 설정결과
Hot 감지`hot_thres_access_freq` 이상의 접근 빈도LRU에서 accessed로 표시해 우선순위를 높임
Cold 감지`cold_min_age` 이상 접근 없음LRU에서 unaccessed로 표시해 우선순위를 낮춤
비용 제한`quota_ms` / `quota_reset_interval_ms`정렬에 쓰는 CPU 시간 제한
자동 활성화`wmarks_high`, `wmarks_mid`, `wmarks_low`free memory 비율에 따라 정렬 시작·중지
관측 대상`monitor_region_start` / `monitor_region_end`기본값은 가장 큰 System RAM 영역
상태 확인`kdamond_pid`와 hot/cold counter시도·성공 byte와 quota 초과 횟수 확인

2. 영어 원문 전체

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

원문 전체 펼치기
1 .. SPDX-License-Identifier: GPL-2.0
2
3 =============================
4 DAMON-based LRU-lists Sorting
5 =============================
6
7 DAMON-based LRU-lists Sorting (DAMON_LRU_SORT) is a static kernel module that
8 aimed to be used for proactive and lightweight data access pattern based
9 (de)prioritization of pages on their LRU-lists for making LRU-lists a more
10 trusworthy data access pattern source.
11
12 Where Proactive LRU-lists Sorting is Required?
13 ==============================================
14
15 As page-granularity access checking overhead could be significant on huge
16 systems, LRU lists are normally not proactively sorted but partially and
17 reactively sorted for special events including specific user requests, system
18 calls and memory pressure. As a result, LRU lists are sometimes not so
19 perfectly prepared to be used as a trustworthy access pattern source for some
20 situations including reclamation target pages selection under sudden memory
21 pressure.
22
23 Because DAMON can identify access patterns of best-effort accuracy while
24 inducing only user-specified range of overhead, proactively running
25 DAMON_LRU_SORT could be helpful for making LRU lists more trustworthy access
26 pattern source with low and controlled overhead.
27
28 How It Works?
29 =============
30
31 DAMON_LRU_SORT finds hot pages (pages of memory regions that showing access
32 rates that higher than a user-specified threshold) and cold pages (pages of
33 memory regions that showing no access for a time that longer than a
34 user-specified threshold) using DAMON, and prioritizes hot pages while
35 deprioritizing cold pages on their LRU-lists. To avoid it consuming too much
36 CPU for the prioritizations, a CPU time usage limit can be configured. Under
37 the limit, it prioritizes and deprioritizes more hot and cold pages first,
38 respectively. System administrators can also configure under what situation
39 this scheme should automatically activated and deactivated with three memory
40 pressure watermarks.
41
42 Its default parameters for hotness/coldness thresholds and CPU quota limit are
43 conservatively chosen. That is, the module under its default parameters could
44 be widely used without harm for common situations while providing a level of
45 benefits for systems having clear hot/cold access patterns under memory
46 pressure while consuming only a limited small portion of CPU time.
47
48 Interface: Module Parameters
49 ============================
50
51 To use this feature, you should first ensure your system is running on a kernel
52 that is built with ``CONFIG_DAMON_LRU_SORT=y``.
53
54 To let sysadmins enable or disable it and tune for the given system,
55 DAMON_LRU_SORT utilizes module parameters. That is, you can put
56 ``damon_lru_sort.<parameter>=<value>`` on the kernel boot command line or write
57 proper values to ``/sys/module/damon_lru_sort/parameters/<parameter>`` files.
58
59 Below are the description of each parameter.
60
61 enabled
62 -------
63
64 Enable or disable DAMON_LRU_SORT.
65
66 You can enable DAMON_LRU_SORT by setting the value of this parameter as ``Y``.
67 Setting it as ``N`` disables DAMON_LRU_SORT. Note that DAMON_LRU_SORT could do
68 no real monitoring and LRU-lists sorting due to the watermarks-based activation
69 condition. Refer to below descriptions for the watermarks parameter for this.
70
71 commit_inputs
72 -------------
73
74 Make DAMON_LRU_SORT reads the input parameters again, except ``enabled``.
75
76 Input parameters that updated while DAMON_LRU_SORT is running are not applied
77 by default. Once this parameter is set as ``Y``, DAMON_LRU_SORT reads values
78 of parametrs except ``enabled`` again. Once the re-reading is done, this
79 parameter is set as ``N``. If invalid parameters are found while the
80 re-reading, DAMON_LRU_SORT will be disabled.
81
82 hot_thres_access_freq
83 ---------------------
84
85 Access frequency threshold for hot memory regions identification in permil.
86
87 If a memory region is accessed in frequency of this or higher, DAMON_LRU_SORT
88 identifies the region as hot, and mark it as accessed on the LRU list, so that
89 it could not be reclaimed under memory pressure. 50% by default.
90
91 cold_min_age
92 ------------
93
94 Time threshold for cold memory regions identification in microseconds.
95
96 If a memory region is not accessed for this or longer time, DAMON_LRU_SORT
97 identifies the region as cold, and mark it as unaccessed on the LRU list, so
98 that it could be reclaimed first under memory pressure. 120 seconds by
99 default.
100
101 quota_ms
102 --------
103
104 Limit of time for trying the LRU lists sorting in milliseconds.
105
106 DAMON_LRU_SORT tries to use only up to this time within a time window
107 (quota_reset_interval_ms) for trying LRU lists sorting. This can be used
108 for limiting CPU consumption of DAMON_LRU_SORT. If the value is zero, the
109 limit is disabled.
110
111 10 ms by default.
112
113 quota_reset_interval_ms
114 -----------------------
115
116 The time quota charge reset interval in milliseconds.
117
118 The charge reset interval for the quota of time (quota_ms). That is,
119 DAMON_LRU_SORT does not try LRU-lists sorting for more than quota_ms
120 milliseconds or quota_sz bytes within quota_reset_interval_ms milliseconds.
121
122 1 second by default.
123
124 wmarks_interval
125 ---------------
126
127 The watermarks check time interval in microseconds.
128
129 Minimal time to wait before checking the watermarks, when DAMON_LRU_SORT is
130 enabled but inactive due to its watermarks rule. 5 seconds by default.
131
132 wmarks_high
133 -----------
134
135 Free memory rate (per thousand) for the high watermark.
136
137 If free memory of the system in bytes per thousand bytes is higher than this,
138 DAMON_LRU_SORT becomes inactive, so it does nothing but periodically checks the
139 watermarks. 200 (20%) by default.
140
141 wmarks_mid
142 ----------
143
144 Free memory rate (per thousand) for the middle watermark.
145
146 If free memory of the system in bytes per thousand bytes is between this and
147 the low watermark, DAMON_LRU_SORT becomes active, so starts the monitoring and
148 the LRU-lists sorting. 150 (15%) by default.
149
150 wmarks_low
151 ----------
152
153 Free memory rate (per thousand) for the low watermark.
154
155 If free memory of the system in bytes per thousand bytes is lower than this,
156 DAMON_LRU_SORT becomes inactive, so it does nothing but periodically checks the
157 watermarks. 50 (5%) by default.
158
159 sample_interval
160 ---------------
161
162 Sampling interval for the monitoring in microseconds.
163
164 The sampling interval of DAMON for the cold memory monitoring. Please refer to
165 the DAMON documentation (:doc:`usage`) for more detail. 5ms by default.
166
167 aggr_interval
168 -------------
169
170 Aggregation interval for the monitoring in microseconds.
171
172 The aggregation interval of DAMON for the cold memory monitoring. Please
173 refer to the DAMON documentation (:doc:`usage`) for more detail. 100ms by
174 default.
175
176 min_nr_regions
177 --------------
178
179 Minimum number of monitoring regions.
180
181 The minimal number of monitoring regions of DAMON for the cold memory
182 monitoring. This can be used to set lower-bound of the monitoring quality.
183 But, setting this too high could result in increased monitoring overhead.
184 Please refer to the DAMON documentation (:doc:`usage`) for more detail. 10 by
185 default.
186
187 max_nr_regions
188 --------------
189
190 Maximum number of monitoring regions.
191
192 The maximum number of monitoring regions of DAMON for the cold memory
193 monitoring. This can be used to set upper-bound of the monitoring overhead.
194 However, setting this too low could result in bad monitoring quality. Please
195 refer to the DAMON documentation (:doc:`usage`) for more detail. 1000 by
196 defaults.
197
198 monitor_region_start
199 --------------------
200
201 Start of target memory region in physical address.
202
203 The start physical address of memory region that DAMON_LRU_SORT will do work
204 against. By default, biggest System RAM is used as the region.
205
206 monitor_region_end
207 ------------------
208
209 End of target memory region in physical address.
210
211 The end physical address of memory region that DAMON_LRU_SORT will do work
212 against. By default, biggest System RAM is used as the region.
213
214 kdamond_pid
215 -----------
216
217 PID of the DAMON thread.
218
219 If DAMON_LRU_SORT is enabled, this becomes the PID of the worker thread. Else,
220 -1.
221
222 nr_lru_sort_tried_hot_regions
223 -----------------------------
224
225 Number of hot memory regions that tried to be LRU-sorted.
226
227 bytes_lru_sort_tried_hot_regions
228 --------------------------------
229
230 Total bytes of hot memory regions that tried to be LRU-sorted.
231
232 nr_lru_sorted_hot_regions
233 -------------------------
234
235 Number of hot memory regions that successfully be LRU-sorted.
236
237 bytes_lru_sorted_hot_regions
238 ----------------------------
239
240 Total bytes of hot memory regions that successfully be LRU-sorted.
241
242 nr_hot_quota_exceeds
243 --------------------
244
245 Number of times that the time quota limit for hot regions have exceeded.
246
247 nr_lru_sort_tried_cold_regions
248 ------------------------------
249
250 Number of cold memory regions that tried to be LRU-sorted.
251
252 bytes_lru_sort_tried_cold_regions
253 ---------------------------------
254
255 Total bytes of cold memory regions that tried to be LRU-sorted.
256
257 nr_lru_sorted_cold_regions
258 --------------------------
259
260 Number of cold memory regions that successfully be LRU-sorted.
261
262 bytes_lru_sorted_cold_regions
263 -----------------------------
264
265 Total bytes of cold memory regions that successfully be LRU-sorted.
266
267 nr_cold_quota_exceeds
268 ---------------------
269
270 Number of times that the time quota limit for cold regions have exceeded.
271
272 Example
273 =======
274
275 Below runtime example commands make DAMON_LRU_SORT to find memory regions
276 having >=50% access frequency and LRU-prioritize while LRU-deprioritizing
277 memory regions that not accessed for 120 seconds. The prioritization and
278 deprioritization is limited to be done using only up to 1% CPU time to avoid
279 DAMON_LRU_SORT consuming too much CPU time for the (de)prioritization. It also
280 asks DAMON_LRU_SORT to do nothing if the system's free memory rate is more than
281 50%, but start the real works if it becomes lower than 40%. If DAMON_RECLAIM
282 doesn't make progress and therefore the free memory rate becomes lower than
283 20%, it asks DAMON_LRU_SORT to do nothing again, so that we can fall back to
284 the LRU-list based page granularity reclamation. ::
285
286 # cd /sys/module/damon_lru_sort/parameters
287 # echo 500 > hot_thres_access_freq
288 # echo 120000000 > cold_min_age
289 # echo 10 > quota_ms
290 # echo 1000 > quota_reset_interval_ms
291 # echo 500 > wmarks_high
292 # echo 400 > wmarks_mid
293 # echo 200 > wmarks_low
294 # echo Y > enabled
295

3. 한국어 전문 번역

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

DAMON 기반 LRU 목록 정렬

1-11

이 문서는 GPL-2.0 라이선스를 따릅니다. DAMON-based LRU-lists Sorting(`DAMON_LRU_SORT`)은 LRU 목록이 데이터 접근 패턴을 더 신뢰할 수 있게 나타내도록, DAMON이 관측한 접근 패턴에 따라 page의 우선순위를 선제적이고 가볍게 높이거나 낮추는 정적 kernel module입니다.

선제적 LRU 목록 정렬이 필요한 이유

12-27

거대한 시스템에서는 page 단위 접근 검사의 오버헤드가 클 수 있으므로 LRU 목록을 늘 선제적으로 정렬하지 않습니다. 특정 사용자 요청, system call, memory pressure 같은 사건이 생길 때 일부를 반응형으로 정렬합니다. 따라서 갑작스러운 memory pressure에서 reclaim 대상을 고르는 상황처럼, LRU 목록이 접근 패턴의 완벽하게 신뢰할 수 있는 자료로 준비되어 있지 않을 수 있습니다.

DAMON은 사용자가 지정한 오버헤드 범위 안에서 best-effort 정확도로 접근 패턴을 식별할 수 있습니다. 그러므로 `DAMON_LRU_SORT`를 선제적으로 실행하면 낮고 통제된 오버헤드로 LRU 목록의 신뢰도를 높일 수 있습니다.

작동 방식

28-47

DAMON_LRU_SORT는 사용자가 지정한 기준보다 접근 빈도가 높은 memory region의 page를 hot page로, 지정한 시간보다 오래 접근되지 않은 region의 page를 cold page로 찾습니다. hot page는 LRU에서 우선순위를 높이고 cold page는 낮춥니다.

우선순위 조정에 CPU를 지나치게 쓰지 않도록 CPU 시간 한도를 설정할 수 있습니다. 이 한도 안에서 더 hot한 page와 더 cold한 page부터 각각 우선 처리합니다. 관리자는 세 개의 memory pressure watermark를 이용해 이 scheme이 자동으로 활성화·비활성화될 조건도 정할 수 있습니다.

hot/cold 기준과 CPU quota의 기본값은 보수적으로 선택되었습니다. 일반적인 환경에서 해를 끼치지 않으면서, memory pressure 아래에 뚜렷한 hot/cold 패턴이 있는 시스템에는 제한된 작은 CPU 시간만 써서 일정한 이점을 주도록 한 값입니다.

Module parameter interface

48-60

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

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

활성화와 입력값 반영

61-81
Parameter동작기본값
enabledY / NDAMON_LRU_SORT를 활성화하거나 비활성화합니다. 활성화되어도 watermark 조건 때문에 실제 모니터링과 정렬이 멈춰 있을 수 있습니다.-
commit_inputsY -> N실행 중 바뀐 입력값을 `enabled`를 제외하고 다시 읽습니다. 잘못된 값이 있으면 DAMON_LRU_SORT가 비활성화됩니다.-

`enabled=Y`는 기능을 켜고 `enabled=N`은 끕니다. 다만 watermark 활성화 조건을 만족하지 않으면 켜진 상태에서도 실제 모니터링과 LRU 정렬은 일어나지 않을 수 있습니다.

실행 중 수정한 입력 parameter는 기본적으로 즉시 적용되지 않습니다. `commit_inputs=Y`를 쓰면 `enabled`를 제외한 값을 다시 읽고, 완료되면 `commit_inputs`가 N으로 돌아갑니다. 다시 읽는 동안 잘못된 parameter가 발견되면 DAMON_LRU_SORT가 비활성화됩니다.

Hot·cold 기준과 시간 quota

82-123
Parameter단위의미기본값
hot_thres_access_freqpermil이 값 이상의 빈도로 접근된 영역을 hot으로 판단해 LRU에서 accessed로 표시합니다.500 (50%)
cold_min_agemicroseconds이 시간 이상 접근되지 않은 영역을 cold로 판단해 LRU에서 unaccessed로 표시합니다.120 seconds
quota_msmilliseconds`quota_reset_interval_ms` 창마다 LRU 정렬에 쓸 수 있는 CPU 시간을 제한합니다. 0이면 제한하지 않습니다.10 ms
quota_reset_interval_msmilliseconds시간 quota의 charge를 초기화하는 간격입니다.1 second

hot region은 LRU에서 accessed로 표시되어 memory pressure 아래에서 reclaim되기 어렵고, cold region은 unaccessed로 표시되어 먼저 reclaim될 수 있습니다. `quota_ms=0`이면 CPU 시간 제한을 사용하지 않습니다.

원문 120행은 시간 quota 설명에서 `quota_sz`도 함께 적습니다. 이 DAMON_LRU_SORT 문서에는 별도의 `quota_sz` parameter가 정의되어 있지 않으며, 여기서는 원문 표기를 그대로 기록합니다.

Memory pressure watermark

124-158
Parameter단위동작기본값
wmarks_intervalmicrosecondswatermark 규칙으로 비활성 상태일 때 다음 watermark 확인까지 기다릴 최소 시간입니다.5 seconds
wmarks_highpermilfree memory 비율이 이 값보다 높으면 비활성화하고 watermark만 주기적으로 확인합니다.200 (20%)
wmarks_midpermilfree memory 비율이 이 값과 low watermark 사이이면 모니터링과 LRU 정렬을 활성화합니다.150 (15%)
wmarks_lowpermilfree memory 비율이 이 값보다 낮으면 비활성화하고 page-granularity reclaim으로 되돌아갈 여지를 줍니다.50 (5%)

free memory 비율이 high watermark보다 높을 때는 정렬할 필요가 적어 비활성화합니다. mid와 low 사이에서는 모니터링과 LRU 정렬을 수행합니다. low보다 낮으면 다시 비활성화해 기존 LRU 기반 page-granularity reclaim이 처리할 수 있게 합니다.

모니터링 간격·영역 수·대상 주소

159-213
Parameter단위의미기본값
sample_intervalmicrosecondscold memory 모니터링을 위한 DAMON sampling 간격입니다.5 ms
aggr_intervalmicrosecondscold memory 모니터링을 위한 DAMON aggregation 간격입니다.100 ms
min_nr_regionsregions모니터링 품질의 하한을 정하는 최소 영역 수입니다. 지나치게 높으면 오버헤드가 늘 수 있습니다.10
max_nr_regionsregions모니터링 오버헤드의 상한을 정하는 최대 영역 수입니다. 지나치게 낮으면 품질이 나빠질 수 있습니다.1000
monitor_region_startphysical address작업 대상 physical memory 영역의 시작 주소입니다.biggest System RAM
monitor_region_endphysical address작업 대상 physical memory 영역의 끝 주소입니다.biggest System RAM

`sample_interval`과 `aggr_interval`, monitoring region 수는 DAMON의 cold memory 관측 비용과 품질을 조절합니다. 자세한 의미는 DAMON `usage` 문서를 참조합니다. 대상 physical address 범위를 따로 지정하지 않으면 가장 큰 System RAM 영역을 사용합니다.

Worker 상태와 정렬 통계

214-271
항목의미
kdamond_pidDAMON_LRU_SORT가 활성화되면 worker thread의 PID이며, 아니면 -1입니다.
nr_lru_sort_tried_hot_regionsLRU 정렬을 시도한 hot memory region 수입니다.
bytes_lru_sort_tried_hot_regionsLRU 정렬을 시도한 hot memory region의 총 byte 수입니다.
nr_lru_sorted_hot_regionsLRU 정렬에 성공한 hot memory region 수입니다.
bytes_lru_sorted_hot_regionsLRU 정렬에 성공한 hot memory region의 총 byte 수입니다.
nr_hot_quota_exceedshot region 작업에서 시간 quota를 초과한 횟수입니다.
nr_lru_sort_tried_cold_regionsLRU 정렬을 시도한 cold memory region 수입니다.
bytes_lru_sort_tried_cold_regionsLRU 정렬을 시도한 cold memory region의 총 byte 수입니다.
nr_lru_sorted_cold_regionsLRU 정렬에 성공한 cold memory region 수입니다.
bytes_lru_sorted_cold_regionsLRU 정렬에 성공한 cold memory region의 총 byte 수입니다.
nr_cold_quota_exceedscold region 작업에서 시간 quota를 초과한 횟수입니다.

hot과 cold 각각에 대해 정렬 시도 region 수·byte, 성공 region 수·byte, quota 초과 횟수를 제공합니다. 이 값으로 제한된 quota 안에서 실제 정렬이 얼마나 진행됐는지 확인할 수 있습니다.

Runtime 설정 예

272-294

다음 명령은 접근 빈도가 50% 이상인 region의 LRU 우선순위를 높이고, 120초 동안 접근되지 않은 region의 우선순위를 낮춥니다. 우선순위 조정에는 CPU 시간의 최대 1%만 사용합니다.

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

원문 281-282행은 이 LRU_SORT 예에서 진행하지 못하는 주체를 `DAMON_RECLAIM`이라고 씁니다. 의미상 DAMON_LRU_SORT를 가리키는 것으로 보이지만 원문 표기를 보존합니다.

# cd /sys/module/damon_lru_sort/parameters
# echo 500 > hot_thres_access_freq
# echo 120000000 > cold_min_age
# echo 10 > quota_ms
# echo 1000 > quota_reset_interval_ms
# echo 500 > wmarks_high
# echo 400 > wmarks_mid
# echo 200 > wmarks_low
# echo Y > enabled