[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20200608114047.26589-7-sjpark@amazon.com>
Date: Mon, 8 Jun 2020 13:40:39 +0200
From: SeongJae Park <sjpark@...zon.com>
To: <akpm@...ux-foundation.org>
CC: SeongJae Park <sjpark@...zon.de>, <Jonathan.Cameron@...wei.com>,
<aarcange@...hat.com>, <acme@...nel.org>,
<alexander.shishkin@...ux.intel.com>, <amit@...nel.org>,
<benh@...nel.crashing.org>, <brendan.d.gregg@...il.com>,
<brendanhiggins@...gle.com>, <cai@....pw>,
<colin.king@...onical.com>, <corbet@....net>, <dwmw@...zon.com>,
<foersleo@...zon.de>, <irogers@...gle.com>, <jolsa@...hat.com>,
<kirill@...temov.name>, <mark.rutland@....com>, <mgorman@...e.de>,
<minchan@...nel.org>, <mingo@...hat.com>, <namhyung@...nel.org>,
<peterz@...radead.org>, <rdunlap@...radead.org>,
<riel@...riel.com>, <rientjes@...gle.com>, <rostedt@...dmis.org>,
<sblbir@...zon.com>, <shakeelb@...gle.com>, <shuah@...nel.org>,
<sj38.park@...il.com>, <snu@...zon.de>, <vbabka@...e.cz>,
<vdavydov.dev@...il.com>, <yang.shi@...ux.alibaba.com>,
<ying.huang@...el.com>, <david@...hat.com>,
<linux-damon@...zon.com>, <linux-mm@...ck.org>,
<linux-doc@...r.kernel.org>, <linux-kernel@...r.kernel.org>
Subject: [PATCH v15 06/14] mm/damon: Implement callbacks
From: SeongJae Park <sjpark@...zon.de>
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@...zon.de>
Reviewed-by: Leonard Foerster <foersleo@...zon.de>
---
include/linux/damon.h | 13 +++++++++++++
mm/damon.c | 4 ++++
2 files changed, 17 insertions(+)
diff --git a/include/linux/damon.h b/include/linux/damon.h
index 5afcb2bb7f77..12536d9d2f74 100644
--- a/include/linux/damon.h
+++ b/include/linux/damon.h
@@ -80,6 +80,15 @@ struct damon_task {
* @kdamond_lock. Accesses to other fields must be protected by themselves.
*
* @tasks_list: Head of monitoring target tasks (&damon_task) list.
+ *
+ * @sample_cb: Called for each sampling interval.
+ * @aggregate_cb: Called for each aggregation interval.
+ *
+ * @sample_cb and @aggregate_cb are called from @kdamond for each of the
+ * sampling intervals and aggregation intervals, respectively. Therefore,
+ * users can safely access to the monitoring results via @tasks_list without
+ * additional protection of @kdamond_lock. For the reason, users are
+ * recommended to use these callback for the accesses to the results.
*/
struct damon_ctx {
unsigned long sample_interval;
@@ -96,6 +105,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 778f4d87042d..1978ec4114bf 100644
--- a/mm/damon.c
+++ b/mm/damon.c
@@ -880,6 +880,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);
@@ -887,6 +889,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
Powered by blists - more mailing lists