162306a36Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci 362306a36Sopenharmony_ci=============== 462306a36Sopenharmony_ciDetailed Usages 562306a36Sopenharmony_ci=============== 662306a36Sopenharmony_ci 762306a36Sopenharmony_ciDAMON provides below interfaces for different users. 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci- *DAMON user space tool.* 1062306a36Sopenharmony_ci `This <https://github.com/awslabs/damo>`_ is for privileged people such as 1162306a36Sopenharmony_ci system administrators who want a just-working human-friendly interface. 1262306a36Sopenharmony_ci Using this, users can use the DAMON’s major features in a human-friendly way. 1362306a36Sopenharmony_ci It may not be highly tuned for special cases, though. For more detail, 1462306a36Sopenharmony_ci please refer to its `usage document 1562306a36Sopenharmony_ci <https://github.com/awslabs/damo/blob/next/USAGE.md>`_. 1662306a36Sopenharmony_ci- *sysfs interface.* 1762306a36Sopenharmony_ci :ref:`This <sysfs_interface>` is for privileged user space programmers who 1862306a36Sopenharmony_ci want more optimized use of DAMON. Using this, users can use DAMON’s major 1962306a36Sopenharmony_ci features by reading from and writing to special sysfs files. Therefore, 2062306a36Sopenharmony_ci you can write and use your personalized DAMON sysfs wrapper programs that 2162306a36Sopenharmony_ci reads/writes the sysfs files instead of you. The `DAMON user space tool 2262306a36Sopenharmony_ci <https://github.com/awslabs/damo>`_ is one example of such programs. 2362306a36Sopenharmony_ci- *debugfs interface. (DEPRECATED!)* 2462306a36Sopenharmony_ci :ref:`This <debugfs_interface>` is almost identical to :ref:`sysfs interface 2562306a36Sopenharmony_ci <sysfs_interface>`. This is deprecated, so users should move to the 2662306a36Sopenharmony_ci :ref:`sysfs interface <sysfs_interface>`. If you depend on this and cannot 2762306a36Sopenharmony_ci move, please report your usecase to damon@lists.linux.dev and 2862306a36Sopenharmony_ci linux-mm@kvack.org. 2962306a36Sopenharmony_ci- *Kernel Space Programming Interface.* 3062306a36Sopenharmony_ci :doc:`This </mm/damon/api>` is for kernel space programmers. Using this, 3162306a36Sopenharmony_ci users can utilize every feature of DAMON most flexibly and efficiently by 3262306a36Sopenharmony_ci writing kernel space DAMON application programs for you. You can even extend 3362306a36Sopenharmony_ci DAMON for various address spaces. For detail, please refer to the interface 3462306a36Sopenharmony_ci :doc:`document </mm/damon/api>`. 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_ci.. _sysfs_interface: 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_cisysfs Interface 3962306a36Sopenharmony_ci=============== 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ciDAMON sysfs interface is built when ``CONFIG_DAMON_SYSFS`` is defined. It 4262306a36Sopenharmony_cicreates multiple directories and files under its sysfs directory, 4362306a36Sopenharmony_ci``<sysfs>/kernel/mm/damon/``. You can control DAMON by writing to and reading 4462306a36Sopenharmony_cifrom the files under the directory. 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_ciFor a short example, users can monitor the virtual address space of a given 4762306a36Sopenharmony_ciworkload as below. :: 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ci # cd /sys/kernel/mm/damon/admin/ 5062306a36Sopenharmony_ci # echo 1 > kdamonds/nr_kdamonds && echo 1 > kdamonds/0/contexts/nr_contexts 5162306a36Sopenharmony_ci # echo vaddr > kdamonds/0/contexts/0/operations 5262306a36Sopenharmony_ci # echo 1 > kdamonds/0/contexts/0/targets/nr_targets 5362306a36Sopenharmony_ci # echo $(pidof <workload>) > kdamonds/0/contexts/0/targets/0/pid_target 5462306a36Sopenharmony_ci # echo on > kdamonds/0/state 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_ciFiles Hierarchy 5762306a36Sopenharmony_ci--------------- 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_ciThe files hierarchy of DAMON sysfs interface is shown below. In the below 6062306a36Sopenharmony_cifigure, parents-children relations are represented with indentations, each 6162306a36Sopenharmony_cidirectory is having ``/`` suffix, and files in each directory are separated by 6262306a36Sopenharmony_cicomma (","). :: 6362306a36Sopenharmony_ci 6462306a36Sopenharmony_ci /sys/kernel/mm/damon/admin 6562306a36Sopenharmony_ci │ kdamonds/nr_kdamonds 6662306a36Sopenharmony_ci │ │ 0/state,pid 6762306a36Sopenharmony_ci │ │ │ contexts/nr_contexts 6862306a36Sopenharmony_ci │ │ │ │ 0/avail_operations,operations 6962306a36Sopenharmony_ci │ │ │ │ │ monitoring_attrs/ 7062306a36Sopenharmony_ci │ │ │ │ │ │ intervals/sample_us,aggr_us,update_us 7162306a36Sopenharmony_ci │ │ │ │ │ │ nr_regions/min,max 7262306a36Sopenharmony_ci │ │ │ │ │ targets/nr_targets 7362306a36Sopenharmony_ci │ │ │ │ │ │ 0/pid_target 7462306a36Sopenharmony_ci │ │ │ │ │ │ │ regions/nr_regions 7562306a36Sopenharmony_ci │ │ │ │ │ │ │ │ 0/start,end 7662306a36Sopenharmony_ci │ │ │ │ │ │ │ │ ... 7762306a36Sopenharmony_ci │ │ │ │ │ │ ... 7862306a36Sopenharmony_ci │ │ │ │ │ schemes/nr_schemes 7962306a36Sopenharmony_ci │ │ │ │ │ │ 0/action 8062306a36Sopenharmony_ci │ │ │ │ │ │ │ access_pattern/ 8162306a36Sopenharmony_ci │ │ │ │ │ │ │ │ sz/min,max 8262306a36Sopenharmony_ci │ │ │ │ │ │ │ │ nr_accesses/min,max 8362306a36Sopenharmony_ci │ │ │ │ │ │ │ │ age/min,max 8462306a36Sopenharmony_ci │ │ │ │ │ │ │ quotas/ms,bytes,reset_interval_ms 8562306a36Sopenharmony_ci │ │ │ │ │ │ │ │ weights/sz_permil,nr_accesses_permil,age_permil 8662306a36Sopenharmony_ci │ │ │ │ │ │ │ watermarks/metric,interval_us,high,mid,low 8762306a36Sopenharmony_ci │ │ │ │ │ │ │ filters/nr_filters 8862306a36Sopenharmony_ci │ │ │ │ │ │ │ │ 0/type,matching,memcg_id 8962306a36Sopenharmony_ci │ │ │ │ │ │ │ stats/nr_tried,sz_tried,nr_applied,sz_applied,qt_exceeds 9062306a36Sopenharmony_ci │ │ │ │ │ │ │ tried_regions/total_bytes 9162306a36Sopenharmony_ci │ │ │ │ │ │ │ │ 0/start,end,nr_accesses,age 9262306a36Sopenharmony_ci │ │ │ │ │ │ │ │ ... 9362306a36Sopenharmony_ci │ │ │ │ │ │ ... 9462306a36Sopenharmony_ci │ │ │ │ ... 9562306a36Sopenharmony_ci │ │ ... 9662306a36Sopenharmony_ci 9762306a36Sopenharmony_ciRoot 9862306a36Sopenharmony_ci---- 9962306a36Sopenharmony_ci 10062306a36Sopenharmony_ciThe root of the DAMON sysfs interface is ``<sysfs>/kernel/mm/damon/``, and it 10162306a36Sopenharmony_cihas one directory named ``admin``. The directory contains the files for 10262306a36Sopenharmony_ciprivileged user space programs' control of DAMON. User space tools or daemons 10362306a36Sopenharmony_cihaving the root permission could use this directory. 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_cikdamonds/ 10662306a36Sopenharmony_ci--------- 10762306a36Sopenharmony_ci 10862306a36Sopenharmony_ciThe monitoring-related information including request specifications and results 10962306a36Sopenharmony_ciare called DAMON context. DAMON executes each context with a kernel thread 11062306a36Sopenharmony_cicalled kdamond, and multiple kdamonds could run in parallel. 11162306a36Sopenharmony_ci 11262306a36Sopenharmony_ciUnder the ``admin`` directory, one directory, ``kdamonds``, which has files for 11362306a36Sopenharmony_cicontrolling the kdamonds exist. In the beginning, this directory has only one 11462306a36Sopenharmony_cifile, ``nr_kdamonds``. Writing a number (``N``) to the file creates the number 11562306a36Sopenharmony_ciof child directories named ``0`` to ``N-1``. Each directory represents each 11662306a36Sopenharmony_cikdamond. 11762306a36Sopenharmony_ci 11862306a36Sopenharmony_cikdamonds/<N>/ 11962306a36Sopenharmony_ci------------- 12062306a36Sopenharmony_ci 12162306a36Sopenharmony_ciIn each kdamond directory, two files (``state`` and ``pid``) and one directory 12262306a36Sopenharmony_ci(``contexts``) exist. 12362306a36Sopenharmony_ci 12462306a36Sopenharmony_ciReading ``state`` returns ``on`` if the kdamond is currently running, or 12562306a36Sopenharmony_ci``off`` if it is not running. Writing ``on`` or ``off`` makes the kdamond be 12662306a36Sopenharmony_ciin the state. Writing ``commit`` to the ``state`` file makes kdamond reads the 12762306a36Sopenharmony_ciuser inputs in the sysfs files except ``state`` file again. Writing 12862306a36Sopenharmony_ci``update_schemes_stats`` to ``state`` file updates the contents of stats files 12962306a36Sopenharmony_cifor each DAMON-based operation scheme of the kdamond. For details of the 13062306a36Sopenharmony_cistats, please refer to :ref:`stats section <sysfs_schemes_stats>`. 13162306a36Sopenharmony_ci 13262306a36Sopenharmony_ciWriting ``update_schemes_tried_regions`` to ``state`` file updates the 13362306a36Sopenharmony_ciDAMON-based operation scheme action tried regions directory for each 13462306a36Sopenharmony_ciDAMON-based operation scheme of the kdamond. Writing 13562306a36Sopenharmony_ci``update_schemes_tried_bytes`` to ``state`` file updates only 13662306a36Sopenharmony_ci``.../tried_regions/total_bytes`` files. Writing 13762306a36Sopenharmony_ci``clear_schemes_tried_regions`` to ``state`` file clears the DAMON-based 13862306a36Sopenharmony_cioperating scheme action tried regions directory for each DAMON-based operation 13962306a36Sopenharmony_cischeme of the kdamond. For details of the DAMON-based operation scheme action 14062306a36Sopenharmony_citried regions directory, please refer to :ref:`tried_regions section 14162306a36Sopenharmony_ci<sysfs_schemes_tried_regions>`. 14262306a36Sopenharmony_ci 14362306a36Sopenharmony_ciIf the state is ``on``, reading ``pid`` shows the pid of the kdamond thread. 14462306a36Sopenharmony_ci 14562306a36Sopenharmony_ci``contexts`` directory contains files for controlling the monitoring contexts 14662306a36Sopenharmony_cithat this kdamond will execute. 14762306a36Sopenharmony_ci 14862306a36Sopenharmony_cikdamonds/<N>/contexts/ 14962306a36Sopenharmony_ci---------------------- 15062306a36Sopenharmony_ci 15162306a36Sopenharmony_ciIn the beginning, this directory has only one file, ``nr_contexts``. Writing a 15262306a36Sopenharmony_cinumber (``N``) to the file creates the number of child directories named as 15362306a36Sopenharmony_ci``0`` to ``N-1``. Each directory represents each monitoring context. At the 15462306a36Sopenharmony_cimoment, only one context per kdamond is supported, so only ``0`` or ``1`` can 15562306a36Sopenharmony_cibe written to the file. 15662306a36Sopenharmony_ci 15762306a36Sopenharmony_ci.. _sysfs_contexts: 15862306a36Sopenharmony_ci 15962306a36Sopenharmony_cicontexts/<N>/ 16062306a36Sopenharmony_ci------------- 16162306a36Sopenharmony_ci 16262306a36Sopenharmony_ciIn each context directory, two files (``avail_operations`` and ``operations``) 16362306a36Sopenharmony_ciand three directories (``monitoring_attrs``, ``targets``, and ``schemes``) 16462306a36Sopenharmony_ciexist. 16562306a36Sopenharmony_ci 16662306a36Sopenharmony_ciDAMON supports multiple types of monitoring operations, including those for 16762306a36Sopenharmony_civirtual address space and the physical address space. You can get the list of 16862306a36Sopenharmony_ciavailable monitoring operations set on the currently running kernel by reading 16962306a36Sopenharmony_ci``avail_operations`` file. Based on the kernel configuration, the file will 17062306a36Sopenharmony_cilist some or all of below keywords. 17162306a36Sopenharmony_ci 17262306a36Sopenharmony_ci - vaddr: Monitor virtual address spaces of specific processes 17362306a36Sopenharmony_ci - fvaddr: Monitor fixed virtual address ranges 17462306a36Sopenharmony_ci - paddr: Monitor the physical address space of the system 17562306a36Sopenharmony_ci 17662306a36Sopenharmony_ciPlease refer to :ref:`regions sysfs directory <sysfs_regions>` for detailed 17762306a36Sopenharmony_cidifferences between the operations sets in terms of the monitoring target 17862306a36Sopenharmony_ciregions. 17962306a36Sopenharmony_ci 18062306a36Sopenharmony_ciYou can set and get what type of monitoring operations DAMON will use for the 18162306a36Sopenharmony_cicontext by writing one of the keywords listed in ``avail_operations`` file and 18262306a36Sopenharmony_cireading from the ``operations`` file. 18362306a36Sopenharmony_ci 18462306a36Sopenharmony_ci.. _sysfs_monitoring_attrs: 18562306a36Sopenharmony_ci 18662306a36Sopenharmony_cicontexts/<N>/monitoring_attrs/ 18762306a36Sopenharmony_ci------------------------------ 18862306a36Sopenharmony_ci 18962306a36Sopenharmony_ciFiles for specifying attributes of the monitoring including required quality 19062306a36Sopenharmony_ciand efficiency of the monitoring are in ``monitoring_attrs`` directory. 19162306a36Sopenharmony_ciSpecifically, two directories, ``intervals`` and ``nr_regions`` exist in this 19262306a36Sopenharmony_cidirectory. 19362306a36Sopenharmony_ci 19462306a36Sopenharmony_ciUnder ``intervals`` directory, three files for DAMON's sampling interval 19562306a36Sopenharmony_ci(``sample_us``), aggregation interval (``aggr_us``), and update interval 19662306a36Sopenharmony_ci(``update_us``) exist. You can set and get the values in micro-seconds by 19762306a36Sopenharmony_ciwriting to and reading from the files. 19862306a36Sopenharmony_ci 19962306a36Sopenharmony_ciUnder ``nr_regions`` directory, two files for the lower-bound and upper-bound 20062306a36Sopenharmony_ciof DAMON's monitoring regions (``min`` and ``max``, respectively), which 20162306a36Sopenharmony_cicontrols the monitoring overhead, exist. You can set and get the values by 20262306a36Sopenharmony_ciwriting to and rading from the files. 20362306a36Sopenharmony_ci 20462306a36Sopenharmony_ciFor more details about the intervals and monitoring regions range, please refer 20562306a36Sopenharmony_cito the Design document (:doc:`/mm/damon/design`). 20662306a36Sopenharmony_ci 20762306a36Sopenharmony_cicontexts/<N>/targets/ 20862306a36Sopenharmony_ci--------------------- 20962306a36Sopenharmony_ci 21062306a36Sopenharmony_ciIn the beginning, this directory has only one file, ``nr_targets``. Writing a 21162306a36Sopenharmony_cinumber (``N``) to the file creates the number of child directories named ``0`` 21262306a36Sopenharmony_cito ``N-1``. Each directory represents each monitoring target. 21362306a36Sopenharmony_ci 21462306a36Sopenharmony_citargets/<N>/ 21562306a36Sopenharmony_ci------------ 21662306a36Sopenharmony_ci 21762306a36Sopenharmony_ciIn each target directory, one file (``pid_target``) and one directory 21862306a36Sopenharmony_ci(``regions``) exist. 21962306a36Sopenharmony_ci 22062306a36Sopenharmony_ciIf you wrote ``vaddr`` to the ``contexts/<N>/operations``, each target should 22162306a36Sopenharmony_cibe a process. You can specify the process to DAMON by writing the pid of the 22262306a36Sopenharmony_ciprocess to the ``pid_target`` file. 22362306a36Sopenharmony_ci 22462306a36Sopenharmony_ci.. _sysfs_regions: 22562306a36Sopenharmony_ci 22662306a36Sopenharmony_citargets/<N>/regions 22762306a36Sopenharmony_ci------------------- 22862306a36Sopenharmony_ci 22962306a36Sopenharmony_ciWhen ``vaddr`` monitoring operations set is being used (``vaddr`` is written to 23062306a36Sopenharmony_cithe ``contexts/<N>/operations`` file), DAMON automatically sets and updates the 23162306a36Sopenharmony_cimonitoring target regions so that entire memory mappings of target processes 23262306a36Sopenharmony_cican be covered. However, users could want to set the initial monitoring region 23362306a36Sopenharmony_cito specific address ranges. 23462306a36Sopenharmony_ci 23562306a36Sopenharmony_ciIn contrast, DAMON do not automatically sets and updates the monitoring target 23662306a36Sopenharmony_ciregions when ``fvaddr`` or ``paddr`` monitoring operations sets are being used 23762306a36Sopenharmony_ci(``fvaddr`` or ``paddr`` have written to the ``contexts/<N>/operations``). 23862306a36Sopenharmony_ciTherefore, users should set the monitoring target regions by themselves in the 23962306a36Sopenharmony_cicases. 24062306a36Sopenharmony_ci 24162306a36Sopenharmony_ciFor such cases, users can explicitly set the initial monitoring target regions 24262306a36Sopenharmony_cias they want, by writing proper values to the files under this directory. 24362306a36Sopenharmony_ci 24462306a36Sopenharmony_ciIn the beginning, this directory has only one file, ``nr_regions``. Writing a 24562306a36Sopenharmony_cinumber (``N``) to the file creates the number of child directories named ``0`` 24662306a36Sopenharmony_cito ``N-1``. Each directory represents each initial monitoring target region. 24762306a36Sopenharmony_ci 24862306a36Sopenharmony_ciregions/<N>/ 24962306a36Sopenharmony_ci------------ 25062306a36Sopenharmony_ci 25162306a36Sopenharmony_ciIn each region directory, you will find two files (``start`` and ``end``). You 25262306a36Sopenharmony_cican set and get the start and end addresses of the initial monitoring target 25362306a36Sopenharmony_ciregion by writing to and reading from the files, respectively. 25462306a36Sopenharmony_ci 25562306a36Sopenharmony_ciEach region should not overlap with others. ``end`` of directory ``N`` should 25662306a36Sopenharmony_cibe equal or smaller than ``start`` of directory ``N+1``. 25762306a36Sopenharmony_ci 25862306a36Sopenharmony_cicontexts/<N>/schemes/ 25962306a36Sopenharmony_ci--------------------- 26062306a36Sopenharmony_ci 26162306a36Sopenharmony_ciThe directory for DAMON-based Operation Schemes (:ref:`DAMOS 26262306a36Sopenharmony_ci<damon_design_damos>`). Users can get and set the schemes by reading from and 26362306a36Sopenharmony_ciwriting to files under this directory. 26462306a36Sopenharmony_ci 26562306a36Sopenharmony_ciIn the beginning, this directory has only one file, ``nr_schemes``. Writing a 26662306a36Sopenharmony_cinumber (``N``) to the file creates the number of child directories named ``0`` 26762306a36Sopenharmony_cito ``N-1``. Each directory represents each DAMON-based operation scheme. 26862306a36Sopenharmony_ci 26962306a36Sopenharmony_cischemes/<N>/ 27062306a36Sopenharmony_ci------------ 27162306a36Sopenharmony_ci 27262306a36Sopenharmony_ciIn each scheme directory, five directories (``access_pattern``, ``quotas``, 27362306a36Sopenharmony_ci``watermarks``, ``filters``, ``stats``, and ``tried_regions``) and one file 27462306a36Sopenharmony_ci(``action``) exist. 27562306a36Sopenharmony_ci 27662306a36Sopenharmony_ciThe ``action`` file is for setting and getting the scheme's :ref:`action 27762306a36Sopenharmony_ci<damon_design_damos_action>`. The keywords that can be written to and read 27862306a36Sopenharmony_cifrom the file and their meaning are as below. 27962306a36Sopenharmony_ci 28062306a36Sopenharmony_ciNote that support of each action depends on the running DAMON operations set 28162306a36Sopenharmony_ci:ref:`implementation <sysfs_contexts>`. 28262306a36Sopenharmony_ci 28362306a36Sopenharmony_ci - ``willneed``: Call ``madvise()`` for the region with ``MADV_WILLNEED``. 28462306a36Sopenharmony_ci Supported by ``vaddr`` and ``fvaddr`` operations set. 28562306a36Sopenharmony_ci - ``cold``: Call ``madvise()`` for the region with ``MADV_COLD``. 28662306a36Sopenharmony_ci Supported by ``vaddr`` and ``fvaddr`` operations set. 28762306a36Sopenharmony_ci - ``pageout``: Call ``madvise()`` for the region with ``MADV_PAGEOUT``. 28862306a36Sopenharmony_ci Supported by ``vaddr``, ``fvaddr`` and ``paddr`` operations set. 28962306a36Sopenharmony_ci - ``hugepage``: Call ``madvise()`` for the region with ``MADV_HUGEPAGE``. 29062306a36Sopenharmony_ci Supported by ``vaddr`` and ``fvaddr`` operations set. 29162306a36Sopenharmony_ci - ``nohugepage``: Call ``madvise()`` for the region with ``MADV_NOHUGEPAGE``. 29262306a36Sopenharmony_ci Supported by ``vaddr`` and ``fvaddr`` operations set. 29362306a36Sopenharmony_ci - ``lru_prio``: Prioritize the region on its LRU lists. 29462306a36Sopenharmony_ci Supported by ``paddr`` operations set. 29562306a36Sopenharmony_ci - ``lru_deprio``: Deprioritize the region on its LRU lists. 29662306a36Sopenharmony_ci Supported by ``paddr`` operations set. 29762306a36Sopenharmony_ci - ``stat``: Do nothing but count the statistics. 29862306a36Sopenharmony_ci Supported by all operations sets. 29962306a36Sopenharmony_ci 30062306a36Sopenharmony_cischemes/<N>/access_pattern/ 30162306a36Sopenharmony_ci--------------------------- 30262306a36Sopenharmony_ci 30362306a36Sopenharmony_ciThe directory for the target access :ref:`pattern 30462306a36Sopenharmony_ci<damon_design_damos_access_pattern>` of the given DAMON-based operation scheme. 30562306a36Sopenharmony_ci 30662306a36Sopenharmony_ciUnder the ``access_pattern`` directory, three directories (``sz``, 30762306a36Sopenharmony_ci``nr_accesses``, and ``age``) each having two files (``min`` and ``max``) 30862306a36Sopenharmony_ciexist. You can set and get the access pattern for the given scheme by writing 30962306a36Sopenharmony_cito and reading from the ``min`` and ``max`` files under ``sz``, 31062306a36Sopenharmony_ci``nr_accesses``, and ``age`` directories, respectively. Note that the ``min`` 31162306a36Sopenharmony_ciand the ``max`` form a closed interval. 31262306a36Sopenharmony_ci 31362306a36Sopenharmony_cischemes/<N>/quotas/ 31462306a36Sopenharmony_ci------------------- 31562306a36Sopenharmony_ci 31662306a36Sopenharmony_ciThe directory for the :ref:`quotas <damon_design_damos_quotas>` of the given 31762306a36Sopenharmony_ciDAMON-based operation scheme. 31862306a36Sopenharmony_ci 31962306a36Sopenharmony_ciUnder ``quotas`` directory, three files (``ms``, ``bytes``, 32062306a36Sopenharmony_ci``reset_interval_ms``) and one directory (``weights``) having three files 32162306a36Sopenharmony_ci(``sz_permil``, ``nr_accesses_permil``, and ``age_permil``) in it exist. 32262306a36Sopenharmony_ci 32362306a36Sopenharmony_ciYou can set the ``time quota`` in milliseconds, ``size quota`` in bytes, and 32462306a36Sopenharmony_ci``reset interval`` in milliseconds by writing the values to the three files, 32562306a36Sopenharmony_cirespectively. Then, DAMON tries to use only up to ``time quota`` milliseconds 32662306a36Sopenharmony_cifor applying the ``action`` to memory regions of the ``access_pattern``, and to 32762306a36Sopenharmony_ciapply the action to only up to ``bytes`` bytes of memory regions within the 32862306a36Sopenharmony_ci``reset_interval_ms``. Setting both ``ms`` and ``bytes`` zero disables the 32962306a36Sopenharmony_ciquota limits. 33062306a36Sopenharmony_ci 33162306a36Sopenharmony_ciYou can also set the :ref:`prioritization weights 33262306a36Sopenharmony_ci<damon_design_damos_quotas_prioritization>` for size, access frequency, and age 33362306a36Sopenharmony_ciin per-thousand unit by writing the values to the three files under the 33462306a36Sopenharmony_ci``weights`` directory. 33562306a36Sopenharmony_ci 33662306a36Sopenharmony_cischemes/<N>/watermarks/ 33762306a36Sopenharmony_ci----------------------- 33862306a36Sopenharmony_ci 33962306a36Sopenharmony_ciThe directory for the :ref:`watermarks <damon_design_damos_watermarks>` of the 34062306a36Sopenharmony_cigiven DAMON-based operation scheme. 34162306a36Sopenharmony_ci 34262306a36Sopenharmony_ciUnder the watermarks directory, five files (``metric``, ``interval_us``, 34362306a36Sopenharmony_ci``high``, ``mid``, and ``low``) for setting the metric, the time interval 34462306a36Sopenharmony_cibetween check of the metric, and the three watermarks exist. You can set and 34562306a36Sopenharmony_ciget the five values by writing to the files, respectively. 34662306a36Sopenharmony_ci 34762306a36Sopenharmony_ciKeywords and meanings of those that can be written to the ``metric`` file are 34862306a36Sopenharmony_cias below. 34962306a36Sopenharmony_ci 35062306a36Sopenharmony_ci - none: Ignore the watermarks 35162306a36Sopenharmony_ci - free_mem_rate: System's free memory rate (per thousand) 35262306a36Sopenharmony_ci 35362306a36Sopenharmony_ciThe ``interval`` should written in microseconds unit. 35462306a36Sopenharmony_ci 35562306a36Sopenharmony_cischemes/<N>/filters/ 35662306a36Sopenharmony_ci-------------------- 35762306a36Sopenharmony_ci 35862306a36Sopenharmony_ciThe directory for the :ref:`filters <damon_design_damos_filters>` of the given 35962306a36Sopenharmony_ciDAMON-based operation scheme. 36062306a36Sopenharmony_ci 36162306a36Sopenharmony_ciIn the beginning, this directory has only one file, ``nr_filters``. Writing a 36262306a36Sopenharmony_cinumber (``N``) to the file creates the number of child directories named ``0`` 36362306a36Sopenharmony_cito ``N-1``. Each directory represents each filter. The filters are evaluated 36462306a36Sopenharmony_ciin the numeric order. 36562306a36Sopenharmony_ci 36662306a36Sopenharmony_ciEach filter directory contains six files, namely ``type``, ``matcing``, 36762306a36Sopenharmony_ci``memcg_path``, ``addr_start``, ``addr_end``, and ``target_idx``. To ``type`` 36862306a36Sopenharmony_cifile, you can write one of four special keywords: ``anon`` for anonymous pages, 36962306a36Sopenharmony_ci``memcg`` for specific memory cgroup, ``addr`` for specific address range (an 37062306a36Sopenharmony_ciopen-ended interval), or ``target`` for specific DAMON monitoring target 37162306a36Sopenharmony_cifiltering. In case of the memory cgroup filtering, you can specify the memory 37262306a36Sopenharmony_cicgroup of the interest by writing the path of the memory cgroup from the 37362306a36Sopenharmony_cicgroups mount point to ``memcg_path`` file. In case of the address range 37462306a36Sopenharmony_cifiltering, you can specify the start and end address of the range to 37562306a36Sopenharmony_ci``addr_start`` and ``addr_end`` files, respectively. For the DAMON monitoring 37662306a36Sopenharmony_citarget filtering, you can specify the index of the target between the list of 37762306a36Sopenharmony_cithe DAMON context's monitoring targets list to ``target_idx`` file. You can 37862306a36Sopenharmony_ciwrite ``Y`` or ``N`` to ``matching`` file to filter out pages that does or does 37962306a36Sopenharmony_cinot match to the type, respectively. Then, the scheme's action will not be 38062306a36Sopenharmony_ciapplied to the pages that specified to be filtered out. 38162306a36Sopenharmony_ci 38262306a36Sopenharmony_ciFor example, below restricts a DAMOS action to be applied to only non-anonymous 38362306a36Sopenharmony_cipages of all memory cgroups except ``/having_care_already``.:: 38462306a36Sopenharmony_ci 38562306a36Sopenharmony_ci # echo 2 > nr_filters 38662306a36Sopenharmony_ci # # filter out anonymous pages 38762306a36Sopenharmony_ci echo anon > 0/type 38862306a36Sopenharmony_ci echo Y > 0/matching 38962306a36Sopenharmony_ci # # further filter out all cgroups except one at '/having_care_already' 39062306a36Sopenharmony_ci echo memcg > 1/type 39162306a36Sopenharmony_ci echo /having_care_already > 1/memcg_path 39262306a36Sopenharmony_ci echo N > 1/matching 39362306a36Sopenharmony_ci 39462306a36Sopenharmony_ciNote that ``anon`` and ``memcg`` filters are currently supported only when 39562306a36Sopenharmony_ci``paddr`` `implementation <sysfs_contexts>` is being used. 39662306a36Sopenharmony_ci 39762306a36Sopenharmony_ciAlso, memory regions that are filtered out by ``addr`` or ``target`` filters 39862306a36Sopenharmony_ciare not counted as the scheme has tried to those, while regions that filtered 39962306a36Sopenharmony_ciout by other type filters are counted as the scheme has tried to. The 40062306a36Sopenharmony_cidifference is applied to :ref:`stats <damos_stats>` and 40162306a36Sopenharmony_ci:ref:`tried regions <sysfs_schemes_tried_regions>`. 40262306a36Sopenharmony_ci 40362306a36Sopenharmony_ci.. _sysfs_schemes_stats: 40462306a36Sopenharmony_ci 40562306a36Sopenharmony_cischemes/<N>/stats/ 40662306a36Sopenharmony_ci------------------ 40762306a36Sopenharmony_ci 40862306a36Sopenharmony_ciDAMON counts the total number and bytes of regions that each scheme is tried to 40962306a36Sopenharmony_cibe applied, the two numbers for the regions that each scheme is successfully 41062306a36Sopenharmony_ciapplied, and the total number of the quota limit exceeds. This statistics can 41162306a36Sopenharmony_cibe used for online analysis or tuning of the schemes. 41262306a36Sopenharmony_ci 41362306a36Sopenharmony_ciThe statistics can be retrieved by reading the files under ``stats`` directory 41462306a36Sopenharmony_ci(``nr_tried``, ``sz_tried``, ``nr_applied``, ``sz_applied``, and 41562306a36Sopenharmony_ci``qt_exceeds``), respectively. The files are not updated in real time, so you 41662306a36Sopenharmony_cishould ask DAMON sysfs interface to update the content of the files for the 41762306a36Sopenharmony_cistats by writing a special keyword, ``update_schemes_stats`` to the relevant 41862306a36Sopenharmony_ci``kdamonds/<N>/state`` file. 41962306a36Sopenharmony_ci 42062306a36Sopenharmony_ci.. _sysfs_schemes_tried_regions: 42162306a36Sopenharmony_ci 42262306a36Sopenharmony_cischemes/<N>/tried_regions/ 42362306a36Sopenharmony_ci-------------------------- 42462306a36Sopenharmony_ci 42562306a36Sopenharmony_ciThis directory initially has one file, ``total_bytes``. 42662306a36Sopenharmony_ci 42762306a36Sopenharmony_ciWhen a special keyword, ``update_schemes_tried_regions``, is written to the 42862306a36Sopenharmony_cirelevant ``kdamonds/<N>/state`` file, DAMON updates the ``total_bytes`` file so 42962306a36Sopenharmony_cithat reading it returns the total size of the scheme tried regions, and creates 43062306a36Sopenharmony_cidirectories named integer starting from ``0`` under this directory. Each 43162306a36Sopenharmony_cidirectory contains files exposing detailed information about each of the memory 43262306a36Sopenharmony_ciregion that the corresponding scheme's ``action`` has tried to be applied under 43362306a36Sopenharmony_cithis directory, during next :ref:`aggregation interval 43462306a36Sopenharmony_ci<sysfs_monitoring_attrs>`. The information includes address range, 43562306a36Sopenharmony_ci``nr_accesses``, and ``age`` of the region. 43662306a36Sopenharmony_ci 43762306a36Sopenharmony_ciWriting ``update_schemes_tried_bytes`` to the relevant ``kdamonds/<N>/state`` 43862306a36Sopenharmony_cifile will only update the ``total_bytes`` file, and will not create the 43962306a36Sopenharmony_cisubdirectories. 44062306a36Sopenharmony_ci 44162306a36Sopenharmony_ciThe directories will be removed when another special keyword, 44262306a36Sopenharmony_ci``clear_schemes_tried_regions``, is written to the relevant 44362306a36Sopenharmony_ci``kdamonds/<N>/state`` file. 44462306a36Sopenharmony_ci 44562306a36Sopenharmony_ciThe expected usage of this directory is investigations of schemes' behaviors, 44662306a36Sopenharmony_ciand query-like efficient data access monitoring results retrievals. For the 44762306a36Sopenharmony_cilatter use case, in particular, users can set the ``action`` as ``stat`` and 44862306a36Sopenharmony_ciset the ``access pattern`` as their interested pattern that they want to query. 44962306a36Sopenharmony_ci 45062306a36Sopenharmony_citried_regions/<N>/ 45162306a36Sopenharmony_ci------------------ 45262306a36Sopenharmony_ci 45362306a36Sopenharmony_ciIn each region directory, you will find four files (``start``, ``end``, 45462306a36Sopenharmony_ci``nr_accesses``, and ``age``). Reading the files will show the start and end 45562306a36Sopenharmony_ciaddresses, ``nr_accesses``, and ``age`` of the region that corresponding 45662306a36Sopenharmony_ciDAMON-based operation scheme ``action`` has tried to be applied. 45762306a36Sopenharmony_ci 45862306a36Sopenharmony_ciExample 45962306a36Sopenharmony_ci~~~~~~~ 46062306a36Sopenharmony_ci 46162306a36Sopenharmony_ciBelow commands applies a scheme saying "If a memory region of size in [4KiB, 46262306a36Sopenharmony_ci8KiB] is showing accesses per aggregate interval in [0, 5] for aggregate 46362306a36Sopenharmony_ciinterval in [10, 20], page out the region. For the paging out, use only up to 46462306a36Sopenharmony_ci10ms per second, and also don't page out more than 1GiB per second. Under the 46562306a36Sopenharmony_cilimitation, page out memory regions having longer age first. Also, check the 46662306a36Sopenharmony_cifree memory rate of the system every 5 seconds, start the monitoring and paging 46762306a36Sopenharmony_ciout when the free memory rate becomes lower than 50%, but stop it if the free 46862306a36Sopenharmony_cimemory rate becomes larger than 60%, or lower than 30%". :: 46962306a36Sopenharmony_ci 47062306a36Sopenharmony_ci # cd <sysfs>/kernel/mm/damon/admin 47162306a36Sopenharmony_ci # # populate directories 47262306a36Sopenharmony_ci # echo 1 > kdamonds/nr_kdamonds; echo 1 > kdamonds/0/contexts/nr_contexts; 47362306a36Sopenharmony_ci # echo 1 > kdamonds/0/contexts/0/schemes/nr_schemes 47462306a36Sopenharmony_ci # cd kdamonds/0/contexts/0/schemes/0 47562306a36Sopenharmony_ci # # set the basic access pattern and the action 47662306a36Sopenharmony_ci # echo 4096 > access_pattern/sz/min 47762306a36Sopenharmony_ci # echo 8192 > access_pattern/sz/max 47862306a36Sopenharmony_ci # echo 0 > access_pattern/nr_accesses/min 47962306a36Sopenharmony_ci # echo 5 > access_pattern/nr_accesses/max 48062306a36Sopenharmony_ci # echo 10 > access_pattern/age/min 48162306a36Sopenharmony_ci # echo 20 > access_pattern/age/max 48262306a36Sopenharmony_ci # echo pageout > action 48362306a36Sopenharmony_ci # # set quotas 48462306a36Sopenharmony_ci # echo 10 > quotas/ms 48562306a36Sopenharmony_ci # echo $((1024*1024*1024)) > quotas/bytes 48662306a36Sopenharmony_ci # echo 1000 > quotas/reset_interval_ms 48762306a36Sopenharmony_ci # # set watermark 48862306a36Sopenharmony_ci # echo free_mem_rate > watermarks/metric 48962306a36Sopenharmony_ci # echo 5000000 > watermarks/interval_us 49062306a36Sopenharmony_ci # echo 600 > watermarks/high 49162306a36Sopenharmony_ci # echo 500 > watermarks/mid 49262306a36Sopenharmony_ci # echo 300 > watermarks/low 49362306a36Sopenharmony_ci 49462306a36Sopenharmony_ciPlease note that it's highly recommended to use user space tools like `damo 49562306a36Sopenharmony_ci<https://github.com/awslabs/damo>`_ rather than manually reading and writing 49662306a36Sopenharmony_cithe files as above. Above is only for an example. 49762306a36Sopenharmony_ci 49862306a36Sopenharmony_ci.. _debugfs_interface: 49962306a36Sopenharmony_ci 50062306a36Sopenharmony_cidebugfs Interface (DEPRECATED!) 50162306a36Sopenharmony_ci=============================== 50262306a36Sopenharmony_ci 50362306a36Sopenharmony_ci.. note:: 50462306a36Sopenharmony_ci 50562306a36Sopenharmony_ci THIS IS DEPRECATED! 50662306a36Sopenharmony_ci 50762306a36Sopenharmony_ci DAMON debugfs interface is deprecated, so users should move to the 50862306a36Sopenharmony_ci :ref:`sysfs interface <sysfs_interface>`. If you depend on this and cannot 50962306a36Sopenharmony_ci move, please report your usecase to damon@lists.linux.dev and 51062306a36Sopenharmony_ci linux-mm@kvack.org. 51162306a36Sopenharmony_ci 51262306a36Sopenharmony_ciDAMON exports eight files, ``attrs``, ``target_ids``, ``init_regions``, 51362306a36Sopenharmony_ci``schemes``, ``monitor_on``, ``kdamond_pid``, ``mk_contexts`` and 51462306a36Sopenharmony_ci``rm_contexts`` under its debugfs directory, ``<debugfs>/damon/``. 51562306a36Sopenharmony_ci 51662306a36Sopenharmony_ci 51762306a36Sopenharmony_ciAttributes 51862306a36Sopenharmony_ci---------- 51962306a36Sopenharmony_ci 52062306a36Sopenharmony_ciUsers can get and set the ``sampling interval``, ``aggregation interval``, 52162306a36Sopenharmony_ci``update interval``, and min/max number of monitoring target regions by 52262306a36Sopenharmony_cireading from and writing to the ``attrs`` file. To know about the monitoring 52362306a36Sopenharmony_ciattributes in detail, please refer to the :doc:`/mm/damon/design`. For 52462306a36Sopenharmony_ciexample, below commands set those values to 5 ms, 100 ms, 1,000 ms, 10 and 52562306a36Sopenharmony_ci1000, and then check it again:: 52662306a36Sopenharmony_ci 52762306a36Sopenharmony_ci # cd <debugfs>/damon 52862306a36Sopenharmony_ci # echo 5000 100000 1000000 10 1000 > attrs 52962306a36Sopenharmony_ci # cat attrs 53062306a36Sopenharmony_ci 5000 100000 1000000 10 1000 53162306a36Sopenharmony_ci 53262306a36Sopenharmony_ci 53362306a36Sopenharmony_ciTarget IDs 53462306a36Sopenharmony_ci---------- 53562306a36Sopenharmony_ci 53662306a36Sopenharmony_ciSome types of address spaces supports multiple monitoring target. For example, 53762306a36Sopenharmony_cithe virtual memory address spaces monitoring can have multiple processes as the 53862306a36Sopenharmony_cimonitoring targets. Users can set the targets by writing relevant id values of 53962306a36Sopenharmony_cithe targets to, and get the ids of the current targets by reading from the 54062306a36Sopenharmony_ci``target_ids`` file. In case of the virtual address spaces monitoring, the 54162306a36Sopenharmony_civalues should be pids of the monitoring target processes. For example, below 54262306a36Sopenharmony_cicommands set processes having pids 42 and 4242 as the monitoring targets and 54362306a36Sopenharmony_cicheck it again:: 54462306a36Sopenharmony_ci 54562306a36Sopenharmony_ci # cd <debugfs>/damon 54662306a36Sopenharmony_ci # echo 42 4242 > target_ids 54762306a36Sopenharmony_ci # cat target_ids 54862306a36Sopenharmony_ci 42 4242 54962306a36Sopenharmony_ci 55062306a36Sopenharmony_ciUsers can also monitor the physical memory address space of the system by 55162306a36Sopenharmony_ciwriting a special keyword, "``paddr\n``" to the file. Because physical address 55262306a36Sopenharmony_cispace monitoring doesn't support multiple targets, reading the file will show a 55362306a36Sopenharmony_cifake value, ``42``, as below:: 55462306a36Sopenharmony_ci 55562306a36Sopenharmony_ci # cd <debugfs>/damon 55662306a36Sopenharmony_ci # echo paddr > target_ids 55762306a36Sopenharmony_ci # cat target_ids 55862306a36Sopenharmony_ci 42 55962306a36Sopenharmony_ci 56062306a36Sopenharmony_ciNote that setting the target ids doesn't start the monitoring. 56162306a36Sopenharmony_ci 56262306a36Sopenharmony_ci 56362306a36Sopenharmony_ciInitial Monitoring Target Regions 56462306a36Sopenharmony_ci--------------------------------- 56562306a36Sopenharmony_ci 56662306a36Sopenharmony_ciIn case of the virtual address space monitoring, DAMON automatically sets and 56762306a36Sopenharmony_ciupdates the monitoring target regions so that entire memory mappings of target 56862306a36Sopenharmony_ciprocesses can be covered. However, users can want to limit the monitoring 56962306a36Sopenharmony_ciregion to specific address ranges, such as the heap, the stack, or specific 57062306a36Sopenharmony_cifile-mapped area. Or, some users can know the initial access pattern of their 57162306a36Sopenharmony_ciworkloads and therefore want to set optimal initial regions for the 'adaptive 57262306a36Sopenharmony_ciregions adjustment'. 57362306a36Sopenharmony_ci 57462306a36Sopenharmony_ciIn contrast, DAMON do not automatically sets and updates the monitoring target 57562306a36Sopenharmony_ciregions in case of physical memory monitoring. Therefore, users should set the 57662306a36Sopenharmony_cimonitoring target regions by themselves. 57762306a36Sopenharmony_ci 57862306a36Sopenharmony_ciIn such cases, users can explicitly set the initial monitoring target regions 57962306a36Sopenharmony_cias they want, by writing proper values to the ``init_regions`` file. The input 58062306a36Sopenharmony_cishould be a sequence of three integers separated by white spaces that represent 58162306a36Sopenharmony_cione region in below form.:: 58262306a36Sopenharmony_ci 58362306a36Sopenharmony_ci <target idx> <start address> <end address> 58462306a36Sopenharmony_ci 58562306a36Sopenharmony_ciThe ``target idx`` should be the index of the target in ``target_ids`` file, 58662306a36Sopenharmony_cistarting from ``0``, and the regions should be passed in address order. For 58762306a36Sopenharmony_ciexample, below commands will set a couple of address ranges, ``1-100`` and 58862306a36Sopenharmony_ci``100-200`` as the initial monitoring target region of pid 42, which is the 58962306a36Sopenharmony_cifirst one (index ``0``) in ``target_ids``, and another couple of address 59062306a36Sopenharmony_ciranges, ``20-40`` and ``50-100`` as that of pid 4242, which is the second one 59162306a36Sopenharmony_ci(index ``1``) in ``target_ids``.:: 59262306a36Sopenharmony_ci 59362306a36Sopenharmony_ci # cd <debugfs>/damon 59462306a36Sopenharmony_ci # cat target_ids 59562306a36Sopenharmony_ci 42 4242 59662306a36Sopenharmony_ci # echo "0 1 100 \ 59762306a36Sopenharmony_ci 0 100 200 \ 59862306a36Sopenharmony_ci 1 20 40 \ 59962306a36Sopenharmony_ci 1 50 100" > init_regions 60062306a36Sopenharmony_ci 60162306a36Sopenharmony_ciNote that this sets the initial monitoring target regions only. In case of 60262306a36Sopenharmony_civirtual memory monitoring, DAMON will automatically updates the boundary of the 60362306a36Sopenharmony_ciregions after one ``update interval``. Therefore, users should set the 60462306a36Sopenharmony_ci``update interval`` large enough in this case, if they don't want the 60562306a36Sopenharmony_ciupdate. 60662306a36Sopenharmony_ci 60762306a36Sopenharmony_ci 60862306a36Sopenharmony_ciSchemes 60962306a36Sopenharmony_ci------- 61062306a36Sopenharmony_ci 61162306a36Sopenharmony_ciUsers can get and set the DAMON-based operation :ref:`schemes 61262306a36Sopenharmony_ci<damon_design_damos>` by reading from and writing to ``schemes`` debugfs file. 61362306a36Sopenharmony_ciReading the file also shows the statistics of each scheme. To the file, each 61462306a36Sopenharmony_ciof the schemes should be represented in each line in below form:: 61562306a36Sopenharmony_ci 61662306a36Sopenharmony_ci <target access pattern> <action> <quota> <watermarks> 61762306a36Sopenharmony_ci 61862306a36Sopenharmony_ciYou can disable schemes by simply writing an empty string to the file. 61962306a36Sopenharmony_ci 62062306a36Sopenharmony_ciTarget Access Pattern 62162306a36Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~ 62262306a36Sopenharmony_ci 62362306a36Sopenharmony_ciThe target access :ref:`pattern <damon_design_damos_access_pattern>` of the 62462306a36Sopenharmony_cischeme. The ``<target access pattern>`` is constructed with three ranges in 62562306a36Sopenharmony_cibelow form:: 62662306a36Sopenharmony_ci 62762306a36Sopenharmony_ci min-size max-size min-acc max-acc min-age max-age 62862306a36Sopenharmony_ci 62962306a36Sopenharmony_ciSpecifically, bytes for the size of regions (``min-size`` and ``max-size``), 63062306a36Sopenharmony_cinumber of monitored accesses per aggregate interval for access frequency 63162306a36Sopenharmony_ci(``min-acc`` and ``max-acc``), number of aggregate intervals for the age of 63262306a36Sopenharmony_ciregions (``min-age`` and ``max-age``) are specified. Note that the ranges are 63362306a36Sopenharmony_ciclosed interval. 63462306a36Sopenharmony_ci 63562306a36Sopenharmony_ciAction 63662306a36Sopenharmony_ci~~~~~~ 63762306a36Sopenharmony_ci 63862306a36Sopenharmony_ciThe ``<action>`` is a predefined integer for memory management :ref:`actions 63962306a36Sopenharmony_ci<damon_design_damos_action>`. The supported numbers and their meanings are as 64062306a36Sopenharmony_cibelow. 64162306a36Sopenharmony_ci 64262306a36Sopenharmony_ci - 0: Call ``madvise()`` for the region with ``MADV_WILLNEED``. Ignored if 64362306a36Sopenharmony_ci ``target`` is ``paddr``. 64462306a36Sopenharmony_ci - 1: Call ``madvise()`` for the region with ``MADV_COLD``. Ignored if 64562306a36Sopenharmony_ci ``target`` is ``paddr``. 64662306a36Sopenharmony_ci - 2: Call ``madvise()`` for the region with ``MADV_PAGEOUT``. 64762306a36Sopenharmony_ci - 3: Call ``madvise()`` for the region with ``MADV_HUGEPAGE``. Ignored if 64862306a36Sopenharmony_ci ``target`` is ``paddr``. 64962306a36Sopenharmony_ci - 4: Call ``madvise()`` for the region with ``MADV_NOHUGEPAGE``. Ignored if 65062306a36Sopenharmony_ci ``target`` is ``paddr``. 65162306a36Sopenharmony_ci - 5: Do nothing but count the statistics 65262306a36Sopenharmony_ci 65362306a36Sopenharmony_ciQuota 65462306a36Sopenharmony_ci~~~~~ 65562306a36Sopenharmony_ci 65662306a36Sopenharmony_ciUsers can set the :ref:`quotas <damon_design_damos_quotas>` of the given scheme 65762306a36Sopenharmony_civia the ``<quota>`` in below form:: 65862306a36Sopenharmony_ci 65962306a36Sopenharmony_ci <ms> <sz> <reset interval> <priority weights> 66062306a36Sopenharmony_ci 66162306a36Sopenharmony_ciThis makes DAMON to try to use only up to ``<ms>`` milliseconds for applying 66262306a36Sopenharmony_cithe action to memory regions of the ``target access pattern`` within the 66362306a36Sopenharmony_ci``<reset interval>`` milliseconds, and to apply the action to only up to 66462306a36Sopenharmony_ci``<sz>`` bytes of memory regions within the ``<reset interval>``. Setting both 66562306a36Sopenharmony_ci``<ms>`` and ``<sz>`` zero disables the quota limits. 66662306a36Sopenharmony_ci 66762306a36Sopenharmony_ciFor the :ref:`prioritization <damon_design_damos_quotas_prioritization>`, users 66862306a36Sopenharmony_cican set the weights for the three properties in ``<priority weights>`` in below 66962306a36Sopenharmony_ciform:: 67062306a36Sopenharmony_ci 67162306a36Sopenharmony_ci <size weight> <access frequency weight> <age weight> 67262306a36Sopenharmony_ci 67362306a36Sopenharmony_ciWatermarks 67462306a36Sopenharmony_ci~~~~~~~~~~ 67562306a36Sopenharmony_ci 67662306a36Sopenharmony_ciUsers can specify :ref:`watermarks <damon_design_damos_watermarks>` of the 67762306a36Sopenharmony_cigiven scheme via ``<watermarks>`` in below form:: 67862306a36Sopenharmony_ci 67962306a36Sopenharmony_ci <metric> <check interval> <high mark> <middle mark> <low mark> 68062306a36Sopenharmony_ci 68162306a36Sopenharmony_ci``<metric>`` is a predefined integer for the metric to be checked. The 68262306a36Sopenharmony_cisupported numbers and their meanings are as below. 68362306a36Sopenharmony_ci 68462306a36Sopenharmony_ci - 0: Ignore the watermarks 68562306a36Sopenharmony_ci - 1: System's free memory rate (per thousand) 68662306a36Sopenharmony_ci 68762306a36Sopenharmony_ciThe value of the metric is checked every ``<check interval>`` microseconds. 68862306a36Sopenharmony_ci 68962306a36Sopenharmony_ciIf the value is higher than ``<high mark>`` or lower than ``<low mark>``, the 69062306a36Sopenharmony_cischeme is deactivated. If the value is lower than ``<mid mark>``, the scheme 69162306a36Sopenharmony_ciis activated. 69262306a36Sopenharmony_ci 69362306a36Sopenharmony_ci.. _damos_stats: 69462306a36Sopenharmony_ci 69562306a36Sopenharmony_ciStatistics 69662306a36Sopenharmony_ci~~~~~~~~~~ 69762306a36Sopenharmony_ci 69862306a36Sopenharmony_ciIt also counts the total number and bytes of regions that each scheme is tried 69962306a36Sopenharmony_cito be applied, the two numbers for the regions that each scheme is successfully 70062306a36Sopenharmony_ciapplied, and the total number of the quota limit exceeds. This statistics can 70162306a36Sopenharmony_cibe used for online analysis or tuning of the schemes. 70262306a36Sopenharmony_ci 70362306a36Sopenharmony_ciThe statistics can be shown by reading the ``schemes`` file. Reading the file 70462306a36Sopenharmony_ciwill show each scheme you entered in each line, and the five numbers for the 70562306a36Sopenharmony_cistatistics will be added at the end of each line. 70662306a36Sopenharmony_ci 70762306a36Sopenharmony_ciExample 70862306a36Sopenharmony_ci~~~~~~~ 70962306a36Sopenharmony_ci 71062306a36Sopenharmony_ciBelow commands applies a scheme saying "If a memory region of size in [4KiB, 71162306a36Sopenharmony_ci8KiB] is showing accesses per aggregate interval in [0, 5] for aggregate 71262306a36Sopenharmony_ciinterval in [10, 20], page out the region. For the paging out, use only up to 71362306a36Sopenharmony_ci10ms per second, and also don't page out more than 1GiB per second. Under the 71462306a36Sopenharmony_cilimitation, page out memory regions having longer age first. Also, check the 71562306a36Sopenharmony_cifree memory rate of the system every 5 seconds, start the monitoring and paging 71662306a36Sopenharmony_ciout when the free memory rate becomes lower than 50%, but stop it if the free 71762306a36Sopenharmony_cimemory rate becomes larger than 60%, or lower than 30%".:: 71862306a36Sopenharmony_ci 71962306a36Sopenharmony_ci # cd <debugfs>/damon 72062306a36Sopenharmony_ci # scheme="4096 8192 0 5 10 20 2" # target access pattern and action 72162306a36Sopenharmony_ci # scheme+=" 10 $((1024*1024*1024)) 1000" # quotas 72262306a36Sopenharmony_ci # scheme+=" 0 0 100" # prioritization weights 72362306a36Sopenharmony_ci # scheme+=" 1 5000000 600 500 300" # watermarks 72462306a36Sopenharmony_ci # echo "$scheme" > schemes 72562306a36Sopenharmony_ci 72662306a36Sopenharmony_ci 72762306a36Sopenharmony_ciTurning On/Off 72862306a36Sopenharmony_ci-------------- 72962306a36Sopenharmony_ci 73062306a36Sopenharmony_ciSetting the files as described above doesn't incur effect unless you explicitly 73162306a36Sopenharmony_cistart the monitoring. You can start, stop, and check the current status of the 73262306a36Sopenharmony_cimonitoring by writing to and reading from the ``monitor_on`` file. Writing 73362306a36Sopenharmony_ci``on`` to the file starts the monitoring of the targets with the attributes. 73462306a36Sopenharmony_ciWriting ``off`` to the file stops those. DAMON also stops if every target 73562306a36Sopenharmony_ciprocess is terminated. Below example commands turn on, off, and check the 73662306a36Sopenharmony_cistatus of DAMON:: 73762306a36Sopenharmony_ci 73862306a36Sopenharmony_ci # cd <debugfs>/damon 73962306a36Sopenharmony_ci # echo on > monitor_on 74062306a36Sopenharmony_ci # echo off > monitor_on 74162306a36Sopenharmony_ci # cat monitor_on 74262306a36Sopenharmony_ci off 74362306a36Sopenharmony_ci 74462306a36Sopenharmony_ciPlease note that you cannot write to the above-mentioned debugfs files while 74562306a36Sopenharmony_cithe monitoring is turned on. If you write to the files while DAMON is running, 74662306a36Sopenharmony_cian error code such as ``-EBUSY`` will be returned. 74762306a36Sopenharmony_ci 74862306a36Sopenharmony_ci 74962306a36Sopenharmony_ciMonitoring Thread PID 75062306a36Sopenharmony_ci--------------------- 75162306a36Sopenharmony_ci 75262306a36Sopenharmony_ciDAMON does requested monitoring with a kernel thread called ``kdamond``. You 75362306a36Sopenharmony_cican get the pid of the thread by reading the ``kdamond_pid`` file. When the 75462306a36Sopenharmony_cimonitoring is turned off, reading the file returns ``none``. :: 75562306a36Sopenharmony_ci 75662306a36Sopenharmony_ci # cd <debugfs>/damon 75762306a36Sopenharmony_ci # cat monitor_on 75862306a36Sopenharmony_ci off 75962306a36Sopenharmony_ci # cat kdamond_pid 76062306a36Sopenharmony_ci none 76162306a36Sopenharmony_ci # echo on > monitor_on 76262306a36Sopenharmony_ci # cat kdamond_pid 76362306a36Sopenharmony_ci 18594 76462306a36Sopenharmony_ci 76562306a36Sopenharmony_ci 76662306a36Sopenharmony_ciUsing Multiple Monitoring Threads 76762306a36Sopenharmony_ci--------------------------------- 76862306a36Sopenharmony_ci 76962306a36Sopenharmony_ciOne ``kdamond`` thread is created for each monitoring context. You can create 77062306a36Sopenharmony_ciand remove monitoring contexts for multiple ``kdamond`` required use case using 77162306a36Sopenharmony_cithe ``mk_contexts`` and ``rm_contexts`` files. 77262306a36Sopenharmony_ci 77362306a36Sopenharmony_ciWriting the name of the new context to the ``mk_contexts`` file creates a 77462306a36Sopenharmony_cidirectory of the name on the DAMON debugfs directory. The directory will have 77562306a36Sopenharmony_ciDAMON debugfs files for the context. :: 77662306a36Sopenharmony_ci 77762306a36Sopenharmony_ci # cd <debugfs>/damon 77862306a36Sopenharmony_ci # ls foo 77962306a36Sopenharmony_ci # ls: cannot access 'foo': No such file or directory 78062306a36Sopenharmony_ci # echo foo > mk_contexts 78162306a36Sopenharmony_ci # ls foo 78262306a36Sopenharmony_ci # attrs init_regions kdamond_pid schemes target_ids 78362306a36Sopenharmony_ci 78462306a36Sopenharmony_ciIf the context is not needed anymore, you can remove it and the corresponding 78562306a36Sopenharmony_cidirectory by putting the name of the context to the ``rm_contexts`` file. :: 78662306a36Sopenharmony_ci 78762306a36Sopenharmony_ci # echo foo > rm_contexts 78862306a36Sopenharmony_ci # ls foo 78962306a36Sopenharmony_ci # ls: cannot access 'foo': No such file or directory 79062306a36Sopenharmony_ci 79162306a36Sopenharmony_ciNote that ``mk_contexts``, ``rm_contexts``, and ``monitor_on`` files are in the 79262306a36Sopenharmony_ciroot directory only. 79362306a36Sopenharmony_ci 79462306a36Sopenharmony_ci 79562306a36Sopenharmony_ci.. _tracepoint: 79662306a36Sopenharmony_ci 79762306a36Sopenharmony_ciTracepoint for Monitoring Results 79862306a36Sopenharmony_ci================================= 79962306a36Sopenharmony_ci 80062306a36Sopenharmony_ciUsers can get the monitoring results via the :ref:`tried_regions 80162306a36Sopenharmony_ci<sysfs_schemes_tried_regions>` or a tracepoint, ``damon:damon_aggregated``. 80262306a36Sopenharmony_ciWhile the tried regions directory is useful for getting a snapshot, the 80362306a36Sopenharmony_citracepoint is useful for getting a full record of the results. While the 80462306a36Sopenharmony_cimonitoring is turned on, you could record the tracepoint events and show 80562306a36Sopenharmony_ciresults using tracepoint supporting tools like ``perf``. For example:: 80662306a36Sopenharmony_ci 80762306a36Sopenharmony_ci # echo on > monitor_on 80862306a36Sopenharmony_ci # perf record -e damon:damon_aggregated & 80962306a36Sopenharmony_ci # sleep 5 81062306a36Sopenharmony_ci # kill 9 $(pidof perf) 81162306a36Sopenharmony_ci # echo off > monitor_on 81262306a36Sopenharmony_ci # perf script 813