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.* 10*23a425aaSSeongJae Park `This <https://github.com/damonitor/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 15*23a425aaSSeongJae Park <https://github.com/damonitor/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 22*23a425aaSSeongJae Park <https://github.com/damonitor/damo>`_ is one example of such programs. 23c4ba6014SSeongJae Park- *Kernel Space Programming Interface.* 24ee65728eSMike Rapoport :doc:`This </mm/damon/api>` is for kernel space programmers. Using this, 2535b43d40SSeongJae Park users can utilize every feature of DAMON most flexibly and efficiently by 2635b43d40SSeongJae Park writing kernel space DAMON application programs for you. You can even extend 2735b43d40SSeongJae Park DAMON for various address spaces. For detail, please refer to the interface 28ee65728eSMike Rapoport :doc:`document </mm/damon/api>`. 294f711278SSeongJae Park- *debugfs interface. (DEPRECATED!)* 304f711278SSeongJae Park :ref:`This <debugfs_interface>` is almost identical to :ref:`sysfs interface 314f711278SSeongJae Park <sysfs_interface>`. This is deprecated, so users should move to the 324f711278SSeongJae Park :ref:`sysfs interface <sysfs_interface>`. If you depend on this and cannot 334f711278SSeongJae Park move, please report your usecase to damon@lists.linux.dev and 344f711278SSeongJae Park linux-mm@kvack.org. 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 629c8c315dSSeongJae Parkcomma (","). 63b1840272SSeongJae Park 649c8c315dSSeongJae Park.. parsed-literal:: 659c8c315dSSeongJae Park 669c8c315dSSeongJae Park :ref:`/sys/kernel/mm/damon <sysfs_root>`/admin 679c8c315dSSeongJae Park │ :ref:`kdamonds <sysfs_kdamonds>`/nr_kdamonds 689c8c315dSSeongJae Park │ │ :ref:`0 <sysfs_kdamond>`/state,pid 699c8c315dSSeongJae Park │ │ │ :ref:`contexts <sysfs_contexts>`/nr_contexts 709c8c315dSSeongJae Park │ │ │ │ :ref:`0 <sysfs_context>`/avail_operations,operations 719c8c315dSSeongJae Park │ │ │ │ │ :ref:`monitoring_attrs <sysfs_monitoring_attrs>`/ 72b1840272SSeongJae Park │ │ │ │ │ │ intervals/sample_us,aggr_us,update_us 73b1840272SSeongJae Park │ │ │ │ │ │ nr_regions/min,max 749c8c315dSSeongJae Park │ │ │ │ │ :ref:`targets <sysfs_targets>`/nr_targets 759c8c315dSSeongJae Park │ │ │ │ │ │ :ref:`0 <sysfs_target>`/pid_target 769c8c315dSSeongJae Park │ │ │ │ │ │ │ :ref:`regions <sysfs_regions>`/nr_regions 779c8c315dSSeongJae Park │ │ │ │ │ │ │ │ :ref:`0 <sysfs_region>`/start,end 78b1840272SSeongJae Park │ │ │ │ │ │ │ │ ... 79b1840272SSeongJae Park │ │ │ │ │ │ ... 809c8c315dSSeongJae Park │ │ │ │ │ :ref:`schemes <sysfs_schemes>`/nr_schemes 8183d0d46aSHonggyu Kim │ │ │ │ │ │ :ref:`0 <sysfs_scheme>`/action,target_nid,apply_interval_us 829c8c315dSSeongJae Park │ │ │ │ │ │ │ :ref:`access_pattern <sysfs_access_pattern>`/ 83b1840272SSeongJae Park │ │ │ │ │ │ │ │ sz/min,max 84b1840272SSeongJae Park │ │ │ │ │ │ │ │ nr_accesses/min,max 85b1840272SSeongJae Park │ │ │ │ │ │ │ │ age/min,max 86a6068d6dSSeongJae Park │ │ │ │ │ │ │ :ref:`quotas <sysfs_quotas>`/ms,bytes,reset_interval_ms,effective_bytes 87b1840272SSeongJae Park │ │ │ │ │ │ │ │ weights/sz_permil,nr_accesses_permil,age_permil 889c8c315dSSeongJae Park │ │ │ │ │ │ │ │ :ref:`goals <sysfs_schemes_quota_goals>`/nr_goals 8957e88e86SSeongJae Park │ │ │ │ │ │ │ │ │ 0/target_metric,target_value,current_value 909c8c315dSSeongJae Park │ │ │ │ │ │ │ :ref:`watermarks <sysfs_watermarks>`/metric,interval_us,high,mid,low 919c8c315dSSeongJae Park │ │ │ │ │ │ │ :ref:`filters <sysfs_filters>`/nr_filters 929b7f9322SSeongJae Park │ │ │ │ │ │ │ │ 0/type,matching,memcg_id 939c8c315dSSeongJae Park │ │ │ │ │ │ │ :ref:`stats <sysfs_schemes_stats>`/nr_tried,sz_tried,nr_applied,sz_applied,qt_exceeds 949c8c315dSSeongJae Park │ │ │ │ │ │ │ :ref:`tried_regions <sysfs_schemes_tried_regions>`/total_bytes 957f0a86f3SSeongJae Park │ │ │ │ │ │ │ │ 0/start,end,nr_accesses,age 967f0a86f3SSeongJae Park │ │ │ │ │ │ │ │ ... 97b1840272SSeongJae Park │ │ │ │ │ │ ... 98b1840272SSeongJae Park │ │ │ │ ... 99b1840272SSeongJae Park │ │ ... 100b1840272SSeongJae Park 1019c8c315dSSeongJae Park.. _sysfs_root: 1029c8c315dSSeongJae Park 103b1840272SSeongJae ParkRoot 104b1840272SSeongJae Park---- 105b1840272SSeongJae Park 106b1840272SSeongJae ParkThe root of the DAMON sysfs interface is ``<sysfs>/kernel/mm/damon/``, and it 107b1840272SSeongJae Parkhas one directory named ``admin``. The directory contains the files for 108d56b699dSBjorn Helgaasprivileged user space programs' control of DAMON. User space tools or daemons 109b1840272SSeongJae Parkhaving the root permission could use this directory. 110b1840272SSeongJae Park 1119c8c315dSSeongJae Park.. _sysfs_kdamonds: 1129c8c315dSSeongJae Park 113b1840272SSeongJae Parkkdamonds/ 114b1840272SSeongJae Park--------- 115b1840272SSeongJae Park 116b1840272SSeongJae ParkUnder the ``admin`` directory, one directory, ``kdamonds``, which has files for 11746158bf2SSeongJae Parkcontrolling the kdamonds (refer to 11846158bf2SSeongJae Park:ref:`design <damon_design_execution_model_and_data_structures>` for more 11946158bf2SSeongJae Parkdetails) exists. In the beginning, this directory has only one file, 12046158bf2SSeongJae Park``nr_kdamonds``. Writing a number (``N``) to the file creates the number of 12146158bf2SSeongJae Parkchild directories named ``0`` to ``N-1``. Each directory represents each 122b1840272SSeongJae Parkkdamond. 123b1840272SSeongJae Park 1246140edeeSSeongJae Park.. _sysfs_kdamond: 1256140edeeSSeongJae Park 126b1840272SSeongJae Parkkdamonds/<N>/ 127b1840272SSeongJae Park------------- 128b1840272SSeongJae Park 129b1840272SSeongJae ParkIn each kdamond directory, two files (``state`` and ``pid``) and one directory 130b1840272SSeongJae Park(``contexts``) exist. 131b1840272SSeongJae Park 132b1840272SSeongJae ParkReading ``state`` returns ``on`` if the kdamond is currently running, or 133e93b81a3SSeongJae Park``off`` if it is not running. 1346140edeeSSeongJae Park 135e93b81a3SSeongJae ParkUsers can write below commands for the kdamond to the ``state`` file. 1366140edeeSSeongJae Park 137e93b81a3SSeongJae Park- ``on``: Start running. 138e93b81a3SSeongJae Park- ``off``: Stop running. 139e93b81a3SSeongJae Park- ``commit``: Read the user inputs in the sysfs files except ``state`` file 140e93b81a3SSeongJae Park again. 141e93b81a3SSeongJae Park- ``commit_schemes_quota_goals``: Read the DAMON-based operation schemes' 142e93b81a3SSeongJae Park :ref:`quota goals <sysfs_schemes_quota_goals>`. 143e93b81a3SSeongJae Park- ``update_schemes_stats``: Update the contents of stats files for each 144e93b81a3SSeongJae Park DAMON-based operation scheme of the kdamond. For details of the stats, 145e93b81a3SSeongJae Park please refer to :ref:`stats section <sysfs_schemes_stats>`. 146e93b81a3SSeongJae Park- ``update_schemes_tried_regions``: Update the DAMON-based operation scheme 147e93b81a3SSeongJae Park action tried regions directory for each DAMON-based operation scheme of the 148e93b81a3SSeongJae Park kdamond. For details of the DAMON-based operation scheme action tried 149e93b81a3SSeongJae Park regions directory, please refer to 150e93b81a3SSeongJae Park :ref:`tried_regions section <sysfs_schemes_tried_regions>`. 151e93b81a3SSeongJae Park- ``update_schemes_tried_bytes``: Update only ``.../tried_regions/total_bytes`` 152e93b81a3SSeongJae Park files. 153e93b81a3SSeongJae Park- ``clear_schemes_tried_regions``: Clear the DAMON-based operating scheme 154e93b81a3SSeongJae Park action tried regions directory for each DAMON-based operation scheme of the 155e93b81a3SSeongJae Park kdamond. 15614e70e46SSeongJae Park- ``update_schemes_effective_quotas``: Update the contents of 157a6068d6dSSeongJae Park ``effective_bytes`` files for each DAMON-based operation scheme of the 158a6068d6dSSeongJae Park kdamond. For more details, refer to :ref:`quotas directory <sysfs_quotas>`. 159b1840272SSeongJae Park 160b1840272SSeongJae ParkIf the state is ``on``, reading ``pid`` shows the pid of the kdamond thread. 161b1840272SSeongJae Park 162b1840272SSeongJae Park``contexts`` directory contains files for controlling the monitoring contexts 163b1840272SSeongJae Parkthat this kdamond will execute. 164b1840272SSeongJae Park 1659c8c315dSSeongJae Park.. _sysfs_contexts: 1669c8c315dSSeongJae Park 167b1840272SSeongJae Parkkdamonds/<N>/contexts/ 168b1840272SSeongJae Park---------------------- 169b1840272SSeongJae Park 170b1840272SSeongJae ParkIn the beginning, this directory has only one file, ``nr_contexts``. Writing a 171b1840272SSeongJae Parknumber (``N``) to the file creates the number of child directories named as 17246158bf2SSeongJae Park``0`` to ``N-1``. Each directory represents each monitoring context (refer to 17346158bf2SSeongJae Park:ref:`design <damon_design_execution_model_and_data_structures>` for more 17446158bf2SSeongJae Parkdetails). At the moment, only one context per kdamond is supported, so only 17546158bf2SSeongJae Park``0`` or ``1`` can be written to the file. 176b1840272SSeongJae Park 177c7ae9634SSeongJae Park.. _sysfs_context: 1789b7f9322SSeongJae Park 179b1840272SSeongJae Parkcontexts/<N>/ 180b1840272SSeongJae Park------------- 181b1840272SSeongJae Park 1822fe60ec9SSeongJae ParkIn each context directory, two files (``avail_operations`` and ``operations``) 1832fe60ec9SSeongJae Parkand three directories (``monitoring_attrs``, ``targets``, and ``schemes``) 1842fe60ec9SSeongJae Parkexist. 185b1840272SSeongJae Park 186669971b4SSeongJae ParkDAMON supports multiple types of :ref:`monitoring operations 187669971b4SSeongJae Park<damon_design_configurable_operations_set>`, including those for virtual address 188669971b4SSeongJae Parkspace and the physical address space. You can get the list of available 189669971b4SSeongJae Parkmonitoring operations set on the currently running kernel by reading 1902fe60ec9SSeongJae Park``avail_operations`` file. Based on the kernel configuration, the file will 191669971b4SSeongJae Parklist different available operation sets. Please refer to the :ref:`design 192669971b4SSeongJae Park<damon_operations_set>` for the list of all available operation sets and their 193669971b4SSeongJae Parkbrief explanations. 19491541808SSeongJae Park 1952fe60ec9SSeongJae ParkYou can set and get what type of monitoring operations DAMON will use for the 1962fe60ec9SSeongJae Parkcontext by writing one of the keywords listed in ``avail_operations`` file and 1972fe60ec9SSeongJae Parkreading from the ``operations`` file. 1982fe60ec9SSeongJae Park 1997f0a86f3SSeongJae Park.. _sysfs_monitoring_attrs: 2007f0a86f3SSeongJae Park 201b1840272SSeongJae Parkcontexts/<N>/monitoring_attrs/ 202b1840272SSeongJae Park------------------------------ 203b1840272SSeongJae Park 204b1840272SSeongJae ParkFiles for specifying attributes of the monitoring including required quality 205b1840272SSeongJae Parkand efficiency of the monitoring are in ``monitoring_attrs`` directory. 206b1840272SSeongJae ParkSpecifically, two directories, ``intervals`` and ``nr_regions`` exist in this 207b1840272SSeongJae Parkdirectory. 208b1840272SSeongJae Park 209b1840272SSeongJae ParkUnder ``intervals`` directory, three files for DAMON's sampling interval 210b1840272SSeongJae Park(``sample_us``), aggregation interval (``aggr_us``), and update interval 211b1840272SSeongJae Park(``update_us``) exist. You can set and get the values in micro-seconds by 212b1840272SSeongJae Parkwriting to and reading from the files. 213b1840272SSeongJae Park 214b1840272SSeongJae ParkUnder ``nr_regions`` directory, two files for the lower-bound and upper-bound 215b1840272SSeongJae Parkof DAMON's monitoring regions (``min`` and ``max``, respectively), which 216b1840272SSeongJae Parkcontrols the monitoring overhead, exist. You can set and get the values by 217b1840272SSeongJae Parkwriting to and rading from the files. 218b1840272SSeongJae Park 219b1840272SSeongJae ParkFor more details about the intervals and monitoring regions range, please refer 220ee65728eSMike Rapoportto the Design document (:doc:`/mm/damon/design`). 221b1840272SSeongJae Park 2229c8c315dSSeongJae Park.. _sysfs_targets: 2239c8c315dSSeongJae Park 224b1840272SSeongJae Parkcontexts/<N>/targets/ 225b1840272SSeongJae Park--------------------- 226b1840272SSeongJae Park 227b1840272SSeongJae ParkIn the beginning, this directory has only one file, ``nr_targets``. Writing a 228b1840272SSeongJae Parknumber (``N``) to the file creates the number of child directories named ``0`` 229b1840272SSeongJae Parkto ``N-1``. Each directory represents each monitoring target. 230b1840272SSeongJae Park 2319c8c315dSSeongJae Park.. _sysfs_target: 2329c8c315dSSeongJae Park 233b1840272SSeongJae Parktargets/<N>/ 234b1840272SSeongJae Park------------ 235b1840272SSeongJae Park 236b1840272SSeongJae ParkIn each target directory, one file (``pid_target``) and one directory 237b1840272SSeongJae Park(``regions``) exist. 238b1840272SSeongJae Park 239b1840272SSeongJae ParkIf you wrote ``vaddr`` to the ``contexts/<N>/operations``, each target should 240b1840272SSeongJae Parkbe a process. You can specify the process to DAMON by writing the pid of the 241b1840272SSeongJae Parkprocess to the ``pid_target`` file. 242b1840272SSeongJae Park 24391541808SSeongJae Park.. _sysfs_regions: 24491541808SSeongJae Park 245b1840272SSeongJae Parktargets/<N>/regions 246b1840272SSeongJae Park------------------- 247b1840272SSeongJae Park 2482d89957cSSeongJae ParkIn case of ``fvaddr`` or ``paddr`` monitoring operations sets, users are 2492d89957cSSeongJae Parkrequired to set the monitoring target address ranges. In case of ``vaddr`` 2502d89957cSSeongJae Parkoperations set, it is not mandatory, but users can optionally set the initial 2512d89957cSSeongJae Parkmonitoring region to specific address ranges. Please refer to the :ref:`design 2522d89957cSSeongJae Park<damon_design_vaddr_target_regions_construction>` for more details. 253b1840272SSeongJae Park 254b1840272SSeongJae ParkFor such cases, users can explicitly set the initial monitoring target regions 255b1840272SSeongJae Parkas they want, by writing proper values to the files under this directory. 256b1840272SSeongJae Park 257b1840272SSeongJae ParkIn the beginning, this directory has only one file, ``nr_regions``. Writing a 258b1840272SSeongJae Parknumber (``N``) to the file creates the number of child directories named ``0`` 259b1840272SSeongJae Parkto ``N-1``. Each directory represents each initial monitoring target region. 260b1840272SSeongJae Park 2619c8c315dSSeongJae Park.. _sysfs_region: 2629c8c315dSSeongJae Park 263b1840272SSeongJae Parkregions/<N>/ 264b1840272SSeongJae Park------------ 265b1840272SSeongJae Park 266b1840272SSeongJae ParkIn each region directory, you will find two files (``start`` and ``end``). You 267b1840272SSeongJae Parkcan set and get the start and end addresses of the initial monitoring target 268b1840272SSeongJae Parkregion by writing to and reading from the files, respectively. 269b1840272SSeongJae Park 270bd414929SSeongJae ParkEach region should not overlap with others. ``end`` of directory ``N`` should 271bd414929SSeongJae Parkbe equal or smaller than ``start`` of directory ``N+1``. 272bd414929SSeongJae Park 2739c8c315dSSeongJae Park.. _sysfs_schemes: 2749c8c315dSSeongJae Park 275b1840272SSeongJae Parkcontexts/<N>/schemes/ 276b1840272SSeongJae Park--------------------- 277b1840272SSeongJae Park 27801e08737SSeongJae ParkThe directory for DAMON-based Operation Schemes (:ref:`DAMOS 27901e08737SSeongJae Park<damon_design_damos>`). Users can get and set the schemes by reading from and 28001e08737SSeongJae Parkwriting to files under this directory. 281b1840272SSeongJae Park 282b1840272SSeongJae ParkIn the beginning, this directory has only one file, ``nr_schemes``. Writing a 283b1840272SSeongJae Parknumber (``N``) to the file creates the number of child directories named ``0`` 284b1840272SSeongJae Parkto ``N-1``. Each directory represents each DAMON-based operation scheme. 285b1840272SSeongJae Park 2869c8c315dSSeongJae Park.. _sysfs_scheme: 2879c8c315dSSeongJae Park 288b1840272SSeongJae Parkschemes/<N>/ 289b1840272SSeongJae Park------------ 290b1840272SSeongJae Park 2917f0a86f3SSeongJae ParkIn each scheme directory, five directories (``access_pattern``, ``quotas``, 29283d0d46aSHonggyu Kim``watermarks``, ``filters``, ``stats``, and ``tried_regions``) and three files 29383d0d46aSHonggyu Kim(``action``, ``target_nid`` and ``apply_interval``) exist. 294b1840272SSeongJae Park 29501e08737SSeongJae ParkThe ``action`` file is for setting and getting the scheme's :ref:`action 29601e08737SSeongJae Park<damon_design_damos_action>`. The keywords that can be written to and read 2975b7708e6SSeongJae Parkfrom the file and their meaning are same to those of the list on 2985b7708e6SSeongJae Park:ref:`design doc <damon_design_damos_action>`. 299b1840272SSeongJae Park 30083d0d46aSHonggyu KimThe ``target_nid`` file is for setting the migration target node, which is 30183d0d46aSHonggyu Kimonly meaningful when the ``action`` is either ``migrate_hot`` or 30283d0d46aSHonggyu Kim``migrate_cold``. 30383d0d46aSHonggyu Kim 304033343d5SSeongJae ParkThe ``apply_interval_us`` file is for setting and getting the scheme's 305033343d5SSeongJae Park:ref:`apply_interval <damon_design_damos>` in microseconds. 306033343d5SSeongJae Park 3079c8c315dSSeongJae Park.. _sysfs_access_pattern: 3089c8c315dSSeongJae Park 309b1840272SSeongJae Parkschemes/<N>/access_pattern/ 310b1840272SSeongJae Park--------------------------- 311b1840272SSeongJae Park 31201e08737SSeongJae ParkThe directory for the target access :ref:`pattern 31301e08737SSeongJae Park<damon_design_damos_access_pattern>` of the given DAMON-based operation scheme. 314b1840272SSeongJae Park 315b1840272SSeongJae ParkUnder the ``access_pattern`` directory, three directories (``sz``, 316b1840272SSeongJae Park``nr_accesses``, and ``age``) each having two files (``min`` and ``max``) 317b1840272SSeongJae Parkexist. You can set and get the access pattern for the given scheme by writing 318b1840272SSeongJae Parkto and reading from the ``min`` and ``max`` files under ``sz``, 31967c34f6cSSeongJae Park``nr_accesses``, and ``age`` directories, respectively. Note that the ``min`` 32067c34f6cSSeongJae Parkand the ``max`` form a closed interval. 321b1840272SSeongJae Park 3229c8c315dSSeongJae Park.. _sysfs_quotas: 3239c8c315dSSeongJae Park 324b1840272SSeongJae Parkschemes/<N>/quotas/ 325b1840272SSeongJae Park------------------- 326b1840272SSeongJae Park 32701e08737SSeongJae ParkThe directory for the :ref:`quotas <damon_design_damos_quotas>` of the given 32801e08737SSeongJae ParkDAMON-based operation scheme. 329b1840272SSeongJae Park 330a6068d6dSSeongJae ParkUnder ``quotas`` directory, four files (``ms``, ``bytes``, 331a6068d6dSSeongJae Park``reset_interval_ms``, ``effective_bytes``) and two directores (``weights`` and 332a6068d6dSSeongJae Park``goals``) exist. 333b1840272SSeongJae Park 334b1840272SSeongJae ParkYou can set the ``time quota`` in milliseconds, ``size quota`` in bytes, and 335b1840272SSeongJae Park``reset interval`` in milliseconds by writing the values to the three files, 33667c34f6cSSeongJae Parkrespectively. Then, DAMON tries to use only up to ``time quota`` milliseconds 33767c34f6cSSeongJae Parkfor applying the ``action`` to memory regions of the ``access_pattern``, and to 33867c34f6cSSeongJae Parkapply the action to only up to ``bytes`` bytes of memory regions within the 33967c34f6cSSeongJae Park``reset_interval_ms``. Setting both ``ms`` and ``bytes`` zero disables the 3407d8cebb9SSeongJae Parkquota limits unless at least one :ref:`goal <sysfs_schemes_quota_goals>` is 3417d8cebb9SSeongJae Parkset. 34267c34f6cSSeongJae Park 343a6068d6dSSeongJae ParkThe time quota is internally transformed to a size quota. Between the 344a6068d6dSSeongJae Parktransformed size quota and user-specified size quota, smaller one is applied. 345a6068d6dSSeongJae ParkBased on the user-specified :ref:`goal <sysfs_schemes_quota_goals>`, the 346a6068d6dSSeongJae Parkeffective size quota is further adjusted. Reading ``effective_bytes`` returns 347a6068d6dSSeongJae Parkthe current effective size quota. The file is not updated in real time, so 348a6068d6dSSeongJae Parkusers should ask DAMON sysfs interface to update the content of the file for 34914e70e46SSeongJae Parkthe stats by writing a special keyword, ``update_schemes_effective_quotas`` to 350a6068d6dSSeongJae Parkthe relevant ``kdamonds/<N>/state`` file. 351a6068d6dSSeongJae Park 3526140edeeSSeongJae ParkUnder ``weights`` directory, three files (``sz_permil``, 3536140edeeSSeongJae Park``nr_accesses_permil``, and ``age_permil``) exist. 3546140edeeSSeongJae ParkYou can set the :ref:`prioritization weights 35501e08737SSeongJae Park<damon_design_damos_quotas_prioritization>` for size, access frequency, and age 35601e08737SSeongJae Parkin per-thousand unit by writing the values to the three files under the 35701e08737SSeongJae Park``weights`` directory. 358b1840272SSeongJae Park 3596140edeeSSeongJae Park.. _sysfs_schemes_quota_goals: 3606140edeeSSeongJae Park 3616140edeeSSeongJae Parkschemes/<N>/quotas/goals/ 3626140edeeSSeongJae Park------------------------- 3636140edeeSSeongJae Park 3646140edeeSSeongJae ParkThe directory for the :ref:`automatic quota tuning goals 3656140edeeSSeongJae Park<damon_design_damos_quotas_auto_tuning>` of the given DAMON-based operation 3666140edeeSSeongJae Parkscheme. 3676140edeeSSeongJae Park 3686140edeeSSeongJae ParkIn the beginning, this directory has only one file, ``nr_goals``. Writing a 3696140edeeSSeongJae Parknumber (``N``) to the file creates the number of child directories named ``0`` 3706140edeeSSeongJae Parkto ``N-1``. Each directory represents each goal and current achievement. 3716140edeeSSeongJae ParkAmong the multiple feedback, the best one is used. 3726140edeeSSeongJae Park 37357e88e86SSeongJae ParkEach goal directory contains three files, namely ``target_metric``, 37457e88e86SSeongJae Park``target_value`` and ``current_value``. Users can set and get the three 37557e88e86SSeongJae Parkparameters for the quota auto-tuning goals that specified on the :ref:`design 37657e88e86SSeongJae Parkdoc <damon_design_damos_quotas_auto_tuning>` by writing to and reading from each 37757e88e86SSeongJae Parkof the files. Note that users should further write 3786140edeeSSeongJae Park``commit_schemes_quota_goals`` to the ``state`` file of the :ref:`kdamond 3796140edeeSSeongJae Parkdirectory <sysfs_kdamond>` to pass the feedback to DAMON. 3806140edeeSSeongJae Park 3819c8c315dSSeongJae Park.. _sysfs_watermarks: 3829c8c315dSSeongJae Park 383b1840272SSeongJae Parkschemes/<N>/watermarks/ 384b1840272SSeongJae Park----------------------- 385b1840272SSeongJae Park 38601e08737SSeongJae ParkThe directory for the :ref:`watermarks <damon_design_damos_watermarks>` of the 38701e08737SSeongJae Parkgiven DAMON-based operation scheme. 388b1840272SSeongJae Park 389b1840272SSeongJae ParkUnder the watermarks directory, five files (``metric``, ``interval_us``, 39001e08737SSeongJae Park``high``, ``mid``, and ``low``) for setting the metric, the time interval 39101e08737SSeongJae Parkbetween check of the metric, and the three watermarks exist. You can set and 392b1840272SSeongJae Parkget the five values by writing to the files, respectively. 393b1840272SSeongJae Park 394b1840272SSeongJae ParkKeywords and meanings of those that can be written to the ``metric`` file are 395b1840272SSeongJae Parkas below. 396b1840272SSeongJae Park 397b1840272SSeongJae Park - none: Ignore the watermarks 398b1840272SSeongJae Park - free_mem_rate: System's free memory rate (per thousand) 399b1840272SSeongJae Park 400b1840272SSeongJae ParkThe ``interval`` should written in microseconds unit. 401b1840272SSeongJae Park 4029c8c315dSSeongJae Park.. _sysfs_filters: 4039c8c315dSSeongJae Park 4049b7f9322SSeongJae Parkschemes/<N>/filters/ 4059b7f9322SSeongJae Park-------------------- 4069b7f9322SSeongJae Park 40701e08737SSeongJae ParkThe directory for the :ref:`filters <damon_design_damos_filters>` of the given 40801e08737SSeongJae ParkDAMON-based operation scheme. 4099b7f9322SSeongJae Park 4109b7f9322SSeongJae ParkIn the beginning, this directory has only one file, ``nr_filters``. Writing a 4119b7f9322SSeongJae Parknumber (``N``) to the file creates the number of child directories named ``0`` 4129b7f9322SSeongJae Parkto ``N-1``. Each directory represents each filter. The filters are evaluated 4139b7f9322SSeongJae Parkin the numeric order. 4149b7f9322SSeongJae Park 41541a7ed8cSSeongJae ParkEach filter directory contains six files, namely ``type``, ``matcing``, 41641a7ed8cSSeongJae Park``memcg_path``, ``addr_start``, ``addr_end``, and ``target_idx``. To ``type`` 417ed13c93bSSeongJae Parkfile, you can write one of five special keywords: ``anon`` for anonymous pages, 418ed13c93bSSeongJae Park``memcg`` for specific memory cgroup, ``young`` for young pages, ``addr`` for 419ed13c93bSSeongJae Parkspecific address range (an open-ended interval), or ``target`` for specific 420ed13c93bSSeongJae ParkDAMON monitoring target filtering. In case of the memory cgroup filtering, you 421ed13c93bSSeongJae Parkcan specify the memory cgroup of the interest by writing the path of the memory 422ed13c93bSSeongJae Parkcgroup from the cgroups mount point to ``memcg_path`` file. In case of the 423ed13c93bSSeongJae Parkaddress range filtering, you can specify the start and end address of the range 424ed13c93bSSeongJae Parkto ``addr_start`` and ``addr_end`` files, respectively. For the DAMON 425ed13c93bSSeongJae Parkmonitoring target filtering, you can specify the index of the target between 426ed13c93bSSeongJae Parkthe list of the DAMON context's monitoring targets list to ``target_idx`` file. 427ed13c93bSSeongJae ParkYou can write ``Y`` or ``N`` to ``matching`` file to filter out pages that does 428ed13c93bSSeongJae Parkor does not match to the type, respectively. Then, the scheme's action will 429ed13c93bSSeongJae Parknot be applied to the pages that specified to be filtered out. 4309b7f9322SSeongJae Park 4319b7f9322SSeongJae ParkFor example, below restricts a DAMOS action to be applied to only non-anonymous 4329b7f9322SSeongJae Parkpages of all memory cgroups except ``/having_care_already``.:: 4339b7f9322SSeongJae Park 4349b7f9322SSeongJae Park # echo 2 > nr_filters 4359b7f9322SSeongJae Park # # filter out anonymous pages 4369b7f9322SSeongJae Park echo anon > 0/type 4379b7f9322SSeongJae Park echo Y > 0/matching 4389b7f9322SSeongJae Park # # further filter out all cgroups except one at '/having_care_already' 4399b7f9322SSeongJae Park echo memcg > 1/type 4409b7f9322SSeongJae Park echo /having_care_already > 1/memcg_path 441da2a0618SSeongJae Park echo Y > 1/matching 4429b7f9322SSeongJae Park 443375af850SSeongJae ParkNote that ``anon`` and ``memcg`` filters are currently supported only when 444c7ae9634SSeongJae Park``paddr`` :ref:`implementation <sysfs_context>` is being used. 445375af850SSeongJae Park 44641a7ed8cSSeongJae ParkAlso, memory regions that are filtered out by ``addr`` or ``target`` filters 44741a7ed8cSSeongJae Parkare not counted as the scheme has tried to those, while regions that filtered 44841a7ed8cSSeongJae Parkout by other type filters are counted as the scheme has tried to. The 44941a7ed8cSSeongJae Parkdifference is applied to :ref:`stats <damos_stats>` and 45041a7ed8cSSeongJae Park:ref:`tried regions <sysfs_schemes_tried_regions>`. 4519b7f9322SSeongJae Park 452b1840272SSeongJae Park.. _sysfs_schemes_stats: 453b1840272SSeongJae Park 454b1840272SSeongJae Parkschemes/<N>/stats/ 455b1840272SSeongJae Park------------------ 456b1840272SSeongJae Park 457b1840272SSeongJae ParkDAMON counts the total number and bytes of regions that each scheme is tried to 458b1840272SSeongJae Parkbe applied, the two numbers for the regions that each scheme is successfully 459b1840272SSeongJae Parkapplied, and the total number of the quota limit exceeds. This statistics can 460b1840272SSeongJae Parkbe used for online analysis or tuning of the schemes. 461b1840272SSeongJae Park 462b1840272SSeongJae ParkThe statistics can be retrieved by reading the files under ``stats`` directory 463b1840272SSeongJae Park(``nr_tried``, ``sz_tried``, ``nr_applied``, ``sz_applied``, and 464b1840272SSeongJae Park``qt_exceeds``), respectively. The files are not updated in real time, so you 465d56b699dSBjorn Helgaasshould ask DAMON sysfs interface to update the content of the files for the 466b1840272SSeongJae Parkstats by writing a special keyword, ``update_schemes_stats`` to the relevant 467b1840272SSeongJae Park``kdamonds/<N>/state`` file. 468b1840272SSeongJae Park 4697f0a86f3SSeongJae Park.. _sysfs_schemes_tried_regions: 4707f0a86f3SSeongJae Park 4717f0a86f3SSeongJae Parkschemes/<N>/tried_regions/ 4727f0a86f3SSeongJae Park-------------------------- 4737f0a86f3SSeongJae Park 474ea7f03a4SSeongJae ParkThis directory initially has one file, ``total_bytes``. 475ea7f03a4SSeongJae Park 4767f0a86f3SSeongJae ParkWhen a special keyword, ``update_schemes_tried_regions``, is written to the 477ea7f03a4SSeongJae Parkrelevant ``kdamonds/<N>/state`` file, DAMON updates the ``total_bytes`` file so 478ea7f03a4SSeongJae Parkthat reading it returns the total size of the scheme tried regions, and creates 479ea7f03a4SSeongJae Parkdirectories named integer starting from ``0`` under this directory. Each 480ea7f03a4SSeongJae Parkdirectory contains files exposing detailed information about each of the memory 481ea7f03a4SSeongJae Parkregion that the corresponding scheme's ``action`` has tried to be applied under 482bc17ea26SSeongJae Parkthis directory, during next :ref:`apply interval <damon_design_damos>` of the 483bc17ea26SSeongJae Parkcorresponding scheme. The information includes address range, ``nr_accesses``, 484bc17ea26SSeongJae Parkand ``age`` of the region. 485ea7f03a4SSeongJae Park 486ea7f03a4SSeongJae ParkWriting ``update_schemes_tried_bytes`` to the relevant ``kdamonds/<N>/state`` 487ea7f03a4SSeongJae Parkfile will only update the ``total_bytes`` file, and will not create the 488ea7f03a4SSeongJae Parksubdirectories. 4897f0a86f3SSeongJae Park 4907f0a86f3SSeongJae ParkThe directories will be removed when another special keyword, 4917f0a86f3SSeongJae Park``clear_schemes_tried_regions``, is written to the relevant 4927f0a86f3SSeongJae Park``kdamonds/<N>/state`` file. 4937f0a86f3SSeongJae Park 494ff71f26fSSeongJae ParkThe expected usage of this directory is investigations of schemes' behaviors, 495ff71f26fSSeongJae Parkand query-like efficient data access monitoring results retrievals. For the 496ff71f26fSSeongJae Parklatter use case, in particular, users can set the ``action`` as ``stat`` and 497ff71f26fSSeongJae Parkset the ``access pattern`` as their interested pattern that they want to query. 498ff71f26fSSeongJae Park 4999c8c315dSSeongJae Park.. _sysfs_schemes_tried_region: 5009c8c315dSSeongJae Park 5017f0a86f3SSeongJae Parktried_regions/<N>/ 5027f0a86f3SSeongJae Park------------------ 5037f0a86f3SSeongJae Park 5047f0a86f3SSeongJae ParkIn each region directory, you will find four files (``start``, ``end``, 5057f0a86f3SSeongJae Park``nr_accesses``, and ``age``). Reading the files will show the start and end 5067f0a86f3SSeongJae Parkaddresses, ``nr_accesses``, and ``age`` of the region that corresponding 5077f0a86f3SSeongJae ParkDAMON-based operation scheme ``action`` has tried to be applied. 5087f0a86f3SSeongJae Park 509b1840272SSeongJae ParkExample 510b1840272SSeongJae Park~~~~~~~ 511b1840272SSeongJae Park 512b1840272SSeongJae ParkBelow commands applies a scheme saying "If a memory region of size in [4KiB, 513b1840272SSeongJae Park8KiB] is showing accesses per aggregate interval in [0, 5] for aggregate 514b1840272SSeongJae Parkinterval in [10, 20], page out the region. For the paging out, use only up to 515b1840272SSeongJae Park10ms per second, and also don't page out more than 1GiB per second. Under the 516b1840272SSeongJae Parklimitation, page out memory regions having longer age first. Also, check the 517b1840272SSeongJae Parkfree memory rate of the system every 5 seconds, start the monitoring and paging 518b1840272SSeongJae Parkout when the free memory rate becomes lower than 50%, but stop it if the free 519b1840272SSeongJae Parkmemory rate becomes larger than 60%, or lower than 30%". :: 520b1840272SSeongJae Park 521b1840272SSeongJae Park # cd <sysfs>/kernel/mm/damon/admin 522b1840272SSeongJae Park # # populate directories 523b1840272SSeongJae Park # echo 1 > kdamonds/nr_kdamonds; echo 1 > kdamonds/0/contexts/nr_contexts; 524b1840272SSeongJae Park # echo 1 > kdamonds/0/contexts/0/schemes/nr_schemes 525b1840272SSeongJae Park # cd kdamonds/0/contexts/0/schemes/0 526b1840272SSeongJae Park # # set the basic access pattern and the action 527465d0eb0SKairui Song # echo 4096 > access_pattern/sz/min 528465d0eb0SKairui Song # echo 8192 > access_pattern/sz/max 529465d0eb0SKairui Song # echo 0 > access_pattern/nr_accesses/min 530465d0eb0SKairui Song # echo 5 > access_pattern/nr_accesses/max 531465d0eb0SKairui Song # echo 10 > access_pattern/age/min 532465d0eb0SKairui Song # echo 20 > access_pattern/age/max 533b1840272SSeongJae Park # echo pageout > action 534b1840272SSeongJae Park # # set quotas 535b1840272SSeongJae Park # echo 10 > quotas/ms 536b1840272SSeongJae Park # echo $((1024*1024*1024)) > quotas/bytes 537b1840272SSeongJae Park # echo 1000 > quotas/reset_interval_ms 538b1840272SSeongJae Park # # set watermark 539b1840272SSeongJae Park # echo free_mem_rate > watermarks/metric 540b1840272SSeongJae Park # echo 5000000 > watermarks/interval_us 541b1840272SSeongJae Park # echo 600 > watermarks/high 542b1840272SSeongJae Park # echo 500 > watermarks/mid 543b1840272SSeongJae Park # echo 300 > watermarks/low 544b1840272SSeongJae Park 545b1840272SSeongJae ParkPlease note that it's highly recommended to use user space tools like `damo 546*23a425aaSSeongJae Park<https://github.com/damonitor/damo>`_ rather than manually reading and writing 547b1840272SSeongJae Parkthe files as above. Above is only for an example. 54835b43d40SSeongJae Park 54975999724SSeongJae Park.. _tracepoint: 55075999724SSeongJae Park 5511b2b7a17SSeongJae ParkTracepoints for Monitoring Results 5521b2b7a17SSeongJae Park================================== 55375999724SSeongJae Park 55475999724SSeongJae ParkUsers can get the monitoring results via the :ref:`tried_regions 5551b2b7a17SSeongJae Park<sysfs_schemes_tried_regions>`. The interface is useful for getting a 5561b2b7a17SSeongJae Parksnapshot, but it could be inefficient for fully recording all the monitoring 5571b2b7a17SSeongJae Parkresults. For the purpose, two trace points, namely ``damon:damon_aggregated`` 5581b2b7a17SSeongJae Parkand ``damon:damos_before_apply``, are provided. ``damon:damon_aggregated`` 5591b2b7a17SSeongJae Parkprovides the whole monitoring results, while ``damon:damos_before_apply`` 5601b2b7a17SSeongJae Parkprovides the monitoring results for regions that each DAMON-based Operation 5611b2b7a17SSeongJae ParkScheme (:ref:`DAMOS <damon_design_damos>`) is gonna be applied. Hence, 5621b2b7a17SSeongJae Park``damon:damos_before_apply`` is more useful for recording internal behavior of 5631b2b7a17SSeongJae ParkDAMOS, or DAMOS target access 5641b2b7a17SSeongJae Park:ref:`pattern <damon_design_damos_access_pattern>` based query-like efficient 5651b2b7a17SSeongJae Parkmonitoring results recording. 5661b2b7a17SSeongJae Park 5671b2b7a17SSeongJae ParkWhile the monitoring is turned on, you could record the tracepoint events and 5681b2b7a17SSeongJae Parkshow results using tracepoint supporting tools like ``perf``. For example:: 56975999724SSeongJae Park 5705af28560SSeongJae Park # echo on > kdamonds/0/state 57175999724SSeongJae Park # perf record -e damon:damon_aggregated & 57275999724SSeongJae Park # sleep 5 57375999724SSeongJae Park # kill 9 $(pidof perf) 5745af28560SSeongJae Park # echo off > kdamonds/0/state 57575999724SSeongJae Park # perf script 5764f554ca1SSeongJae Park kdamond.0 46568 [027] 79357.842179: damon:damon_aggregated: target_id=0 nr_regions=11 122509119488-135708762112: 0 864 5774f554ca1SSeongJae Park [...] 5784f554ca1SSeongJae Park 5794f554ca1SSeongJae ParkEach line of the perf script output represents each monitoring region. The 5804f554ca1SSeongJae Parkfirst five fields are as usual other tracepoint outputs. The sixth field 5814f554ca1SSeongJae Park(``target_id=X``) shows the ide of the monitoring target of the region. The 5824f554ca1SSeongJae Parkseventh field (``nr_regions=X``) shows the total number of monitoring regions 5834f554ca1SSeongJae Parkfor the target. The eighth field (``X-Y:``) shows the start (``X``) and end 5844f554ca1SSeongJae Park(``Y``) addresses of the region in bytes. The ninth field (``X``) shows the 5854f554ca1SSeongJae Park``nr_accesses`` of the region (refer to 5864f554ca1SSeongJae Park:ref:`design <damon_design_region_based_sampling>` for more details of the 5874f554ca1SSeongJae Parkcounter). Finally the tenth field (``X``) shows the ``age`` of the region 5884f554ca1SSeongJae Park(refer to :ref:`design <damon_design_age_tracking>` for more details of the 5894f554ca1SSeongJae Parkcounter). 59075999724SSeongJae Park 5911b2b7a17SSeongJae ParkIf the event was ``damon:damos_beofre_apply``, the ``perf script`` output would 5921b2b7a17SSeongJae Parkbe somewhat like below:: 5931b2b7a17SSeongJae Park 5941b2b7a17SSeongJae Park kdamond.0 47293 [000] 80801.060214: damon:damos_before_apply: ctx_idx=0 scheme_idx=0 target_idx=0 nr_regions=11 121932607488-135128711168: 0 136 5951b2b7a17SSeongJae Park [...] 5961b2b7a17SSeongJae Park 5971b2b7a17SSeongJae ParkEach line of the output represents each monitoring region that each DAMON-based 5981b2b7a17SSeongJae ParkOperation Scheme was about to be applied at the traced time. The first five 5991b2b7a17SSeongJae Parkfields are as usual. It shows the index of the DAMON context (``ctx_idx=X``) 6001b2b7a17SSeongJae Parkof the scheme in the list of the contexts of the context's kdamond, the index 6011b2b7a17SSeongJae Parkof the scheme (``scheme_idx=X``) in the list of the schemes of the context, in 6021b2b7a17SSeongJae Parkaddition to the output of ``damon_aggregated`` tracepoint. 6031b2b7a17SSeongJae Park 6041b2b7a17SSeongJae Park 60535b43d40SSeongJae Park.. _debugfs_interface: 606c4ba6014SSeongJae Park 6075445fcbcSSeongJae Parkdebugfs Interface (DEPRECATED!) 6085445fcbcSSeongJae Park=============================== 609c4ba6014SSeongJae Park 610f1f3afd5SSeongJae Park.. note:: 611f1f3afd5SSeongJae Park 6125445fcbcSSeongJae Park THIS IS DEPRECATED! 6135445fcbcSSeongJae Park 6145445fcbcSSeongJae Park DAMON debugfs interface is deprecated, so users should move to the 6155445fcbcSSeongJae Park :ref:`sysfs interface <sysfs_interface>`. If you depend on this and cannot 6165445fcbcSSeongJae Park move, please report your usecase to damon@lists.linux.dev and 6175445fcbcSSeongJae Park linux-mm@kvack.org. 618f1f3afd5SSeongJae Park 619cf3810ccSSeongJae ParkDAMON exports nine files, ``DEPRECATED``, ``attrs``, ``target_ids``, 620ec28cf53SSeongJae Park``init_regions``, ``schemes``, ``monitor_on_DEPRECATED``, ``kdamond_pid``, 621ec28cf53SSeongJae Park``mk_contexts`` and ``rm_contexts`` under its debugfs directory, 622ec28cf53SSeongJae Park``<debugfs>/damon/``. 623cf3810ccSSeongJae Park 624cf3810ccSSeongJae Park 625cf3810ccSSeongJae Park``DEPRECATED`` is a read-only file for the DAMON debugfs interface deprecation 626cf3810ccSSeongJae Parknotice. Reading it returns the deprecation notice, as below:: 627cf3810ccSSeongJae Park 628cf3810ccSSeongJae Park # cat DEPRECATED 629cf3810ccSSeongJae Park DAMON debugfs interface is deprecated, so users should move to DAMON_SYSFS. If you cannot, please report your usecase to damon@lists.linux.dev and linux-mm@kvack.org. 630c4ba6014SSeongJae Park 631c4ba6014SSeongJae Park 632c4ba6014SSeongJae ParkAttributes 633c4ba6014SSeongJae Park---------- 634c4ba6014SSeongJae Park 635c4ba6014SSeongJae ParkUsers can get and set the ``sampling interval``, ``aggregation interval``, 6364c1f287fSSeongJae Park``update interval``, and min/max number of monitoring target regions by 637c4ba6014SSeongJae Parkreading from and writing to the ``attrs`` file. To know about the monitoring 638ee65728eSMike Rapoportattributes in detail, please refer to the :doc:`/mm/damon/design`. For 639c4ba6014SSeongJae Parkexample, below commands set those values to 5 ms, 100 ms, 1,000 ms, 10 and 640c4ba6014SSeongJae Park1000, and then check it again:: 641c4ba6014SSeongJae Park 642c4ba6014SSeongJae Park # cd <debugfs>/damon 643c4ba6014SSeongJae Park # echo 5000 100000 1000000 10 1000 > attrs 644c4ba6014SSeongJae Park # cat attrs 645c4ba6014SSeongJae Park 5000 100000 1000000 10 1000 646c4ba6014SSeongJae Park 647c4ba6014SSeongJae Park 648c4ba6014SSeongJae ParkTarget IDs 649c4ba6014SSeongJae Park---------- 650c4ba6014SSeongJae Park 651c4ba6014SSeongJae ParkSome types of address spaces supports multiple monitoring target. For example, 652c4ba6014SSeongJae Parkthe virtual memory address spaces monitoring can have multiple processes as the 653c4ba6014SSeongJae Parkmonitoring targets. Users can set the targets by writing relevant id values of 654c4ba6014SSeongJae Parkthe targets to, and get the ids of the current targets by reading from the 655c4ba6014SSeongJae Park``target_ids`` file. In case of the virtual address spaces monitoring, the 656c4ba6014SSeongJae Parkvalues should be pids of the monitoring target processes. For example, below 657c4ba6014SSeongJae Parkcommands set processes having pids 42 and 4242 as the monitoring targets and 658c4ba6014SSeongJae Parkcheck it again:: 659c4ba6014SSeongJae Park 660c4ba6014SSeongJae Park # cd <debugfs>/damon 661c4ba6014SSeongJae Park # echo 42 4242 > target_ids 662c4ba6014SSeongJae Park # cat target_ids 663c4ba6014SSeongJae Park 42 4242 664c4ba6014SSeongJae Park 665c6380721SSeongJae ParkUsers can also monitor the physical memory address space of the system by 666c6380721SSeongJae Parkwriting a special keyword, "``paddr\n``" to the file. Because physical address 667c6380721SSeongJae Parkspace monitoring doesn't support multiple targets, reading the file will show a 668c6380721SSeongJae Parkfake value, ``42``, as below:: 669c6380721SSeongJae Park 670c6380721SSeongJae Park # cd <debugfs>/damon 671c6380721SSeongJae Park # echo paddr > target_ids 672c6380721SSeongJae Park # cat target_ids 673c6380721SSeongJae Park 42 674c6380721SSeongJae Park 675c4ba6014SSeongJae ParkNote that setting the target ids doesn't start the monitoring. 676c4ba6014SSeongJae Park 677c4ba6014SSeongJae Park 678c2fe4987SSeongJae ParkInitial Monitoring Target Regions 679c2fe4987SSeongJae Park--------------------------------- 680c2fe4987SSeongJae Park 681c6380721SSeongJae ParkIn case of the virtual address space monitoring, DAMON automatically sets and 682c6380721SSeongJae Parkupdates the monitoring target regions so that entire memory mappings of target 683c2fe4987SSeongJae Parkprocesses can be covered. However, users can want to limit the monitoring 684c2fe4987SSeongJae Parkregion to specific address ranges, such as the heap, the stack, or specific 685c2fe4987SSeongJae Parkfile-mapped area. Or, some users can know the initial access pattern of their 686c2fe4987SSeongJae Parkworkloads and therefore want to set optimal initial regions for the 'adaptive 687c2fe4987SSeongJae Parkregions adjustment'. 688c2fe4987SSeongJae Park 689c6380721SSeongJae ParkIn contrast, DAMON do not automatically sets and updates the monitoring target 690c6380721SSeongJae Parkregions in case of physical memory monitoring. Therefore, users should set the 691c6380721SSeongJae Parkmonitoring target regions by themselves. 692c6380721SSeongJae Park 693c2fe4987SSeongJae ParkIn such cases, users can explicitly set the initial monitoring target regions 6941b016638SSeongJae Parkas they want, by writing proper values to the ``init_regions`` file. The input 6951b016638SSeongJae Parkshould be a sequence of three integers separated by white spaces that represent 6961b016638SSeongJae Parkone region in below form.:: 697c2fe4987SSeongJae Park 6988041c87bSSeongJae Park <target idx> <start address> <end address> 699c2fe4987SSeongJae Park 7008041c87bSSeongJae ParkThe ``target idx`` should be the index of the target in ``target_ids`` file, 7018041c87bSSeongJae Parkstarting from ``0``, and the regions should be passed in address order. For 7028041c87bSSeongJae Parkexample, below commands will set a couple of address ranges, ``1-100`` and 7038041c87bSSeongJae Park``100-200`` as the initial monitoring target region of pid 42, which is the 7048041c87bSSeongJae Parkfirst one (index ``0``) in ``target_ids``, and another couple of address 7058041c87bSSeongJae Parkranges, ``20-40`` and ``50-100`` as that of pid 4242, which is the second one 7068041c87bSSeongJae Park(index ``1``) in ``target_ids``.:: 707c2fe4987SSeongJae Park 708c2fe4987SSeongJae Park # cd <debugfs>/damon 7098041c87bSSeongJae Park # cat target_ids 7108041c87bSSeongJae Park 42 4242 7111b016638SSeongJae Park # echo "0 1 100 \ 7121b016638SSeongJae Park 0 100 200 \ 7131b016638SSeongJae Park 1 20 40 \ 7148041c87bSSeongJae Park 1 50 100" > init_regions 715c2fe4987SSeongJae Park 716c2fe4987SSeongJae ParkNote that this sets the initial monitoring target regions only. In case of 717c2fe4987SSeongJae Parkvirtual memory monitoring, DAMON will automatically updates the boundary of the 7184c1f287fSSeongJae Parkregions after one ``update interval``. Therefore, users should set the 7194c1f287fSSeongJae Park``update interval`` large enough in this case, if they don't want the 720c2fe4987SSeongJae Parkupdate. 721c2fe4987SSeongJae Park 722c2fe4987SSeongJae Park 72368536f8eSSeongJae ParkSchemes 72468536f8eSSeongJae Park------- 72568536f8eSSeongJae Park 72601e08737SSeongJae ParkUsers can get and set the DAMON-based operation :ref:`schemes 72701e08737SSeongJae Park<damon_design_damos>` by reading from and writing to ``schemes`` debugfs file. 72801e08737SSeongJae ParkReading the file also shows the statistics of each scheme. To the file, each 72901e08737SSeongJae Parkof the schemes should be represented in each line in below form:: 73068536f8eSSeongJae Park 7316322416bSSeongJae Park <target access pattern> <action> <quota> <watermarks> 73268536f8eSSeongJae Park 7336322416bSSeongJae ParkYou can disable schemes by simply writing an empty string to the file. 7346322416bSSeongJae Park 7356322416bSSeongJae ParkTarget Access Pattern 7366322416bSSeongJae Park~~~~~~~~~~~~~~~~~~~~~ 7376322416bSSeongJae Park 73801e08737SSeongJae ParkThe target access :ref:`pattern <damon_design_damos_access_pattern>` of the 73901e08737SSeongJae Parkscheme. The ``<target access pattern>`` is constructed with three ranges in 74001e08737SSeongJae Parkbelow form:: 7416322416bSSeongJae Park 7426322416bSSeongJae Park min-size max-size min-acc max-acc min-age max-age 7436322416bSSeongJae Park 7446322416bSSeongJae ParkSpecifically, bytes for the size of regions (``min-size`` and ``max-size``), 7456322416bSSeongJae Parknumber of monitored accesses per aggregate interval for access frequency 7466322416bSSeongJae Park(``min-acc`` and ``max-acc``), number of aggregate intervals for the age of 7476322416bSSeongJae Parkregions (``min-age`` and ``max-age``) are specified. Note that the ranges are 7486322416bSSeongJae Parkclosed interval. 7496322416bSSeongJae Park 7506322416bSSeongJae ParkAction 7516322416bSSeongJae Park~~~~~~ 7526322416bSSeongJae Park 75301e08737SSeongJae ParkThe ``<action>`` is a predefined integer for memory management :ref:`actions 7545b7708e6SSeongJae Park<damon_design_damos_action>`. The mapping between the ``<action>`` values and 7555b7708e6SSeongJae Parkthe memory management actions is as below. For the detailed meaning of the 7565b7708e6SSeongJae Parkaction and DAMON operations set supporting each action, please refer to the 7575b7708e6SSeongJae Parklist on :ref:`design doc <damon_design_damos_action>`. 75868536f8eSSeongJae Park 7595b7708e6SSeongJae Park - 0: ``willneed`` 7605b7708e6SSeongJae Park - 1: ``cold`` 7615b7708e6SSeongJae Park - 2: ``pageout`` 7625b7708e6SSeongJae Park - 3: ``hugepage`` 7635b7708e6SSeongJae Park - 4: ``nohugepage`` 7645b7708e6SSeongJae Park - 5: ``stat`` 76568536f8eSSeongJae Park 7666322416bSSeongJae ParkQuota 7676322416bSSeongJae Park~~~~~ 7686322416bSSeongJae Park 76901e08737SSeongJae ParkUsers can set the :ref:`quotas <damon_design_damos_quotas>` of the given scheme 77001e08737SSeongJae Parkvia the ``<quota>`` in below form:: 7716322416bSSeongJae Park 7726322416bSSeongJae Park <ms> <sz> <reset interval> <priority weights> 7736322416bSSeongJae Park 7746322416bSSeongJae ParkThis makes DAMON to try to use only up to ``<ms>`` milliseconds for applying 7756322416bSSeongJae Parkthe action to memory regions of the ``target access pattern`` within the 7766322416bSSeongJae Park``<reset interval>`` milliseconds, and to apply the action to only up to 7776322416bSSeongJae Park``<sz>`` bytes of memory regions within the ``<reset interval>``. Setting both 7786322416bSSeongJae Park``<ms>`` and ``<sz>`` zero disables the quota limits. 7796322416bSSeongJae Park 78001e08737SSeongJae ParkFor the :ref:`prioritization <damon_design_damos_quotas_prioritization>`, users 78101e08737SSeongJae Parkcan set the weights for the three properties in ``<priority weights>`` in below 78201e08737SSeongJae Parkform:: 7836322416bSSeongJae Park 7846322416bSSeongJae Park <size weight> <access frequency weight> <age weight> 7856322416bSSeongJae Park 7866322416bSSeongJae ParkWatermarks 7876322416bSSeongJae Park~~~~~~~~~~ 7886322416bSSeongJae Park 78901e08737SSeongJae ParkUsers can specify :ref:`watermarks <damon_design_damos_watermarks>` of the 79001e08737SSeongJae Parkgiven scheme via ``<watermarks>`` in below form:: 7916322416bSSeongJae Park 7926322416bSSeongJae Park <metric> <check interval> <high mark> <middle mark> <low mark> 7936322416bSSeongJae Park 7946322416bSSeongJae Park``<metric>`` is a predefined integer for the metric to be checked. The 7956322416bSSeongJae Parksupported numbers and their meanings are as below. 7966322416bSSeongJae Park 7976322416bSSeongJae Park - 0: Ignore the watermarks 7986322416bSSeongJae Park - 1: System's free memory rate (per thousand) 7996322416bSSeongJae Park 8006322416bSSeongJae ParkThe value of the metric is checked every ``<check interval>`` microseconds. 8016322416bSSeongJae Park 8026322416bSSeongJae ParkIf the value is higher than ``<high mark>`` or lower than ``<low mark>``, the 8036322416bSSeongJae Parkscheme is deactivated. If the value is lower than ``<mid mark>``, the scheme 8046322416bSSeongJae Parkis activated. 8056322416bSSeongJae Park 8064492bf45SSeongJae Park.. _damos_stats: 8074492bf45SSeongJae Park 8086322416bSSeongJae ParkStatistics 8096322416bSSeongJae Park~~~~~~~~~~ 8106322416bSSeongJae Park 811dbcb9b9fSSeongJae ParkIt also counts the total number and bytes of regions that each scheme is tried 812dbcb9b9fSSeongJae Parkto be applied, the two numbers for the regions that each scheme is successfully 813dbcb9b9fSSeongJae Parkapplied, and the total number of the quota limit exceeds. This statistics can 814dbcb9b9fSSeongJae Parkbe used for online analysis or tuning of the schemes. 8156322416bSSeongJae Park 8166322416bSSeongJae ParkThe statistics can be shown by reading the ``schemes`` file. Reading the file 817dbcb9b9fSSeongJae Parkwill show each scheme you entered in each line, and the five numbers for the 8186322416bSSeongJae Parkstatistics will be added at the end of each line. 8196322416bSSeongJae Park 8206322416bSSeongJae ParkExample 8216322416bSSeongJae Park~~~~~~~ 8226322416bSSeongJae Park 8236322416bSSeongJae ParkBelow commands applies a scheme saying "If a memory region of size in [4KiB, 8246322416bSSeongJae Park8KiB] is showing accesses per aggregate interval in [0, 5] for aggregate 8256322416bSSeongJae Parkinterval in [10, 20], page out the region. For the paging out, use only up to 8266322416bSSeongJae Park10ms per second, and also don't page out more than 1GiB per second. Under the 8276322416bSSeongJae Parklimitation, page out memory regions having longer age first. Also, check the 8286322416bSSeongJae Parkfree memory rate of the system every 5 seconds, start the monitoring and paging 8296322416bSSeongJae Parkout when the free memory rate becomes lower than 50%, but stop it if the free 8306322416bSSeongJae Parkmemory rate becomes larger than 60%, or lower than 30%".:: 83168536f8eSSeongJae Park 83268536f8eSSeongJae Park # cd <debugfs>/damon 8336322416bSSeongJae Park # scheme="4096 8192 0 5 10 20 2" # target access pattern and action 8346322416bSSeongJae Park # scheme+=" 10 $((1024*1024*1024)) 1000" # quotas 8356322416bSSeongJae Park # scheme+=" 0 0 100" # prioritization weights 8366322416bSSeongJae Park # scheme+=" 1 5000000 600 500 300" # watermarks 8376322416bSSeongJae Park # echo "$scheme" > schemes 83868536f8eSSeongJae Park 83968536f8eSSeongJae Park 840c4ba6014SSeongJae ParkTurning On/Off 841c4ba6014SSeongJae Park-------------- 842c4ba6014SSeongJae Park 843c4ba6014SSeongJae ParkSetting the files as described above doesn't incur effect unless you explicitly 844c4ba6014SSeongJae Parkstart the monitoring. You can start, stop, and check the current status of the 845ec28cf53SSeongJae Parkmonitoring by writing to and reading from the ``monitor_on_DEPRECATED`` file. 846ec28cf53SSeongJae ParkWriting ``on`` to the file starts the monitoring of the targets with the 847ec28cf53SSeongJae Parkattributes. Writing ``off`` to the file stops those. DAMON also stops if 848ec28cf53SSeongJae Parkevery target process is terminated. Below example commands turn on, off, and 849ec28cf53SSeongJae Parkcheck the status of DAMON:: 850c4ba6014SSeongJae Park 851c4ba6014SSeongJae Park # cd <debugfs>/damon 852ec28cf53SSeongJae Park # echo on > monitor_on_DEPRECATED 853ec28cf53SSeongJae Park # echo off > monitor_on_DEPRECATED 854ec28cf53SSeongJae Park # cat monitor_on_DEPRECATED 855c4ba6014SSeongJae Park off 856c4ba6014SSeongJae Park 857c4ba6014SSeongJae ParkPlease note that you cannot write to the above-mentioned debugfs files while 858c4ba6014SSeongJae Parkthe monitoring is turned on. If you write to the files while DAMON is running, 859c4ba6014SSeongJae Parkan error code such as ``-EBUSY`` will be returned. 860c4ba6014SSeongJae Park 861c4ba6014SSeongJae Park 862995d739cSSeongJae ParkMonitoring Thread PID 863995d739cSSeongJae Park--------------------- 864995d739cSSeongJae Park 865995d739cSSeongJae ParkDAMON does requested monitoring with a kernel thread called ``kdamond``. You 866995d739cSSeongJae Parkcan get the pid of the thread by reading the ``kdamond_pid`` file. When the 867995d739cSSeongJae Parkmonitoring is turned off, reading the file returns ``none``. :: 868995d739cSSeongJae Park 869995d739cSSeongJae Park # cd <debugfs>/damon 870ec28cf53SSeongJae Park # cat monitor_on_DEPRECATED 871995d739cSSeongJae Park off 872995d739cSSeongJae Park # cat kdamond_pid 873995d739cSSeongJae Park none 874ec28cf53SSeongJae Park # echo on > monitor_on_DEPRECATED 875995d739cSSeongJae Park # cat kdamond_pid 876995d739cSSeongJae Park 18594 877995d739cSSeongJae Park 878995d739cSSeongJae Park 879995d739cSSeongJae ParkUsing Multiple Monitoring Threads 880995d739cSSeongJae Park--------------------------------- 881995d739cSSeongJae Park 882995d739cSSeongJae ParkOne ``kdamond`` thread is created for each monitoring context. You can create 883995d739cSSeongJae Parkand remove monitoring contexts for multiple ``kdamond`` required use case using 884995d739cSSeongJae Parkthe ``mk_contexts`` and ``rm_contexts`` files. 885995d739cSSeongJae Park 886995d739cSSeongJae ParkWriting the name of the new context to the ``mk_contexts`` file creates a 887995d739cSSeongJae Parkdirectory of the name on the DAMON debugfs directory. The directory will have 888995d739cSSeongJae ParkDAMON debugfs files for the context. :: 889995d739cSSeongJae Park 890995d739cSSeongJae Park # cd <debugfs>/damon 891995d739cSSeongJae Park # ls foo 892995d739cSSeongJae Park # ls: cannot access 'foo': No such file or directory 893995d739cSSeongJae Park # echo foo > mk_contexts 894995d739cSSeongJae Park # ls foo 895995d739cSSeongJae Park # attrs init_regions kdamond_pid schemes target_ids 896995d739cSSeongJae Park 897995d739cSSeongJae ParkIf the context is not needed anymore, you can remove it and the corresponding 898995d739cSSeongJae Parkdirectory by putting the name of the context to the ``rm_contexts`` file. :: 899995d739cSSeongJae Park 900995d739cSSeongJae Park # echo foo > rm_contexts 901995d739cSSeongJae Park # ls foo 902995d739cSSeongJae Park # ls: cannot access 'foo': No such file or directory 903995d739cSSeongJae Park 904ec28cf53SSeongJae ParkNote that ``mk_contexts``, ``rm_contexts``, and ``monitor_on_DEPRECATED`` files 905ec28cf53SSeongJae Parkare in the root directory only. 906