reclaim.rst 10 KB

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