Back to home page

OSCL-LXR

 
 

    


0001 .. SPDX-License-Identifier: GPL-2.0
0002 
0003 =============================
0004 DAMON-based LRU-lists Sorting
0005 =============================
0006 
0007 DAMON-based LRU-lists Sorting (DAMON_LRU_SORT) is a static kernel module that
0008 aimed to be used for proactive and lightweight data access pattern based
0009 (de)prioritization of pages on their LRU-lists for making LRU-lists a more
0010 trusworthy data access pattern source.
0011 
0012 Where Proactive LRU-lists Sorting is Required?
0013 ==============================================
0014 
0015 As page-granularity access checking overhead could be significant on huge
0016 systems, LRU lists are normally not proactively sorted but partially and
0017 reactively sorted for special events including specific user requests, system
0018 calls and memory pressure.  As a result, LRU lists are sometimes not so
0019 perfectly prepared to be used as a trustworthy access pattern source for some
0020 situations including reclamation target pages selection under sudden memory
0021 pressure.
0022 
0023 Because DAMON can identify access patterns of best-effort accuracy while
0024 inducing only user-specified range of overhead, proactively running
0025 DAMON_LRU_SORT could be helpful for making LRU lists more trustworthy access
0026 pattern source with low and controlled overhead.
0027 
0028 How It Works?
0029 =============
0030 
0031 DAMON_LRU_SORT finds hot pages (pages of memory regions that showing access
0032 rates that higher than a user-specified threshold) and cold pages (pages of
0033 memory regions that showing no access for a time that longer than a
0034 user-specified threshold) using DAMON, and prioritizes hot pages while
0035 deprioritizing cold pages on their LRU-lists.  To avoid it consuming too much
0036 CPU for the prioritizations, a CPU time usage limit can be configured.  Under
0037 the limit, it prioritizes and deprioritizes more hot and cold pages first,
0038 respectively.  System administrators can also configure under what situation
0039 this scheme should automatically activated and deactivated with three memory
0040 pressure watermarks.
0041 
0042 Its default parameters for hotness/coldness thresholds and CPU quota limit are
0043 conservatively chosen.  That is, the module under its default parameters could
0044 be widely used without harm for common situations while providing a level of
0045 benefits for systems having clear hot/cold access patterns under memory
0046 pressure while consuming only a limited small portion of CPU time.
0047 
0048 Interface: Module Parameters
0049 ============================
0050 
0051 To use this feature, you should first ensure your system is running on a kernel
0052 that is built with ``CONFIG_DAMON_LRU_SORT=y``.
0053 
0054 To let sysadmins enable or disable it and tune for the given system,
0055 DAMON_LRU_SORT utilizes module parameters.  That is, you can put
0056 ``damon_lru_sort.<parameter>=<value>`` on the kernel boot command line or write
0057 proper values to ``/sys/modules/damon_lru_sort/parameters/<parameter>`` files.
0058 
0059 Below are the description of each parameter.
0060 
0061 enabled
0062 -------
0063 
0064 Enable or disable DAMON_LRU_SORT.
0065 
0066 You can enable DAMON_LRU_SORT by setting the value of this parameter as ``Y``.
0067 Setting it as ``N`` disables DAMON_LRU_SORT.  Note that DAMON_LRU_SORT could do
0068 no real monitoring and LRU-lists sorting due to the watermarks-based activation
0069 condition.  Refer to below descriptions for the watermarks parameter for this.
0070 
0071 commit_inputs
0072 -------------
0073 
0074 Make DAMON_LRU_SORT reads the input parameters again, except ``enabled``.
0075 
0076 Input parameters that updated while DAMON_LRU_SORT is running are not applied
0077 by default.  Once this parameter is set as ``Y``, DAMON_LRU_SORT reads values
0078 of parametrs except ``enabled`` again.  Once the re-reading is done, this
0079 parameter is set as ``N``.  If invalid parameters are found while the
0080 re-reading, DAMON_LRU_SORT will be disabled.
0081 
0082 hot_thres_access_freq
0083 ---------------------
0084 
0085 Access frequency threshold for hot memory regions identification in permil.
0086 
0087 If a memory region is accessed in frequency of this or higher, DAMON_LRU_SORT
0088 identifies the region as hot, and mark it as accessed on the LRU list, so that
0089 it could not be reclaimed under memory pressure.  50% by default.
0090 
0091 cold_min_age
0092 ------------
0093 
0094 Time threshold for cold memory regions identification in microseconds.
0095 
0096 If a memory region is not accessed for this or longer time, DAMON_LRU_SORT
0097 identifies the region as cold, and mark it as unaccessed on the LRU list, so
0098 that it could be reclaimed first under memory pressure.  120 seconds by
0099 default.
0100 
0101 quota_ms
0102 --------
0103 
0104 Limit of time for trying the LRU lists sorting in milliseconds.
0105 
0106 DAMON_LRU_SORT tries to use only up to this time within a time window
0107 (quota_reset_interval_ms) for trying LRU lists sorting.  This can be used
0108 for limiting CPU consumption of DAMON_LRU_SORT.  If the value is zero, the
0109 limit is disabled.
0110 
0111 10 ms by default.
0112 
0113 quota_reset_interval_ms
0114 -----------------------
0115 
0116 The time quota charge reset interval in milliseconds.
0117 
0118 The charge reset interval for the quota of time (quota_ms).  That is,
0119 DAMON_LRU_SORT does not try LRU-lists sorting for more than quota_ms
0120 milliseconds or quota_sz bytes within quota_reset_interval_ms milliseconds.
0121 
0122 1 second by default.
0123 
0124 wmarks_interval
0125 ---------------
0126 
0127 The watermarks check time interval in microseconds.
0128 
0129 Minimal time to wait before checking the watermarks, when DAMON_LRU_SORT is
0130 enabled but inactive due to its watermarks rule.  5 seconds by default.
0131 
0132 wmarks_high
0133 -----------
0134 
0135 Free memory rate (per thousand) for the high watermark.
0136 
0137 If free memory of the system in bytes per thousand bytes is higher than this,
0138 DAMON_LRU_SORT becomes inactive, so it does nothing but periodically checks the
0139 watermarks.  200 (20%) by default.
0140 
0141 wmarks_mid
0142 ----------
0143 
0144 Free memory rate (per thousand) for the middle watermark.
0145 
0146 If free memory of the system in bytes per thousand bytes is between this and
0147 the low watermark, DAMON_LRU_SORT becomes active, so starts the monitoring and
0148 the LRU-lists sorting.  150 (15%) by default.
0149 
0150 wmarks_low
0151 ----------
0152 
0153 Free memory rate (per thousand) for the low watermark.
0154 
0155 If free memory of the system in bytes per thousand bytes is lower than this,
0156 DAMON_LRU_SORT becomes inactive, so it does nothing but periodically checks the
0157 watermarks.  50 (5%) by default.
0158 
0159 sample_interval
0160 ---------------
0161 
0162 Sampling interval for the monitoring in microseconds.
0163 
0164 The sampling interval of DAMON for the cold memory monitoring.  Please refer to
0165 the DAMON documentation (:doc:`usage`) for more detail.  5ms by default.
0166 
0167 aggr_interval
0168 -------------
0169 
0170 Aggregation interval for the monitoring in microseconds.
0171 
0172 The aggregation interval of DAMON for the cold memory monitoring.  Please
0173 refer to the DAMON documentation (:doc:`usage`) for more detail.  100ms by
0174 default.
0175 
0176 min_nr_regions
0177 --------------
0178 
0179 Minimum number of monitoring regions.
0180 
0181 The minimal number of monitoring regions of DAMON for the cold memory
0182 monitoring.  This can be used to set lower-bound of the monitoring quality.
0183 But, setting this too high could result in increased monitoring overhead.
0184 Please refer to the DAMON documentation (:doc:`usage`) for more detail.  10 by
0185 default.
0186 
0187 max_nr_regions
0188 --------------
0189 
0190 Maximum number of monitoring regions.
0191 
0192 The maximum number of monitoring regions of DAMON for the cold memory
0193 monitoring.  This can be used to set upper-bound of the monitoring overhead.
0194 However, setting this too low could result in bad monitoring quality.  Please
0195 refer to the DAMON documentation (:doc:`usage`) for more detail.  1000 by
0196 defaults.
0197 
0198 monitor_region_start
0199 --------------------
0200 
0201 Start of target memory region in physical address.
0202 
0203 The start physical address of memory region that DAMON_LRU_SORT will do work
0204 against.  By default, biggest System RAM is used as the region.
0205 
0206 monitor_region_end
0207 ------------------
0208 
0209 End of target memory region in physical address.
0210 
0211 The end physical address of memory region that DAMON_LRU_SORT will do work
0212 against.  By default, biggest System RAM is used as the region.
0213 
0214 kdamond_pid
0215 -----------
0216 
0217 PID of the DAMON thread.
0218 
0219 If DAMON_LRU_SORT is enabled, this becomes the PID of the worker thread.  Else,
0220 -1.
0221 
0222 nr_lru_sort_tried_hot_regions
0223 -----------------------------
0224 
0225 Number of hot memory regions that tried to be LRU-sorted.
0226 
0227 bytes_lru_sort_tried_hot_regions
0228 --------------------------------
0229 
0230 Total bytes of hot memory regions that tried to be LRU-sorted.
0231 
0232 nr_lru_sorted_hot_regions
0233 -------------------------
0234 
0235 Number of hot memory regions that successfully be LRU-sorted.
0236 
0237 bytes_lru_sorted_hot_regions
0238 ----------------------------
0239 
0240 Total bytes of hot memory regions that successfully be LRU-sorted.
0241 
0242 nr_hot_quota_exceeds
0243 --------------------
0244 
0245 Number of times that the time quota limit for hot regions have exceeded.
0246 
0247 nr_lru_sort_tried_cold_regions
0248 ------------------------------
0249 
0250 Number of cold memory regions that tried to be LRU-sorted.
0251 
0252 bytes_lru_sort_tried_cold_regions
0253 ---------------------------------
0254 
0255 Total bytes of cold memory regions that tried to be LRU-sorted.
0256 
0257 nr_lru_sorted_cold_regions
0258 --------------------------
0259 
0260 Number of cold memory regions that successfully be LRU-sorted.
0261 
0262 bytes_lru_sorted_cold_regions
0263 -----------------------------
0264 
0265 Total bytes of cold memory regions that successfully be LRU-sorted.
0266 
0267 nr_cold_quota_exceeds
0268 ---------------------
0269 
0270 Number of times that the time quota limit for cold regions have exceeded.
0271 
0272 Example
0273 =======
0274 
0275 Below runtime example commands make DAMON_LRU_SORT to find memory regions
0276 having >=50% access frequency and LRU-prioritize while LRU-deprioritizing
0277 memory regions that not accessed for 120 seconds.  The prioritization and
0278 deprioritization is limited to be done using only up to 1% CPU time to avoid
0279 DAMON_LRU_SORT consuming too much CPU time for the (de)prioritization.  It also
0280 asks DAMON_LRU_SORT to do nothing if the system's free memory rate is more than
0281 50%, but start the real works if it becomes lower than 40%.  If DAMON_RECLAIM
0282 doesn't make progress and therefore the free memory rate becomes lower than
0283 20%, it asks DAMON_LRU_SORT to do nothing again, so that we can fall back to
0284 the LRU-list based page granularity reclamation. ::
0285 
0286     # cd /sys/modules/damon_lru_sort/parameters
0287     # echo 500 > hot_thres_access_freq
0288     # echo 120000000 > cold_min_age
0289     # echo 10 > quota_ms
0290     # echo 1000 > quota_reset_interval_ms
0291     # echo 500 > wmarks_high
0292     # echo 400 > wmarks_mid
0293     # echo 200 > wmarks_low
0294     # echo Y > enabled