design.rst 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. .. SPDX-License-Identifier: GPL-2.0
  2. ======
  3. Design
  4. ======
  5. .. _damon_design_execution_model_and_data_structures:
  6. Execution Model and Data Structures
  7. ===================================
  8. The monitoring-related information including the monitoring request
  9. specification and DAMON-based operation schemes are stored in a data structure
  10. called DAMON ``context``. DAMON executes each context with a kernel thread
  11. called ``kdamond``. Multiple kdamonds could run in parallel, for different
  12. types of monitoring.
  13. To know how user-space can do the configurations and start/stop DAMON, refer to
  14. :ref:`DAMON sysfs interface <sysfs_interface>` documentation.
  15. Overall Architecture
  16. ====================
  17. DAMON subsystem is configured with three layers including
  18. - :ref:`Operations Set <damon_operations_set>`: Implements fundamental
  19. operations for DAMON that depends on the given monitoring target
  20. address-space and available set of software/hardware primitives,
  21. - :ref:`Core <damon_core_logic>`: Implements core logics including monitoring
  22. overhead/accuracy control and access-aware system operations on top of the
  23. operations set layer, and
  24. - :ref:`Modules <damon_modules>`: Implements kernel modules for various
  25. purposes that provides interfaces for the user space, on top of the core
  26. layer.
  27. .. _damon_operations_set:
  28. Operations Set Layer
  29. ====================
  30. .. _damon_design_configurable_operations_set:
  31. For data access monitoring and additional low level work, DAMON needs a set of
  32. implementations for specific operations that are dependent on and optimized for
  33. the given target address space. For example, below two operations for access
  34. monitoring are address-space dependent.
  35. 1. Identification of the monitoring target address range for the address space.
  36. 2. Access check of specific address range in the target space.
  37. DAMON consolidates these implementations in a layer called DAMON Operations
  38. Set, and defines the interface between it and the upper layer. The upper layer
  39. is dedicated for DAMON's core logics including the mechanism for control of the
  40. monitoring accruracy and the overhead.
  41. Hence, DAMON can easily be extended for any address space and/or available
  42. hardware features by configuring the core logic to use the appropriate
  43. operations set. If there is no available operations set for a given purpose, a
  44. new operations set can be implemented following the interface between the
  45. layers.
  46. For example, physical memory, virtual memory, swap space, those for specific
  47. processes, NUMA nodes, files, and backing memory devices would be supportable.
  48. Also, if some architectures or devices support special optimized access check
  49. features, those will be easily configurable.
  50. DAMON currently provides below three operation sets. Below two subsections
  51. describe how those work.
  52. - vaddr: Monitor virtual address spaces of specific processes
  53. - fvaddr: Monitor fixed virtual address ranges
  54. - paddr: Monitor the physical address space of the system
  55. To know how user-space can do the configuration via :ref:`DAMON sysfs interface
  56. <sysfs_interface>`, refer to :ref:`operations <sysfs_context>` file part of the
  57. documentation.
  58. .. _damon_design_vaddr_target_regions_construction:
  59. VMA-based Target Address Range Construction
  60. -------------------------------------------
  61. A mechanism of ``vaddr`` DAMON operations set that automatically initializes
  62. and updates the monitoring target address regions so that entire memory
  63. mappings of the target processes can be covered.
  64. This mechanism is only for the ``vaddr`` operations set. In cases of
  65. ``fvaddr`` and ``paddr`` operation sets, users are asked to manually set the
  66. monitoring target address ranges.
  67. Only small parts in the super-huge virtual address space of the processes are
  68. mapped to the physical memory and accessed. Thus, tracking the unmapped
  69. address regions is just wasteful. However, because DAMON can deal with some
  70. level of noise using the adaptive regions adjustment mechanism, tracking every
  71. mapping is not strictly required but could even incur a high overhead in some
  72. cases. That said, too huge unmapped areas inside the monitoring target should
  73. be removed to not take the time for the adaptive mechanism.
  74. For the reason, this implementation converts the complex mappings to three
  75. distinct regions that cover every mapped area of the address space. The two
  76. gaps between the three regions are the two biggest unmapped areas in the given
  77. address space. The two biggest unmapped areas would be the gap between the
  78. heap and the uppermost mmap()-ed region, and the gap between the lowermost
  79. mmap()-ed region and the stack in most of the cases. Because these gaps are
  80. exceptionally huge in usual address spaces, excluding these will be sufficient
  81. to make a reasonable trade-off. Below shows this in detail::
  82. <heap>
  83. <BIG UNMAPPED REGION 1>
  84. <uppermost mmap()-ed region>
  85. (small mmap()-ed regions and munmap()-ed regions)
  86. <lowermost mmap()-ed region>
  87. <BIG UNMAPPED REGION 2>
  88. <stack>
  89. PTE Accessed-bit Based Access Check
  90. -----------------------------------
  91. Both of the implementations for physical and virtual address spaces use PTE
  92. Accessed-bit for basic access checks. Only one difference is the way of
  93. finding the relevant PTE Accessed bit(s) from the address. While the
  94. implementation for the virtual address walks the page table for the target task
  95. of the address, the implementation for the physical address walks every page
  96. table having a mapping to the address. In this way, the implementations find
  97. and clear the bit(s) for next sampling target address and checks whether the
  98. bit(s) set again after one sampling period. This could disturb other kernel
  99. subsystems using the Accessed bits, namely Idle page tracking and the reclaim
  100. logic. DAMON does nothing to avoid disturbing Idle page tracking, so handling
  101. the interference is the responsibility of sysadmins. However, it solves the
  102. conflict with the reclaim logic using ``PG_idle`` and ``PG_young`` page flags,
  103. as Idle page tracking does.
  104. .. _damon_core_logic:
  105. Core Logics
  106. ===========
  107. .. _damon_design_monitoring:
  108. Monitoring
  109. ----------
  110. Below four sections describe each of the DAMON core mechanisms and the five
  111. monitoring attributes, ``sampling interval``, ``aggregation interval``,
  112. ``update interval``, ``minimum number of regions``, and ``maximum number of
  113. regions``.
  114. To know how user-space can set the attributes via :ref:`DAMON sysfs interface
  115. <sysfs_interface>`, refer to :ref:`monitoring_attrs <sysfs_monitoring_attrs>`
  116. part of the documentation.
  117. Access Frequency Monitoring
  118. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  119. The output of DAMON says what pages are how frequently accessed for a given
  120. duration. The resolution of the access frequency is controlled by setting
  121. ``sampling interval`` and ``aggregation interval``. In detail, DAMON checks
  122. access to each page per ``sampling interval`` and aggregates the results. In
  123. other words, counts the number of the accesses to each page. After each
  124. ``aggregation interval`` passes, DAMON calls callback functions that previously
  125. registered by users so that users can read the aggregated results and then
  126. clears the results. This can be described in below simple pseudo-code::
  127. while monitoring_on:
  128. for page in monitoring_target:
  129. if accessed(page):
  130. nr_accesses[page] += 1
  131. if time() % aggregation_interval == 0:
  132. for callback in user_registered_callbacks:
  133. callback(monitoring_target, nr_accesses)
  134. for page in monitoring_target:
  135. nr_accesses[page] = 0
  136. sleep(sampling interval)
  137. The monitoring overhead of this mechanism will arbitrarily increase as the
  138. size of the target workload grows.
  139. .. _damon_design_region_based_sampling:
  140. Region Based Sampling
  141. ~~~~~~~~~~~~~~~~~~~~~
  142. To avoid the unbounded increase of the overhead, DAMON groups adjacent pages
  143. that assumed to have the same access frequencies into a region. As long as the
  144. assumption (pages in a region have the same access frequencies) is kept, only
  145. one page in the region is required to be checked. Thus, for each ``sampling
  146. interval``, DAMON randomly picks one page in each region, waits for one
  147. ``sampling interval``, checks whether the page is accessed meanwhile, and
  148. increases the access frequency counter of the region if so. The counter is
  149. called ``nr_accesses`` of the region. Therefore, the monitoring overhead is
  150. controllable by setting the number of regions. DAMON allows users to set the
  151. minimum and the maximum number of regions for the trade-off.
  152. This scheme, however, cannot preserve the quality of the output if the
  153. assumption is not guaranteed.
  154. Adaptive Regions Adjustment
  155. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  156. Even somehow the initial monitoring target regions are well constructed to
  157. fulfill the assumption (pages in same region have similar access frequencies),
  158. the data access pattern can be dynamically changed. This will result in low
  159. monitoring quality. To keep the assumption as much as possible, DAMON
  160. adaptively merges and splits each region based on their access frequency.
  161. For each ``aggregation interval``, it compares the access frequencies
  162. (``nr_accesses``) of adjacent regions. If the difference is small, and if the
  163. sum of the two regions' sizes is smaller than the size of total regions divided
  164. by the ``minimum number of regions``, DAMON merges the two regions. If the
  165. resulting number of total regions is still higher than ``maximum number of
  166. regions``, it repeats the merging with increasing access frequenceis difference
  167. threshold until the upper-limit of the number of regions is met, or the
  168. threshold becomes higher than possible maximum value (``aggregation interval``
  169. divided by ``sampling interval``). Then, after it reports and clears the
  170. aggregated access frequency of each region, it splits each region into two or
  171. three regions if the total number of regions will not exceed the user-specified
  172. maximum number of regions after the split.
  173. In this way, DAMON provides its best-effort quality and minimal overhead while
  174. keeping the bounds users set for their trade-off.
  175. .. _damon_design_age_tracking:
  176. Age Tracking
  177. ~~~~~~~~~~~~
  178. By analyzing the monitoring results, users can also find how long the current
  179. access pattern of a region has maintained. That could be used for good
  180. understanding of the access pattern. For example, page placement algorithm
  181. utilizing both the frequency and the recency could be implemented using that.
  182. To make such access pattern maintained period analysis easier, DAMON maintains
  183. yet another counter called ``age`` in each region. For each ``aggregation
  184. interval``, DAMON checks if the region's size and access frequency
  185. (``nr_accesses``) has significantly changed. If so, the counter is reset to
  186. zero. Otherwise, the counter is increased.
  187. Dynamic Target Space Updates Handling
  188. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  189. The monitoring target address range could dynamically changed. For example,
  190. virtual memory could be dynamically mapped and unmapped. Physical memory could
  191. be hot-plugged.
  192. As the changes could be quite frequent in some cases, DAMON allows the
  193. monitoring operations to check dynamic changes including memory mapping changes
  194. and applies it to monitoring operations-related data structures such as the
  195. abstracted monitoring target memory area only for each of a user-specified time
  196. interval (``update interval``).
  197. User-space can get the monitoring results via DAMON sysfs interface and/or
  198. tracepoints. For more details, please refer to the documentations for
  199. :ref:`DAMOS tried regions <sysfs_schemes_tried_regions>` and :ref:`tracepoint`,
  200. respectively.
  201. .. _damon_design_damos:
  202. Operation Schemes
  203. -----------------
  204. One common purpose of data access monitoring is access-aware system efficiency
  205. optimizations. For example,
  206. paging out memory regions that are not accessed for more than two minutes
  207. or
  208. using THP for memory regions that are larger than 2 MiB and showing a high
  209. access frequency for more than one minute.
  210. One straightforward approach for such schemes would be profile-guided
  211. optimizations. That is, getting data access monitoring results of the
  212. workloads or the system using DAMON, finding memory regions of special
  213. characteristics by profiling the monitoring results, and making system
  214. operation changes for the regions. The changes could be made by modifying or
  215. providing advice to the software (the application and/or the kernel), or
  216. reconfiguring the hardware. Both offline and online approaches could be
  217. available.
  218. Among those, providing advice to the kernel at runtime would be flexible and
  219. effective, and therefore widely be used. However, implementing such schemes
  220. could impose unnecessary redundancy and inefficiency. The profiling could be
  221. redundant if the type of interest is common. Exchanging the information
  222. including monitoring results and operation advice between kernel and user
  223. spaces could be inefficient.
  224. To allow users to reduce such redundancy and inefficiencies by offloading the
  225. works, DAMON provides a feature called Data Access Monitoring-based Operation
  226. Schemes (DAMOS). It lets users specify their desired schemes at a high
  227. level. For such specifications, DAMON starts monitoring, finds regions having
  228. the access pattern of interest, and applies the user-desired operation actions
  229. to the regions, for every user-specified time interval called
  230. ``apply_interval``.
  231. To know how user-space can set ``apply_interval`` via :ref:`DAMON sysfs
  232. interface <sysfs_interface>`, refer to :ref:`apply_interval_us <sysfs_scheme>`
  233. part of the documentation.
  234. .. _damon_design_damos_action:
  235. Operation Action
  236. ~~~~~~~~~~~~~~~~
  237. The management action that the users desire to apply to the regions of their
  238. interest. For example, paging out, prioritizing for next reclamation victim
  239. selection, advising ``khugepaged`` to collapse or split, or doing nothing but
  240. collecting statistics of the regions.
  241. The list of supported actions is defined in DAMOS, but the implementation of
  242. each action is in the DAMON operations set layer because the implementation
  243. normally depends on the monitoring target address space. For example, the code
  244. for paging specific virtual address ranges out would be different from that for
  245. physical address ranges. And the monitoring operations implementation sets are
  246. not mandated to support all actions of the list. Hence, the availability of
  247. specific DAMOS action depends on what operations set is selected to be used
  248. together.
  249. The list of the supported actions, their meaning, and DAMON operations sets
  250. that supports each action are as below.
  251. - ``willneed``: Call ``madvise()`` for the region with ``MADV_WILLNEED``.
  252. Supported by ``vaddr`` and ``fvaddr`` operations set.
  253. - ``cold``: Call ``madvise()`` for the region with ``MADV_COLD``.
  254. Supported by ``vaddr`` and ``fvaddr`` operations set.
  255. - ``pageout``: Reclaim the region.
  256. Supported by ``vaddr``, ``fvaddr`` and ``paddr`` operations set.
  257. - ``hugepage``: Call ``madvise()`` for the region with ``MADV_HUGEPAGE``.
  258. Supported by ``vaddr`` and ``fvaddr`` operations set.
  259. - ``nohugepage``: Call ``madvise()`` for the region with ``MADV_NOHUGEPAGE``.
  260. Supported by ``vaddr`` and ``fvaddr`` operations set.
  261. - ``lru_prio``: Prioritize the region on its LRU lists.
  262. Supported by ``paddr`` operations set.
  263. - ``lru_deprio``: Deprioritize the region on its LRU lists.
  264. Supported by ``paddr`` operations set.
  265. - ``migrate_hot``: Migrate the regions prioritizing warmer regions.
  266. Supported by ``paddr`` operations set.
  267. - ``migrate_cold``: Migrate the regions prioritizing colder regions.
  268. Supported by ``paddr`` operations set.
  269. - ``stat``: Do nothing but count the statistics.
  270. Supported by all operations sets.
  271. Applying the actions except ``stat`` to a region is considered as changing the
  272. region's characteristics. Hence, DAMOS resets the age of regions when any such
  273. actions are applied to those.
  274. To know how user-space can set the action via :ref:`DAMON sysfs interface
  275. <sysfs_interface>`, refer to :ref:`action <sysfs_scheme>` part of the
  276. documentation.
  277. .. _damon_design_damos_access_pattern:
  278. Target Access Pattern
  279. ~~~~~~~~~~~~~~~~~~~~~
  280. The access pattern of the schemes' interest. The patterns are constructed with
  281. the properties that DAMON's monitoring results provide, specifically the size,
  282. the access frequency, and the age. Users can describe their access pattern of
  283. interest by setting minimum and maximum values of the three properties. If a
  284. region's three properties are in the ranges, DAMOS classifies it as one of the
  285. regions that the scheme is having an interest in.
  286. To know how user-space can set the access pattern via :ref:`DAMON sysfs
  287. interface <sysfs_interface>`, refer to :ref:`access_pattern
  288. <sysfs_access_pattern>` part of the documentation.
  289. .. _damon_design_damos_quotas:
  290. Quotas
  291. ~~~~~~
  292. DAMOS upper-bound overhead control feature. DAMOS could incur high overhead if
  293. the target access pattern is not properly tuned. For example, if a huge memory
  294. region having the access pattern of interest is found, applying the scheme's
  295. action to all pages of the huge region could consume unacceptably large system
  296. resources. Preventing such issues by tuning the access pattern could be
  297. challenging, especially if the access patterns of the workloads are highly
  298. dynamic.
  299. To mitigate that situation, DAMOS provides an upper-bound overhead control
  300. feature called quotas. It lets users specify an upper limit of time that DAMOS
  301. can use for applying the action, and/or a maximum bytes of memory regions that
  302. the action can be applied within a user-specified time duration.
  303. To know how user-space can set the basic quotas via :ref:`DAMON sysfs interface
  304. <sysfs_interface>`, refer to :ref:`quotas <sysfs_quotas>` part of the
  305. documentation.
  306. .. _damon_design_damos_quotas_prioritization:
  307. Prioritization
  308. ^^^^^^^^^^^^^^
  309. A mechanism for making a good decision under the quotas. When the action
  310. cannot be applied to all regions of interest due to the quotas, DAMOS
  311. prioritizes regions and applies the action to only regions having high enough
  312. priorities so that it will not exceed the quotas.
  313. The prioritization mechanism should be different for each action. For example,
  314. rarely accessed (colder) memory regions would be prioritized for page-out
  315. scheme action. In contrast, the colder regions would be deprioritized for huge
  316. page collapse scheme action. Hence, the prioritization mechanisms for each
  317. action are implemented in each DAMON operations set, together with the actions.
  318. Though the implementation is up to the DAMON operations set, it would be common
  319. to calculate the priority using the access pattern properties of the regions.
  320. Some users would want the mechanisms to be personalized for their specific
  321. case. For example, some users would want the mechanism to weigh the recency
  322. (``age``) more than the access frequency (``nr_accesses``). DAMOS allows users
  323. to specify the weight of each access pattern property and passes the
  324. information to the underlying mechanism. Nevertheless, how and even whether
  325. the weight will be respected are up to the underlying prioritization mechanism
  326. implementation.
  327. To know how user-space can set the prioritization weights via :ref:`DAMON sysfs
  328. interface <sysfs_interface>`, refer to :ref:`weights <sysfs_quotas>` part of
  329. the documentation.
  330. .. _damon_design_damos_quotas_auto_tuning:
  331. Aim-oriented Feedback-driven Auto-tuning
  332. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  333. Automatic feedback-driven quota tuning. Instead of setting the absolute quota
  334. value, users can specify the metric of their interest, and what target value
  335. they want the metric value to be. DAMOS then automatically tunes the
  336. aggressiveness (the quota) of the corresponding scheme. For example, if DAMOS
  337. is under achieving the goal, DAMOS automatically increases the quota. If DAMOS
  338. is over achieving the goal, it decreases the quota.
  339. The goal can be specified with three parameters, namely ``target_metric``,
  340. ``target_value``, and ``current_value``. The auto-tuning mechanism tries to
  341. make ``current_value`` of ``target_metric`` be same to ``target_value``.
  342. Currently, two ``target_metric`` are provided.
  343. - ``user_input``: User-provided value. Users could use any metric that they
  344. has interest in for the value. Use space main workload's latency or
  345. throughput, system metrics like free memory ratio or memory pressure stall
  346. time (PSI) could be examples. Note that users should explicitly set
  347. ``current_value`` on their own in this case. In other words, users should
  348. repeatedly provide the feedback.
  349. - ``some_mem_psi_us``: System-wide ``some`` memory pressure stall information
  350. in microseconds that measured from last quota reset to next quota reset.
  351. DAMOS does the measurement on its own, so only ``target_value`` need to be
  352. set by users at the initial time. In other words, DAMOS does self-feedback.
  353. To know how user-space can set the tuning goal metric, the target value, and/or
  354. the current value via :ref:`DAMON sysfs interface <sysfs_interface>`, refer to
  355. :ref:`quota goals <sysfs_schemes_quota_goals>` part of the documentation.
  356. .. _damon_design_damos_watermarks:
  357. Watermarks
  358. ~~~~~~~~~~
  359. Conditional DAMOS (de)activation automation. Users might want DAMOS to run
  360. only under certain situations. For example, when a sufficient amount of free
  361. memory is guaranteed, running a scheme for proactive reclamation would only
  362. consume unnecessary system resources. To avoid such consumption, the user would
  363. need to manually monitor some metrics such as free memory ratio, and turn
  364. DAMON/DAMOS on or off.
  365. DAMOS allows users to offload such works using three watermarks. It allows the
  366. users to configure the metric of their interest, and three watermark values,
  367. namely high, middle, and low. If the value of the metric becomes above the
  368. high watermark or below the low watermark, the scheme is deactivated. If the
  369. metric becomes below the mid watermark but above the low watermark, the scheme
  370. is activated. If all schemes are deactivated by the watermarks, the monitoring
  371. is also deactivated. In this case, the DAMON worker thread only periodically
  372. checks the watermarks and therefore incurs nearly zero overhead.
  373. To know how user-space can set the watermarks via :ref:`DAMON sysfs interface
  374. <sysfs_interface>`, refer to :ref:`watermarks <sysfs_watermarks>` part of the
  375. documentation.
  376. .. _damon_design_damos_filters:
  377. Filters
  378. ~~~~~~~
  379. Non-access pattern-based target memory regions filtering. If users run
  380. self-written programs or have good profiling tools, they could know something
  381. more than the kernel, such as future access patterns or some special
  382. requirements for specific types of memory. For example, some users may know
  383. only anonymous pages can impact their program's performance. They can also
  384. have a list of latency-critical processes.
  385. To let users optimize DAMOS schemes with such special knowledge, DAMOS provides
  386. a feature called DAMOS filters. The feature allows users to set an arbitrary
  387. number of filters for each scheme. Each filter specifies the type of target
  388. memory, and whether it should exclude the memory of the type (filter-out), or
  389. all except the memory of the type (filter-in).
  390. For efficient handling of filters, some types of filters are handled by the
  391. core layer, while others are handled by operations set. In the latter case,
  392. hence, support of the filter types depends on the DAMON operations set. In
  393. case of the core layer-handled filters, the memory regions that excluded by the
  394. filter are not counted as the scheme has tried to the region. In contrast, if
  395. a memory regions is filtered by an operations set layer-handled filter, it is
  396. counted as the scheme has tried. This difference affects the statistics.
  397. Below types of filters are currently supported.
  398. - anonymous page
  399. - Applied to pages that containing data that not stored in files.
  400. - Handled by operations set layer. Supported by only ``paddr`` set.
  401. - memory cgroup
  402. - Applied to pages that belonging to a given cgroup.
  403. - Handled by operations set layer. Supported by only ``paddr`` set.
  404. - young page
  405. - Applied to pages that are accessed after the last access check from the
  406. scheme.
  407. - Handled by operations set layer. Supported by only ``paddr`` set.
  408. - address range
  409. - Applied to pages that belonging to a given address range.
  410. - Handled by the core logic.
  411. - DAMON monitoring target
  412. - Applied to pages that belonging to a given DAMON monitoring target.
  413. - Handled by the core logic.
  414. To know how user-space can set the watermarks via :ref:`DAMON sysfs interface
  415. <sysfs_interface>`, refer to :ref:`filters <sysfs_filters>` part of the
  416. documentation.
  417. Application Programming Interface
  418. ---------------------------------
  419. The programming interface for kernel space data access-aware applications.
  420. DAMON is a framework, so it does nothing by itself. Instead, it only helps
  421. other kernel components such as subsystems and modules building their data
  422. access-aware applications using DAMON's core features. For this, DAMON exposes
  423. its all features to other kernel components via its application programming
  424. interface, namely ``include/linux/damon.h``. Please refer to the API
  425. :doc:`document </mm/damon/api>` for details of the interface.
  426. .. _damon_modules:
  427. Modules
  428. =======
  429. Because the core of DAMON is a framework for kernel components, it doesn't
  430. provide any direct interface for the user space. Such interfaces should be
  431. implemented by each DAMON API user kernel components, instead. DAMON subsystem
  432. itself implements such DAMON API user modules, which are supposed to be used
  433. for general purpose DAMON control and special purpose data access-aware system
  434. operations, and provides stable application binary interfaces (ABI) for the
  435. user space. The user space can build their efficient data access-aware
  436. applications using the interfaces.
  437. General Purpose User Interface Modules
  438. --------------------------------------
  439. DAMON modules that provide user space ABIs for general purpose DAMON usage in
  440. runtime.
  441. DAMON user interface modules, namely 'DAMON sysfs interface' and 'DAMON debugfs
  442. interface' are DAMON API user kernel modules that provide ABIs to the
  443. user-space. Please note that DAMON debugfs interface is currently deprecated.
  444. Like many other ABIs, the modules create files on sysfs and debugfs, allow
  445. users to specify their requests to and get the answers from DAMON by writing to
  446. and reading from the files. As a response to such I/O, DAMON user interface
  447. modules control DAMON and retrieve the results as user requested via the DAMON
  448. API, and return the results to the user-space.
  449. The ABIs are designed to be used for user space applications development,
  450. rather than human beings' fingers. Human users are recommended to use such
  451. user space tools. One such Python-written user space tool is available at
  452. Github (https://github.com/damonitor/damo), Pypi
  453. (https://pypistats.org/packages/damo), and Fedora
  454. (https://packages.fedoraproject.org/pkgs/python-damo/damo/).
  455. Please refer to the ABI :doc:`document </admin-guide/mm/damon/usage>` for
  456. details of the interfaces.
  457. Special-Purpose Access-aware Kernel Modules
  458. -------------------------------------------
  459. DAMON modules that provide user space ABI for specific purpose DAMON usage.
  460. DAMON sysfs/debugfs user interfaces are for full control of all DAMON features
  461. in runtime. For each special-purpose system-wide data access-aware system
  462. operations such as proactive reclamation or LRU lists balancing, the interfaces
  463. could be simplified by removing unnecessary knobs for the specific purpose, and
  464. extended for boot-time and even compile time control. Default values of DAMON
  465. control parameters for the usage would also need to be optimized for the
  466. purpose.
  467. To support such cases, yet more DAMON API user kernel modules that provide more
  468. simple and optimized user space interfaces are available. Currently, two
  469. modules for proactive reclamation and LRU lists manipulation are provided. For
  470. more detail, please read the usage documents for those
  471. (:doc:`/admin-guide/mm/damon/reclaim` and
  472. :doc:`/admin-guide/mm/damon/lru_sort`).