906 lines · plain
1.. SPDX-License-Identifier: GPL-2.02 3===============4Detailed Usages5===============6 7DAMON provides below interfaces for different users.8 9- *DAMON user space tool.*10 `This <https://github.com/damonitor/damo>`_ is for privileged people such as11 system administrators who want a just-working human-friendly interface.12 Using this, users can use the DAMON’s major features in a human-friendly way.13 It may not be highly tuned for special cases, though. For more detail,14 please refer to its `usage document15 <https://github.com/damonitor/damo/blob/next/USAGE.md>`_.16- *sysfs interface.*17 :ref:`This <sysfs_interface>` is for privileged user space programmers who18 want more optimized use of DAMON. Using this, users can use DAMON’s major19 features by reading from and writing to special sysfs files. Therefore,20 you can write and use your personalized DAMON sysfs wrapper programs that21 reads/writes the sysfs files instead of you. The `DAMON user space tool22 <https://github.com/damonitor/damo>`_ is one example of such programs.23- *Kernel Space Programming Interface.*24 :doc:`This </mm/damon/api>` is for kernel space programmers. Using this,25 users can utilize every feature of DAMON most flexibly and efficiently by26 writing kernel space DAMON application programs for you. You can even extend27 DAMON for various address spaces. For detail, please refer to the interface28 :doc:`document </mm/damon/api>`.29- *debugfs interface. (DEPRECATED!)*30 :ref:`This <debugfs_interface>` is almost identical to :ref:`sysfs interface31 <sysfs_interface>`. This is deprecated, so users should move to the32 :ref:`sysfs interface <sysfs_interface>`. If you depend on this and cannot33 move, please report your usecase to damon@lists.linux.dev and34 linux-mm@kvack.org.35 36.. _sysfs_interface:37 38sysfs Interface39===============40 41DAMON sysfs interface is built when ``CONFIG_DAMON_SYSFS`` is defined. It42creates multiple directories and files under its sysfs directory,43``<sysfs>/kernel/mm/damon/``. You can control DAMON by writing to and reading44from the files under the directory.45 46For a short example, users can monitor the virtual address space of a given47workload as below. ::48 49 # cd /sys/kernel/mm/damon/admin/50 # echo 1 > kdamonds/nr_kdamonds && echo 1 > kdamonds/0/contexts/nr_contexts51 # echo vaddr > kdamonds/0/contexts/0/operations52 # echo 1 > kdamonds/0/contexts/0/targets/nr_targets53 # echo $(pidof <workload>) > kdamonds/0/contexts/0/targets/0/pid_target54 # echo on > kdamonds/0/state55 56Files Hierarchy57---------------58 59The files hierarchy of DAMON sysfs interface is shown below. In the below60figure, parents-children relations are represented with indentations, each61directory is having ``/`` suffix, and files in each directory are separated by62comma (",").63 64.. parsed-literal::65 66 :ref:`/sys/kernel/mm/damon <sysfs_root>`/admin67 │ :ref:`kdamonds <sysfs_kdamonds>`/nr_kdamonds68 │ │ :ref:`0 <sysfs_kdamond>`/state,pid69 │ │ │ :ref:`contexts <sysfs_contexts>`/nr_contexts70 │ │ │ │ :ref:`0 <sysfs_context>`/avail_operations,operations71 │ │ │ │ │ :ref:`monitoring_attrs <sysfs_monitoring_attrs>`/72 │ │ │ │ │ │ intervals/sample_us,aggr_us,update_us73 │ │ │ │ │ │ nr_regions/min,max74 │ │ │ │ │ :ref:`targets <sysfs_targets>`/nr_targets75 │ │ │ │ │ │ :ref:`0 <sysfs_target>`/pid_target76 │ │ │ │ │ │ │ :ref:`regions <sysfs_regions>`/nr_regions77 │ │ │ │ │ │ │ │ :ref:`0 <sysfs_region>`/start,end78 │ │ │ │ │ │ │ │ ...79 │ │ │ │ │ │ ...80 │ │ │ │ │ :ref:`schemes <sysfs_schemes>`/nr_schemes81 │ │ │ │ │ │ :ref:`0 <sysfs_scheme>`/action,target_nid,apply_interval_us82 │ │ │ │ │ │ │ :ref:`access_pattern <sysfs_access_pattern>`/83 │ │ │ │ │ │ │ │ sz/min,max84 │ │ │ │ │ │ │ │ nr_accesses/min,max85 │ │ │ │ │ │ │ │ age/min,max86 │ │ │ │ │ │ │ :ref:`quotas <sysfs_quotas>`/ms,bytes,reset_interval_ms,effective_bytes87 │ │ │ │ │ │ │ │ weights/sz_permil,nr_accesses_permil,age_permil88 │ │ │ │ │ │ │ │ :ref:`goals <sysfs_schemes_quota_goals>`/nr_goals89 │ │ │ │ │ │ │ │ │ 0/target_metric,target_value,current_value90 │ │ │ │ │ │ │ :ref:`watermarks <sysfs_watermarks>`/metric,interval_us,high,mid,low91 │ │ │ │ │ │ │ :ref:`filters <sysfs_filters>`/nr_filters92 │ │ │ │ │ │ │ │ 0/type,matching,memcg_id93 │ │ │ │ │ │ │ :ref:`stats <sysfs_schemes_stats>`/nr_tried,sz_tried,nr_applied,sz_applied,qt_exceeds94 │ │ │ │ │ │ │ :ref:`tried_regions <sysfs_schemes_tried_regions>`/total_bytes95 │ │ │ │ │ │ │ │ 0/start,end,nr_accesses,age96 │ │ │ │ │ │ │ │ ...97 │ │ │ │ │ │ ...98 │ │ │ │ ...99 │ │ ...100 101.. _sysfs_root:102 103Root104----105 106The root of the DAMON sysfs interface is ``<sysfs>/kernel/mm/damon/``, and it107has one directory named ``admin``. The directory contains the files for108privileged user space programs' control of DAMON. User space tools or daemons109having the root permission could use this directory.110 111.. _sysfs_kdamonds:112 113kdamonds/114---------115 116Under the ``admin`` directory, one directory, ``kdamonds``, which has files for117controlling the kdamonds (refer to118:ref:`design <damon_design_execution_model_and_data_structures>` for more119details) exists. In the beginning, this directory has only one file,120``nr_kdamonds``. Writing a number (``N``) to the file creates the number of121child directories named ``0`` to ``N-1``. Each directory represents each122kdamond.123 124.. _sysfs_kdamond:125 126kdamonds/<N>/127-------------128 129In each kdamond directory, two files (``state`` and ``pid``) and one directory130(``contexts``) exist.131 132Reading ``state`` returns ``on`` if the kdamond is currently running, or133``off`` if it is not running.134 135Users can write below commands for the kdamond to the ``state`` file.136 137- ``on``: Start running.138- ``off``: Stop running.139- ``commit``: Read the user inputs in the sysfs files except ``state`` file140 again.141- ``commit_schemes_quota_goals``: Read the DAMON-based operation schemes'142 :ref:`quota goals <sysfs_schemes_quota_goals>`.143- ``update_schemes_stats``: Update the contents of stats files for each144 DAMON-based operation scheme of the kdamond. For details of the stats,145 please refer to :ref:`stats section <sysfs_schemes_stats>`.146- ``update_schemes_tried_regions``: Update the DAMON-based operation scheme147 action tried regions directory for each DAMON-based operation scheme of the148 kdamond. For details of the DAMON-based operation scheme action tried149 regions directory, please refer to150 :ref:`tried_regions section <sysfs_schemes_tried_regions>`.151- ``update_schemes_tried_bytes``: Update only ``.../tried_regions/total_bytes``152 files.153- ``clear_schemes_tried_regions``: Clear the DAMON-based operating scheme154 action tried regions directory for each DAMON-based operation scheme of the155 kdamond.156- ``update_schemes_effective_quotas``: Update the contents of157 ``effective_bytes`` files for each DAMON-based operation scheme of the158 kdamond. For more details, refer to :ref:`quotas directory <sysfs_quotas>`.159 160If the state is ``on``, reading ``pid`` shows the pid of the kdamond thread.161 162``contexts`` directory contains files for controlling the monitoring contexts163that this kdamond will execute.164 165.. _sysfs_contexts:166 167kdamonds/<N>/contexts/168----------------------169 170In the beginning, this directory has only one file, ``nr_contexts``. Writing a171number (``N``) to the file creates the number of child directories named as172``0`` to ``N-1``. Each directory represents each monitoring context (refer to173:ref:`design <damon_design_execution_model_and_data_structures>` for more174details). At the moment, only one context per kdamond is supported, so only175``0`` or ``1`` can be written to the file.176 177.. _sysfs_context:178 179contexts/<N>/180-------------181 182In each context directory, two files (``avail_operations`` and ``operations``)183and three directories (``monitoring_attrs``, ``targets``, and ``schemes``)184exist.185 186DAMON supports multiple types of :ref:`monitoring operations187<damon_design_configurable_operations_set>`, including those for virtual address188space and the physical address space. You can get the list of available189monitoring operations set on the currently running kernel by reading190``avail_operations`` file. Based on the kernel configuration, the file will191list different available operation sets. Please refer to the :ref:`design192<damon_operations_set>` for the list of all available operation sets and their193brief explanations.194 195You can set and get what type of monitoring operations DAMON will use for the196context by writing one of the keywords listed in ``avail_operations`` file and197reading from the ``operations`` file.198 199.. _sysfs_monitoring_attrs:200 201contexts/<N>/monitoring_attrs/202------------------------------203 204Files for specifying attributes of the monitoring including required quality205and efficiency of the monitoring are in ``monitoring_attrs`` directory.206Specifically, two directories, ``intervals`` and ``nr_regions`` exist in this207directory.208 209Under ``intervals`` directory, three files for DAMON's sampling interval210(``sample_us``), aggregation interval (``aggr_us``), and update interval211(``update_us``) exist. You can set and get the values in micro-seconds by212writing to and reading from the files.213 214Under ``nr_regions`` directory, two files for the lower-bound and upper-bound215of DAMON's monitoring regions (``min`` and ``max``, respectively), which216controls the monitoring overhead, exist. You can set and get the values by217writing to and rading from the files.218 219For more details about the intervals and monitoring regions range, please refer220to the Design document (:doc:`/mm/damon/design`).221 222.. _sysfs_targets:223 224contexts/<N>/targets/225---------------------226 227In the beginning, this directory has only one file, ``nr_targets``. Writing a228number (``N``) to the file creates the number of child directories named ``0``229to ``N-1``. Each directory represents each monitoring target.230 231.. _sysfs_target:232 233targets/<N>/234------------235 236In each target directory, one file (``pid_target``) and one directory237(``regions``) exist.238 239If you wrote ``vaddr`` to the ``contexts/<N>/operations``, each target should240be a process. You can specify the process to DAMON by writing the pid of the241process to the ``pid_target`` file.242 243.. _sysfs_regions:244 245targets/<N>/regions246-------------------247 248In case of ``fvaddr`` or ``paddr`` monitoring operations sets, users are249required to set the monitoring target address ranges. In case of ``vaddr``250operations set, it is not mandatory, but users can optionally set the initial251monitoring region to specific address ranges. Please refer to the :ref:`design252<damon_design_vaddr_target_regions_construction>` for more details.253 254For such cases, users can explicitly set the initial monitoring target regions255as they want, by writing proper values to the files under this directory.256 257In the beginning, this directory has only one file, ``nr_regions``. Writing a258number (``N``) to the file creates the number of child directories named ``0``259to ``N-1``. Each directory represents each initial monitoring target region.260 261.. _sysfs_region:262 263regions/<N>/264------------265 266In each region directory, you will find two files (``start`` and ``end``). You267can set and get the start and end addresses of the initial monitoring target268region by writing to and reading from the files, respectively.269 270Each region should not overlap with others. ``end`` of directory ``N`` should271be equal or smaller than ``start`` of directory ``N+1``.272 273.. _sysfs_schemes:274 275contexts/<N>/schemes/276---------------------277 278The directory for DAMON-based Operation Schemes (:ref:`DAMOS279<damon_design_damos>`). Users can get and set the schemes by reading from and280writing to files under this directory.281 282In the beginning, this directory has only one file, ``nr_schemes``. Writing a283number (``N``) to the file creates the number of child directories named ``0``284to ``N-1``. Each directory represents each DAMON-based operation scheme.285 286.. _sysfs_scheme:287 288schemes/<N>/289------------290 291In each scheme directory, five directories (``access_pattern``, ``quotas``,292``watermarks``, ``filters``, ``stats``, and ``tried_regions``) and three files293(``action``, ``target_nid`` and ``apply_interval``) exist.294 295The ``action`` file is for setting and getting the scheme's :ref:`action296<damon_design_damos_action>`. The keywords that can be written to and read297from the file and their meaning are same to those of the list on298:ref:`design doc <damon_design_damos_action>`.299 300The ``target_nid`` file is for setting the migration target node, which is301only meaningful when the ``action`` is either ``migrate_hot`` or302``migrate_cold``.303 304The ``apply_interval_us`` file is for setting and getting the scheme's305:ref:`apply_interval <damon_design_damos>` in microseconds.306 307.. _sysfs_access_pattern:308 309schemes/<N>/access_pattern/310---------------------------311 312The directory for the target access :ref:`pattern313<damon_design_damos_access_pattern>` of the given DAMON-based operation scheme.314 315Under the ``access_pattern`` directory, three directories (``sz``,316``nr_accesses``, and ``age``) each having two files (``min`` and ``max``)317exist. You can set and get the access pattern for the given scheme by writing318to and reading from the ``min`` and ``max`` files under ``sz``,319``nr_accesses``, and ``age`` directories, respectively. Note that the ``min``320and the ``max`` form a closed interval.321 322.. _sysfs_quotas:323 324schemes/<N>/quotas/325-------------------326 327The directory for the :ref:`quotas <damon_design_damos_quotas>` of the given328DAMON-based operation scheme.329 330Under ``quotas`` directory, four files (``ms``, ``bytes``,331``reset_interval_ms``, ``effective_bytes``) and two directores (``weights`` and332``goals``) exist.333 334You can set the ``time quota`` in milliseconds, ``size quota`` in bytes, and335``reset interval`` in milliseconds by writing the values to the three files,336respectively. Then, DAMON tries to use only up to ``time quota`` milliseconds337for applying the ``action`` to memory regions of the ``access_pattern``, and to338apply the action to only up to ``bytes`` bytes of memory regions within the339``reset_interval_ms``. Setting both ``ms`` and ``bytes`` zero disables the340quota limits unless at least one :ref:`goal <sysfs_schemes_quota_goals>` is341set.342 343The time quota is internally transformed to a size quota. Between the344transformed size quota and user-specified size quota, smaller one is applied.345Based on the user-specified :ref:`goal <sysfs_schemes_quota_goals>`, the346effective size quota is further adjusted. Reading ``effective_bytes`` returns347the current effective size quota. The file is not updated in real time, so348users should ask DAMON sysfs interface to update the content of the file for349the stats by writing a special keyword, ``update_schemes_effective_quotas`` to350the relevant ``kdamonds/<N>/state`` file.351 352Under ``weights`` directory, three files (``sz_permil``,353``nr_accesses_permil``, and ``age_permil``) exist.354You can set the :ref:`prioritization weights355<damon_design_damos_quotas_prioritization>` for size, access frequency, and age356in per-thousand unit by writing the values to the three files under the357``weights`` directory.358 359.. _sysfs_schemes_quota_goals:360 361schemes/<N>/quotas/goals/362-------------------------363 364The directory for the :ref:`automatic quota tuning goals365<damon_design_damos_quotas_auto_tuning>` of the given DAMON-based operation366scheme.367 368In the beginning, this directory has only one file, ``nr_goals``. Writing a369number (``N``) to the file creates the number of child directories named ``0``370to ``N-1``. Each directory represents each goal and current achievement.371Among the multiple feedback, the best one is used.372 373Each goal directory contains three files, namely ``target_metric``,374``target_value`` and ``current_value``. Users can set and get the three375parameters for the quota auto-tuning goals that specified on the :ref:`design376doc <damon_design_damos_quotas_auto_tuning>` by writing to and reading from each377of the files. Note that users should further write378``commit_schemes_quota_goals`` to the ``state`` file of the :ref:`kdamond379directory <sysfs_kdamond>` to pass the feedback to DAMON.380 381.. _sysfs_watermarks:382 383schemes/<N>/watermarks/384-----------------------385 386The directory for the :ref:`watermarks <damon_design_damos_watermarks>` of the387given DAMON-based operation scheme.388 389Under the watermarks directory, five files (``metric``, ``interval_us``,390``high``, ``mid``, and ``low``) for setting the metric, the time interval391between check of the metric, and the three watermarks exist. You can set and392get the five values by writing to the files, respectively.393 394Keywords and meanings of those that can be written to the ``metric`` file are395as below.396 397 - none: Ignore the watermarks398 - free_mem_rate: System's free memory rate (per thousand)399 400The ``interval`` should written in microseconds unit.401 402.. _sysfs_filters:403 404schemes/<N>/filters/405--------------------406 407The directory for the :ref:`filters <damon_design_damos_filters>` of the given408DAMON-based operation scheme.409 410In the beginning, this directory has only one file, ``nr_filters``. Writing a411number (``N``) to the file creates the number of child directories named ``0``412to ``N-1``. Each directory represents each filter. The filters are evaluated413in the numeric order.414 415Each filter directory contains six files, namely ``type``, ``matcing``,416``memcg_path``, ``addr_start``, ``addr_end``, and ``target_idx``. To ``type``417file, you can write one of five special keywords: ``anon`` for anonymous pages,418``memcg`` for specific memory cgroup, ``young`` for young pages, ``addr`` for419specific address range (an open-ended interval), or ``target`` for specific420DAMON monitoring target filtering. In case of the memory cgroup filtering, you421can specify the memory cgroup of the interest by writing the path of the memory422cgroup from the cgroups mount point to ``memcg_path`` file. In case of the423address range filtering, you can specify the start and end address of the range424to ``addr_start`` and ``addr_end`` files, respectively. For the DAMON425monitoring target filtering, you can specify the index of the target between426the list of the DAMON context's monitoring targets list to ``target_idx`` file.427You can write ``Y`` or ``N`` to ``matching`` file to filter out pages that does428or does not match to the type, respectively. Then, the scheme's action will429not be applied to the pages that specified to be filtered out.430 431For example, below restricts a DAMOS action to be applied to only non-anonymous432pages of all memory cgroups except ``/having_care_already``.::433 434 # echo 2 > nr_filters435 # # filter out anonymous pages436 echo anon > 0/type437 echo Y > 0/matching438 # # further filter out all cgroups except one at '/having_care_already'439 echo memcg > 1/type440 echo /having_care_already > 1/memcg_path441 echo Y > 1/matching442 443Note that ``anon`` and ``memcg`` filters are currently supported only when444``paddr`` :ref:`implementation <sysfs_context>` is being used.445 446Also, memory regions that are filtered out by ``addr`` or ``target`` filters447are not counted as the scheme has tried to those, while regions that filtered448out by other type filters are counted as the scheme has tried to. The449difference is applied to :ref:`stats <damos_stats>` and450:ref:`tried regions <sysfs_schemes_tried_regions>`.451 452.. _sysfs_schemes_stats:453 454schemes/<N>/stats/455------------------456 457DAMON counts the total number and bytes of regions that each scheme is tried to458be applied, the two numbers for the regions that each scheme is successfully459applied, and the total number of the quota limit exceeds. This statistics can460be used for online analysis or tuning of the schemes.461 462The statistics can be retrieved by reading the files under ``stats`` directory463(``nr_tried``, ``sz_tried``, ``nr_applied``, ``sz_applied``, and464``qt_exceeds``), respectively. The files are not updated in real time, so you465should ask DAMON sysfs interface to update the content of the files for the466stats by writing a special keyword, ``update_schemes_stats`` to the relevant467``kdamonds/<N>/state`` file.468 469.. _sysfs_schemes_tried_regions:470 471schemes/<N>/tried_regions/472--------------------------473 474This directory initially has one file, ``total_bytes``.475 476When a special keyword, ``update_schemes_tried_regions``, is written to the477relevant ``kdamonds/<N>/state`` file, DAMON updates the ``total_bytes`` file so478that reading it returns the total size of the scheme tried regions, and creates479directories named integer starting from ``0`` under this directory. Each480directory contains files exposing detailed information about each of the memory481region that the corresponding scheme's ``action`` has tried to be applied under482this directory, during next :ref:`apply interval <damon_design_damos>` of the483corresponding scheme. The information includes address range, ``nr_accesses``,484and ``age`` of the region.485 486Writing ``update_schemes_tried_bytes`` to the relevant ``kdamonds/<N>/state``487file will only update the ``total_bytes`` file, and will not create the488subdirectories.489 490The directories will be removed when another special keyword,491``clear_schemes_tried_regions``, is written to the relevant492``kdamonds/<N>/state`` file.493 494The expected usage of this directory is investigations of schemes' behaviors,495and query-like efficient data access monitoring results retrievals. For the496latter use case, in particular, users can set the ``action`` as ``stat`` and497set the ``access pattern`` as their interested pattern that they want to query.498 499.. _sysfs_schemes_tried_region:500 501tried_regions/<N>/502------------------503 504In each region directory, you will find four files (``start``, ``end``,505``nr_accesses``, and ``age``). Reading the files will show the start and end506addresses, ``nr_accesses``, and ``age`` of the region that corresponding507DAMON-based operation scheme ``action`` has tried to be applied.508 509Example510~~~~~~~511 512Below commands applies a scheme saying "If a memory region of size in [4KiB,5138KiB] is showing accesses per aggregate interval in [0, 5] for aggregate514interval in [10, 20], page out the region. For the paging out, use only up to51510ms per second, and also don't page out more than 1GiB per second. Under the516limitation, page out memory regions having longer age first. Also, check the517free memory rate of the system every 5 seconds, start the monitoring and paging518out when the free memory rate becomes lower than 50%, but stop it if the free519memory rate becomes larger than 60%, or lower than 30%". ::520 521 # cd <sysfs>/kernel/mm/damon/admin522 # # populate directories523 # echo 1 > kdamonds/nr_kdamonds; echo 1 > kdamonds/0/contexts/nr_contexts;524 # echo 1 > kdamonds/0/contexts/0/schemes/nr_schemes525 # cd kdamonds/0/contexts/0/schemes/0526 # # set the basic access pattern and the action527 # echo 4096 > access_pattern/sz/min528 # echo 8192 > access_pattern/sz/max529 # echo 0 > access_pattern/nr_accesses/min530 # echo 5 > access_pattern/nr_accesses/max531 # echo 10 > access_pattern/age/min532 # echo 20 > access_pattern/age/max533 # echo pageout > action534 # # set quotas535 # echo 10 > quotas/ms536 # echo $((1024*1024*1024)) > quotas/bytes537 # echo 1000 > quotas/reset_interval_ms538 # # set watermark539 # echo free_mem_rate > watermarks/metric540 # echo 5000000 > watermarks/interval_us541 # echo 600 > watermarks/high542 # echo 500 > watermarks/mid543 # echo 300 > watermarks/low544 545Please note that it's highly recommended to use user space tools like `damo546<https://github.com/damonitor/damo>`_ rather than manually reading and writing547the files as above. Above is only for an example.548 549.. _tracepoint:550 551Tracepoints for Monitoring Results552==================================553 554Users can get the monitoring results via the :ref:`tried_regions555<sysfs_schemes_tried_regions>`. The interface is useful for getting a556snapshot, but it could be inefficient for fully recording all the monitoring557results. For the purpose, two trace points, namely ``damon:damon_aggregated``558and ``damon:damos_before_apply``, are provided. ``damon:damon_aggregated``559provides the whole monitoring results, while ``damon:damos_before_apply``560provides the monitoring results for regions that each DAMON-based Operation561Scheme (:ref:`DAMOS <damon_design_damos>`) is gonna be applied. Hence,562``damon:damos_before_apply`` is more useful for recording internal behavior of563DAMOS, or DAMOS target access564:ref:`pattern <damon_design_damos_access_pattern>` based query-like efficient565monitoring results recording.566 567While the monitoring is turned on, you could record the tracepoint events and568show results using tracepoint supporting tools like ``perf``. For example::569 570 # echo on > kdamonds/0/state571 # perf record -e damon:damon_aggregated &572 # sleep 5573 # kill 9 $(pidof perf)574 # echo off > kdamonds/0/state575 # perf script576 kdamond.0 46568 [027] 79357.842179: damon:damon_aggregated: target_id=0 nr_regions=11 122509119488-135708762112: 0 864577 [...]578 579Each line of the perf script output represents each monitoring region. The580first five fields are as usual other tracepoint outputs. The sixth field581(``target_id=X``) shows the ide of the monitoring target of the region. The582seventh field (``nr_regions=X``) shows the total number of monitoring regions583for the target. The eighth field (``X-Y:``) shows the start (``X``) and end584(``Y``) addresses of the region in bytes. The ninth field (``X``) shows the585``nr_accesses`` of the region (refer to586:ref:`design <damon_design_region_based_sampling>` for more details of the587counter). Finally the tenth field (``X``) shows the ``age`` of the region588(refer to :ref:`design <damon_design_age_tracking>` for more details of the589counter).590 591If the event was ``damon:damos_beofre_apply``, the ``perf script`` output would592be somewhat like below::593 594 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 136595 [...]596 597Each line of the output represents each monitoring region that each DAMON-based598Operation Scheme was about to be applied at the traced time. The first five599fields are as usual. It shows the index of the DAMON context (``ctx_idx=X``)600of the scheme in the list of the contexts of the context's kdamond, the index601of the scheme (``scheme_idx=X``) in the list of the schemes of the context, in602addition to the output of ``damon_aggregated`` tracepoint.603 604 605.. _debugfs_interface:606 607debugfs Interface (DEPRECATED!)608===============================609 610.. note::611 612 THIS IS DEPRECATED!613 614 DAMON debugfs interface is deprecated, so users should move to the615 :ref:`sysfs interface <sysfs_interface>`. If you depend on this and cannot616 move, please report your usecase to damon@lists.linux.dev and617 linux-mm@kvack.org.618 619DAMON exports nine files, ``DEPRECATED``, ``attrs``, ``target_ids``,620``init_regions``, ``schemes``, ``monitor_on_DEPRECATED``, ``kdamond_pid``,621``mk_contexts`` and ``rm_contexts`` under its debugfs directory,622``<debugfs>/damon/``.623 624 625``DEPRECATED`` is a read-only file for the DAMON debugfs interface deprecation626notice. Reading it returns the deprecation notice, as below::627 628 # cat DEPRECATED629 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.630 631 632Attributes633----------634 635Users can get and set the ``sampling interval``, ``aggregation interval``,636``update interval``, and min/max number of monitoring target regions by637reading from and writing to the ``attrs`` file. To know about the monitoring638attributes in detail, please refer to the :doc:`/mm/damon/design`. For639example, below commands set those values to 5 ms, 100 ms, 1,000 ms, 10 and6401000, and then check it again::641 642 # cd <debugfs>/damon643 # echo 5000 100000 1000000 10 1000 > attrs644 # cat attrs645 5000 100000 1000000 10 1000646 647 648Target IDs649----------650 651Some types of address spaces supports multiple monitoring target. For example,652the virtual memory address spaces monitoring can have multiple processes as the653monitoring targets. Users can set the targets by writing relevant id values of654the targets to, and get the ids of the current targets by reading from the655``target_ids`` file. In case of the virtual address spaces monitoring, the656values should be pids of the monitoring target processes. For example, below657commands set processes having pids 42 and 4242 as the monitoring targets and658check it again::659 660 # cd <debugfs>/damon661 # echo 42 4242 > target_ids662 # cat target_ids663 42 4242664 665Users can also monitor the physical memory address space of the system by666writing a special keyword, "``paddr\n``" to the file. Because physical address667space monitoring doesn't support multiple targets, reading the file will show a668fake value, ``42``, as below::669 670 # cd <debugfs>/damon671 # echo paddr > target_ids672 # cat target_ids673 42674 675Note that setting the target ids doesn't start the monitoring.676 677 678Initial Monitoring Target Regions679---------------------------------680 681In case of the virtual address space monitoring, DAMON automatically sets and682updates the monitoring target regions so that entire memory mappings of target683processes can be covered. However, users can want to limit the monitoring684region to specific address ranges, such as the heap, the stack, or specific685file-mapped area. Or, some users can know the initial access pattern of their686workloads and therefore want to set optimal initial regions for the 'adaptive687regions adjustment'.688 689In contrast, DAMON do not automatically sets and updates the monitoring target690regions in case of physical memory monitoring. Therefore, users should set the691monitoring target regions by themselves.692 693In such cases, users can explicitly set the initial monitoring target regions694as they want, by writing proper values to the ``init_regions`` file. The input695should be a sequence of three integers separated by white spaces that represent696one region in below form.::697 698 <target idx> <start address> <end address>699 700The ``target idx`` should be the index of the target in ``target_ids`` file,701starting from ``0``, and the regions should be passed in address order. For702example, below commands will set a couple of address ranges, ``1-100`` and703``100-200`` as the initial monitoring target region of pid 42, which is the704first one (index ``0``) in ``target_ids``, and another couple of address705ranges, ``20-40`` and ``50-100`` as that of pid 4242, which is the second one706(index ``1``) in ``target_ids``.::707 708 # cd <debugfs>/damon709 # cat target_ids710 42 4242711 # echo "0 1 100 \712 0 100 200 \713 1 20 40 \714 1 50 100" > init_regions715 716Note that this sets the initial monitoring target regions only. In case of717virtual memory monitoring, DAMON will automatically updates the boundary of the718regions after one ``update interval``. Therefore, users should set the719``update interval`` large enough in this case, if they don't want the720update.721 722 723Schemes724-------725 726Users can get and set the DAMON-based operation :ref:`schemes727<damon_design_damos>` by reading from and writing to ``schemes`` debugfs file.728Reading the file also shows the statistics of each scheme. To the file, each729of the schemes should be represented in each line in below form::730 731 <target access pattern> <action> <quota> <watermarks>732 733You can disable schemes by simply writing an empty string to the file.734 735Target Access Pattern736~~~~~~~~~~~~~~~~~~~~~737 738The target access :ref:`pattern <damon_design_damos_access_pattern>` of the739scheme. The ``<target access pattern>`` is constructed with three ranges in740below form::741 742 min-size max-size min-acc max-acc min-age max-age743 744Specifically, bytes for the size of regions (``min-size`` and ``max-size``),745number of monitored accesses per aggregate interval for access frequency746(``min-acc`` and ``max-acc``), number of aggregate intervals for the age of747regions (``min-age`` and ``max-age``) are specified. Note that the ranges are748closed interval.749 750Action751~~~~~~752 753The ``<action>`` is a predefined integer for memory management :ref:`actions754<damon_design_damos_action>`. The mapping between the ``<action>`` values and755the memory management actions is as below. For the detailed meaning of the756action and DAMON operations set supporting each action, please refer to the757list on :ref:`design doc <damon_design_damos_action>`.758 759 - 0: ``willneed``760 - 1: ``cold``761 - 2: ``pageout``762 - 3: ``hugepage``763 - 4: ``nohugepage``764 - 5: ``stat``765 766Quota767~~~~~768 769Users can set the :ref:`quotas <damon_design_damos_quotas>` of the given scheme770via the ``<quota>`` in below form::771 772 <ms> <sz> <reset interval> <priority weights>773 774This makes DAMON to try to use only up to ``<ms>`` milliseconds for applying775the action to memory regions of the ``target access pattern`` within the776``<reset interval>`` milliseconds, and to apply the action to only up to777``<sz>`` bytes of memory regions within the ``<reset interval>``. Setting both778``<ms>`` and ``<sz>`` zero disables the quota limits.779 780For the :ref:`prioritization <damon_design_damos_quotas_prioritization>`, users781can set the weights for the three properties in ``<priority weights>`` in below782form::783 784 <size weight> <access frequency weight> <age weight>785 786Watermarks787~~~~~~~~~~788 789Users can specify :ref:`watermarks <damon_design_damos_watermarks>` of the790given scheme via ``<watermarks>`` in below form::791 792 <metric> <check interval> <high mark> <middle mark> <low mark>793 794``<metric>`` is a predefined integer for the metric to be checked. The795supported numbers and their meanings are as below.796 797 - 0: Ignore the watermarks798 - 1: System's free memory rate (per thousand)799 800The value of the metric is checked every ``<check interval>`` microseconds.801 802If the value is higher than ``<high mark>`` or lower than ``<low mark>``, the803scheme is deactivated. If the value is lower than ``<mid mark>``, the scheme804is activated.805 806.. _damos_stats:807 808Statistics809~~~~~~~~~~810 811It also counts the total number and bytes of regions that each scheme is tried812to be applied, the two numbers for the regions that each scheme is successfully813applied, and the total number of the quota limit exceeds. This statistics can814be used for online analysis or tuning of the schemes.815 816The statistics can be shown by reading the ``schemes`` file. Reading the file817will show each scheme you entered in each line, and the five numbers for the818statistics will be added at the end of each line.819 820Example821~~~~~~~822 823Below commands applies a scheme saying "If a memory region of size in [4KiB,8248KiB] is showing accesses per aggregate interval in [0, 5] for aggregate825interval in [10, 20], page out the region. For the paging out, use only up to82610ms per second, and also don't page out more than 1GiB per second. Under the827limitation, page out memory regions having longer age first. Also, check the828free memory rate of the system every 5 seconds, start the monitoring and paging829out when the free memory rate becomes lower than 50%, but stop it if the free830memory rate becomes larger than 60%, or lower than 30%".::831 832 # cd <debugfs>/damon833 # scheme="4096 8192 0 5 10 20 2" # target access pattern and action834 # scheme+=" 10 $((1024*1024*1024)) 1000" # quotas835 # scheme+=" 0 0 100" # prioritization weights836 # scheme+=" 1 5000000 600 500 300" # watermarks837 # echo "$scheme" > schemes838 839 840Turning On/Off841--------------842 843Setting the files as described above doesn't incur effect unless you explicitly844start the monitoring. You can start, stop, and check the current status of the845monitoring by writing to and reading from the ``monitor_on_DEPRECATED`` file.846Writing ``on`` to the file starts the monitoring of the targets with the847attributes. Writing ``off`` to the file stops those. DAMON also stops if848every target process is terminated. Below example commands turn on, off, and849check the status of DAMON::850 851 # cd <debugfs>/damon852 # echo on > monitor_on_DEPRECATED853 # echo off > monitor_on_DEPRECATED854 # cat monitor_on_DEPRECATED855 off856 857Please note that you cannot write to the above-mentioned debugfs files while858the monitoring is turned on. If you write to the files while DAMON is running,859an error code such as ``-EBUSY`` will be returned.860 861 862Monitoring Thread PID863---------------------864 865DAMON does requested monitoring with a kernel thread called ``kdamond``. You866can get the pid of the thread by reading the ``kdamond_pid`` file. When the867monitoring is turned off, reading the file returns ``none``. ::868 869 # cd <debugfs>/damon870 # cat monitor_on_DEPRECATED871 off872 # cat kdamond_pid873 none874 # echo on > monitor_on_DEPRECATED875 # cat kdamond_pid876 18594877 878 879Using Multiple Monitoring Threads880---------------------------------881 882One ``kdamond`` thread is created for each monitoring context. You can create883and remove monitoring contexts for multiple ``kdamond`` required use case using884the ``mk_contexts`` and ``rm_contexts`` files.885 886Writing the name of the new context to the ``mk_contexts`` file creates a887directory of the name on the DAMON debugfs directory. The directory will have888DAMON debugfs files for the context. ::889 890 # cd <debugfs>/damon891 # ls foo892 # ls: cannot access 'foo': No such file or directory893 # echo foo > mk_contexts894 # ls foo895 # attrs init_regions kdamond_pid schemes target_ids896 897If the context is not needed anymore, you can remove it and the corresponding898directory by putting the name of the context to the ``rm_contexts`` file. ::899 900 # echo foo > rm_contexts901 # ls foo902 # ls: cannot access 'foo': No such file or directory903 904Note that ``mk_contexts``, ``rm_contexts``, and ``monitor_on_DEPRECATED`` files905are in the root directory only.906