요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
.. SPDX-License-Identifier: GPL-2.0
=============================
DAMON-based LRU-lists Sorting
=============================
DAMON-based LRU-lists Sorting (DAMON_LRU_SORT) is a static kernel module that
aimed to be used for proactive and lightweight data access pattern based
(de)prioritization of pages on their LRU-lists for making LRU-lists a more
trusworthy data access pattern source.
Where Proactive LRU-lists Sorting is Required?
==============================================
As page-granularity access checking overhead could be significant on huge
systems, LRU lists are normally not proactively sorted but partially and
reactively sorted for special events including specific user requests, system
calls and memory pressure. As a result, LRU lists are sometimes not so
perfectly prepared to be used as a trustworthy access pattern source for some
situations including reclamation target pages selection under sudden memory
pressure.
Because DAMON can identify access patterns of best-effort accuracy while
inducing only user-specified range of overhead, proactively running
DAMON_LRU_SORT could be helpful for making LRU lists more trustworthy access
pattern source with low and controlled overhead.
How It Works?
=============
DAMON_LRU_SORT finds hot pages (pages of memory regions that showing access
rates that higher than a user-specified threshold) and cold pages (pages of
memory regions that showing no access for a time that longer than a
user-specified threshold) using DAMON, and prioritizes hot pages while
deprioritizing cold pages on their LRU-lists. To avoid it consuming too much
CPU for the prioritizations, a CPU time usage limit can be configured. Under
the limit, it prioritizes and deprioritizes more hot and cold pages first,
respectively. System administrators can also configure under what situation
this scheme should automatically activated and deactivated with three memory
pressure watermarks.
Its default parameters for hotness/coldness thresholds and CPU quota limit are
conservatively chosen. That is, the module under its default parameters could
be widely used without harm for common situations while providing a level of
benefits for systems having clear hot/cold access patterns under memory
pressure while consuming only a limited small portion of CPU time.
Interface: Module Parameters
============================
To use this feature, you should first ensure your system is running on a kernel
that is built with ``CONFIG_DAMON_LRU_SORT=y``.
To let sysadmins enable or disable it and tune for the given system,
DAMON_LRU_SORT utilizes module parameters. That is, you can put
``damon_lru_sort.<parameter>=<value>`` on the kernel boot command line or write
proper values to ``/sys/module/damon_lru_sort/parameters/<parameter>`` files.
Below are the description of each parameter.
enabled
-------
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.
commit_inputs
-------------
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 parametrs 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.
hot_thres_access_freq
---------------------
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.
cold_min_age
------------
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.
quota_ms
--------
Limit of time for trying the LRU lists sorting in milliseconds.
DAMON_LRU_SORT tries to use only up to this time within a time window
(quota_reset_interval_ms) for trying LRU lists sorting. This can be used
for limiting CPU consumption of DAMON_LRU_SORT. If the value is zero, the
limit is disabled.
10 ms by default.
quota_reset_interval_ms
-----------------------
The time quota charge reset interval in milliseconds.
The charge reset interval for the quota of time (quota_ms). That is,
DAMON_LRU_SORT does not try LRU-lists sorting for more than quota_ms
milliseconds or quota_sz bytes within quota_reset_interval_ms milliseconds.
1 second by default.
wmarks_interval
---------------
The watermarks check time interval in microseconds.
Minimal time to wait before checking the watermarks, when DAMON_LRU_SORT is
enabled but inactive due to its watermarks rule. 5 seconds by default.
wmarks_high
-----------
Free memory rate (per thousand) for the high watermark.
If free memory of the system in bytes per thousand bytes is higher than this,
DAMON_LRU_SORT becomes inactive, so it does nothing but periodically checks the
watermarks. 200 (20%) by default.
wmarks_mid
----------
Free memory rate (per thousand) for the middle watermark.
If free memory of the system in bytes per thousand bytes is between this and
the low watermark, DAMON_LRU_SORT becomes active, so starts the monitoring and
the LRU-lists sorting. 150 (15%) by default.
wmarks_low
----------
Free memory rate (per thousand) for the low watermark.
If free memory of the system in bytes per thousand bytes is lower than this,
DAMON_LRU_SORT becomes inactive, so it does nothing but periodically checks the
watermarks. 50 (5%) by default.
sample_interval
---------------
Sampling interval for the monitoring in microseconds.
The sampling interval of DAMON for the cold memory monitoring. Please refer to
the DAMON documentation (:doc:`usage`) for more detail. 5ms by default.
aggr_interval
-------------
Aggregation interval for the monitoring in microseconds.
The aggregation interval of DAMON for the cold memory monitoring. Please
refer to the DAMON documentation (:doc:`usage`) for more detail. 100ms by
default.
min_nr_regions
--------------
Minimum number of monitoring regions.
The minimal number of monitoring regions of DAMON for the cold memory
monitoring. This can be used to set lower-bound of the monitoring quality.
But, setting this too high could result in increased monitoring overhead.
Please refer to the DAMON documentation (:doc:`usage`) for more detail. 10 by
default.
max_nr_regions
--------------
Maximum number of monitoring regions.
The maximum number of monitoring regions of DAMON for the cold memory
monitoring. This can be used to set upper-bound of the monitoring overhead.
However, setting this too low could result in bad monitoring quality. Please
refer to the DAMON documentation (:doc:`usage`) for more detail. 1000 by
defaults.
monitor_region_start
--------------------
Start of target memory region in physical address.
The start physical address of memory region that DAMON_LRU_SORT will do work
against. By default, biggest System RAM is used as the region.
monitor_region_end
------------------
End of target memory region in physical address.
The end physical address of memory region that DAMON_LRU_SORT will do work
against. By default, biggest System RAM is used as the region.
kdamond_pid
-----------
PID of the DAMON thread.
If DAMON_LRU_SORT is enabled, this becomes the PID of the worker thread. Else,
-1.
nr_lru_sort_tried_hot_regions
-----------------------------
Number of hot memory regions that tried to be LRU-sorted.
bytes_lru_sort_tried_hot_regions
--------------------------------
Total bytes of hot memory regions that tried to be LRU-sorted.
nr_lru_sorted_hot_regions
-------------------------
Number of hot memory regions that successfully be LRU-sorted.
bytes_lru_sorted_hot_regions
----------------------------
Total bytes of hot memory regions that successfully be LRU-sorted.
nr_hot_quota_exceeds
--------------------
Number of times that the time quota limit for hot regions have exceeded.
nr_lru_sort_tried_cold_regions
------------------------------
Number of cold memory regions that tried to be LRU-sorted.
bytes_lru_sort_tried_cold_regions
---------------------------------
Total bytes of cold memory regions that tried to be LRU-sorted.
nr_lru_sorted_cold_regions
--------------------------
Number of cold memory regions that successfully be LRU-sorted.
bytes_lru_sorted_cold_regions
-----------------------------
Total bytes of cold memory regions that successfully be LRU-sorted.
nr_cold_quota_exceeds
---------------------
Number of times that the time quota limit for cold regions have exceeded.
Example
=======
Below runtime example commands make DAMON_LRU_SORT to find memory regions
having >=50% access frequency and LRU-prioritize while LRU-deprioritizing
memory regions that not accessed for 120 seconds. The prioritization and
deprioritization is limited to be done using only up to 1% CPU time to avoid
DAMON_LRU_SORT consuming too much CPU time for the (de)prioritization. It also
asks DAMON_LRU_SORT to do nothing if the system's free memory rate is more than
50%, but start the real works if it becomes lower than 40%. If DAMON_RECLAIM
doesn't make progress and therefore the free memory rate becomes lower than
20%, it asks DAMON_LRU_SORT to do nothing again, so that we can fall back to
the LRU-list based page granularity reclamation. ::
# 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
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-47DAMON_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 | 값 | 동작 | 기본값 |
|---|---|---|---|
| enabled | Y / N | DAMON_LRU_SORT를 활성화하거나 비활성화합니다. 활성화되어도 watermark 조건 때문에 실제 모니터링과 정렬이 멈춰 있을 수 있습니다. | - |
| commit_inputs | Y -> 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_freq | permil | 이 값 이상의 빈도로 접근된 영역을 hot으로 판단해 LRU에서 accessed로 표시합니다. | 500 (50%) |
| cold_min_age | microseconds | 이 시간 이상 접근되지 않은 영역을 cold로 판단해 LRU에서 unaccessed로 표시합니다. | 120 seconds |
| quota_ms | milliseconds | `quota_reset_interval_ms` 창마다 LRU 정렬에 쓸 수 있는 CPU 시간을 제한합니다. 0이면 제한하지 않습니다. | 10 ms |
| quota_reset_interval_ms | milliseconds | 시간 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_interval | microseconds | watermark 규칙으로 비활성 상태일 때 다음 watermark 확인까지 기다릴 최소 시간입니다. | 5 seconds |
| wmarks_high | permil | free memory 비율이 이 값보다 높으면 비활성화하고 watermark만 주기적으로 확인합니다. | 200 (20%) |
| wmarks_mid | permil | free memory 비율이 이 값과 low watermark 사이이면 모니터링과 LRU 정렬을 활성화합니다. | 150 (15%) |
| wmarks_low | permil | free memory 비율이 이 값보다 낮으면 비활성화하고 page-granularity reclaim으로 되돌아갈 여지를 줍니다. | 50 (5%) |
free memory 비율이 high watermark보다 높을 때는 정렬할 필요가 적어 비활성화합니다. mid와 low 사이에서는 모니터링과 LRU 정렬을 수행합니다. low보다 낮으면 다시 비활성화해 기존 LRU 기반 page-granularity reclaim이 처리할 수 있게 합니다.
모니터링 간격·영역 수·대상 주소
159-213| Parameter | 단위 | 의미 | 기본값 |
|---|---|---|---|
| sample_interval | microseconds | cold memory 모니터링을 위한 DAMON sampling 간격입니다. | 5 ms |
| aggr_interval | microseconds | cold memory 모니터링을 위한 DAMON aggregation 간격입니다. | 100 ms |
| min_nr_regions | regions | 모니터링 품질의 하한을 정하는 최소 영역 수입니다. 지나치게 높으면 오버헤드가 늘 수 있습니다. | 10 |
| max_nr_regions | regions | 모니터링 오버헤드의 상한을 정하는 최대 영역 수입니다. 지나치게 낮으면 품질이 나빠질 수 있습니다. | 1000 |
| monitor_region_start | physical address | 작업 대상 physical memory 영역의 시작 주소입니다. | biggest System RAM |
| monitor_region_end | physical 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_pid | DAMON_LRU_SORT가 활성화되면 worker thread의 PID이며, 아니면 -1입니다. |
| nr_lru_sort_tried_hot_regions | LRU 정렬을 시도한 hot memory region 수입니다. |
| bytes_lru_sort_tried_hot_regions | LRU 정렬을 시도한 hot memory region의 총 byte 수입니다. |
| nr_lru_sorted_hot_regions | LRU 정렬에 성공한 hot memory region 수입니다. |
| bytes_lru_sorted_hot_regions | LRU 정렬에 성공한 hot memory region의 총 byte 수입니다. |
| nr_hot_quota_exceeds | hot region 작업에서 시간 quota를 초과한 횟수입니다. |
| nr_lru_sort_tried_cold_regions | LRU 정렬을 시도한 cold memory region 수입니다. |
| bytes_lru_sort_tried_cold_regions | LRU 정렬을 시도한 cold memory region의 총 byte 수입니다. |
| nr_lru_sorted_cold_regions | LRU 정렬에 성공한 cold memory region 수입니다. |
| bytes_lru_sorted_cold_regions | LRU 정렬에 성공한 cold memory region의 총 byte 수입니다. |
| nr_cold_quota_exceeds | cold 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
DAMON_LRU_SORT 운용 지도
lru_sort.rst:1-294DAMON_LRU_SORT는 page 단위 접근 검사의 큰 비용 없이 LRU 목록을 접근 패턴에 더 가깝게 정돈합니다. threshold, CPU quota, 세 watermark, monitoring 범위를 함께 설정하고 hot/cold 통계로 효과를 확인합니다.