0001 .. SPDX-License-Identifier: GPL-2.0
0002
0003 ===============
0004 Detailed Usages
0005 ===============
0006
0007 DAMON provides below interfaces for different users.
0008
0009 - *DAMON user space tool.*
0010 `This <https://github.com/awslabs/damo>`_ is for privileged people such as
0011 system administrators who want a just-working human-friendly interface.
0012 Using this, users can use the DAMON’s major features in a human-friendly way.
0013 It may not be highly tuned for special cases, though. It supports both
0014 virtual and physical address spaces monitoring. For more detail, please
0015 refer to its `usage document
0016 <https://github.com/awslabs/damo/blob/next/USAGE.md>`_.
0017 - *sysfs interface.*
0018 :ref:`This <sysfs_interface>` is for privileged user space programmers who
0019 want more optimized use of DAMON. Using this, users can use DAMON’s major
0020 features by reading from and writing to special sysfs files. Therefore,
0021 you can write and use your personalized DAMON sysfs wrapper programs that
0022 reads/writes the sysfs files instead of you. The `DAMON user space tool
0023 <https://github.com/awslabs/damo>`_ is one example of such programs. It
0024 supports both virtual and physical address spaces monitoring. Note that this
0025 interface provides only simple :ref:`statistics <damos_stats>` for the
0026 monitoring results. For detailed monitoring results, DAMON provides a
0027 :ref:`tracepoint <tracepoint>`.
0028 - *debugfs interface.*
0029 :ref:`This <debugfs_interface>` is almost identical to :ref:`sysfs interface
0030 <sysfs_interface>`. This will be removed after next LTS kernel is released,
0031 so users should move to the :ref:`sysfs interface <sysfs_interface>`.
0032 - *Kernel Space Programming Interface.*
0033 :doc:`This </mm/damon/api>` is for kernel space programmers. Using this,
0034 users can utilize every feature of DAMON most flexibly and efficiently by
0035 writing kernel space DAMON application programs for you. You can even extend
0036 DAMON for various address spaces. For detail, please refer to the interface
0037 :doc:`document </mm/damon/api>`.
0038
0039 .. _sysfs_interface:
0040
0041 sysfs Interface
0042 ===============
0043
0044 DAMON sysfs interface is built when ``CONFIG_DAMON_SYSFS`` is defined. It
0045 creates multiple directories and files under its sysfs directory,
0046 ``<sysfs>/kernel/mm/damon/``. You can control DAMON by writing to and reading
0047 from the files under the directory.
0048
0049 For a short example, users can monitor the virtual address space of a given
0050 workload as below. ::
0051
0052 # cd /sys/kernel/mm/damon/admin/
0053 # echo 1 > kdamonds/nr_kdamonds && echo 1 > kdamonds/0/contexts/nr_contexts
0054 # echo vaddr > kdamonds/0/contexts/0/operations
0055 # echo 1 > kdamonds/0/contexts/0/targets/nr_targets
0056 # echo $(pidof <workload>) > kdamonds/0/contexts/0/targets/0/pid_target
0057 # echo on > kdamonds/0/state
0058
0059 Files Hierarchy
0060 ---------------
0061
0062 The files hierarchy of DAMON sysfs interface is shown below. In the below
0063 figure, parents-children relations are represented with indentations, each
0064 directory is having ``/`` suffix, and files in each directory are separated by
0065 comma (","). ::
0066
0067 /sys/kernel/mm/damon/admin
0068 │ kdamonds/nr_kdamonds
0069 │ │ 0/state,pid
0070 │ │ │ contexts/nr_contexts
0071 │ │ │ │ 0/avail_operations,operations
0072 │ │ │ │ │ monitoring_attrs/
0073 │ │ │ │ │ │ intervals/sample_us,aggr_us,update_us
0074 │ │ │ │ │ │ nr_regions/min,max
0075 │ │ │ │ │ targets/nr_targets
0076 │ │ │ │ │ │ 0/pid_target
0077 │ │ │ │ │ │ │ regions/nr_regions
0078 │ │ │ │ │ │ │ │ 0/start,end
0079 │ │ │ │ │ │ │ │ ...
0080 │ │ │ │ │ │ ...
0081 │ │ │ │ │ schemes/nr_schemes
0082 │ │ │ │ │ │ 0/action
0083 │ │ │ │ │ │ │ access_pattern/
0084 │ │ │ │ │ │ │ │ sz/min,max
0085 │ │ │ │ │ │ │ │ nr_accesses/min,max
0086 │ │ │ │ │ │ │ │ age/min,max
0087 │ │ │ │ │ │ │ quotas/ms,bytes,reset_interval_ms
0088 │ │ │ │ │ │ │ │ weights/sz_permil,nr_accesses_permil,age_permil
0089 │ │ │ │ │ │ │ watermarks/metric,interval_us,high,mid,low
0090 │ │ │ │ │ │ │ stats/nr_tried,sz_tried,nr_applied,sz_applied,qt_exceeds
0091 │ │ │ │ │ │ ...
0092 │ │ │ │ ...
0093 │ │ ...
0094
0095 Root
0096 ----
0097
0098 The root of the DAMON sysfs interface is ``<sysfs>/kernel/mm/damon/``, and it
0099 has one directory named ``admin``. The directory contains the files for
0100 privileged user space programs' control of DAMON. User space tools or deamons
0101 having the root permission could use this directory.
0102
0103 kdamonds/
0104 ---------
0105
0106 The monitoring-related information including request specifications and results
0107 are called DAMON context. DAMON executes each context with a kernel thread
0108 called kdamond, and multiple kdamonds could run in parallel.
0109
0110 Under the ``admin`` directory, one directory, ``kdamonds``, which has files for
0111 controlling the kdamonds exist. In the beginning, this directory has only one
0112 file, ``nr_kdamonds``. Writing a number (``N``) to the file creates the number
0113 of child directories named ``0`` to ``N-1``. Each directory represents each
0114 kdamond.
0115
0116 kdamonds/<N>/
0117 -------------
0118
0119 In each kdamond directory, two files (``state`` and ``pid``) and one directory
0120 (``contexts``) exist.
0121
0122 Reading ``state`` returns ``on`` if the kdamond is currently running, or
0123 ``off`` if it is not running. Writing ``on`` or ``off`` makes the kdamond be
0124 in the state. Writing ``commit`` to the ``state`` file makes kdamond reads the
0125 user inputs in the sysfs files except ``state`` file again. Writing
0126 ``update_schemes_stats`` to ``state`` file updates the contents of stats files
0127 for each DAMON-based operation scheme of the kdamond. For details of the
0128 stats, please refer to :ref:`stats section <sysfs_schemes_stats>`.
0129
0130 If the state is ``on``, reading ``pid`` shows the pid of the kdamond thread.
0131
0132 ``contexts`` directory contains files for controlling the monitoring contexts
0133 that this kdamond will execute.
0134
0135 kdamonds/<N>/contexts/
0136 ----------------------
0137
0138 In the beginning, this directory has only one file, ``nr_contexts``. Writing a
0139 number (``N``) to the file creates the number of child directories named as
0140 ``0`` to ``N-1``. Each directory represents each monitoring context. At the
0141 moment, only one context per kdamond is supported, so only ``0`` or ``1`` can
0142 be written to the file.
0143
0144 contexts/<N>/
0145 -------------
0146
0147 In each context directory, two files (``avail_operations`` and ``operations``)
0148 and three directories (``monitoring_attrs``, ``targets``, and ``schemes``)
0149 exist.
0150
0151 DAMON supports multiple types of monitoring operations, including those for
0152 virtual address space and the physical address space. You can get the list of
0153 available monitoring operations set on the currently running kernel by reading
0154 ``avail_operations`` file. Based on the kernel configuration, the file will
0155 list some or all of below keywords.
0156
0157 - vaddr: Monitor virtual address spaces of specific processes
0158 - fvaddr: Monitor fixed virtual address ranges
0159 - paddr: Monitor the physical address space of the system
0160
0161 Please refer to :ref:`regions sysfs directory <sysfs_regions>` for detailed
0162 differences between the operations sets in terms of the monitoring target
0163 regions.
0164
0165 You can set and get what type of monitoring operations DAMON will use for the
0166 context by writing one of the keywords listed in ``avail_operations`` file and
0167 reading from the ``operations`` file.
0168
0169 contexts/<N>/monitoring_attrs/
0170 ------------------------------
0171
0172 Files for specifying attributes of the monitoring including required quality
0173 and efficiency of the monitoring are in ``monitoring_attrs`` directory.
0174 Specifically, two directories, ``intervals`` and ``nr_regions`` exist in this
0175 directory.
0176
0177 Under ``intervals`` directory, three files for DAMON's sampling interval
0178 (``sample_us``), aggregation interval (``aggr_us``), and update interval
0179 (``update_us``) exist. You can set and get the values in micro-seconds by
0180 writing to and reading from the files.
0181
0182 Under ``nr_regions`` directory, two files for the lower-bound and upper-bound
0183 of DAMON's monitoring regions (``min`` and ``max``, respectively), which
0184 controls the monitoring overhead, exist. You can set and get the values by
0185 writing to and rading from the files.
0186
0187 For more details about the intervals and monitoring regions range, please refer
0188 to the Design document (:doc:`/mm/damon/design`).
0189
0190 contexts/<N>/targets/
0191 ---------------------
0192
0193 In the beginning, this directory has only one file, ``nr_targets``. Writing a
0194 number (``N``) to the file creates the number of child directories named ``0``
0195 to ``N-1``. Each directory represents each monitoring target.
0196
0197 targets/<N>/
0198 ------------
0199
0200 In each target directory, one file (``pid_target``) and one directory
0201 (``regions``) exist.
0202
0203 If you wrote ``vaddr`` to the ``contexts/<N>/operations``, each target should
0204 be a process. You can specify the process to DAMON by writing the pid of the
0205 process to the ``pid_target`` file.
0206
0207 .. _sysfs_regions:
0208
0209 targets/<N>/regions
0210 -------------------
0211
0212 When ``vaddr`` monitoring operations set is being used (``vaddr`` is written to
0213 the ``contexts/<N>/operations`` file), DAMON automatically sets and updates the
0214 monitoring target regions so that entire memory mappings of target processes
0215 can be covered. However, users could want to set the initial monitoring region
0216 to specific address ranges.
0217
0218 In contrast, DAMON do not automatically sets and updates the monitoring target
0219 regions when ``fvaddr`` or ``paddr`` monitoring operations sets are being used
0220 (``fvaddr`` or ``paddr`` have written to the ``contexts/<N>/operations``).
0221 Therefore, users should set the monitoring target regions by themselves in the
0222 cases.
0223
0224 For such cases, users can explicitly set the initial monitoring target regions
0225 as they want, by writing proper values to the files under this directory.
0226
0227 In the beginning, this directory has only one file, ``nr_regions``. Writing a
0228 number (``N``) to the file creates the number of child directories named ``0``
0229 to ``N-1``. Each directory represents each initial monitoring target region.
0230
0231 regions/<N>/
0232 ------------
0233
0234 In each region directory, you will find two files (``start`` and ``end``). You
0235 can set and get the start and end addresses of the initial monitoring target
0236 region by writing to and reading from the files, respectively.
0237
0238 contexts/<N>/schemes/
0239 ---------------------
0240
0241 For usual DAMON-based data access aware memory management optimizations, users
0242 would normally want the system to apply a memory management action to a memory
0243 region of a specific access pattern. DAMON receives such formalized operation
0244 schemes from the user and applies those to the target memory regions. Users
0245 can get and set the schemes by reading from and writing to files under this
0246 directory.
0247
0248 In the beginning, this directory has only one file, ``nr_schemes``. Writing a
0249 number (``N``) to the file creates the number of child directories named ``0``
0250 to ``N-1``. Each directory represents each DAMON-based operation scheme.
0251
0252 schemes/<N>/
0253 ------------
0254
0255 In each scheme directory, four directories (``access_pattern``, ``quotas``,
0256 ``watermarks``, and ``stats``) and one file (``action``) exist.
0257
0258 The ``action`` file is for setting and getting what action you want to apply to
0259 memory regions having specific access pattern of the interest. The keywords
0260 that can be written to and read from the file and their meaning are as below.
0261
0262 - ``willneed``: Call ``madvise()`` for the region with ``MADV_WILLNEED``
0263 - ``cold``: Call ``madvise()`` for the region with ``MADV_COLD``
0264 - ``pageout``: Call ``madvise()`` for the region with ``MADV_PAGEOUT``
0265 - ``hugepage``: Call ``madvise()`` for the region with ``MADV_HUGEPAGE``
0266 - ``nohugepage``: Call ``madvise()`` for the region with ``MADV_NOHUGEPAGE``
0267 - ``lru_prio``: Prioritize the region on its LRU lists.
0268 - ``lru_deprio``: Deprioritize the region on its LRU lists.
0269 - ``stat``: Do nothing but count the statistics
0270
0271 schemes/<N>/access_pattern/
0272 ---------------------------
0273
0274 The target access pattern of each DAMON-based operation scheme is constructed
0275 with three ranges including the size of the region in bytes, number of
0276 monitored accesses per aggregate interval, and number of aggregated intervals
0277 for the age of the region.
0278
0279 Under the ``access_pattern`` directory, three directories (``sz``,
0280 ``nr_accesses``, and ``age``) each having two files (``min`` and ``max``)
0281 exist. You can set and get the access pattern for the given scheme by writing
0282 to and reading from the ``min`` and ``max`` files under ``sz``,
0283 ``nr_accesses``, and ``age`` directories, respectively.
0284
0285 schemes/<N>/quotas/
0286 -------------------
0287
0288 Optimal ``target access pattern`` for each ``action`` is workload dependent, so
0289 not easy to find. Worse yet, setting a scheme of some action too aggressive
0290 can cause severe overhead. To avoid such overhead, users can limit time and
0291 size quota for each scheme. In detail, users can ask DAMON to try to use only
0292 up to specific time (``time quota``) for applying the action, and to apply the
0293 action to only up to specific amount (``size quota``) of memory regions having
0294 the target access pattern within a given time interval (``reset interval``).
0295
0296 When the quota limit is expected to be exceeded, DAMON prioritizes found memory
0297 regions of the ``target access pattern`` based on their size, access frequency,
0298 and age. For personalized prioritization, users can set the weights for the
0299 three properties.
0300
0301 Under ``quotas`` directory, three files (``ms``, ``bytes``,
0302 ``reset_interval_ms``) and one directory (``weights``) having three files
0303 (``sz_permil``, ``nr_accesses_permil``, and ``age_permil``) in it exist.
0304
0305 You can set the ``time quota`` in milliseconds, ``size quota`` in bytes, and
0306 ``reset interval`` in milliseconds by writing the values to the three files,
0307 respectively. You can also set the prioritization weights for size, access
0308 frequency, and age in per-thousand unit by writing the values to the three
0309 files under the ``weights`` directory.
0310
0311 schemes/<N>/watermarks/
0312 -----------------------
0313
0314 To allow easy activation and deactivation of each scheme based on system
0315 status, DAMON provides a feature called watermarks. The feature receives five
0316 values called ``metric``, ``interval``, ``high``, ``mid``, and ``low``. The
0317 ``metric`` is the system metric such as free memory ratio that can be measured.
0318 If the metric value of the system is higher than the value in ``high`` or lower
0319 than ``low`` at the memoent, the scheme is deactivated. If the value is lower
0320 than ``mid``, the scheme is activated.
0321
0322 Under the watermarks directory, five files (``metric``, ``interval_us``,
0323 ``high``, ``mid``, and ``low``) for setting each value exist. You can set and
0324 get the five values by writing to the files, respectively.
0325
0326 Keywords and meanings of those that can be written to the ``metric`` file are
0327 as below.
0328
0329 - none: Ignore the watermarks
0330 - free_mem_rate: System's free memory rate (per thousand)
0331
0332 The ``interval`` should written in microseconds unit.
0333
0334 .. _sysfs_schemes_stats:
0335
0336 schemes/<N>/stats/
0337 ------------------
0338
0339 DAMON counts the total number and bytes of regions that each scheme is tried to
0340 be applied, the two numbers for the regions that each scheme is successfully
0341 applied, and the total number of the quota limit exceeds. This statistics can
0342 be used for online analysis or tuning of the schemes.
0343
0344 The statistics can be retrieved by reading the files under ``stats`` directory
0345 (``nr_tried``, ``sz_tried``, ``nr_applied``, ``sz_applied``, and
0346 ``qt_exceeds``), respectively. The files are not updated in real time, so you
0347 should ask DAMON sysfs interface to updte the content of the files for the
0348 stats by writing a special keyword, ``update_schemes_stats`` to the relevant
0349 ``kdamonds/<N>/state`` file.
0350
0351 Example
0352 ~~~~~~~
0353
0354 Below commands applies a scheme saying "If a memory region of size in [4KiB,
0355 8KiB] is showing accesses per aggregate interval in [0, 5] for aggregate
0356 interval in [10, 20], page out the region. For the paging out, use only up to
0357 10ms per second, and also don't page out more than 1GiB per second. Under the
0358 limitation, page out memory regions having longer age first. Also, check the
0359 free memory rate of the system every 5 seconds, start the monitoring and paging
0360 out when the free memory rate becomes lower than 50%, but stop it if the free
0361 memory rate becomes larger than 60%, or lower than 30%". ::
0362
0363 # cd <sysfs>/kernel/mm/damon/admin
0364 # # populate directories
0365 # echo 1 > kdamonds/nr_kdamonds; echo 1 > kdamonds/0/contexts/nr_contexts;
0366 # echo 1 > kdamonds/0/contexts/0/schemes/nr_schemes
0367 # cd kdamonds/0/contexts/0/schemes/0
0368 # # set the basic access pattern and the action
0369 # echo 4096 > access_pattern/sz/min
0370 # echo 8192 > access_pattern/sz/max
0371 # echo 0 > access_pattern/nr_accesses/min
0372 # echo 5 > access_pattern/nr_accesses/max
0373 # echo 10 > access_pattern/age/min
0374 # echo 20 > access_pattern/age/max
0375 # echo pageout > action
0376 # # set quotas
0377 # echo 10 > quotas/ms
0378 # echo $((1024*1024*1024)) > quotas/bytes
0379 # echo 1000 > quotas/reset_interval_ms
0380 # # set watermark
0381 # echo free_mem_rate > watermarks/metric
0382 # echo 5000000 > watermarks/interval_us
0383 # echo 600 > watermarks/high
0384 # echo 500 > watermarks/mid
0385 # echo 300 > watermarks/low
0386
0387 Please note that it's highly recommended to use user space tools like `damo
0388 <https://github.com/awslabs/damo>`_ rather than manually reading and writing
0389 the files as above. Above is only for an example.
0390
0391 .. _debugfs_interface:
0392
0393 debugfs Interface
0394 =================
0395
0396 DAMON exports eight files, ``attrs``, ``target_ids``, ``init_regions``,
0397 ``schemes``, ``monitor_on``, ``kdamond_pid``, ``mk_contexts`` and
0398 ``rm_contexts`` under its debugfs directory, ``<debugfs>/damon/``.
0399
0400
0401 Attributes
0402 ----------
0403
0404 Users can get and set the ``sampling interval``, ``aggregation interval``,
0405 ``update interval``, and min/max number of monitoring target regions by
0406 reading from and writing to the ``attrs`` file. To know about the monitoring
0407 attributes in detail, please refer to the :doc:`/mm/damon/design`. For
0408 example, below commands set those values to 5 ms, 100 ms, 1,000 ms, 10 and
0409 1000, and then check it again::
0410
0411 # cd <debugfs>/damon
0412 # echo 5000 100000 1000000 10 1000 > attrs
0413 # cat attrs
0414 5000 100000 1000000 10 1000
0415
0416
0417 Target IDs
0418 ----------
0419
0420 Some types of address spaces supports multiple monitoring target. For example,
0421 the virtual memory address spaces monitoring can have multiple processes as the
0422 monitoring targets. Users can set the targets by writing relevant id values of
0423 the targets to, and get the ids of the current targets by reading from the
0424 ``target_ids`` file. In case of the virtual address spaces monitoring, the
0425 values should be pids of the monitoring target processes. For example, below
0426 commands set processes having pids 42 and 4242 as the monitoring targets and
0427 check it again::
0428
0429 # cd <debugfs>/damon
0430 # echo 42 4242 > target_ids
0431 # cat target_ids
0432 42 4242
0433
0434 Users can also monitor the physical memory address space of the system by
0435 writing a special keyword, "``paddr\n``" to the file. Because physical address
0436 space monitoring doesn't support multiple targets, reading the file will show a
0437 fake value, ``42``, as below::
0438
0439 # cd <debugfs>/damon
0440 # echo paddr > target_ids
0441 # cat target_ids
0442 42
0443
0444 Note that setting the target ids doesn't start the monitoring.
0445
0446
0447 Initial Monitoring Target Regions
0448 ---------------------------------
0449
0450 In case of the virtual address space monitoring, DAMON automatically sets and
0451 updates the monitoring target regions so that entire memory mappings of target
0452 processes can be covered. However, users can want to limit the monitoring
0453 region to specific address ranges, such as the heap, the stack, or specific
0454 file-mapped area. Or, some users can know the initial access pattern of their
0455 workloads and therefore want to set optimal initial regions for the 'adaptive
0456 regions adjustment'.
0457
0458 In contrast, DAMON do not automatically sets and updates the monitoring target
0459 regions in case of physical memory monitoring. Therefore, users should set the
0460 monitoring target regions by themselves.
0461
0462 In such cases, users can explicitly set the initial monitoring target regions
0463 as they want, by writing proper values to the ``init_regions`` file. Each line
0464 of the input should represent one region in below form.::
0465
0466 <target idx> <start address> <end address>
0467
0468 The ``target idx`` should be the index of the target in ``target_ids`` file,
0469 starting from ``0``, and the regions should be passed in address order. For
0470 example, below commands will set a couple of address ranges, ``1-100`` and
0471 ``100-200`` as the initial monitoring target region of pid 42, which is the
0472 first one (index ``0``) in ``target_ids``, and another couple of address
0473 ranges, ``20-40`` and ``50-100`` as that of pid 4242, which is the second one
0474 (index ``1``) in ``target_ids``.::
0475
0476 # cd <debugfs>/damon
0477 # cat target_ids
0478 42 4242
0479 # echo "0 1 100
0480 0 100 200
0481 1 20 40
0482 1 50 100" > init_regions
0483
0484 Note that this sets the initial monitoring target regions only. In case of
0485 virtual memory monitoring, DAMON will automatically updates the boundary of the
0486 regions after one ``update interval``. Therefore, users should set the
0487 ``update interval`` large enough in this case, if they don't want the
0488 update.
0489
0490
0491 Schemes
0492 -------
0493
0494 For usual DAMON-based data access aware memory management optimizations, users
0495 would simply want the system to apply a memory management action to a memory
0496 region of a specific access pattern. DAMON receives such formalized operation
0497 schemes from the user and applies those to the target processes.
0498
0499 Users can get and set the schemes by reading from and writing to ``schemes``
0500 debugfs file. Reading the file also shows the statistics of each scheme. To
0501 the file, each of the schemes should be represented in each line in below
0502 form::
0503
0504 <target access pattern> <action> <quota> <watermarks>
0505
0506 You can disable schemes by simply writing an empty string to the file.
0507
0508 Target Access Pattern
0509 ~~~~~~~~~~~~~~~~~~~~~
0510
0511 The ``<target access pattern>`` is constructed with three ranges in below
0512 form::
0513
0514 min-size max-size min-acc max-acc min-age max-age
0515
0516 Specifically, bytes for the size of regions (``min-size`` and ``max-size``),
0517 number of monitored accesses per aggregate interval for access frequency
0518 (``min-acc`` and ``max-acc``), number of aggregate intervals for the age of
0519 regions (``min-age`` and ``max-age``) are specified. Note that the ranges are
0520 closed interval.
0521
0522 Action
0523 ~~~~~~
0524
0525 The ``<action>`` is a predefined integer for memory management actions, which
0526 DAMON will apply to the regions having the target access pattern. The
0527 supported numbers and their meanings are as below.
0528
0529 - 0: Call ``madvise()`` for the region with ``MADV_WILLNEED``
0530 - 1: Call ``madvise()`` for the region with ``MADV_COLD``
0531 - 2: Call ``madvise()`` for the region with ``MADV_PAGEOUT``
0532 - 3: Call ``madvise()`` for the region with ``MADV_HUGEPAGE``
0533 - 4: Call ``madvise()`` for the region with ``MADV_NOHUGEPAGE``
0534 - 5: Do nothing but count the statistics
0535
0536 Quota
0537 ~~~~~
0538
0539 Optimal ``target access pattern`` for each ``action`` is workload dependent, so
0540 not easy to find. Worse yet, setting a scheme of some action too aggressive
0541 can cause severe overhead. To avoid such overhead, users can limit time and
0542 size quota for the scheme via the ``<quota>`` in below form::
0543
0544 <ms> <sz> <reset interval> <priority weights>
0545
0546 This makes DAMON to try to use only up to ``<ms>`` milliseconds for applying
0547 the action to memory regions of the ``target access pattern`` within the
0548 ``<reset interval>`` milliseconds, and to apply the action to only up to
0549 ``<sz>`` bytes of memory regions within the ``<reset interval>``. Setting both
0550 ``<ms>`` and ``<sz>`` zero disables the quota limits.
0551
0552 When the quota limit is expected to be exceeded, DAMON prioritizes found memory
0553 regions of the ``target access pattern`` based on their size, access frequency,
0554 and age. For personalized prioritization, users can set the weights for the
0555 three properties in ``<priority weights>`` in below form::
0556
0557 <size weight> <access frequency weight> <age weight>
0558
0559 Watermarks
0560 ~~~~~~~~~~
0561
0562 Some schemes would need to run based on current value of the system's specific
0563 metrics like free memory ratio. For such cases, users can specify watermarks
0564 for the condition.::
0565
0566 <metric> <check interval> <high mark> <middle mark> <low mark>
0567
0568 ``<metric>`` is a predefined integer for the metric to be checked. The
0569 supported numbers and their meanings are as below.
0570
0571 - 0: Ignore the watermarks
0572 - 1: System's free memory rate (per thousand)
0573
0574 The value of the metric is checked every ``<check interval>`` microseconds.
0575
0576 If the value is higher than ``<high mark>`` or lower than ``<low mark>``, the
0577 scheme is deactivated. If the value is lower than ``<mid mark>``, the scheme
0578 is activated.
0579
0580 .. _damos_stats:
0581
0582 Statistics
0583 ~~~~~~~~~~
0584
0585 It also counts the total number and bytes of regions that each scheme is tried
0586 to be applied, the two numbers for the regions that each scheme is successfully
0587 applied, and the total number of the quota limit exceeds. This statistics can
0588 be used for online analysis or tuning of the schemes.
0589
0590 The statistics can be shown by reading the ``schemes`` file. Reading the file
0591 will show each scheme you entered in each line, and the five numbers for the
0592 statistics will be added at the end of each line.
0593
0594 Example
0595 ~~~~~~~
0596
0597 Below commands applies a scheme saying "If a memory region of size in [4KiB,
0598 8KiB] is showing accesses per aggregate interval in [0, 5] for aggregate
0599 interval in [10, 20], page out the region. For the paging out, use only up to
0600 10ms per second, and also don't page out more than 1GiB per second. Under the
0601 limitation, page out memory regions having longer age first. Also, check the
0602 free memory rate of the system every 5 seconds, start the monitoring and paging
0603 out when the free memory rate becomes lower than 50%, but stop it if the free
0604 memory rate becomes larger than 60%, or lower than 30%".::
0605
0606 # cd <debugfs>/damon
0607 # scheme="4096 8192 0 5 10 20 2" # target access pattern and action
0608 # scheme+=" 10 $((1024*1024*1024)) 1000" # quotas
0609 # scheme+=" 0 0 100" # prioritization weights
0610 # scheme+=" 1 5000000 600 500 300" # watermarks
0611 # echo "$scheme" > schemes
0612
0613
0614 Turning On/Off
0615 --------------
0616
0617 Setting the files as described above doesn't incur effect unless you explicitly
0618 start the monitoring. You can start, stop, and check the current status of the
0619 monitoring by writing to and reading from the ``monitor_on`` file. Writing
0620 ``on`` to the file starts the monitoring of the targets with the attributes.
0621 Writing ``off`` to the file stops those. DAMON also stops if every target
0622 process is terminated. Below example commands turn on, off, and check the
0623 status of DAMON::
0624
0625 # cd <debugfs>/damon
0626 # echo on > monitor_on
0627 # echo off > monitor_on
0628 # cat monitor_on
0629 off
0630
0631 Please note that you cannot write to the above-mentioned debugfs files while
0632 the monitoring is turned on. If you write to the files while DAMON is running,
0633 an error code such as ``-EBUSY`` will be returned.
0634
0635
0636 Monitoring Thread PID
0637 ---------------------
0638
0639 DAMON does requested monitoring with a kernel thread called ``kdamond``. You
0640 can get the pid of the thread by reading the ``kdamond_pid`` file. When the
0641 monitoring is turned off, reading the file returns ``none``. ::
0642
0643 # cd <debugfs>/damon
0644 # cat monitor_on
0645 off
0646 # cat kdamond_pid
0647 none
0648 # echo on > monitor_on
0649 # cat kdamond_pid
0650 18594
0651
0652
0653 Using Multiple Monitoring Threads
0654 ---------------------------------
0655
0656 One ``kdamond`` thread is created for each monitoring context. You can create
0657 and remove monitoring contexts for multiple ``kdamond`` required use case using
0658 the ``mk_contexts`` and ``rm_contexts`` files.
0659
0660 Writing the name of the new context to the ``mk_contexts`` file creates a
0661 directory of the name on the DAMON debugfs directory. The directory will have
0662 DAMON debugfs files for the context. ::
0663
0664 # cd <debugfs>/damon
0665 # ls foo
0666 # ls: cannot access 'foo': No such file or directory
0667 # echo foo > mk_contexts
0668 # ls foo
0669 # attrs init_regions kdamond_pid schemes target_ids
0670
0671 If the context is not needed anymore, you can remove it and the corresponding
0672 directory by putting the name of the context to the ``rm_contexts`` file. ::
0673
0674 # echo foo > rm_contexts
0675 # ls foo
0676 # ls: cannot access 'foo': No such file or directory
0677
0678 Note that ``mk_contexts``, ``rm_contexts``, and ``monitor_on`` files are in the
0679 root directory only.
0680
0681
0682 .. _tracepoint:
0683
0684 Tracepoint for Monitoring Results
0685 =================================
0686
0687 DAMON provides the monitoring results via a tracepoint,
0688 ``damon:damon_aggregated``. While the monitoring is turned on, you could
0689 record the tracepoint events and show results using tracepoint supporting tools
0690 like ``perf``. For example::
0691
0692 # echo on > monitor_on
0693 # perf record -e damon:damon_aggregated &
0694 # sleep 5
0695 # kill 9 $(pidof perf)
0696 # echo off > monitor_on
0697 # perf script