start.rst 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. .. SPDX-License-Identifier: GPL-2.0
  2. ===============
  3. Getting Started
  4. ===============
  5. This document briefly describes how you can use DAMON by demonstrating its
  6. default user space tool. Please note that this document describes only a part
  7. of its features for brevity. Please refer to the usage `doc
  8. <https://github.com/damonitor/damo/blob/next/USAGE.md>`_ of the tool for more
  9. details.
  10. Prerequisites
  11. =============
  12. Kernel
  13. ------
  14. You should first ensure your system is running on a kernel built with
  15. ``CONFIG_DAMON_*=y``.
  16. User Space Tool
  17. ---------------
  18. For the demonstration, we will use the default user space tool for DAMON,
  19. called DAMON Operator (DAMO). It is available at
  20. https://github.com/damonitor/damo. The examples below assume that ``damo`` is on
  21. your ``$PATH``. It's not mandatory, though.
  22. Because DAMO is using the sysfs interface (refer to :doc:`usage` for the
  23. detail) of DAMON, you should ensure :doc:`sysfs </filesystems/sysfs>` is
  24. mounted.
  25. Snapshot Data Access Patterns
  26. =============================
  27. The commands below show the memory access pattern of a program at the moment of
  28. the execution. ::
  29. $ git clone https://github.com/sjp38/masim; cd masim; make
  30. $ sudo damo start "./masim ./configs/stairs.cfg --quiet"
  31. $ sudo ./damo show
  32. 0 addr [85.541 TiB , 85.541 TiB ) (57.707 MiB ) access 0 % age 10.400 s
  33. 1 addr [85.541 TiB , 85.542 TiB ) (413.285 MiB) access 0 % age 11.400 s
  34. 2 addr [127.649 TiB , 127.649 TiB) (57.500 MiB ) access 0 % age 1.600 s
  35. 3 addr [127.649 TiB , 127.649 TiB) (32.500 MiB ) access 0 % age 500 ms
  36. 4 addr [127.649 TiB , 127.649 TiB) (9.535 MiB ) access 100 % age 300 ms
  37. 5 addr [127.649 TiB , 127.649 TiB) (8.000 KiB ) access 60 % age 0 ns
  38. 6 addr [127.649 TiB , 127.649 TiB) (6.926 MiB ) access 0 % age 1 s
  39. 7 addr [127.998 TiB , 127.998 TiB) (120.000 KiB) access 0 % age 11.100 s
  40. 8 addr [127.998 TiB , 127.998 TiB) (8.000 KiB ) access 40 % age 100 ms
  41. 9 addr [127.998 TiB , 127.998 TiB) (4.000 KiB ) access 0 % age 11 s
  42. total size: 577.590 MiB
  43. $ sudo ./damo stop
  44. The first command of the above example downloads and builds an artificial
  45. memory access generator program called ``masim``. The second command asks DAMO
  46. to execute the artificial generator process start via the given command and
  47. make DAMON monitors the generator process. The third command retrieves the
  48. current snapshot of the monitored access pattern of the process from DAMON and
  49. shows the pattern in a human readable format.
  50. Each line of the output shows which virtual address range (``addr [XX, XX)``)
  51. of the process is how frequently (``access XX %``) accessed for how long time
  52. (``age XX``). For example, the fifth region of ~9 MiB size is being most
  53. frequently accessed for last 300 milliseconds. Finally, the fourth command
  54. stops DAMON.
  55. Note that DAMON can monitor not only virtual address spaces but multiple types
  56. of address spaces including the physical address space.
  57. Recording Data Access Patterns
  58. ==============================
  59. The commands below record the memory access patterns of a program and save the
  60. monitoring results to a file. ::
  61. $ ./masim ./configs/zigzag.cfg &
  62. $ sudo damo record -o damon.data $(pidof masim)
  63. The line of the commands run the artificial memory access
  64. generator program again. The generator will repeatedly
  65. access two 100 MiB sized memory regions one by one. You can substitute this
  66. with your real workload. The last line asks ``damo`` to record the access
  67. pattern in the ``damon.data`` file.
  68. Visualizing Recorded Patterns
  69. =============================
  70. You can visualize the pattern in a heatmap, showing which memory region
  71. (x-axis) got accessed when (y-axis) and how frequently (number).::
  72. $ sudo damo report heats --heatmap stdout
  73. 22222222222222222222222222222222222222211111111111111111111111111111111111111100
  74. 44444444444444444444444444444444444444434444444444444444444444444444444444443200
  75. 44444444444444444444444444444444444444433444444444444444444444444444444444444200
  76. 33333333333333333333333333333333333333344555555555555555555555555555555555555200
  77. 33333333333333333333333333333333333344444444444444444444444444444444444444444200
  78. 22222222222222222222222222222222222223355555555555555555555555555555555555555200
  79. 00000000000000000000000000000000000000288888888888888888888888888888888888888400
  80. 00000000000000000000000000000000000000288888888888888888888888888888888888888400
  81. 33333333333333333333333333333333333333355555555555555555555555555555555555555200
  82. 88888888888888888888888888888888888888600000000000000000000000000000000000000000
  83. 88888888888888888888888888888888888888600000000000000000000000000000000000000000
  84. 33333333333333333333333333333333333333444444444444444444444444444444444444443200
  85. 00000000000000000000000000000000000000288888888888888888888888888888888888888400
  86. [...]
  87. # access_frequency: 0 1 2 3 4 5 6 7 8 9
  88. # x-axis: space (139728247021568-139728453431248: 196.848 MiB)
  89. # y-axis: time (15256597248362-15326899978162: 1 m 10.303 s)
  90. # resolution: 80x40 (2.461 MiB and 1.758 s for each character)
  91. You can also visualize the distribution of the working set size, sorted by the
  92. size.::
  93. $ sudo damo report wss --range 0 101 10
  94. # <percentile> <wss>
  95. # target_id 18446632103789443072
  96. # avr: 107.708 MiB
  97. 0 0 B | |
  98. 10 95.328 MiB |**************************** |
  99. 20 95.332 MiB |**************************** |
  100. 30 95.340 MiB |**************************** |
  101. 40 95.387 MiB |**************************** |
  102. 50 95.387 MiB |**************************** |
  103. 60 95.398 MiB |**************************** |
  104. 70 95.398 MiB |**************************** |
  105. 80 95.504 MiB |**************************** |
  106. 90 190.703 MiB |********************************************************* |
  107. 100 196.875 MiB |***********************************************************|
  108. Using ``--sortby`` option with the above command, you can show how the working
  109. set size has chronologically changed.::
  110. $ sudo damo report wss --range 0 101 10 --sortby time
  111. # <percentile> <wss>
  112. # target_id 18446632103789443072
  113. # avr: 107.708 MiB
  114. 0 3.051 MiB | |
  115. 10 190.703 MiB |***********************************************************|
  116. 20 95.336 MiB |***************************** |
  117. 30 95.328 MiB |***************************** |
  118. 40 95.387 MiB |***************************** |
  119. 50 95.332 MiB |***************************** |
  120. 60 95.320 MiB |***************************** |
  121. 70 95.398 MiB |***************************** |
  122. 80 95.398 MiB |***************************** |
  123. 90 95.340 MiB |***************************** |
  124. 100 95.398 MiB |***************************** |
  125. Data Access Pattern Aware Memory Management
  126. ===========================================
  127. Below command makes every memory region of size >=4K that has not accessed for
  128. >=60 seconds in your workload to be swapped out. ::
  129. $ sudo damo schemes --damos_access_rate 0 0 --damos_sz_region 4K max \
  130. --damos_age 60s max --damos_action pageout \
  131. <pid of your workload>