요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
.. SPDX-License-Identifier: GPL-2.0
=======================
DAMON-based Reclamation
=======================
DAMON-based Reclamation (DAMON_RECLAIM) is a static kernel module that aimed to
be used for proactive and lightweight reclamation under light memory pressure.
It doesn't aim to replace the LRU-list based page_granularity reclamation, but
to be selectively used for different level of memory pressure and requirements.
Where Proactive Reclamation is Required?
========================================
On general memory over-committed systems, proactively reclaiming cold pages
helps saving memory and reducing latency spikes that incurred by the direct
reclaim of the process or CPU consumption of kswapd, while incurring only
minimal performance degradation [1]_ [2]_ .
Free Pages Reporting [3]_ based memory over-commit virtualization systems are
good example of the cases. In such systems, the guest VMs reports their free
memory to host, and the host reallocates the reported memory to other guests.
As a result, the memory of the systems are fully utilized. However, the
guests could be not so memory-frugal, mainly because some kernel subsystems and
user-space applications are designed to use as much memory as available. Then,
guests could report only small amount of memory as free to host, results in
memory utilization drop of the systems. Running the proactive reclamation in
guests could mitigate this problem.
How It Works?
=============
DAMON_RECLAIM finds memory regions that didn't accessed for specific time
duration and page out. To avoid it consuming too much CPU for the paging out
operation, a speed limit can be configured. Under the speed limit, it pages
out memory regions that didn't accessed longer time first. System
administrators can also configure under what situation this scheme should
automatically activated and deactivated with three memory pressure watermarks.
Interface: Module Parameters
============================
To use this feature, you should first ensure your system is running on a kernel
that is built with ``CONFIG_DAMON_RECLAIM=y``.
To let sysadmins enable or disable it and tune for the given system,
DAMON_RECLAIM utilizes module parameters. That is, you can put
``damon_reclaim.<parameter>=<value>`` on the kernel boot command line or write
proper values to ``/sys/module/damon_reclaim/parameters/<parameter>`` files.
Below are the description of each parameter.
enabled
-------
Enable or disable DAMON_RECLAIM.
You can enable DAMON_RCLAIM by setting the value of this parameter as ``Y``.
Setting it as ``N`` disables DAMON_RECLAIM. Note that DAMON_RECLAIM could do
no real monitoring and reclamation due to the watermarks-based activation
condition. Refer to below descriptions for the watermarks parameter for this.
commit_inputs
-------------
Make DAMON_RECLAIM reads the input parameters again, except ``enabled``.
Input parameters that updated while DAMON_RECLAIM is running are not applied
by default. Once this parameter is set as ``Y``, DAMON_RECLAIM 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_RECLAIM will be disabled.
Once ``Y`` is written to this parameter, the user must not write to any
parameters until reading ``commit_inputs`` again returns ``N``. If users
violate this rule, the kernel may exhibit undefined behavior.
min_age
-------
Time threshold for cold memory regions identification in microseconds.
If a memory region is not accessed for this or longer time, DAMON_RECLAIM
identifies the region as cold, and reclaims it.
120 seconds by default.
quota_ms
--------
Limit of time for the reclamation in milliseconds.
DAMON_RECLAIM tries to use only up to this time within a time window
(quota_reset_interval_ms) for trying reclamation of cold pages. This can be
used for limiting CPU consumption of DAMON_RECLAIM. If the value is zero, the
limit is disabled.
10 ms by default.
quota_sz
--------
Limit of size of memory for the reclamation in bytes.
DAMON_RECLAIM charges amount of memory which it tried to reclaim within a time
window (quota_reset_interval_ms) and makes no more than this limit is tried.
This can be used for limiting consumption of CPU and IO. If this value is
zero, the limit is disabled.
128 MiB by default.
quota_reset_interval_ms
-----------------------
The time/size quota charge reset interval in milliseconds.
The charget reset interval for the quota of time (quota_ms) and size
(quota_sz). That is, DAMON_RECLAIM does not try reclamation for more than
quota_ms milliseconds or quota_sz bytes within quota_reset_interval_ms
milliseconds.
1 second by default.
quota_mem_pressure_us
---------------------
Desired level of memory pressure-stall time in microseconds.
While keeping the caps that set by other quotas, DAMON_RECLAIM automatically
increases and decreases the effective level of the quota aiming this level of
memory pressure is incurred. System-wide ``some`` memory PSI in microseconds
per quota reset interval (``quota_reset_interval_ms``) is collected and
compared to this value to see if the aim is satisfied. Value zero means
disabling this auto-tuning feature.
Disabled by default.
quota_autotune_feedback
-----------------------
User-specifiable feedback for auto-tuning of the effective quota.
While keeping the caps that set by other quotas, DAMON_RECLAIM automatically
increases and decreases the effective level of the quota aiming receiving this
feedback of value ``10,000`` from the user. DAMON_RECLAIM assumes the feedback
value and the quota are positively proportional. Value zero means disabling
this auto-tuning feature.
Disabled by default.
wmarks_interval
---------------
Minimal time to wait before checking the watermarks, when DAMON_RECLAIM is
enabled but inactive due to its watermarks rule.
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_RECLAIM becomes inactive, so it does nothing but only periodically checks
the watermarks.
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_RECLAIM becomes active, so starts the monitoring and
the reclaiming.
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_RECLAIM becomes inactive, so it does nothing but periodically checks the
watermarks. In the case, the system falls back to the LRU-list based page
granularity reclamation logic.
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.
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.
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.
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.
monitor_region_start
--------------------
Start of target memory region in physical address.
The start physical address of memory region that DAMON_RECLAIM will do work
against. That is, DAMON_RECLAIM will find cold memory regions in this region
and reclaims. 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_RECLAIM will do work
against. That is, DAMON_RECLAIM will find cold memory regions in this region
and reclaims. By default, biggest System RAM is used as the region.
skip_anon
---------
Skip anonymous pages reclamation.
If this parameter is set as ``Y``, DAMON_RECLAIM does not reclaim anonymous
pages. By default, ``N``.
kdamond_pid
-----------
PID of the DAMON thread.
If DAMON_RECLAIM is enabled, this becomes the PID of the worker thread. Else,
-1.
nr_reclaim_tried_regions
------------------------
Number of memory regions that tried to be reclaimed by DAMON_RECLAIM.
bytes_reclaim_tried_regions
---------------------------
Total bytes of memory regions that tried to be reclaimed by DAMON_RECLAIM.
nr_reclaimed_regions
--------------------
Number of memory regions that successfully be reclaimed by DAMON_RECLAIM.
bytes_reclaimed_regions
-----------------------
Total bytes of memory regions that successfully be reclaimed by DAMON_RECLAIM.
nr_quota_exceeds
----------------
Number of times that the time/space quota limits have exceeded.
Example
=======
Below runtime example commands make DAMON_RECLAIM to find memory regions that
not accessed for 30 seconds or more and pages out. The reclamation is limited
to be done only up to 1 GiB per second to avoid DAMON_RECLAIM consuming too
much CPU time for the paging out operation. It also asks DAMON_RECLAIM 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_RECLAIM to
do nothing again, so that we can fall back to the LRU-list based page
granularity reclamation. ::
# 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
.. [1] https://research.google/pubs/pub48551/
.. [2] https://lwn.net/Articles/787611/
.. [3] https://www.kernel.org/doc/html/latest/mm/free_page_reporting.html
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-39DAMON_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 | 값 | 동작 | 기본값 |
|---|---|---|---|
| enabled | Y / N | DAMON_RECLAIM을 활성화하거나 비활성화합니다. 활성화되어도 watermark 조건 때문에 실제 작업은 멈춰 있을 수 있습니다. | - |
| commit_inputs | Y -> 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_age | microseconds | 이 시간 이상 접근되지 않은 영역을 cold로 판단해 reclaim합니다. | 120 seconds |
| quota_ms | milliseconds | `quota_reset_interval_ms` 창마다 reclaim에 쓸 수 있는 CPU 시간을 제한합니다. 0이면 제한하지 않습니다. | 10 ms |
| quota_sz | bytes | 한 quota 창에서 reclaim을 시도할 memory 양을 제한해 CPU와 I/O 소비를 제어합니다. 0이면 제한하지 않습니다. | 128 MiB |
| quota_reset_interval_ms | milliseconds | 시간 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_us | microseconds | quota 창마다 system-wide `some` memory PSI가 이 목표에 가깝도록 유효 quota를 자동 조정합니다. 0이면 비활성화합니다. | disabled |
| quota_autotune_feedback | feedback | 사용자 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_interval | microseconds | watermark 규칙으로 비활성 상태일 때 다음 watermark 확인까지 기다릴 최소 시간입니다. | not specified |
| wmarks_high | permil | free memory 비율이 이 값보다 높으면 비활성화하고 watermark만 주기적으로 확인합니다. | not specified |
| wmarks_mid | permil | free memory 비율이 이 값과 low watermark 사이이면 모니터링과 reclaim을 활성화합니다. | not specified |
| wmarks_low | permil | free 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_interval | microseconds | cold memory 모니터링을 위한 DAMON sampling 간격입니다. | not specified |
| aggr_interval | microseconds | cold memory 모니터링을 위한 DAMON aggregation 간격입니다. | not specified |
| min_nr_regions | regions | 모니터링 품질의 하한을 정하는 최소 영역 수입니다. 지나치게 높으면 오버헤드가 늘 수 있습니다. | not specified |
| max_nr_regions | regions | 모니터링 오버헤드의 상한을 정하는 최대 영역 수입니다. 지나치게 낮으면 품질이 나빠질 수 있습니다. | not specified |
| monitor_region_start | physical address | cold region을 찾아 reclaim할 physical memory 영역의 시작 주소입니다. | biggest System RAM |
| monitor_region_end | physical address | cold region을 찾아 reclaim할 physical memory 영역의 끝 주소입니다. | biggest System RAM |
| skip_anon | Y / N | Y이면 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_pid | DAMON_RECLAIM이 활성화되면 worker thread의 PID이며, 아니면 -1입니다. |
| nr_reclaim_tried_regions | DAMON_RECLAIM이 reclaim을 시도한 memory region 수입니다. |
| bytes_reclaim_tried_regions | reclaim을 시도한 memory region의 총 byte 수입니다. |
| nr_reclaimed_regions | DAMON_RECLAIM이 reclaim에 성공한 memory region 수입니다. |
| bytes_reclaimed_regions | reclaim에 성공한 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
DAMON_RECLAIM 운용 지도
reclaim.rst:1-305DAMON_RECLAIM은 cold region을 먼저 찾아 제한된 속도로 reclaim하고, pressure가 너무 낮거나 너무 높을 때는 물러납니다. 시간·크기 quota와 PSI·feedback 자동 조정, 세 watermark를 조합해 기존 LRU reclaim을 보완합니다.