Linux 5.18's DAMON Adds DAMOS Configuration Interface
The DAMON feature patches for Linux 5.18 were merged on Tuesday by way of Andrew Morton's patch series. Most notable with the DAMON changes for Linux 5.18 is the introduction of a sysfs interface for it and dubbed as "DAMOS" - DAMON-based Operation Schemes.
DAMON's sysfs interface / DAMOS is aimed to improve the ease of configurability around DAMON and superior design to the existing DebugFS interface. This new sysfs interface to DAMON is designed to be easier to use and more easily extensible. DAMOS relies upon the directory hierarchies of sysfs and has a dedicated file for each value, per sysfs requirements. Here's how the patch series summed up the DAMOS work:
At the moment, DAMON_DBGFS and DAMON_SYSFS provides same features. One important difference between them is their exclusiveness. DAMON_DBGFS works in an exclusive manner, so that no DAMON worker thread (kdamond) in the system can run concurrently and interfere somehow. For the reason, DAMON_DBGFS asks users to construct all monitoring contexts and start them at once. It's not a big problem but makes the operation a little bit complex and unflexible.
For more flexible usage, DAMON_SYSFS moves the responsibility of preventing any possible interference to the admins and work in a non-exclusive manner. That is, users can configure and start contexts one by one. Note that DAMON respects both exclusive groups and non-exclusive groups of contexts, in a manner similar to that of reader-writer locks. That is, if any exclusive monitoring contexts (e.g., contexts that started via DAMON_DBGFS) are running, DAMON_SYSFS does not start new contexts, and vice versa.
DAMON's DebugFS interface is to be eventually deprecated and focused just on the sysfs interface. Here's an example of virtual address monitoring for a process using the new DAMOS interface:
# cd /sys/kernel/mm/damon/admin/
# echo 1 > kdamonds/nr_kdamonds
# echo 1 > kdamonds/0/contexts/nr_contexts
# echo vaddr > kdamonds/0/contexts/0/operations
# echo 1 > kdamonds/0/contexts/0/targets/nr_targets
# echo $(pidof
) > kdamonds/0/contexts/0/targets/0/pid_target
# echo on > kdamonds/0/state
This documentation patch for Linux 5.18 provides more detailed explanation of the DAMON sysfs configuration interface.
All this work is now in Linux 5.18 Git thanks to the latest akpm patches.