1*c4ba6014SSeongJae Park.. SPDX-License-Identifier: GPL-2.0 2*c4ba6014SSeongJae Park 3*c4ba6014SSeongJae Park=============== 4*c4ba6014SSeongJae ParkDetailed Usages 5*c4ba6014SSeongJae Park=============== 6*c4ba6014SSeongJae Park 7*c4ba6014SSeongJae ParkDAMON provides below three interfaces for different users. 8*c4ba6014SSeongJae Park 9*c4ba6014SSeongJae Park- *DAMON user space tool.* 10*c4ba6014SSeongJae Park This is for privileged people such as system administrators who want a 11*c4ba6014SSeongJae Park just-working human-friendly interface. Using this, users can use the DAMON’s 12*c4ba6014SSeongJae Park major features in a human-friendly way. It may not be highly tuned for 13*c4ba6014SSeongJae Park special cases, though. It supports only virtual address spaces monitoring. 14*c4ba6014SSeongJae Park- *debugfs interface.* 15*c4ba6014SSeongJae Park This is for privileged user space programmers who want more optimized use of 16*c4ba6014SSeongJae Park DAMON. Using this, users can use DAMON’s major features by reading 17*c4ba6014SSeongJae Park from and writing to special debugfs files. Therefore, you can write and use 18*c4ba6014SSeongJae Park your personalized DAMON debugfs wrapper programs that reads/writes the 19*c4ba6014SSeongJae Park debugfs files instead of you. The DAMON user space tool is also a reference 20*c4ba6014SSeongJae Park implementation of such programs. It supports only virtual address spaces 21*c4ba6014SSeongJae Park monitoring. 22*c4ba6014SSeongJae Park- *Kernel Space Programming Interface.* 23*c4ba6014SSeongJae Park This is for kernel space programmers. Using this, users can utilize every 24*c4ba6014SSeongJae Park feature of DAMON most flexibly and efficiently by writing kernel space 25*c4ba6014SSeongJae Park DAMON application programs for you. You can even extend DAMON for various 26*c4ba6014SSeongJae Park address spaces. 27*c4ba6014SSeongJae Park 28*c4ba6014SSeongJae ParkNevertheless, you could write your own user space tool using the debugfs 29*c4ba6014SSeongJae Parkinterface. A reference implementation is available at 30*c4ba6014SSeongJae Parkhttps://github.com/awslabs/damo. If you are a kernel programmer, you could 31*c4ba6014SSeongJae Parkrefer to :doc:`/vm/damon/api` for the kernel space programming interface. For 32*c4ba6014SSeongJae Parkthe reason, this document describes only the debugfs interface 33*c4ba6014SSeongJae Park 34*c4ba6014SSeongJae Parkdebugfs Interface 35*c4ba6014SSeongJae Park================= 36*c4ba6014SSeongJae Park 37*c4ba6014SSeongJae ParkDAMON exports three files, ``attrs``, ``target_ids``, and ``monitor_on`` under 38*c4ba6014SSeongJae Parkits debugfs directory, ``<debugfs>/damon/``. 39*c4ba6014SSeongJae Park 40*c4ba6014SSeongJae Park 41*c4ba6014SSeongJae ParkAttributes 42*c4ba6014SSeongJae Park---------- 43*c4ba6014SSeongJae Park 44*c4ba6014SSeongJae ParkUsers can get and set the ``sampling interval``, ``aggregation interval``, 45*c4ba6014SSeongJae Park``regions update interval``, and min/max number of monitoring target regions by 46*c4ba6014SSeongJae Parkreading from and writing to the ``attrs`` file. To know about the monitoring 47*c4ba6014SSeongJae Parkattributes in detail, please refer to the :doc:`/vm/damon/design`. For 48*c4ba6014SSeongJae Parkexample, below commands set those values to 5 ms, 100 ms, 1,000 ms, 10 and 49*c4ba6014SSeongJae Park1000, and then check it again:: 50*c4ba6014SSeongJae Park 51*c4ba6014SSeongJae Park # cd <debugfs>/damon 52*c4ba6014SSeongJae Park # echo 5000 100000 1000000 10 1000 > attrs 53*c4ba6014SSeongJae Park # cat attrs 54*c4ba6014SSeongJae Park 5000 100000 1000000 10 1000 55*c4ba6014SSeongJae Park 56*c4ba6014SSeongJae Park 57*c4ba6014SSeongJae ParkTarget IDs 58*c4ba6014SSeongJae Park---------- 59*c4ba6014SSeongJae Park 60*c4ba6014SSeongJae ParkSome types of address spaces supports multiple monitoring target. For example, 61*c4ba6014SSeongJae Parkthe virtual memory address spaces monitoring can have multiple processes as the 62*c4ba6014SSeongJae Parkmonitoring targets. Users can set the targets by writing relevant id values of 63*c4ba6014SSeongJae Parkthe targets to, and get the ids of the current targets by reading from the 64*c4ba6014SSeongJae Park``target_ids`` file. In case of the virtual address spaces monitoring, the 65*c4ba6014SSeongJae Parkvalues should be pids of the monitoring target processes. For example, below 66*c4ba6014SSeongJae Parkcommands set processes having pids 42 and 4242 as the monitoring targets and 67*c4ba6014SSeongJae Parkcheck it again:: 68*c4ba6014SSeongJae Park 69*c4ba6014SSeongJae Park # cd <debugfs>/damon 70*c4ba6014SSeongJae Park # echo 42 4242 > target_ids 71*c4ba6014SSeongJae Park # cat target_ids 72*c4ba6014SSeongJae Park 42 4242 73*c4ba6014SSeongJae Park 74*c4ba6014SSeongJae ParkNote that setting the target ids doesn't start the monitoring. 75*c4ba6014SSeongJae Park 76*c4ba6014SSeongJae Park 77*c4ba6014SSeongJae ParkTurning On/Off 78*c4ba6014SSeongJae Park-------------- 79*c4ba6014SSeongJae Park 80*c4ba6014SSeongJae ParkSetting the files as described above doesn't incur effect unless you explicitly 81*c4ba6014SSeongJae Parkstart the monitoring. You can start, stop, and check the current status of the 82*c4ba6014SSeongJae Parkmonitoring by writing to and reading from the ``monitor_on`` file. Writing 83*c4ba6014SSeongJae Park``on`` to the file starts the monitoring of the targets with the attributes. 84*c4ba6014SSeongJae ParkWriting ``off`` to the file stops those. DAMON also stops if every target 85*c4ba6014SSeongJae Parkprocess is terminated. Below example commands turn on, off, and check the 86*c4ba6014SSeongJae Parkstatus of DAMON:: 87*c4ba6014SSeongJae Park 88*c4ba6014SSeongJae Park # cd <debugfs>/damon 89*c4ba6014SSeongJae Park # echo on > monitor_on 90*c4ba6014SSeongJae Park # echo off > monitor_on 91*c4ba6014SSeongJae Park # cat monitor_on 92*c4ba6014SSeongJae Park off 93*c4ba6014SSeongJae Park 94*c4ba6014SSeongJae ParkPlease note that you cannot write to the above-mentioned debugfs files while 95*c4ba6014SSeongJae Parkthe monitoring is turned on. If you write to the files while DAMON is running, 96*c4ba6014SSeongJae Parkan error code such as ``-EBUSY`` will be returned. 97*c4ba6014SSeongJae Park 98*c4ba6014SSeongJae Park 99*c4ba6014SSeongJae ParkTracepoint for Monitoring Results 100*c4ba6014SSeongJae Park================================= 101*c4ba6014SSeongJae Park 102*c4ba6014SSeongJae ParkDAMON provides the monitoring results via a tracepoint, 103*c4ba6014SSeongJae Park``damon:damon_aggregated``. While the monitoring is turned on, you could 104*c4ba6014SSeongJae Parkrecord the tracepoint events and show results using tracepoint supporting tools 105*c4ba6014SSeongJae Parklike ``perf``. For example:: 106*c4ba6014SSeongJae Park 107*c4ba6014SSeongJae Park # echo on > monitor_on 108*c4ba6014SSeongJae Park # perf record -e damon:damon_aggregated & 109*c4ba6014SSeongJae Park # sleep 5 110*c4ba6014SSeongJae Park # kill 9 $(pidof perf) 111*c4ba6014SSeongJae Park # echo off > monitor_on 112*c4ba6014SSeongJae Park # perf script 113