[PATCH v12 08/16] mm/damon: Implement callbacks

From: SeongJae Park
Date: Mon May 18 2020 - 06:08:18 EST


From: SeongJae Park <sjpark@xxxxxxxxx>

This commit implements callbacks for DAMON. Using this, DAMON users can
install their callbacks for each step of the access monitoring so that
they can do something interesting with the monitored access patterns
online. For example, callbacks can report the monitored patterns to
users or do some access pattern based memory management such as
proactive reclamations or access pattern based THP promotions/demotions
decision makings.

Signed-off-by: SeongJae Park <sjpark@xxxxxxxxx>
---
include/linux/damon.h | 4 ++++
mm/damon.c | 4 ++++
2 files changed, 8 insertions(+)

diff --git a/include/linux/damon.h b/include/linux/damon.h
index 62b9f90ed87b..264569b21502 100644
--- a/include/linux/damon.h
+++ b/include/linux/damon.h
@@ -55,6 +55,10 @@ struct damon_ctx {
struct mutex kdamond_lock;

struct list_head tasks_list; /* 'damon_task' objects */
+
+ /* callbacks */
+ void (*sample_cb)(struct damon_ctx *context);
+ void (*aggregate_cb)(struct damon_ctx *context);
};

int damon_set_pids(struct damon_ctx *ctx, int *pids, ssize_t nr_pids);
diff --git a/mm/damon.c b/mm/damon.c
index 38a8a68b7beb..498160b5e086 100644
--- a/mm/damon.c
+++ b/mm/damon.c
@@ -851,6 +851,8 @@ static int kdamond_fn(void *data)
kdamond_init_regions(ctx);
while (!kdamond_need_stop(ctx)) {
kdamond_prepare_access_checks(ctx);
+ if (ctx->sample_cb)
+ ctx->sample_cb(ctx);

usleep_range(ctx->sample_interval, ctx->sample_interval + 1);

@@ -858,6 +860,8 @@ static int kdamond_fn(void *data)

if (kdamond_aggregate_interval_passed(ctx)) {
kdamond_merge_regions(ctx, max_nr_accesses / 10);
+ if (ctx->aggregate_cb)
+ ctx->aggregate_cb(ctx);
kdamond_reset_aggregated(ctx);
kdamond_split_regions(ctx);
}
--
2.17.1