Changes from RFC
(https://lore.kernel.org/damon/[email protected]/):
- Split out cleanup/refactoring parts[1]
[1] https://lore.kernel.org/damon/[email protected]/
-----------------------------------------------------------------------
DAMON users can retrieve the monitoring results via 'after_aggregation'
callbacks if the user is using the kernel API, or 'damon_aggregated'
tracepoint if the user is in the user space. Those are useful if full
monitoring results are necessary. However, if the user has interest in
only a snapshot of the results for some regions having specific access
pattern, the interfaces could be inefficient. For example, some users
only want to know which memory regions are not accessed for more than a
specific time at the moment.
Also, some DAMOS users would want to know exactly to what memory regions
the schemes' actions tried to be applied, for a debugging or a tuning.
As DAMOS has its internal mechanism for quota and regions
prioritization, the users would need to simulate DAMOS' mechanism
against the monitoring results. That's unnecessarily complex.
This patchset implements DAMON kernel API callbacks and sysfs directory
for efficient exposure of the information for the use cases. The new
callback will be called for each region when a DAMOS action is gonna
tried to be applied to it. The sysfs directory will be called
'tried_regions' and placed under each scheme sysfs directory. Users can
write a special keyworkd, 'update_schemes_regions', to the 'state' file
of a kdamond sysfs directory. Then, DAMON sysfs interface will fill the
directory with the information of regions that corresponding scheme
action was tried to be applied for next one aggregation interval.
Patches Sequence
----------------
The first one (patch 1) implements the callback for the kernel space
users. Following two patches (patches 2 and 3) implements sysfs
directories for the information and its sub directories. Two patches
(patches 4 and 5) for implementing the special keywords for filling the
data to and cleaning up the directories follow. Patch 6 adds a selftest
for the new sysfs directory. Finally, two patches (patches 7 and 8)
document the new feature in the administrator guide and the ABI
document.
Assembled Tree
--------------
This patchset is based on the latest mm-unstable tree[1]. Assembled
tree is also available at the damon/next tree[2].
[1] https://git.kernel.org/akpm/mm/h/mm-unstable
[2] https://git.kernel.org/sj/h/damon/next
SeongJae Park (8):
mm/damon/core: add a callback for scheme target regions check
mm/damon/sysfs-schemes: implement schemes/tried_regions directory
mm/damon/sysfs-schemes: implement scheme region directory
mm/damon/sysfs: implement DAMOS tried regions update command
mm/damon/sysfs-schemes: implement DAMOS-tried regions clear command
tools/selftets/damon/sysfs: test tried_regions directory existence
Docs/admin-guide/mm/damon/usage: document schemes/<s>/tried_regions
sysfs directory
Docs/ABI/damon: document 'schemes/<s>/tried_regions' sysfs directory
.../ABI/testing/sysfs-kernel-mm-damon | 32 +++
Documentation/admin-guide/mm/damon/usage.rst | 45 ++-
include/linux/damon.h | 5 +
mm/damon/core.c | 6 +-
mm/damon/sysfs-common.h | 10 +
mm/damon/sysfs-schemes.c | 261 ++++++++++++++++++
mm/damon/sysfs.c | 77 +++++-
tools/testing/selftests/damon/sysfs.sh | 7 +
8 files changed, 437 insertions(+), 6 deletions(-)
--
2.25.1
For efficient and simple query-like DAMON monitoring results readings
and deep level investigations of DAMOS, DAMON kernel API
(include/linux/damon.h) users can use 'before_damos_apply' DAMON
callback. However, DAMON sysfs interface users don't have such option.
Add a directory, namely 'tried_regions', under each scheme directory to
use it as the interface for the purpose. Note that this commit is
implementing only the directory but the data filling.
After the data filling change is made, users will be able to signal
DAMON to fill the directory with the regions that corresponding scheme
has tried to be applied. By setting the access pattern of the scheme,
users could do the efficient query-like monitoring.
Signed-off-by: SeongJae Park <[email protected]>
---
mm/damon/sysfs-schemes.c | 57 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 57 insertions(+)
diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c
index 7ea4bcce90cb..f9714ac62565 100644
--- a/mm/damon/sysfs-schemes.c
+++ b/mm/damon/sysfs-schemes.c
@@ -9,6 +9,36 @@
#include "sysfs-common.h"
+/*
+ * scheme regions directory
+ */
+
+struct damon_sysfs_scheme_regions {
+ struct kobject kobj;
+};
+
+static struct damon_sysfs_scheme_regions *
+damon_sysfs_scheme_regions_alloc(void)
+{
+ return kzalloc(sizeof(struct damon_sysfs_scheme_regions), GFP_KERNEL);
+}
+
+static void damon_sysfs_scheme_regions_release(struct kobject *kobj)
+{
+ kfree(container_of(kobj, struct damon_sysfs_scheme_regions, kobj));
+}
+
+static struct attribute *damon_sysfs_scheme_regions_attrs[] = {
+ NULL,
+};
+ATTRIBUTE_GROUPS(damon_sysfs_scheme_regions);
+
+static struct kobj_type damon_sysfs_scheme_regions_ktype = {
+ .release = damon_sysfs_scheme_regions_release,
+ .sysfs_ops = &kobj_sysfs_ops,
+ .default_groups = damon_sysfs_scheme_regions_groups,
+};
+
/*
* schemes/stats directory
*/
@@ -635,6 +665,7 @@ struct damon_sysfs_scheme {
struct damon_sysfs_quotas *quotas;
struct damon_sysfs_watermarks *watermarks;
struct damon_sysfs_stats *stats;
+ struct damon_sysfs_scheme_regions *tried_regions;
};
/* This should match with enum damos_action */
@@ -743,6 +774,25 @@ static int damon_sysfs_scheme_set_stats(struct damon_sysfs_scheme *scheme)
return err;
}
+static int damon_sysfs_scheme_set_tried_regions(
+ struct damon_sysfs_scheme *scheme)
+{
+ struct damon_sysfs_scheme_regions *tried_regions =
+ damon_sysfs_scheme_regions_alloc();
+ int err;
+
+ if (!tried_regions)
+ return -ENOMEM;
+ err = kobject_init_and_add(&tried_regions->kobj,
+ &damon_sysfs_scheme_regions_ktype, &scheme->kobj,
+ "tried_regions");
+ if (err)
+ kobject_put(&tried_regions->kobj);
+ else
+ scheme->tried_regions = tried_regions;
+ return err;
+}
+
static int damon_sysfs_scheme_add_dirs(struct damon_sysfs_scheme *scheme)
{
int err;
@@ -759,8 +809,14 @@ static int damon_sysfs_scheme_add_dirs(struct damon_sysfs_scheme *scheme)
err = damon_sysfs_scheme_set_stats(scheme);
if (err)
goto put_watermarks_quotas_access_pattern_out;
+ err = damon_sysfs_scheme_set_tried_regions(scheme);
+ if (err)
+ goto put_tried_regions_out;
return 0;
+put_tried_regions_out:
+ kobject_put(&scheme->tried_regions->kobj);
+ scheme->tried_regions = NULL;
put_watermarks_quotas_access_pattern_out:
kobject_put(&scheme->watermarks->kobj);
scheme->watermarks = NULL;
@@ -781,6 +837,7 @@ static void damon_sysfs_scheme_rm_dirs(struct damon_sysfs_scheme *scheme)
kobject_put(&scheme->quotas->kobj);
kobject_put(&scheme->watermarks->kobj);
kobject_put(&scheme->stats->kobj);
+ kobject_put(&scheme->tried_regions->kobj);
}
static ssize_t action_show(struct kobject *kobj, struct kobj_attribute *attr,
--
2.25.1