1c4ba6014SSeongJae Park.. SPDX-License-Identifier: GPL-2.0 2c4ba6014SSeongJae Park 3c4ba6014SSeongJae Park=============== 4c4ba6014SSeongJae ParkDetailed Usages 5c4ba6014SSeongJae Park=============== 6c4ba6014SSeongJae Park 7b1840272SSeongJae ParkDAMON provides below interfaces for different users. 8c4ba6014SSeongJae Park 9c4ba6014SSeongJae Park- *DAMON user space tool.* 1035b43d40SSeongJae Park `This <https://github.com/awslabs/damo>`_ is for privileged people such as 1135b43d40SSeongJae Park system administrators who want a just-working human-friendly interface. 1235b43d40SSeongJae Park Using this, users can use the DAMON’s major features in a human-friendly way. 13ddb7d012SSeongJae Park It may not be highly tuned for special cases, though. For more detail, 14ddb7d012SSeongJae Park please refer to its `usage document 1535b43d40SSeongJae Park <https://github.com/awslabs/damo/blob/next/USAGE.md>`_. 16b1840272SSeongJae Park- *sysfs interface.* 17b1840272SSeongJae Park :ref:`This <sysfs_interface>` is for privileged user space programmers who 1835b43d40SSeongJae Park want more optimized use of DAMON. Using this, users can use DAMON’s major 19b1840272SSeongJae Park features by reading from and writing to special sysfs files. Therefore, 20b1840272SSeongJae Park you can write and use your personalized DAMON sysfs wrapper programs that 21b1840272SSeongJae Park reads/writes the sysfs files instead of you. The `DAMON user space tool 22ff71f26fSSeongJae Park <https://github.com/awslabs/damo>`_ is one example of such programs. 235445fcbcSSeongJae Park- *debugfs interface. (DEPRECATED!)* 24b1840272SSeongJae Park :ref:`This <debugfs_interface>` is almost identical to :ref:`sysfs interface 255445fcbcSSeongJae Park <sysfs_interface>`. This is deprecated, so users should move to the 265445fcbcSSeongJae Park :ref:`sysfs interface <sysfs_interface>`. If you depend on this and cannot 275445fcbcSSeongJae Park move, please report your usecase to damon@lists.linux.dev and 285445fcbcSSeongJae Park linux-mm@kvack.org. 29c4ba6014SSeongJae Park- *Kernel Space Programming Interface.* 30ee65728eSMike Rapoport :doc:`This </mm/damon/api>` is for kernel space programmers. Using this, 3135b43d40SSeongJae Park users can utilize every feature of DAMON most flexibly and efficiently by 3235b43d40SSeongJae Park writing kernel space DAMON application programs for you. You can even extend 3335b43d40SSeongJae Park DAMON for various address spaces. For detail, please refer to the interface 34ee65728eSMike Rapoport :doc:`document </mm/damon/api>`. 35c4ba6014SSeongJae Park 36b1840272SSeongJae Park.. _sysfs_interface: 37b1840272SSeongJae Park 38b1840272SSeongJae Parksysfs Interface 39b1840272SSeongJae Park=============== 40b1840272SSeongJae Park 41b1840272SSeongJae ParkDAMON sysfs interface is built when ``CONFIG_DAMON_SYSFS`` is defined. It 42b1840272SSeongJae Parkcreates multiple directories and files under its sysfs directory, 43b1840272SSeongJae Park``<sysfs>/kernel/mm/damon/``. You can control DAMON by writing to and reading 44b1840272SSeongJae Parkfrom the files under the directory. 45b1840272SSeongJae Park 46b1840272SSeongJae ParkFor a short example, users can monitor the virtual address space of a given 47b1840272SSeongJae Parkworkload as below. :: 48b1840272SSeongJae Park 49b1840272SSeongJae Park # cd /sys/kernel/mm/damon/admin/ 50465d0eb0SKairui Song # echo 1 > kdamonds/nr_kdamonds && echo 1 > kdamonds/0/contexts/nr_contexts 51b1840272SSeongJae Park # echo vaddr > kdamonds/0/contexts/0/operations 52465d0eb0SKairui Song # echo 1 > kdamonds/0/contexts/0/targets/nr_targets 53465d0eb0SKairui Song # echo $(pidof <workload>) > kdamonds/0/contexts/0/targets/0/pid_target 54b1840272SSeongJae Park # echo on > kdamonds/0/state 55b1840272SSeongJae Park 56b1840272SSeongJae ParkFiles Hierarchy 57b1840272SSeongJae Park--------------- 58b1840272SSeongJae Park 59b1840272SSeongJae ParkThe files hierarchy of DAMON sysfs interface is shown below. In the below 60b1840272SSeongJae Parkfigure, parents-children relations are represented with indentations, each 61b1840272SSeongJae Parkdirectory is having ``/`` suffix, and files in each directory are separated by 62b1840272SSeongJae Parkcomma (","). :: 63b1840272SSeongJae Park 64b1840272SSeongJae Park /sys/kernel/mm/damon/admin 65b1840272SSeongJae Park │ kdamonds/nr_kdamonds 66b1840272SSeongJae Park │ │ 0/state,pid 67b1840272SSeongJae Park │ │ │ contexts/nr_contexts 682fe60ec9SSeongJae Park │ │ │ │ 0/avail_operations,operations 69b1840272SSeongJae Park │ │ │ │ │ monitoring_attrs/ 70b1840272SSeongJae Park │ │ │ │ │ │ intervals/sample_us,aggr_us,update_us 71b1840272SSeongJae Park │ │ │ │ │ │ nr_regions/min,max 72b1840272SSeongJae Park │ │ │ │ │ targets/nr_targets 73b1840272SSeongJae Park │ │ │ │ │ │ 0/pid_target 74b1840272SSeongJae Park │ │ │ │ │ │ │ regions/nr_regions 75b1840272SSeongJae Park │ │ │ │ │ │ │ │ 0/start,end 76b1840272SSeongJae Park │ │ │ │ │ │ │ │ ... 77b1840272SSeongJae Park │ │ │ │ │ │ ... 78b1840272SSeongJae Park │ │ │ │ │ schemes/nr_schemes 79b1840272SSeongJae Park │ │ │ │ │ │ 0/action 80b1840272SSeongJae Park │ │ │ │ │ │ │ access_pattern/ 81b1840272SSeongJae Park │ │ │ │ │ │ │ │ sz/min,max 82b1840272SSeongJae Park │ │ │ │ │ │ │ │ nr_accesses/min,max 83b1840272SSeongJae Park │ │ │ │ │ │ │ │ age/min,max 84b1840272SSeongJae Park │ │ │ │ │ │ │ quotas/ms,bytes,reset_interval_ms 85b1840272SSeongJae Park │ │ │ │ │ │ │ │ weights/sz_permil,nr_accesses_permil,age_permil 86b1840272SSeongJae Park │ │ │ │ │ │ │ watermarks/metric,interval_us,high,mid,low 879b7f9322SSeongJae Park │ │ │ │ │ │ │ filters/nr_filters 889b7f9322SSeongJae Park │ │ │ │ │ │ │ │ 0/type,matching,memcg_id 89b1840272SSeongJae Park │ │ │ │ │ │ │ stats/nr_tried,sz_tried,nr_applied,sz_applied,qt_exceeds 90ea7f03a4SSeongJae Park │ │ │ │ │ │ │ tried_regions/total_bytes 917f0a86f3SSeongJae Park │ │ │ │ │ │ │ │ 0/start,end,nr_accesses,age 927f0a86f3SSeongJae Park │ │ │ │ │ │ │ │ ... 93b1840272SSeongJae Park │ │ │ │ │ │ ... 94b1840272SSeongJae Park │ │ │ │ ... 95b1840272SSeongJae Park │ │ ... 96b1840272SSeongJae Park 97b1840272SSeongJae ParkRoot 98b1840272SSeongJae Park---- 99b1840272SSeongJae Park 100b1840272SSeongJae ParkThe root of the DAMON sysfs interface is ``<sysfs>/kernel/mm/damon/``, and it 101b1840272SSeongJae Parkhas one directory named ``admin``. The directory contains the files for 102d56b699dSBjorn Helgaasprivileged user space programs' control of DAMON. User space tools or daemons 103b1840272SSeongJae Parkhaving the root permission could use this directory. 104b1840272SSeongJae Park 105b1840272SSeongJae Parkkdamonds/ 106b1840272SSeongJae Park--------- 107b1840272SSeongJae Park 108b1840272SSeongJae ParkThe monitoring-related information including request specifications and results 109b1840272SSeongJae Parkare called DAMON context. DAMON executes each context with a kernel thread 110b1840272SSeongJae Parkcalled kdamond, and multiple kdamonds could run in parallel. 111b1840272SSeongJae Park 112b1840272SSeongJae ParkUnder the ``admin`` directory, one directory, ``kdamonds``, which has files for 113b1840272SSeongJae Parkcontrolling the kdamonds exist. In the beginning, this directory has only one 114b1840272SSeongJae Parkfile, ``nr_kdamonds``. Writing a number (``N``) to the file creates the number 115b1840272SSeongJae Parkof child directories named ``0`` to ``N-1``. Each directory represents each 116b1840272SSeongJae Parkkdamond. 117b1840272SSeongJae Park 118b1840272SSeongJae Parkkdamonds/<N>/ 119b1840272SSeongJae Park------------- 120b1840272SSeongJae Park 121b1840272SSeongJae ParkIn each kdamond directory, two files (``state`` and ``pid``) and one directory 122b1840272SSeongJae Park(``contexts``) exist. 123b1840272SSeongJae Park 124b1840272SSeongJae ParkReading ``state`` returns ``on`` if the kdamond is currently running, or 125b1840272SSeongJae Park``off`` if it is not running. Writing ``on`` or ``off`` makes the kdamond be 126adc286e6SSeongJae Parkin the state. Writing ``commit`` to the ``state`` file makes kdamond reads the 127adc286e6SSeongJae Parkuser inputs in the sysfs files except ``state`` file again. Writing 128adc286e6SSeongJae Park``update_schemes_stats`` to ``state`` file updates the contents of stats files 129adc286e6SSeongJae Parkfor each DAMON-based operation scheme of the kdamond. For details of the 130ea7f03a4SSeongJae Parkstats, please refer to :ref:`stats section <sysfs_schemes_stats>`. 131ea7f03a4SSeongJae Park 132ea7f03a4SSeongJae ParkWriting ``update_schemes_tried_regions`` to ``state`` file updates the 133ea7f03a4SSeongJae ParkDAMON-based operation scheme action tried regions directory for each 134ea7f03a4SSeongJae ParkDAMON-based operation scheme of the kdamond. Writing 135ea7f03a4SSeongJae Park``update_schemes_tried_bytes`` to ``state`` file updates only 136ea7f03a4SSeongJae Park``.../tried_regions/total_bytes`` files. Writing 137ea7f03a4SSeongJae Park``clear_schemes_tried_regions`` to ``state`` file clears the DAMON-based 138ea7f03a4SSeongJae Parkoperating scheme action tried regions directory for each DAMON-based operation 139ea7f03a4SSeongJae Parkscheme of the kdamond. For details of the DAMON-based operation scheme action 140ea7f03a4SSeongJae Parktried regions directory, please refer to :ref:`tried_regions section 141ea7f03a4SSeongJae Park<sysfs_schemes_tried_regions>`. 142b1840272SSeongJae Park 143b1840272SSeongJae ParkIf the state is ``on``, reading ``pid`` shows the pid of the kdamond thread. 144b1840272SSeongJae Park 145b1840272SSeongJae Park``contexts`` directory contains files for controlling the monitoring contexts 146b1840272SSeongJae Parkthat this kdamond will execute. 147b1840272SSeongJae Park 148b1840272SSeongJae Parkkdamonds/<N>/contexts/ 149b1840272SSeongJae Park---------------------- 150b1840272SSeongJae Park 151b1840272SSeongJae ParkIn the beginning, this directory has only one file, ``nr_contexts``. Writing a 152b1840272SSeongJae Parknumber (``N``) to the file creates the number of child directories named as 153b1840272SSeongJae Park``0`` to ``N-1``. Each directory represents each monitoring context. At the 154b1840272SSeongJae Parkmoment, only one context per kdamond is supported, so only ``0`` or ``1`` can 155b1840272SSeongJae Parkbe written to the file. 156b1840272SSeongJae Park 1579b7f9322SSeongJae Park.. _sysfs_contexts: 1589b7f9322SSeongJae Park 159b1840272SSeongJae Parkcontexts/<N>/ 160b1840272SSeongJae Park------------- 161b1840272SSeongJae Park 1622fe60ec9SSeongJae ParkIn each context directory, two files (``avail_operations`` and ``operations``) 1632fe60ec9SSeongJae Parkand three directories (``monitoring_attrs``, ``targets``, and ``schemes``) 1642fe60ec9SSeongJae Parkexist. 165b1840272SSeongJae Park 166b1840272SSeongJae ParkDAMON supports multiple types of monitoring operations, including those for 1672fe60ec9SSeongJae Parkvirtual address space and the physical address space. You can get the list of 1682fe60ec9SSeongJae Parkavailable monitoring operations set on the currently running kernel by reading 1692fe60ec9SSeongJae Park``avail_operations`` file. Based on the kernel configuration, the file will 1702fe60ec9SSeongJae Parklist some or all of below keywords. 171b1840272SSeongJae Park 172b1840272SSeongJae Park - vaddr: Monitor virtual address spaces of specific processes 17391541808SSeongJae Park - fvaddr: Monitor fixed virtual address ranges 174b1840272SSeongJae Park - paddr: Monitor the physical address space of the system 175b1840272SSeongJae Park 17691541808SSeongJae ParkPlease refer to :ref:`regions sysfs directory <sysfs_regions>` for detailed 17791541808SSeongJae Parkdifferences between the operations sets in terms of the monitoring target 17891541808SSeongJae Parkregions. 17991541808SSeongJae Park 1802fe60ec9SSeongJae ParkYou can set and get what type of monitoring operations DAMON will use for the 1812fe60ec9SSeongJae Parkcontext by writing one of the keywords listed in ``avail_operations`` file and 1822fe60ec9SSeongJae Parkreading from the ``operations`` file. 1832fe60ec9SSeongJae Park 1847f0a86f3SSeongJae Park.. _sysfs_monitoring_attrs: 1857f0a86f3SSeongJae Park 186b1840272SSeongJae Parkcontexts/<N>/monitoring_attrs/ 187b1840272SSeongJae Park------------------------------ 188b1840272SSeongJae Park 189b1840272SSeongJae ParkFiles for specifying attributes of the monitoring including required quality 190b1840272SSeongJae Parkand efficiency of the monitoring are in ``monitoring_attrs`` directory. 191b1840272SSeongJae ParkSpecifically, two directories, ``intervals`` and ``nr_regions`` exist in this 192b1840272SSeongJae Parkdirectory. 193b1840272SSeongJae Park 194b1840272SSeongJae ParkUnder ``intervals`` directory, three files for DAMON's sampling interval 195b1840272SSeongJae Park(``sample_us``), aggregation interval (``aggr_us``), and update interval 196b1840272SSeongJae Park(``update_us``) exist. You can set and get the values in micro-seconds by 197b1840272SSeongJae Parkwriting to and reading from the files. 198b1840272SSeongJae Park 199b1840272SSeongJae ParkUnder ``nr_regions`` directory, two files for the lower-bound and upper-bound 200b1840272SSeongJae Parkof DAMON's monitoring regions (``min`` and ``max``, respectively), which 201b1840272SSeongJae Parkcontrols the monitoring overhead, exist. You can set and get the values by 202b1840272SSeongJae Parkwriting to and rading from the files. 203b1840272SSeongJae Park 204b1840272SSeongJae ParkFor more details about the intervals and monitoring regions range, please refer 205ee65728eSMike Rapoportto the Design document (:doc:`/mm/damon/design`). 206b1840272SSeongJae Park 207b1840272SSeongJae Parkcontexts/<N>/targets/ 208b1840272SSeongJae Park--------------------- 209b1840272SSeongJae Park 210b1840272SSeongJae ParkIn the beginning, this directory has only one file, ``nr_targets``. Writing a 211b1840272SSeongJae Parknumber (``N``) to the file creates the number of child directories named ``0`` 212b1840272SSeongJae Parkto ``N-1``. Each directory represents each monitoring target. 213b1840272SSeongJae Park 214b1840272SSeongJae Parktargets/<N>/ 215b1840272SSeongJae Park------------ 216b1840272SSeongJae Park 217b1840272SSeongJae ParkIn each target directory, one file (``pid_target``) and one directory 218b1840272SSeongJae Park(``regions``) exist. 219b1840272SSeongJae Park 220b1840272SSeongJae ParkIf you wrote ``vaddr`` to the ``contexts/<N>/operations``, each target should 221b1840272SSeongJae Parkbe a process. You can specify the process to DAMON by writing the pid of the 222b1840272SSeongJae Parkprocess to the ``pid_target`` file. 223b1840272SSeongJae Park 22491541808SSeongJae Park.. _sysfs_regions: 22591541808SSeongJae Park 226b1840272SSeongJae Parktargets/<N>/regions 227b1840272SSeongJae Park------------------- 228b1840272SSeongJae Park 229b1840272SSeongJae ParkWhen ``vaddr`` monitoring operations set is being used (``vaddr`` is written to 230b1840272SSeongJae Parkthe ``contexts/<N>/operations`` file), DAMON automatically sets and updates the 231b1840272SSeongJae Parkmonitoring target regions so that entire memory mappings of target processes 232b1840272SSeongJae Parkcan be covered. However, users could want to set the initial monitoring region 233b1840272SSeongJae Parkto specific address ranges. 234b1840272SSeongJae Park 235b1840272SSeongJae ParkIn contrast, DAMON do not automatically sets and updates the monitoring target 23691541808SSeongJae Parkregions when ``fvaddr`` or ``paddr`` monitoring operations sets are being used 23791541808SSeongJae Park(``fvaddr`` or ``paddr`` have written to the ``contexts/<N>/operations``). 23891541808SSeongJae ParkTherefore, users should set the monitoring target regions by themselves in the 23991541808SSeongJae Parkcases. 240b1840272SSeongJae Park 241b1840272SSeongJae ParkFor such cases, users can explicitly set the initial monitoring target regions 242b1840272SSeongJae Parkas they want, by writing proper values to the files under this directory. 243b1840272SSeongJae Park 244b1840272SSeongJae ParkIn the beginning, this directory has only one file, ``nr_regions``. Writing a 245b1840272SSeongJae Parknumber (``N``) to the file creates the number of child directories named ``0`` 246b1840272SSeongJae Parkto ``N-1``. Each directory represents each initial monitoring target region. 247b1840272SSeongJae Park 248b1840272SSeongJae Parkregions/<N>/ 249b1840272SSeongJae Park------------ 250b1840272SSeongJae Park 251b1840272SSeongJae ParkIn each region directory, you will find two files (``start`` and ``end``). You 252b1840272SSeongJae Parkcan set and get the start and end addresses of the initial monitoring target 253b1840272SSeongJae Parkregion by writing to and reading from the files, respectively. 254b1840272SSeongJae Park 255bd414929SSeongJae ParkEach region should not overlap with others. ``end`` of directory ``N`` should 256bd414929SSeongJae Parkbe equal or smaller than ``start`` of directory ``N+1``. 257bd414929SSeongJae Park 258b1840272SSeongJae Parkcontexts/<N>/schemes/ 259b1840272SSeongJae Park--------------------- 260b1840272SSeongJae Park 26101e08737SSeongJae ParkThe directory for DAMON-based Operation Schemes (:ref:`DAMOS 26201e08737SSeongJae Park<damon_design_damos>`). Users can get and set the schemes by reading from and 26301e08737SSeongJae Parkwriting to files under this directory. 264b1840272SSeongJae Park 265b1840272SSeongJae ParkIn the beginning, this directory has only one file, ``nr_schemes``. Writing a 266b1840272SSeongJae Parknumber (``N``) to the file creates the number of child directories named ``0`` 267b1840272SSeongJae Parkto ``N-1``. Each directory represents each DAMON-based operation scheme. 268b1840272SSeongJae Park 269b1840272SSeongJae Parkschemes/<N>/ 270b1840272SSeongJae Park------------ 271b1840272SSeongJae Park 2727f0a86f3SSeongJae ParkIn each scheme directory, five directories (``access_pattern``, ``quotas``, 2739b7f9322SSeongJae Park``watermarks``, ``filters``, ``stats``, and ``tried_regions``) and one file 2749b7f9322SSeongJae Park(``action``) exist. 275b1840272SSeongJae Park 27601e08737SSeongJae ParkThe ``action`` file is for setting and getting the scheme's :ref:`action 27701e08737SSeongJae Park<damon_design_damos_action>`. The keywords that can be written to and read 27801e08737SSeongJae Parkfrom the file and their meaning are as below. 279b1840272SSeongJae Park 2809a47c411SSeongJae ParkNote that support of each action depends on the running DAMON operations set 281cc5ece59SSeongJae Park:ref:`implementation <sysfs_contexts>`. 2829a47c411SSeongJae Park 2839a47c411SSeongJae Park - ``willneed``: Call ``madvise()`` for the region with ``MADV_WILLNEED``. 2849a47c411SSeongJae Park Supported by ``vaddr`` and ``fvaddr`` operations set. 2859a47c411SSeongJae Park - ``cold``: Call ``madvise()`` for the region with ``MADV_COLD``. 2869a47c411SSeongJae Park Supported by ``vaddr`` and ``fvaddr`` operations set. 2879a47c411SSeongJae Park - ``pageout``: Call ``madvise()`` for the region with ``MADV_PAGEOUT``. 2889a47c411SSeongJae Park Supported by ``vaddr``, ``fvaddr`` and ``paddr`` operations set. 2899a47c411SSeongJae Park - ``hugepage``: Call ``madvise()`` for the region with ``MADV_HUGEPAGE``. 2909a47c411SSeongJae Park Supported by ``vaddr`` and ``fvaddr`` operations set. 2919a47c411SSeongJae Park - ``nohugepage``: Call ``madvise()`` for the region with ``MADV_NOHUGEPAGE``. 2929a47c411SSeongJae Park Supported by ``vaddr`` and ``fvaddr`` operations set. 2930bcba960SSeongJae Park - ``lru_prio``: Prioritize the region on its LRU lists. 2949a47c411SSeongJae Park Supported by ``paddr`` operations set. 295b57e39a7SSeongJae Park - ``lru_deprio``: Deprioritize the region on its LRU lists. 2969a47c411SSeongJae Park Supported by ``paddr`` operations set. 2979a47c411SSeongJae Park - ``stat``: Do nothing but count the statistics. 2989a47c411SSeongJae Park Supported by all operations sets. 299b1840272SSeongJae Park 300b1840272SSeongJae Parkschemes/<N>/access_pattern/ 301b1840272SSeongJae Park--------------------------- 302b1840272SSeongJae Park 30301e08737SSeongJae ParkThe directory for the target access :ref:`pattern 30401e08737SSeongJae Park<damon_design_damos_access_pattern>` of the given DAMON-based operation scheme. 305b1840272SSeongJae Park 306b1840272SSeongJae ParkUnder the ``access_pattern`` directory, three directories (``sz``, 307b1840272SSeongJae Park``nr_accesses``, and ``age``) each having two files (``min`` and ``max``) 308b1840272SSeongJae Parkexist. You can set and get the access pattern for the given scheme by writing 309b1840272SSeongJae Parkto and reading from the ``min`` and ``max`` files under ``sz``, 31067c34f6cSSeongJae Park``nr_accesses``, and ``age`` directories, respectively. Note that the ``min`` 31167c34f6cSSeongJae Parkand the ``max`` form a closed interval. 312b1840272SSeongJae Park 313b1840272SSeongJae Parkschemes/<N>/quotas/ 314b1840272SSeongJae Park------------------- 315b1840272SSeongJae Park 31601e08737SSeongJae ParkThe directory for the :ref:`quotas <damon_design_damos_quotas>` of the given 31701e08737SSeongJae ParkDAMON-based operation scheme. 318b1840272SSeongJae Park 319b1840272SSeongJae ParkUnder ``quotas`` directory, three files (``ms``, ``bytes``, 320b1840272SSeongJae Park``reset_interval_ms``) and one directory (``weights``) having three files 321b1840272SSeongJae Park(``sz_permil``, ``nr_accesses_permil``, and ``age_permil``) in it exist. 322b1840272SSeongJae Park 323b1840272SSeongJae ParkYou can set the ``time quota`` in milliseconds, ``size quota`` in bytes, and 324b1840272SSeongJae Park``reset interval`` in milliseconds by writing the values to the three files, 32567c34f6cSSeongJae Parkrespectively. Then, DAMON tries to use only up to ``time quota`` milliseconds 32667c34f6cSSeongJae Parkfor applying the ``action`` to memory regions of the ``access_pattern``, and to 32767c34f6cSSeongJae Parkapply the action to only up to ``bytes`` bytes of memory regions within the 32867c34f6cSSeongJae Park``reset_interval_ms``. Setting both ``ms`` and ``bytes`` zero disables the 32967c34f6cSSeongJae Parkquota limits. 33067c34f6cSSeongJae Park 33167c34f6cSSeongJae ParkYou can also set the :ref:`prioritization weights 33201e08737SSeongJae Park<damon_design_damos_quotas_prioritization>` for size, access frequency, and age 33301e08737SSeongJae Parkin per-thousand unit by writing the values to the three files under the 33401e08737SSeongJae Park``weights`` directory. 335b1840272SSeongJae Park 336b1840272SSeongJae Parkschemes/<N>/watermarks/ 337b1840272SSeongJae Park----------------------- 338b1840272SSeongJae Park 33901e08737SSeongJae ParkThe directory for the :ref:`watermarks <damon_design_damos_watermarks>` of the 34001e08737SSeongJae Parkgiven DAMON-based operation scheme. 341b1840272SSeongJae Park 342b1840272SSeongJae ParkUnder the watermarks directory, five files (``metric``, ``interval_us``, 34301e08737SSeongJae Park``high``, ``mid``, and ``low``) for setting the metric, the time interval 34401e08737SSeongJae Parkbetween check of the metric, and the three watermarks exist. You can set and 345b1840272SSeongJae Parkget the five values by writing to the files, respectively. 346b1840272SSeongJae Park 347b1840272SSeongJae ParkKeywords and meanings of those that can be written to the ``metric`` file are 348b1840272SSeongJae Parkas below. 349b1840272SSeongJae Park 350b1840272SSeongJae Park - none: Ignore the watermarks 351b1840272SSeongJae Park - free_mem_rate: System's free memory rate (per thousand) 352b1840272SSeongJae Park 353b1840272SSeongJae ParkThe ``interval`` should written in microseconds unit. 354b1840272SSeongJae Park 3559b7f9322SSeongJae Parkschemes/<N>/filters/ 3569b7f9322SSeongJae Park-------------------- 3579b7f9322SSeongJae Park 35801e08737SSeongJae ParkThe directory for the :ref:`filters <damon_design_damos_filters>` of the given 35901e08737SSeongJae ParkDAMON-based operation scheme. 3609b7f9322SSeongJae Park 3619b7f9322SSeongJae ParkIn the beginning, this directory has only one file, ``nr_filters``. Writing a 3629b7f9322SSeongJae Parknumber (``N``) to the file creates the number of child directories named ``0`` 3639b7f9322SSeongJae Parkto ``N-1``. Each directory represents each filter. The filters are evaluated 3649b7f9322SSeongJae Parkin the numeric order. 3659b7f9322SSeongJae Park 36641a7ed8cSSeongJae ParkEach filter directory contains six files, namely ``type``, ``matcing``, 36741a7ed8cSSeongJae Park``memcg_path``, ``addr_start``, ``addr_end``, and ``target_idx``. To ``type`` 36841a7ed8cSSeongJae Parkfile, you can write one of four special keywords: ``anon`` for anonymous pages, 36941a7ed8cSSeongJae Park``memcg`` for specific memory cgroup, ``addr`` for specific address range (an 37041a7ed8cSSeongJae Parkopen-ended interval), or ``target`` for specific DAMON monitoring target 37141a7ed8cSSeongJae Parkfiltering. In case of the memory cgroup filtering, you can specify the memory 37241a7ed8cSSeongJae Parkcgroup of the interest by writing the path of the memory cgroup from the 37341a7ed8cSSeongJae Parkcgroups mount point to ``memcg_path`` file. In case of the address range 37441a7ed8cSSeongJae Parkfiltering, you can specify the start and end address of the range to 37541a7ed8cSSeongJae Park``addr_start`` and ``addr_end`` files, respectively. For the DAMON monitoring 37641a7ed8cSSeongJae Parktarget filtering, you can specify the index of the target between the list of 37741a7ed8cSSeongJae Parkthe DAMON context's monitoring targets list to ``target_idx`` file. You can 37841a7ed8cSSeongJae Parkwrite ``Y`` or ``N`` to ``matching`` file to filter out pages that does or does 37941a7ed8cSSeongJae Parknot match to the type, respectively. Then, the scheme's action will not be 38041a7ed8cSSeongJae Parkapplied to the pages that specified to be filtered out. 3819b7f9322SSeongJae Park 3829b7f9322SSeongJae ParkFor example, below restricts a DAMOS action to be applied to only non-anonymous 3839b7f9322SSeongJae Parkpages of all memory cgroups except ``/having_care_already``.:: 3849b7f9322SSeongJae Park 3859b7f9322SSeongJae Park # echo 2 > nr_filters 3869b7f9322SSeongJae Park # # filter out anonymous pages 3879b7f9322SSeongJae Park echo anon > 0/type 3889b7f9322SSeongJae Park echo Y > 0/matching 3899b7f9322SSeongJae Park # # further filter out all cgroups except one at '/having_care_already' 3909b7f9322SSeongJae Park echo memcg > 1/type 3919b7f9322SSeongJae Park echo /having_care_already > 1/memcg_path 392*fe4549b1SSeongJae Park echo Y > 1/matching 3939b7f9322SSeongJae Park 394375af850SSeongJae ParkNote that ``anon`` and ``memcg`` filters are currently supported only when 395375af850SSeongJae Park``paddr`` `implementation <sysfs_contexts>` is being used. 396375af850SSeongJae Park 39741a7ed8cSSeongJae ParkAlso, memory regions that are filtered out by ``addr`` or ``target`` filters 39841a7ed8cSSeongJae Parkare not counted as the scheme has tried to those, while regions that filtered 39941a7ed8cSSeongJae Parkout by other type filters are counted as the scheme has tried to. The 40041a7ed8cSSeongJae Parkdifference is applied to :ref:`stats <damos_stats>` and 40141a7ed8cSSeongJae Park:ref:`tried regions <sysfs_schemes_tried_regions>`. 4029b7f9322SSeongJae Park 403b1840272SSeongJae Park.. _sysfs_schemes_stats: 404b1840272SSeongJae Park 405b1840272SSeongJae Parkschemes/<N>/stats/ 406b1840272SSeongJae Park------------------ 407b1840272SSeongJae Park 408b1840272SSeongJae ParkDAMON counts the total number and bytes of regions that each scheme is tried to 409b1840272SSeongJae Parkbe applied, the two numbers for the regions that each scheme is successfully 410b1840272SSeongJae Parkapplied, and the total number of the quota limit exceeds. This statistics can 411b1840272SSeongJae Parkbe used for online analysis or tuning of the schemes. 412b1840272SSeongJae Park 413b1840272SSeongJae ParkThe statistics can be retrieved by reading the files under ``stats`` directory 414b1840272SSeongJae Park(``nr_tried``, ``sz_tried``, ``nr_applied``, ``sz_applied``, and 415b1840272SSeongJae Park``qt_exceeds``), respectively. The files are not updated in real time, so you 416d56b699dSBjorn Helgaasshould ask DAMON sysfs interface to update the content of the files for the 417b1840272SSeongJae Parkstats by writing a special keyword, ``update_schemes_stats`` to the relevant 418b1840272SSeongJae Park``kdamonds/<N>/state`` file. 419b1840272SSeongJae Park 4207f0a86f3SSeongJae Park.. _sysfs_schemes_tried_regions: 4217f0a86f3SSeongJae Park 4227f0a86f3SSeongJae Parkschemes/<N>/tried_regions/ 4237f0a86f3SSeongJae Park-------------------------- 4247f0a86f3SSeongJae Park 425ea7f03a4SSeongJae ParkThis directory initially has one file, ``total_bytes``. 426ea7f03a4SSeongJae Park 4277f0a86f3SSeongJae ParkWhen a special keyword, ``update_schemes_tried_regions``, is written to the 428ea7f03a4SSeongJae Parkrelevant ``kdamonds/<N>/state`` file, DAMON updates the ``total_bytes`` file so 429ea7f03a4SSeongJae Parkthat reading it returns the total size of the scheme tried regions, and creates 430ea7f03a4SSeongJae Parkdirectories named integer starting from ``0`` under this directory. Each 431ea7f03a4SSeongJae Parkdirectory contains files exposing detailed information about each of the memory 432ea7f03a4SSeongJae Parkregion that the corresponding scheme's ``action`` has tried to be applied under 433ea7f03a4SSeongJae Parkthis directory, during next :ref:`aggregation interval 434ea7f03a4SSeongJae Park<sysfs_monitoring_attrs>`. The information includes address range, 435ea7f03a4SSeongJae Park``nr_accesses``, and ``age`` of the region. 436ea7f03a4SSeongJae Park 437ea7f03a4SSeongJae ParkWriting ``update_schemes_tried_bytes`` to the relevant ``kdamonds/<N>/state`` 438ea7f03a4SSeongJae Parkfile will only update the ``total_bytes`` file, and will not create the 439ea7f03a4SSeongJae Parksubdirectories. 4407f0a86f3SSeongJae Park 4417f0a86f3SSeongJae ParkThe directories will be removed when another special keyword, 4427f0a86f3SSeongJae Park``clear_schemes_tried_regions``, is written to the relevant 4437f0a86f3SSeongJae Park``kdamonds/<N>/state`` file. 4447f0a86f3SSeongJae Park 445ff71f26fSSeongJae ParkThe expected usage of this directory is investigations of schemes' behaviors, 446ff71f26fSSeongJae Parkand query-like efficient data access monitoring results retrievals. For the 447ff71f26fSSeongJae Parklatter use case, in particular, users can set the ``action`` as ``stat`` and 448ff71f26fSSeongJae Parkset the ``access pattern`` as their interested pattern that they want to query. 449ff71f26fSSeongJae Park 4507f0a86f3SSeongJae Parktried_regions/<N>/ 4517f0a86f3SSeongJae Park------------------ 4527f0a86f3SSeongJae Park 4537f0a86f3SSeongJae ParkIn each region directory, you will find four files (``start``, ``end``, 4547f0a86f3SSeongJae Park``nr_accesses``, and ``age``). Reading the files will show the start and end 4557f0a86f3SSeongJae Parkaddresses, ``nr_accesses``, and ``age`` of the region that corresponding 4567f0a86f3SSeongJae ParkDAMON-based operation scheme ``action`` has tried to be applied. 4577f0a86f3SSeongJae Park 458b1840272SSeongJae ParkExample 459b1840272SSeongJae Park~~~~~~~ 460b1840272SSeongJae Park 461b1840272SSeongJae ParkBelow commands applies a scheme saying "If a memory region of size in [4KiB, 462b1840272SSeongJae Park8KiB] is showing accesses per aggregate interval in [0, 5] for aggregate 463b1840272SSeongJae Parkinterval in [10, 20], page out the region. For the paging out, use only up to 464b1840272SSeongJae Park10ms per second, and also don't page out more than 1GiB per second. Under the 465b1840272SSeongJae Parklimitation, page out memory regions having longer age first. Also, check the 466b1840272SSeongJae Parkfree memory rate of the system every 5 seconds, start the monitoring and paging 467b1840272SSeongJae Parkout when the free memory rate becomes lower than 50%, but stop it if the free 468b1840272SSeongJae Parkmemory rate becomes larger than 60%, or lower than 30%". :: 469b1840272SSeongJae Park 470b1840272SSeongJae Park # cd <sysfs>/kernel/mm/damon/admin 471b1840272SSeongJae Park # # populate directories 472b1840272SSeongJae Park # echo 1 > kdamonds/nr_kdamonds; echo 1 > kdamonds/0/contexts/nr_contexts; 473b1840272SSeongJae Park # echo 1 > kdamonds/0/contexts/0/schemes/nr_schemes 474b1840272SSeongJae Park # cd kdamonds/0/contexts/0/schemes/0 475b1840272SSeongJae Park # # set the basic access pattern and the action 476465d0eb0SKairui Song # echo 4096 > access_pattern/sz/min 477465d0eb0SKairui Song # echo 8192 > access_pattern/sz/max 478465d0eb0SKairui Song # echo 0 > access_pattern/nr_accesses/min 479465d0eb0SKairui Song # echo 5 > access_pattern/nr_accesses/max 480465d0eb0SKairui Song # echo 10 > access_pattern/age/min 481465d0eb0SKairui Song # echo 20 > access_pattern/age/max 482b1840272SSeongJae Park # echo pageout > action 483b1840272SSeongJae Park # # set quotas 484b1840272SSeongJae Park # echo 10 > quotas/ms 485b1840272SSeongJae Park # echo $((1024*1024*1024)) > quotas/bytes 486b1840272SSeongJae Park # echo 1000 > quotas/reset_interval_ms 487b1840272SSeongJae Park # # set watermark 488b1840272SSeongJae Park # echo free_mem_rate > watermarks/metric 489b1840272SSeongJae Park # echo 5000000 > watermarks/interval_us 490b1840272SSeongJae Park # echo 600 > watermarks/high 491b1840272SSeongJae Park # echo 500 > watermarks/mid 492b1840272SSeongJae Park # echo 300 > watermarks/low 493b1840272SSeongJae Park 494b1840272SSeongJae ParkPlease note that it's highly recommended to use user space tools like `damo 495b1840272SSeongJae Park<https://github.com/awslabs/damo>`_ rather than manually reading and writing 496b1840272SSeongJae Parkthe files as above. Above is only for an example. 49735b43d40SSeongJae Park 49835b43d40SSeongJae Park.. _debugfs_interface: 499c4ba6014SSeongJae Park 5005445fcbcSSeongJae Parkdebugfs Interface (DEPRECATED!) 5015445fcbcSSeongJae Park=============================== 502c4ba6014SSeongJae Park 503f1f3afd5SSeongJae Park.. note:: 504f1f3afd5SSeongJae Park 5055445fcbcSSeongJae Park THIS IS DEPRECATED! 5065445fcbcSSeongJae Park 5075445fcbcSSeongJae Park DAMON debugfs interface is deprecated, so users should move to the 5085445fcbcSSeongJae Park :ref:`sysfs interface <sysfs_interface>`. If you depend on this and cannot 5095445fcbcSSeongJae Park move, please report your usecase to damon@lists.linux.dev and 5105445fcbcSSeongJae Park linux-mm@kvack.org. 511f1f3afd5SSeongJae Park 512995d739cSSeongJae ParkDAMON exports eight files, ``attrs``, ``target_ids``, ``init_regions``, 513995d739cSSeongJae Park``schemes``, ``monitor_on``, ``kdamond_pid``, ``mk_contexts`` and 514995d739cSSeongJae Park``rm_contexts`` under its debugfs directory, ``<debugfs>/damon/``. 515c4ba6014SSeongJae Park 516c4ba6014SSeongJae Park 517c4ba6014SSeongJae ParkAttributes 518c4ba6014SSeongJae Park---------- 519c4ba6014SSeongJae Park 520c4ba6014SSeongJae ParkUsers can get and set the ``sampling interval``, ``aggregation interval``, 5214c1f287fSSeongJae Park``update interval``, and min/max number of monitoring target regions by 522c4ba6014SSeongJae Parkreading from and writing to the ``attrs`` file. To know about the monitoring 523ee65728eSMike Rapoportattributes in detail, please refer to the :doc:`/mm/damon/design`. For 524c4ba6014SSeongJae Parkexample, below commands set those values to 5 ms, 100 ms, 1,000 ms, 10 and 525c4ba6014SSeongJae Park1000, and then check it again:: 526c4ba6014SSeongJae Park 527c4ba6014SSeongJae Park # cd <debugfs>/damon 528c4ba6014SSeongJae Park # echo 5000 100000 1000000 10 1000 > attrs 529c4ba6014SSeongJae Park # cat attrs 530c4ba6014SSeongJae Park 5000 100000 1000000 10 1000 531c4ba6014SSeongJae Park 532c4ba6014SSeongJae Park 533c4ba6014SSeongJae ParkTarget IDs 534c4ba6014SSeongJae Park---------- 535c4ba6014SSeongJae Park 536c4ba6014SSeongJae ParkSome types of address spaces supports multiple monitoring target. For example, 537c4ba6014SSeongJae Parkthe virtual memory address spaces monitoring can have multiple processes as the 538c4ba6014SSeongJae Parkmonitoring targets. Users can set the targets by writing relevant id values of 539c4ba6014SSeongJae Parkthe targets to, and get the ids of the current targets by reading from the 540c4ba6014SSeongJae Park``target_ids`` file. In case of the virtual address spaces monitoring, the 541c4ba6014SSeongJae Parkvalues should be pids of the monitoring target processes. For example, below 542c4ba6014SSeongJae Parkcommands set processes having pids 42 and 4242 as the monitoring targets and 543c4ba6014SSeongJae Parkcheck it again:: 544c4ba6014SSeongJae Park 545c4ba6014SSeongJae Park # cd <debugfs>/damon 546c4ba6014SSeongJae Park # echo 42 4242 > target_ids 547c4ba6014SSeongJae Park # cat target_ids 548c4ba6014SSeongJae Park 42 4242 549c4ba6014SSeongJae Park 550c6380721SSeongJae ParkUsers can also monitor the physical memory address space of the system by 551c6380721SSeongJae Parkwriting a special keyword, "``paddr\n``" to the file. Because physical address 552c6380721SSeongJae Parkspace monitoring doesn't support multiple targets, reading the file will show a 553c6380721SSeongJae Parkfake value, ``42``, as below:: 554c6380721SSeongJae Park 555c6380721SSeongJae Park # cd <debugfs>/damon 556c6380721SSeongJae Park # echo paddr > target_ids 557c6380721SSeongJae Park # cat target_ids 558c6380721SSeongJae Park 42 559c6380721SSeongJae Park 560c4ba6014SSeongJae ParkNote that setting the target ids doesn't start the monitoring. 561c4ba6014SSeongJae Park 562c4ba6014SSeongJae Park 563c2fe4987SSeongJae ParkInitial Monitoring Target Regions 564c2fe4987SSeongJae Park--------------------------------- 565c2fe4987SSeongJae Park 566c6380721SSeongJae ParkIn case of the virtual address space monitoring, DAMON automatically sets and 567c6380721SSeongJae Parkupdates the monitoring target regions so that entire memory mappings of target 568c2fe4987SSeongJae Parkprocesses can be covered. However, users can want to limit the monitoring 569c2fe4987SSeongJae Parkregion to specific address ranges, such as the heap, the stack, or specific 570c2fe4987SSeongJae Parkfile-mapped area. Or, some users can know the initial access pattern of their 571c2fe4987SSeongJae Parkworkloads and therefore want to set optimal initial regions for the 'adaptive 572c2fe4987SSeongJae Parkregions adjustment'. 573c2fe4987SSeongJae Park 574c6380721SSeongJae ParkIn contrast, DAMON do not automatically sets and updates the monitoring target 575c6380721SSeongJae Parkregions in case of physical memory monitoring. Therefore, users should set the 576c6380721SSeongJae Parkmonitoring target regions by themselves. 577c6380721SSeongJae Park 578c2fe4987SSeongJae ParkIn such cases, users can explicitly set the initial monitoring target regions 5791b016638SSeongJae Parkas they want, by writing proper values to the ``init_regions`` file. The input 5801b016638SSeongJae Parkshould be a sequence of three integers separated by white spaces that represent 5811b016638SSeongJae Parkone region in below form.:: 582c2fe4987SSeongJae Park 5838041c87bSSeongJae Park <target idx> <start address> <end address> 584c2fe4987SSeongJae Park 5858041c87bSSeongJae ParkThe ``target idx`` should be the index of the target in ``target_ids`` file, 5868041c87bSSeongJae Parkstarting from ``0``, and the regions should be passed in address order. For 5878041c87bSSeongJae Parkexample, below commands will set a couple of address ranges, ``1-100`` and 5888041c87bSSeongJae Park``100-200`` as the initial monitoring target region of pid 42, which is the 5898041c87bSSeongJae Parkfirst one (index ``0``) in ``target_ids``, and another couple of address 5908041c87bSSeongJae Parkranges, ``20-40`` and ``50-100`` as that of pid 4242, which is the second one 5918041c87bSSeongJae Park(index ``1``) in ``target_ids``.:: 592c2fe4987SSeongJae Park 593c2fe4987SSeongJae Park # cd <debugfs>/damon 5948041c87bSSeongJae Park # cat target_ids 5958041c87bSSeongJae Park 42 4242 5961b016638SSeongJae Park # echo "0 1 100 \ 5971b016638SSeongJae Park 0 100 200 \ 5981b016638SSeongJae Park 1 20 40 \ 5998041c87bSSeongJae Park 1 50 100" > init_regions 600c2fe4987SSeongJae Park 601c2fe4987SSeongJae ParkNote that this sets the initial monitoring target regions only. In case of 602c2fe4987SSeongJae Parkvirtual memory monitoring, DAMON will automatically updates the boundary of the 6034c1f287fSSeongJae Parkregions after one ``update interval``. Therefore, users should set the 6044c1f287fSSeongJae Park``update interval`` large enough in this case, if they don't want the 605c2fe4987SSeongJae Parkupdate. 606c2fe4987SSeongJae Park 607c2fe4987SSeongJae Park 60868536f8eSSeongJae ParkSchemes 60968536f8eSSeongJae Park------- 61068536f8eSSeongJae Park 61101e08737SSeongJae ParkUsers can get and set the DAMON-based operation :ref:`schemes 61201e08737SSeongJae Park<damon_design_damos>` by reading from and writing to ``schemes`` debugfs file. 61301e08737SSeongJae ParkReading the file also shows the statistics of each scheme. To the file, each 61401e08737SSeongJae Parkof the schemes should be represented in each line in below form:: 61568536f8eSSeongJae Park 6166322416bSSeongJae Park <target access pattern> <action> <quota> <watermarks> 61768536f8eSSeongJae Park 6186322416bSSeongJae ParkYou can disable schemes by simply writing an empty string to the file. 6196322416bSSeongJae Park 6206322416bSSeongJae ParkTarget Access Pattern 6216322416bSSeongJae Park~~~~~~~~~~~~~~~~~~~~~ 6226322416bSSeongJae Park 62301e08737SSeongJae ParkThe target access :ref:`pattern <damon_design_damos_access_pattern>` of the 62401e08737SSeongJae Parkscheme. The ``<target access pattern>`` is constructed with three ranges in 62501e08737SSeongJae Parkbelow form:: 6266322416bSSeongJae Park 6276322416bSSeongJae Park min-size max-size min-acc max-acc min-age max-age 6286322416bSSeongJae Park 6296322416bSSeongJae ParkSpecifically, bytes for the size of regions (``min-size`` and ``max-size``), 6306322416bSSeongJae Parknumber of monitored accesses per aggregate interval for access frequency 6316322416bSSeongJae Park(``min-acc`` and ``max-acc``), number of aggregate intervals for the age of 6326322416bSSeongJae Parkregions (``min-age`` and ``max-age``) are specified. Note that the ranges are 6336322416bSSeongJae Parkclosed interval. 6346322416bSSeongJae Park 6356322416bSSeongJae ParkAction 6366322416bSSeongJae Park~~~~~~ 6376322416bSSeongJae Park 63801e08737SSeongJae ParkThe ``<action>`` is a predefined integer for memory management :ref:`actions 63901e08737SSeongJae Park<damon_design_damos_action>`. The supported numbers and their meanings are as 64001e08737SSeongJae Parkbelow. 64168536f8eSSeongJae Park 6429a47c411SSeongJae Park - 0: Call ``madvise()`` for the region with ``MADV_WILLNEED``. Ignored if 6439a47c411SSeongJae Park ``target`` is ``paddr``. 6449a47c411SSeongJae Park - 1: Call ``madvise()`` for the region with ``MADV_COLD``. Ignored if 6459a47c411SSeongJae Park ``target`` is ``paddr``. 6469a47c411SSeongJae Park - 2: Call ``madvise()`` for the region with ``MADV_PAGEOUT``. 6479a47c411SSeongJae Park - 3: Call ``madvise()`` for the region with ``MADV_HUGEPAGE``. Ignored if 6489a47c411SSeongJae Park ``target`` is ``paddr``. 6499a47c411SSeongJae Park - 4: Call ``madvise()`` for the region with ``MADV_NOHUGEPAGE``. Ignored if 6509a47c411SSeongJae Park ``target`` is ``paddr``. 65168536f8eSSeongJae Park - 5: Do nothing but count the statistics 65268536f8eSSeongJae Park 6536322416bSSeongJae ParkQuota 6546322416bSSeongJae Park~~~~~ 6556322416bSSeongJae Park 65601e08737SSeongJae ParkUsers can set the :ref:`quotas <damon_design_damos_quotas>` of the given scheme 65701e08737SSeongJae Parkvia the ``<quota>`` in below form:: 6586322416bSSeongJae Park 6596322416bSSeongJae Park <ms> <sz> <reset interval> <priority weights> 6606322416bSSeongJae Park 6616322416bSSeongJae ParkThis makes DAMON to try to use only up to ``<ms>`` milliseconds for applying 6626322416bSSeongJae Parkthe action to memory regions of the ``target access pattern`` within the 6636322416bSSeongJae Park``<reset interval>`` milliseconds, and to apply the action to only up to 6646322416bSSeongJae Park``<sz>`` bytes of memory regions within the ``<reset interval>``. Setting both 6656322416bSSeongJae Park``<ms>`` and ``<sz>`` zero disables the quota limits. 6666322416bSSeongJae Park 66701e08737SSeongJae ParkFor the :ref:`prioritization <damon_design_damos_quotas_prioritization>`, users 66801e08737SSeongJae Parkcan set the weights for the three properties in ``<priority weights>`` in below 66901e08737SSeongJae Parkform:: 6706322416bSSeongJae Park 6716322416bSSeongJae Park <size weight> <access frequency weight> <age weight> 6726322416bSSeongJae Park 6736322416bSSeongJae ParkWatermarks 6746322416bSSeongJae Park~~~~~~~~~~ 6756322416bSSeongJae Park 67601e08737SSeongJae ParkUsers can specify :ref:`watermarks <damon_design_damos_watermarks>` of the 67701e08737SSeongJae Parkgiven scheme via ``<watermarks>`` in below form:: 6786322416bSSeongJae Park 6796322416bSSeongJae Park <metric> <check interval> <high mark> <middle mark> <low mark> 6806322416bSSeongJae Park 6816322416bSSeongJae Park``<metric>`` is a predefined integer for the metric to be checked. The 6826322416bSSeongJae Parksupported numbers and their meanings are as below. 6836322416bSSeongJae Park 6846322416bSSeongJae Park - 0: Ignore the watermarks 6856322416bSSeongJae Park - 1: System's free memory rate (per thousand) 6866322416bSSeongJae Park 6876322416bSSeongJae ParkThe value of the metric is checked every ``<check interval>`` microseconds. 6886322416bSSeongJae Park 6896322416bSSeongJae ParkIf the value is higher than ``<high mark>`` or lower than ``<low mark>``, the 6906322416bSSeongJae Parkscheme is deactivated. If the value is lower than ``<mid mark>``, the scheme 6916322416bSSeongJae Parkis activated. 6926322416bSSeongJae Park 6934492bf45SSeongJae Park.. _damos_stats: 6944492bf45SSeongJae Park 6956322416bSSeongJae ParkStatistics 6966322416bSSeongJae Park~~~~~~~~~~ 6976322416bSSeongJae Park 698dbcb9b9fSSeongJae ParkIt also counts the total number and bytes of regions that each scheme is tried 699dbcb9b9fSSeongJae Parkto be applied, the two numbers for the regions that each scheme is successfully 700dbcb9b9fSSeongJae Parkapplied, and the total number of the quota limit exceeds. This statistics can 701dbcb9b9fSSeongJae Parkbe used for online analysis or tuning of the schemes. 7026322416bSSeongJae Park 7036322416bSSeongJae ParkThe statistics can be shown by reading the ``schemes`` file. Reading the file 704dbcb9b9fSSeongJae Parkwill show each scheme you entered in each line, and the five numbers for the 7056322416bSSeongJae Parkstatistics will be added at the end of each line. 7066322416bSSeongJae Park 7076322416bSSeongJae ParkExample 7086322416bSSeongJae Park~~~~~~~ 7096322416bSSeongJae Park 7106322416bSSeongJae ParkBelow commands applies a scheme saying "If a memory region of size in [4KiB, 7116322416bSSeongJae Park8KiB] is showing accesses per aggregate interval in [0, 5] for aggregate 7126322416bSSeongJae Parkinterval in [10, 20], page out the region. For the paging out, use only up to 7136322416bSSeongJae Park10ms per second, and also don't page out more than 1GiB per second. Under the 7146322416bSSeongJae Parklimitation, page out memory regions having longer age first. Also, check the 7156322416bSSeongJae Parkfree memory rate of the system every 5 seconds, start the monitoring and paging 7166322416bSSeongJae Parkout when the free memory rate becomes lower than 50%, but stop it if the free 7176322416bSSeongJae Parkmemory rate becomes larger than 60%, or lower than 30%".:: 71868536f8eSSeongJae Park 71968536f8eSSeongJae Park # cd <debugfs>/damon 7206322416bSSeongJae Park # scheme="4096 8192 0 5 10 20 2" # target access pattern and action 7216322416bSSeongJae Park # scheme+=" 10 $((1024*1024*1024)) 1000" # quotas 7226322416bSSeongJae Park # scheme+=" 0 0 100" # prioritization weights 7236322416bSSeongJae Park # scheme+=" 1 5000000 600 500 300" # watermarks 7246322416bSSeongJae Park # echo "$scheme" > schemes 72568536f8eSSeongJae Park 72668536f8eSSeongJae Park 727c4ba6014SSeongJae ParkTurning On/Off 728c4ba6014SSeongJae Park-------------- 729c4ba6014SSeongJae Park 730c4ba6014SSeongJae ParkSetting the files as described above doesn't incur effect unless you explicitly 731c4ba6014SSeongJae Parkstart the monitoring. You can start, stop, and check the current status of the 732c4ba6014SSeongJae Parkmonitoring by writing to and reading from the ``monitor_on`` file. Writing 733c4ba6014SSeongJae Park``on`` to the file starts the monitoring of the targets with the attributes. 734c4ba6014SSeongJae ParkWriting ``off`` to the file stops those. DAMON also stops if every target 735c4ba6014SSeongJae Parkprocess is terminated. Below example commands turn on, off, and check the 736c4ba6014SSeongJae Parkstatus of DAMON:: 737c4ba6014SSeongJae Park 738c4ba6014SSeongJae Park # cd <debugfs>/damon 739c4ba6014SSeongJae Park # echo on > monitor_on 740c4ba6014SSeongJae Park # echo off > monitor_on 741c4ba6014SSeongJae Park # cat monitor_on 742c4ba6014SSeongJae Park off 743c4ba6014SSeongJae Park 744c4ba6014SSeongJae ParkPlease note that you cannot write to the above-mentioned debugfs files while 745c4ba6014SSeongJae Parkthe monitoring is turned on. If you write to the files while DAMON is running, 746c4ba6014SSeongJae Parkan error code such as ``-EBUSY`` will be returned. 747c4ba6014SSeongJae Park 748c4ba6014SSeongJae Park 749995d739cSSeongJae ParkMonitoring Thread PID 750995d739cSSeongJae Park--------------------- 751995d739cSSeongJae Park 752995d739cSSeongJae ParkDAMON does requested monitoring with a kernel thread called ``kdamond``. You 753995d739cSSeongJae Parkcan get the pid of the thread by reading the ``kdamond_pid`` file. When the 754995d739cSSeongJae Parkmonitoring is turned off, reading the file returns ``none``. :: 755995d739cSSeongJae Park 756995d739cSSeongJae Park # cd <debugfs>/damon 757995d739cSSeongJae Park # cat monitor_on 758995d739cSSeongJae Park off 759995d739cSSeongJae Park # cat kdamond_pid 760995d739cSSeongJae Park none 761995d739cSSeongJae Park # echo on > monitor_on 762995d739cSSeongJae Park # cat kdamond_pid 763995d739cSSeongJae Park 18594 764995d739cSSeongJae Park 765995d739cSSeongJae Park 766995d739cSSeongJae ParkUsing Multiple Monitoring Threads 767995d739cSSeongJae Park--------------------------------- 768995d739cSSeongJae Park 769995d739cSSeongJae ParkOne ``kdamond`` thread is created for each monitoring context. You can create 770995d739cSSeongJae Parkand remove monitoring contexts for multiple ``kdamond`` required use case using 771995d739cSSeongJae Parkthe ``mk_contexts`` and ``rm_contexts`` files. 772995d739cSSeongJae Park 773995d739cSSeongJae ParkWriting the name of the new context to the ``mk_contexts`` file creates a 774995d739cSSeongJae Parkdirectory of the name on the DAMON debugfs directory. The directory will have 775995d739cSSeongJae ParkDAMON debugfs files for the context. :: 776995d739cSSeongJae Park 777995d739cSSeongJae Park # cd <debugfs>/damon 778995d739cSSeongJae Park # ls foo 779995d739cSSeongJae Park # ls: cannot access 'foo': No such file or directory 780995d739cSSeongJae Park # echo foo > mk_contexts 781995d739cSSeongJae Park # ls foo 782995d739cSSeongJae Park # attrs init_regions kdamond_pid schemes target_ids 783995d739cSSeongJae Park 784995d739cSSeongJae ParkIf the context is not needed anymore, you can remove it and the corresponding 785995d739cSSeongJae Parkdirectory by putting the name of the context to the ``rm_contexts`` file. :: 786995d739cSSeongJae Park 787995d739cSSeongJae Park # echo foo > rm_contexts 788995d739cSSeongJae Park # ls foo 789995d739cSSeongJae Park # ls: cannot access 'foo': No such file or directory 790995d739cSSeongJae Park 791995d739cSSeongJae ParkNote that ``mk_contexts``, ``rm_contexts``, and ``monitor_on`` files are in the 792995d739cSSeongJae Parkroot directory only. 793995d739cSSeongJae Park 794995d739cSSeongJae Park 7954492bf45SSeongJae Park.. _tracepoint: 7964492bf45SSeongJae Park 797c4ba6014SSeongJae ParkTracepoint for Monitoring Results 798c4ba6014SSeongJae Park================================= 799c4ba6014SSeongJae Park 800ff71f26fSSeongJae ParkUsers can get the monitoring results via the :ref:`tried_regions 801ff71f26fSSeongJae Park<sysfs_schemes_tried_regions>` or a tracepoint, ``damon:damon_aggregated``. 802ff71f26fSSeongJae ParkWhile the tried regions directory is useful for getting a snapshot, the 803ff71f26fSSeongJae Parktracepoint is useful for getting a full record of the results. While the 804ff71f26fSSeongJae Parkmonitoring is turned on, you could record the tracepoint events and show 805ff71f26fSSeongJae Parkresults using tracepoint supporting tools like ``perf``. For example:: 806c4ba6014SSeongJae Park 807c4ba6014SSeongJae Park # echo on > monitor_on 808c4ba6014SSeongJae Park # perf record -e damon:damon_aggregated & 809c4ba6014SSeongJae Park # sleep 5 810c4ba6014SSeongJae Park # kill 9 $(pidof perf) 811c4ba6014SSeongJae Park # echo off > monitor_on 812c4ba6014SSeongJae Park # perf script 813