162306a36Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci 362306a36Sopenharmony_ci====== 462306a36Sopenharmony_ciDesign 562306a36Sopenharmony_ci====== 662306a36Sopenharmony_ci 762306a36Sopenharmony_ci 862306a36Sopenharmony_ciOverall Architecture 962306a36Sopenharmony_ci==================== 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ciDAMON subsystem is configured with three layers including 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ci- Operations Set: Implements fundamental operations for DAMON that depends on 1462306a36Sopenharmony_ci the given monitoring target address-space and available set of 1562306a36Sopenharmony_ci software/hardware primitives, 1662306a36Sopenharmony_ci- Core: Implements core logics including monitoring overhead/accurach control 1762306a36Sopenharmony_ci and access-aware system operations on top of the operations set layer, and 1862306a36Sopenharmony_ci- Modules: Implements kernel modules for various purposes that provides 1962306a36Sopenharmony_ci interfaces for the user space, on top of the core layer. 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ciConfigurable Operations Set 2362306a36Sopenharmony_ci--------------------------- 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_ciFor data access monitoring and additional low level work, DAMON needs a set of 2662306a36Sopenharmony_ciimplementations for specific operations that are dependent on and optimized for 2762306a36Sopenharmony_cithe given target address space. On the other hand, the accuracy and overhead 2862306a36Sopenharmony_citradeoff mechanism, which is the core logic of DAMON, is in the pure logic 2962306a36Sopenharmony_cispace. DAMON separates the two parts in different layers, namely DAMON 3062306a36Sopenharmony_ciOperations Set and DAMON Core Logics Layers, respectively. It further defines 3162306a36Sopenharmony_cithe interface between the layers to allow various operations sets to be 3262306a36Sopenharmony_ciconfigured with the core logic. 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ciDue to this design, users can extend DAMON for any address space by configuring 3562306a36Sopenharmony_cithe core logic to use the appropriate operations set. If any appropriate set 3662306a36Sopenharmony_ciis unavailable, users can implement one on their own. 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ciFor example, physical memory, virtual memory, swap space, those for specific 3962306a36Sopenharmony_ciprocesses, NUMA nodes, files, and backing memory devices would be supportable. 4062306a36Sopenharmony_ciAlso, if some architectures or devices supporting special optimized access 4162306a36Sopenharmony_cicheck primitives, those will be easily configurable. 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ci 4462306a36Sopenharmony_ciProgrammable Modules 4562306a36Sopenharmony_ci-------------------- 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_ciCore layer of DAMON is implemented as a framework, and exposes its application 4862306a36Sopenharmony_ciprogramming interface to all kernel space components such as subsystems and 4962306a36Sopenharmony_cimodules. For common use cases of DAMON, DAMON subsystem provides kernel 5062306a36Sopenharmony_cimodules that built on top of the core layer using the API, which can be easily 5162306a36Sopenharmony_ciused by the user space end users. 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_ci 5462306a36Sopenharmony_ciOperations Set Layer 5562306a36Sopenharmony_ci==================== 5662306a36Sopenharmony_ci 5762306a36Sopenharmony_ciThe monitoring operations are defined in two parts: 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_ci1. Identification of the monitoring target address range for the address space. 6062306a36Sopenharmony_ci2. Access check of specific address range in the target space. 6162306a36Sopenharmony_ci 6262306a36Sopenharmony_ciDAMON currently provides the implementations of the operations for the physical 6362306a36Sopenharmony_ciand virtual address spaces. Below two subsections describe how those work. 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ciVMA-based Target Address Range Construction 6762306a36Sopenharmony_ci------------------------------------------- 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_ciThis is only for the virtual address space monitoring operations 7062306a36Sopenharmony_ciimplementation. That for the physical address space simply asks users to 7162306a36Sopenharmony_cimanually set the monitoring target address ranges. 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_ciOnly small parts in the super-huge virtual address space of the processes are 7462306a36Sopenharmony_cimapped to the physical memory and accessed. Thus, tracking the unmapped 7562306a36Sopenharmony_ciaddress regions is just wasteful. However, because DAMON can deal with some 7662306a36Sopenharmony_cilevel of noise using the adaptive regions adjustment mechanism, tracking every 7762306a36Sopenharmony_cimapping is not strictly required but could even incur a high overhead in some 7862306a36Sopenharmony_cicases. That said, too huge unmapped areas inside the monitoring target should 7962306a36Sopenharmony_cibe removed to not take the time for the adaptive mechanism. 8062306a36Sopenharmony_ci 8162306a36Sopenharmony_ciFor the reason, this implementation converts the complex mappings to three 8262306a36Sopenharmony_cidistinct regions that cover every mapped area of the address space. The two 8362306a36Sopenharmony_cigaps between the three regions are the two biggest unmapped areas in the given 8462306a36Sopenharmony_ciaddress space. The two biggest unmapped areas would be the gap between the 8562306a36Sopenharmony_ciheap and the uppermost mmap()-ed region, and the gap between the lowermost 8662306a36Sopenharmony_cimmap()-ed region and the stack in most of the cases. Because these gaps are 8762306a36Sopenharmony_ciexceptionally huge in usual address spaces, excluding these will be sufficient 8862306a36Sopenharmony_cito make a reasonable trade-off. Below shows this in detail:: 8962306a36Sopenharmony_ci 9062306a36Sopenharmony_ci <heap> 9162306a36Sopenharmony_ci <BIG UNMAPPED REGION 1> 9262306a36Sopenharmony_ci <uppermost mmap()-ed region> 9362306a36Sopenharmony_ci (small mmap()-ed regions and munmap()-ed regions) 9462306a36Sopenharmony_ci <lowermost mmap()-ed region> 9562306a36Sopenharmony_ci <BIG UNMAPPED REGION 2> 9662306a36Sopenharmony_ci <stack> 9762306a36Sopenharmony_ci 9862306a36Sopenharmony_ci 9962306a36Sopenharmony_ciPTE Accessed-bit Based Access Check 10062306a36Sopenharmony_ci----------------------------------- 10162306a36Sopenharmony_ci 10262306a36Sopenharmony_ciBoth of the implementations for physical and virtual address spaces use PTE 10362306a36Sopenharmony_ciAccessed-bit for basic access checks. Only one difference is the way of 10462306a36Sopenharmony_cifinding the relevant PTE Accessed bit(s) from the address. While the 10562306a36Sopenharmony_ciimplementation for the virtual address walks the page table for the target task 10662306a36Sopenharmony_ciof the address, the implementation for the physical address walks every page 10762306a36Sopenharmony_citable having a mapping to the address. In this way, the implementations find 10862306a36Sopenharmony_ciand clear the bit(s) for next sampling target address and checks whether the 10962306a36Sopenharmony_cibit(s) set again after one sampling period. This could disturb other kernel 11062306a36Sopenharmony_cisubsystems using the Accessed bits, namely Idle page tracking and the reclaim 11162306a36Sopenharmony_cilogic. DAMON does nothing to avoid disturbing Idle page tracking, so handling 11262306a36Sopenharmony_cithe interference is the responsibility of sysadmins. However, it solves the 11362306a36Sopenharmony_ciconflict with the reclaim logic using ``PG_idle`` and ``PG_young`` page flags, 11462306a36Sopenharmony_cias Idle page tracking does. 11562306a36Sopenharmony_ci 11662306a36Sopenharmony_ci 11762306a36Sopenharmony_ciCore Logics 11862306a36Sopenharmony_ci=========== 11962306a36Sopenharmony_ci 12062306a36Sopenharmony_ci 12162306a36Sopenharmony_ciMonitoring 12262306a36Sopenharmony_ci---------- 12362306a36Sopenharmony_ci 12462306a36Sopenharmony_ciBelow four sections describe each of the DAMON core mechanisms and the five 12562306a36Sopenharmony_cimonitoring attributes, ``sampling interval``, ``aggregation interval``, 12662306a36Sopenharmony_ci``update interval``, ``minimum number of regions``, and ``maximum number of 12762306a36Sopenharmony_ciregions``. 12862306a36Sopenharmony_ci 12962306a36Sopenharmony_ci 13062306a36Sopenharmony_ciAccess Frequency Monitoring 13162306a36Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~~~~~~ 13262306a36Sopenharmony_ci 13362306a36Sopenharmony_ciThe output of DAMON says what pages are how frequently accessed for a given 13462306a36Sopenharmony_ciduration. The resolution of the access frequency is controlled by setting 13562306a36Sopenharmony_ci``sampling interval`` and ``aggregation interval``. In detail, DAMON checks 13662306a36Sopenharmony_ciaccess to each page per ``sampling interval`` and aggregates the results. In 13762306a36Sopenharmony_ciother words, counts the number of the accesses to each page. After each 13862306a36Sopenharmony_ci``aggregation interval`` passes, DAMON calls callback functions that previously 13962306a36Sopenharmony_ciregistered by users so that users can read the aggregated results and then 14062306a36Sopenharmony_ciclears the results. This can be described in below simple pseudo-code:: 14162306a36Sopenharmony_ci 14262306a36Sopenharmony_ci while monitoring_on: 14362306a36Sopenharmony_ci for page in monitoring_target: 14462306a36Sopenharmony_ci if accessed(page): 14562306a36Sopenharmony_ci nr_accesses[page] += 1 14662306a36Sopenharmony_ci if time() % aggregation_interval == 0: 14762306a36Sopenharmony_ci for callback in user_registered_callbacks: 14862306a36Sopenharmony_ci callback(monitoring_target, nr_accesses) 14962306a36Sopenharmony_ci for page in monitoring_target: 15062306a36Sopenharmony_ci nr_accesses[page] = 0 15162306a36Sopenharmony_ci sleep(sampling interval) 15262306a36Sopenharmony_ci 15362306a36Sopenharmony_ciThe monitoring overhead of this mechanism will arbitrarily increase as the 15462306a36Sopenharmony_cisize of the target workload grows. 15562306a36Sopenharmony_ci 15662306a36Sopenharmony_ci 15762306a36Sopenharmony_ciRegion Based Sampling 15862306a36Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~ 15962306a36Sopenharmony_ci 16062306a36Sopenharmony_ciTo avoid the unbounded increase of the overhead, DAMON groups adjacent pages 16162306a36Sopenharmony_cithat assumed to have the same access frequencies into a region. As long as the 16262306a36Sopenharmony_ciassumption (pages in a region have the same access frequencies) is kept, only 16362306a36Sopenharmony_cione page in the region is required to be checked. Thus, for each ``sampling 16462306a36Sopenharmony_ciinterval``, DAMON randomly picks one page in each region, waits for one 16562306a36Sopenharmony_ci``sampling interval``, checks whether the page is accessed meanwhile, and 16662306a36Sopenharmony_ciincreases the access frequency of the region if so. Therefore, the monitoring 16762306a36Sopenharmony_cioverhead is controllable by setting the number of regions. DAMON allows users 16862306a36Sopenharmony_cito set the minimum and the maximum number of regions for the trade-off. 16962306a36Sopenharmony_ci 17062306a36Sopenharmony_ciThis scheme, however, cannot preserve the quality of the output if the 17162306a36Sopenharmony_ciassumption is not guaranteed. 17262306a36Sopenharmony_ci 17362306a36Sopenharmony_ci 17462306a36Sopenharmony_ciAdaptive Regions Adjustment 17562306a36Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~~~~~~ 17662306a36Sopenharmony_ci 17762306a36Sopenharmony_ciEven somehow the initial monitoring target regions are well constructed to 17862306a36Sopenharmony_cifulfill the assumption (pages in same region have similar access frequencies), 17962306a36Sopenharmony_cithe data access pattern can be dynamically changed. This will result in low 18062306a36Sopenharmony_cimonitoring quality. To keep the assumption as much as possible, DAMON 18162306a36Sopenharmony_ciadaptively merges and splits each region based on their access frequency. 18262306a36Sopenharmony_ci 18362306a36Sopenharmony_ciFor each ``aggregation interval``, it compares the access frequencies of 18462306a36Sopenharmony_ciadjacent regions and merges those if the frequency difference is small. Then, 18562306a36Sopenharmony_ciafter it reports and clears the aggregated access frequency of each region, it 18662306a36Sopenharmony_cisplits each region into two or three regions if the total number of regions 18762306a36Sopenharmony_ciwill not exceed the user-specified maximum number of regions after the split. 18862306a36Sopenharmony_ci 18962306a36Sopenharmony_ciIn this way, DAMON provides its best-effort quality and minimal overhead while 19062306a36Sopenharmony_cikeeping the bounds users set for their trade-off. 19162306a36Sopenharmony_ci 19262306a36Sopenharmony_ci 19362306a36Sopenharmony_ciAge Tracking 19462306a36Sopenharmony_ci~~~~~~~~~~~~ 19562306a36Sopenharmony_ci 19662306a36Sopenharmony_ciBy analyzing the monitoring results, users can also find how long the current 19762306a36Sopenharmony_ciaccess pattern of a region has maintained. That could be used for good 19862306a36Sopenharmony_ciunderstanding of the access pattern. For example, page placement algorithm 19962306a36Sopenharmony_ciutilizing both the frequency and the recency could be implemented using that. 20062306a36Sopenharmony_ciTo make such access pattern maintained period analysis easier, DAMON maintains 20162306a36Sopenharmony_ciyet another counter called ``age`` in each region. For each ``aggregation 20262306a36Sopenharmony_ciinterval``, DAMON checks if the region's size and access frequency 20362306a36Sopenharmony_ci(``nr_accesses``) has significantly changed. If so, the counter is reset to 20462306a36Sopenharmony_cizero. Otherwise, the counter is increased. 20562306a36Sopenharmony_ci 20662306a36Sopenharmony_ci 20762306a36Sopenharmony_ciDynamic Target Space Updates Handling 20862306a36Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 20962306a36Sopenharmony_ci 21062306a36Sopenharmony_ciThe monitoring target address range could dynamically changed. For example, 21162306a36Sopenharmony_civirtual memory could be dynamically mapped and unmapped. Physical memory could 21262306a36Sopenharmony_cibe hot-plugged. 21362306a36Sopenharmony_ci 21462306a36Sopenharmony_ciAs the changes could be quite frequent in some cases, DAMON allows the 21562306a36Sopenharmony_cimonitoring operations to check dynamic changes including memory mapping changes 21662306a36Sopenharmony_ciand applies it to monitoring operations-related data structures such as the 21762306a36Sopenharmony_ciabstracted monitoring target memory area only for each of a user-specified time 21862306a36Sopenharmony_ciinterval (``update interval``). 21962306a36Sopenharmony_ci 22062306a36Sopenharmony_ci 22162306a36Sopenharmony_ci.. _damon_design_damos: 22262306a36Sopenharmony_ci 22362306a36Sopenharmony_ciOperation Schemes 22462306a36Sopenharmony_ci----------------- 22562306a36Sopenharmony_ci 22662306a36Sopenharmony_ciOne common purpose of data access monitoring is access-aware system efficiency 22762306a36Sopenharmony_cioptimizations. For example, 22862306a36Sopenharmony_ci 22962306a36Sopenharmony_ci paging out memory regions that are not accessed for more than two minutes 23062306a36Sopenharmony_ci 23162306a36Sopenharmony_cior 23262306a36Sopenharmony_ci 23362306a36Sopenharmony_ci using THP for memory regions that are larger than 2 MiB and showing a high 23462306a36Sopenharmony_ci access frequency for more than one minute. 23562306a36Sopenharmony_ci 23662306a36Sopenharmony_ciOne straightforward approach for such schemes would be profile-guided 23762306a36Sopenharmony_cioptimizations. That is, getting data access monitoring results of the 23862306a36Sopenharmony_ciworkloads or the system using DAMON, finding memory regions of special 23962306a36Sopenharmony_cicharacteristics by profiling the monitoring results, and making system 24062306a36Sopenharmony_cioperation changes for the regions. The changes could be made by modifying or 24162306a36Sopenharmony_ciproviding advice to the software (the application and/or the kernel), or 24262306a36Sopenharmony_cireconfiguring the hardware. Both offline and online approaches could be 24362306a36Sopenharmony_ciavailable. 24462306a36Sopenharmony_ci 24562306a36Sopenharmony_ciAmong those, providing advice to the kernel at runtime would be flexible and 24662306a36Sopenharmony_cieffective, and therefore widely be used. However, implementing such schemes 24762306a36Sopenharmony_cicould impose unnecessary redundancy and inefficiency. The profiling could be 24862306a36Sopenharmony_ciredundant if the type of interest is common. Exchanging the information 24962306a36Sopenharmony_ciincluding monitoring results and operation advice between kernel and user 25062306a36Sopenharmony_cispaces could be inefficient. 25162306a36Sopenharmony_ci 25262306a36Sopenharmony_ciTo allow users to reduce such redundancy and inefficiencies by offloading the 25362306a36Sopenharmony_ciworks, DAMON provides a feature called Data Access Monitoring-based Operation 25462306a36Sopenharmony_ciSchemes (DAMOS). It lets users specify their desired schemes at a high 25562306a36Sopenharmony_cilevel. For such specifications, DAMON starts monitoring, finds regions having 25662306a36Sopenharmony_cithe access pattern of interest, and applies the user-desired operation actions 25762306a36Sopenharmony_cito the regions as soon as found. 25862306a36Sopenharmony_ci 25962306a36Sopenharmony_ci 26062306a36Sopenharmony_ci.. _damon_design_damos_action: 26162306a36Sopenharmony_ci 26262306a36Sopenharmony_ciOperation Action 26362306a36Sopenharmony_ci~~~~~~~~~~~~~~~~ 26462306a36Sopenharmony_ci 26562306a36Sopenharmony_ciThe management action that the users desire to apply to the regions of their 26662306a36Sopenharmony_ciinterest. For example, paging out, prioritizing for next reclamation victim 26762306a36Sopenharmony_ciselection, advising ``khugepaged`` to collapse or split, or doing nothing but 26862306a36Sopenharmony_cicollecting statistics of the regions. 26962306a36Sopenharmony_ci 27062306a36Sopenharmony_ciThe list of supported actions is defined in DAMOS, but the implementation of 27162306a36Sopenharmony_cieach action is in the DAMON operations set layer because the implementation 27262306a36Sopenharmony_cinormally depends on the monitoring target address space. For example, the code 27362306a36Sopenharmony_cifor paging specific virtual address ranges out would be different from that for 27462306a36Sopenharmony_ciphysical address ranges. And the monitoring operations implementation sets are 27562306a36Sopenharmony_cinot mandated to support all actions of the list. Hence, the availability of 27662306a36Sopenharmony_cispecific DAMOS action depends on what operations set is selected to be used 27762306a36Sopenharmony_citogether. 27862306a36Sopenharmony_ci 27962306a36Sopenharmony_ciApplying an action to a region is considered as changing the region's 28062306a36Sopenharmony_cicharacteristics. Hence, DAMOS resets the age of regions when an action is 28162306a36Sopenharmony_ciapplied to those. 28262306a36Sopenharmony_ci 28362306a36Sopenharmony_ci 28462306a36Sopenharmony_ci.. _damon_design_damos_access_pattern: 28562306a36Sopenharmony_ci 28662306a36Sopenharmony_ciTarget Access Pattern 28762306a36Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~ 28862306a36Sopenharmony_ci 28962306a36Sopenharmony_ciThe access pattern of the schemes' interest. The patterns are constructed with 29062306a36Sopenharmony_cithe properties that DAMON's monitoring results provide, specifically the size, 29162306a36Sopenharmony_cithe access frequency, and the age. Users can describe their access pattern of 29262306a36Sopenharmony_ciinterest by setting minimum and maximum values of the three properties. If a 29362306a36Sopenharmony_ciregion's three properties are in the ranges, DAMOS classifies it as one of the 29462306a36Sopenharmony_ciregions that the scheme is having an interest in. 29562306a36Sopenharmony_ci 29662306a36Sopenharmony_ci 29762306a36Sopenharmony_ci.. _damon_design_damos_quotas: 29862306a36Sopenharmony_ci 29962306a36Sopenharmony_ciQuotas 30062306a36Sopenharmony_ci~~~~~~ 30162306a36Sopenharmony_ci 30262306a36Sopenharmony_ciDAMOS upper-bound overhead control feature. DAMOS could incur high overhead if 30362306a36Sopenharmony_cithe target access pattern is not properly tuned. For example, if a huge memory 30462306a36Sopenharmony_ciregion having the access pattern of interest is found, applying the scheme's 30562306a36Sopenharmony_ciaction to all pages of the huge region could consume unacceptably large system 30662306a36Sopenharmony_ciresources. Preventing such issues by tuning the access pattern could be 30762306a36Sopenharmony_cichallenging, especially if the access patterns of the workloads are highly 30862306a36Sopenharmony_cidynamic. 30962306a36Sopenharmony_ci 31062306a36Sopenharmony_ciTo mitigate that situation, DAMOS provides an upper-bound overhead control 31162306a36Sopenharmony_cifeature called quotas. It lets users specify an upper limit of time that DAMOS 31262306a36Sopenharmony_cican use for applying the action, and/or a maximum bytes of memory regions that 31362306a36Sopenharmony_cithe action can be applied within a user-specified time duration. 31462306a36Sopenharmony_ci 31562306a36Sopenharmony_ci 31662306a36Sopenharmony_ci.. _damon_design_damos_quotas_prioritization: 31762306a36Sopenharmony_ci 31862306a36Sopenharmony_ciPrioritization 31962306a36Sopenharmony_ci^^^^^^^^^^^^^^ 32062306a36Sopenharmony_ci 32162306a36Sopenharmony_ciA mechanism for making a good decision under the quotas. When the action 32262306a36Sopenharmony_cicannot be applied to all regions of interest due to the quotas, DAMOS 32362306a36Sopenharmony_ciprioritizes regions and applies the action to only regions having high enough 32462306a36Sopenharmony_cipriorities so that it will not exceed the quotas. 32562306a36Sopenharmony_ci 32662306a36Sopenharmony_ciThe prioritization mechanism should be different for each action. For example, 32762306a36Sopenharmony_cirarely accessed (colder) memory regions would be prioritized for page-out 32862306a36Sopenharmony_cischeme action. In contrast, the colder regions would be deprioritized for huge 32962306a36Sopenharmony_cipage collapse scheme action. Hence, the prioritization mechanisms for each 33062306a36Sopenharmony_ciaction are implemented in each DAMON operations set, together with the actions. 33162306a36Sopenharmony_ci 33262306a36Sopenharmony_ciThough the implementation is up to the DAMON operations set, it would be common 33362306a36Sopenharmony_cito calculate the priority using the access pattern properties of the regions. 33462306a36Sopenharmony_ciSome users would want the mechanisms to be personalized for their specific 33562306a36Sopenharmony_cicase. For example, some users would want the mechanism to weigh the recency 33662306a36Sopenharmony_ci(``age``) more than the access frequency (``nr_accesses``). DAMOS allows users 33762306a36Sopenharmony_cito specify the weight of each access pattern property and passes the 33862306a36Sopenharmony_ciinformation to the underlying mechanism. Nevertheless, how and even whether 33962306a36Sopenharmony_cithe weight will be respected are up to the underlying prioritization mechanism 34062306a36Sopenharmony_ciimplementation. 34162306a36Sopenharmony_ci 34262306a36Sopenharmony_ci 34362306a36Sopenharmony_ci.. _damon_design_damos_watermarks: 34462306a36Sopenharmony_ci 34562306a36Sopenharmony_ciWatermarks 34662306a36Sopenharmony_ci~~~~~~~~~~ 34762306a36Sopenharmony_ci 34862306a36Sopenharmony_ciConditional DAMOS (de)activation automation. Users might want DAMOS to run 34962306a36Sopenharmony_cionly under certain situations. For example, when a sufficient amount of free 35062306a36Sopenharmony_cimemory is guaranteed, running a scheme for proactive reclamation would only 35162306a36Sopenharmony_ciconsume unnecessary system resources. To avoid such consumption, the user would 35262306a36Sopenharmony_cineed to manually monitor some metrics such as free memory ratio, and turn 35362306a36Sopenharmony_ciDAMON/DAMOS on or off. 35462306a36Sopenharmony_ci 35562306a36Sopenharmony_ciDAMOS allows users to offload such works using three watermarks. It allows the 35662306a36Sopenharmony_ciusers to configure the metric of their interest, and three watermark values, 35762306a36Sopenharmony_cinamely high, middle, and low. If the value of the metric becomes above the 35862306a36Sopenharmony_cihigh watermark or below the low watermark, the scheme is deactivated. If the 35962306a36Sopenharmony_cimetric becomes below the mid watermark but above the low watermark, the scheme 36062306a36Sopenharmony_ciis activated. If all schemes are deactivated by the watermarks, the monitoring 36162306a36Sopenharmony_ciis also deactivated. In this case, the DAMON worker thread only periodically 36262306a36Sopenharmony_cichecks the watermarks and therefore incurs nearly zero overhead. 36362306a36Sopenharmony_ci 36462306a36Sopenharmony_ci 36562306a36Sopenharmony_ci.. _damon_design_damos_filters: 36662306a36Sopenharmony_ci 36762306a36Sopenharmony_ciFilters 36862306a36Sopenharmony_ci~~~~~~~ 36962306a36Sopenharmony_ci 37062306a36Sopenharmony_ciNon-access pattern-based target memory regions filtering. If users run 37162306a36Sopenharmony_ciself-written programs or have good profiling tools, they could know something 37262306a36Sopenharmony_cimore than the kernel, such as future access patterns or some special 37362306a36Sopenharmony_cirequirements for specific types of memory. For example, some users may know 37462306a36Sopenharmony_cionly anonymous pages can impact their program's performance. They can also 37562306a36Sopenharmony_cihave a list of latency-critical processes. 37662306a36Sopenharmony_ci 37762306a36Sopenharmony_ciTo let users optimize DAMOS schemes with such special knowledge, DAMOS provides 37862306a36Sopenharmony_cia feature called DAMOS filters. The feature allows users to set an arbitrary 37962306a36Sopenharmony_cinumber of filters for each scheme. Each filter specifies the type of target 38062306a36Sopenharmony_cimemory, and whether it should exclude the memory of the type (filter-out), or 38162306a36Sopenharmony_ciall except the memory of the type (filter-in). 38262306a36Sopenharmony_ci 38362306a36Sopenharmony_ciCurrently, anonymous page, memory cgroup, address range, and DAMON monitoring 38462306a36Sopenharmony_citarget type filters are supported by the feature. Some filter target types 38562306a36Sopenharmony_cirequire additional arguments. The memory cgroup filter type asks users to 38662306a36Sopenharmony_cispecify the file path of the memory cgroup for the filter. The address range 38762306a36Sopenharmony_citype asks the start and end addresses of the range. The DAMON monitoring 38862306a36Sopenharmony_citarget type asks the index of the target from the context's monitoring targets 38962306a36Sopenharmony_cilist. Hence, users can apply specific schemes to only anonymous pages, 39062306a36Sopenharmony_cinon-anonymous pages, pages of specific cgroups, all pages excluding those of 39162306a36Sopenharmony_cispecific cgroups, pages in specific address range, pages in specific DAMON 39262306a36Sopenharmony_cimonitoring targets, and any combination of those. 39362306a36Sopenharmony_ci 39462306a36Sopenharmony_ciTo handle filters efficiently, the address range and DAMON monitoring target 39562306a36Sopenharmony_citype filters are handled by the core layer, while others are handled by 39662306a36Sopenharmony_cioperations set. If a memory region is filtered by a core layer-handled filter, 39762306a36Sopenharmony_ciit is not counted as the scheme has tried to the region. In contrast, if a 39862306a36Sopenharmony_cimemory regions is filtered by an operations set layer-handled filter, it is 39962306a36Sopenharmony_cicounted as the scheme has tried. The difference in accounting leads to changes 40062306a36Sopenharmony_ciin the statistics. 40162306a36Sopenharmony_ci 40262306a36Sopenharmony_ci 40362306a36Sopenharmony_ciApplication Programming Interface 40462306a36Sopenharmony_ci--------------------------------- 40562306a36Sopenharmony_ci 40662306a36Sopenharmony_ciThe programming interface for kernel space data access-aware applications. 40762306a36Sopenharmony_ciDAMON is a framework, so it does nothing by itself. Instead, it only helps 40862306a36Sopenharmony_ciother kernel components such as subsystems and modules building their data 40962306a36Sopenharmony_ciaccess-aware applications using DAMON's core features. For this, DAMON exposes 41062306a36Sopenharmony_ciits all features to other kernel components via its application programming 41162306a36Sopenharmony_ciinterface, namely ``include/linux/damon.h``. Please refer to the API 41262306a36Sopenharmony_ci:doc:`document </mm/damon/api>` for details of the interface. 41362306a36Sopenharmony_ci 41462306a36Sopenharmony_ci 41562306a36Sopenharmony_ciModules 41662306a36Sopenharmony_ci======= 41762306a36Sopenharmony_ci 41862306a36Sopenharmony_ciBecause the core of DAMON is a framework for kernel components, it doesn't 41962306a36Sopenharmony_ciprovide any direct interface for the user space. Such interfaces should be 42062306a36Sopenharmony_ciimplemented by each DAMON API user kernel components, instead. DAMON subsystem 42162306a36Sopenharmony_ciitself implements such DAMON API user modules, which are supposed to be used 42262306a36Sopenharmony_cifor general purpose DAMON control and special purpose data access-aware system 42362306a36Sopenharmony_cioperations, and provides stable application binary interfaces (ABI) for the 42462306a36Sopenharmony_ciuser space. The user space can build their efficient data access-aware 42562306a36Sopenharmony_ciapplications using the interfaces. 42662306a36Sopenharmony_ci 42762306a36Sopenharmony_ci 42862306a36Sopenharmony_ciGeneral Purpose User Interface Modules 42962306a36Sopenharmony_ci-------------------------------------- 43062306a36Sopenharmony_ci 43162306a36Sopenharmony_ciDAMON modules that provide user space ABIs for general purpose DAMON usage in 43262306a36Sopenharmony_ciruntime. 43362306a36Sopenharmony_ci 43462306a36Sopenharmony_ciDAMON user interface modules, namely 'DAMON sysfs interface' and 'DAMON debugfs 43562306a36Sopenharmony_ciinterface' are DAMON API user kernel modules that provide ABIs to the 43662306a36Sopenharmony_ciuser-space. Please note that DAMON debugfs interface is currently deprecated. 43762306a36Sopenharmony_ci 43862306a36Sopenharmony_ciLike many other ABIs, the modules create files on sysfs and debugfs, allow 43962306a36Sopenharmony_ciusers to specify their requests to and get the answers from DAMON by writing to 44062306a36Sopenharmony_ciand reading from the files. As a response to such I/O, DAMON user interface 44162306a36Sopenharmony_cimodules control DAMON and retrieve the results as user requested via the DAMON 44262306a36Sopenharmony_ciAPI, and return the results to the user-space. 44362306a36Sopenharmony_ci 44462306a36Sopenharmony_ciThe ABIs are designed to be used for user space applications development, 44562306a36Sopenharmony_cirather than human beings' fingers. Human users are recommended to use such 44662306a36Sopenharmony_ciuser space tools. One such Python-written user space tool is available at 44762306a36Sopenharmony_ciGithub (https://github.com/awslabs/damo), Pypi 44862306a36Sopenharmony_ci(https://pypistats.org/packages/damo), and Fedora 44962306a36Sopenharmony_ci(https://packages.fedoraproject.org/pkgs/python-damo/damo/). 45062306a36Sopenharmony_ci 45162306a36Sopenharmony_ciPlease refer to the ABI :doc:`document </admin-guide/mm/damon/usage>` for 45262306a36Sopenharmony_cidetails of the interfaces. 45362306a36Sopenharmony_ci 45462306a36Sopenharmony_ci 45562306a36Sopenharmony_ciSpecial-Purpose Access-aware Kernel Modules 45662306a36Sopenharmony_ci------------------------------------------- 45762306a36Sopenharmony_ci 45862306a36Sopenharmony_ciDAMON modules that provide user space ABI for specific purpose DAMON usage. 45962306a36Sopenharmony_ci 46062306a36Sopenharmony_ciDAMON sysfs/debugfs user interfaces are for full control of all DAMON features 46162306a36Sopenharmony_ciin runtime. For each special-purpose system-wide data access-aware system 46262306a36Sopenharmony_cioperations such as proactive reclamation or LRU lists balancing, the interfaces 46362306a36Sopenharmony_cicould be simplified by removing unnecessary knobs for the specific purpose, and 46462306a36Sopenharmony_ciextended for boot-time and even compile time control. Default values of DAMON 46562306a36Sopenharmony_cicontrol parameters for the usage would also need to be optimized for the 46662306a36Sopenharmony_cipurpose. 46762306a36Sopenharmony_ci 46862306a36Sopenharmony_ciTo support such cases, yet more DAMON API user kernel modules that provide more 46962306a36Sopenharmony_cisimple and optimized user space interfaces are available. Currently, two 47062306a36Sopenharmony_cimodules for proactive reclamation and LRU lists manipulation are provided. For 47162306a36Sopenharmony_cimore detail, please read the usage documents for those 47262306a36Sopenharmony_ci(:doc:`/admin-guide/mm/damon/reclaim` and 47362306a36Sopenharmony_ci:doc:`/admin-guide/mm/damon/lru_sort`). 474