From: Alex Rusuf <yorha.op@gmail.com>
To: damon@lists.linux.dev
Cc: sj@kernel.org
Subject: [RFC PATCH v1 3/7] mm/damon/lru_sort: kdamond_struct abstraction layer
Date: Wed, 15 May 2024 18:24:53 +0300 [thread overview]
Message-ID: <20240515152457.603724-4-yorha.op@gmail.com> (raw)
In-Reply-To: <20240515152457.603724-1-yorha.op@gmail.com>
This patch implements support for DAMON_LRU_SORT
module to use kdamond_struct level of abstraction
brought in by previous patches.
Signed-off-by: Alex Rusuf <yorha.op@gmail.com>
---
mm/damon/lru_sort.c | 31 +++++++++++++++++++++++--------
mm/damon/modules-common.c | 36 +++++++++++++++++++++++++++---------
mm/damon/modules-common.h | 3 +--
3 files changed, 51 insertions(+), 19 deletions(-)
diff --git a/mm/damon/lru_sort.c b/mm/damon/lru_sort.c
index 3de2916a6..1247a94fc 100644
--- a/mm/damon/lru_sort.c
+++ b/mm/damon/lru_sort.c
@@ -142,8 +142,18 @@ static struct damos_access_pattern damon_lru_sort_stub_pattern = {
.max_age_region = UINT_MAX,
};
-static struct damon_ctx *ctx;
-static struct damon_target *target;
+static struct kdamond_struct *kdamond;
+
+static inline struct damon_ctx *damon_lru_sort_ctx(void)
+{
+ return damon_first_ctx(kdamond);
+}
+
+static inline struct damon_target *damon_lru_sort_target(void)
+{
+ return damon_first_target(
+ damon_lru_sort_ctx());
+}
static struct damos *damon_lru_sort_new_scheme(
struct damos_access_pattern *pattern, enum damos_action action)
@@ -201,6 +211,7 @@ static int damon_lru_sort_apply_parameters(void)
struct damos *scheme, *hot_scheme, *cold_scheme;
struct damos *old_hot_scheme = NULL, *old_cold_scheme = NULL;
unsigned int hot_thres, cold_thres;
+ struct damon_ctx *ctx = damon_lru_sort_ctx();
int err = 0;
err = damon_set_attrs(ctx, &damon_lru_sort_mon_attrs);
@@ -237,7 +248,8 @@ static int damon_lru_sort_apply_parameters(void)
damon_set_schemes(ctx, &hot_scheme, 1);
damon_add_scheme(ctx, cold_scheme);
- return damon_set_region_biggest_system_ram_default(target,
+ return damon_set_region_biggest_system_ram_default(
+ damon_lru_sort_target(),
&monitor_region_start,
&monitor_region_end);
}
@@ -247,7 +259,7 @@ static int damon_lru_sort_turn(bool on)
int err;
if (!on) {
- err = damon_stop(&ctx, 1);
+ err = damon_stop(kdamond);
if (!err)
kdamond_pid = -1;
return err;
@@ -257,10 +269,11 @@ static int damon_lru_sort_turn(bool on)
if (err)
return err;
- err = damon_start(&ctx, 1, true);
+ err = damon_start(kdamond, true);
if (err)
return err;
- kdamond_pid = ctx->kdamond->pid;
+
+ kdamond_pid = kdamond->self->pid;
return 0;
}
@@ -279,7 +292,7 @@ static int damon_lru_sort_enabled_store(const char *val,
return 0;
/* Called before init function. The function will handle this. */
- if (!ctx)
+ if (!kdamond)
goto set_param_out;
err = damon_lru_sort_turn(enable);
@@ -334,11 +347,13 @@ static int damon_lru_sort_after_wmarks_check(struct damon_ctx *c)
static int __init damon_lru_sort_init(void)
{
- int err = damon_modules_new_paddr_ctx_target(&ctx, &target);
+ struct damon_ctx *ctx;
+ int err = damon_modules_new_paddr_kdamond(&kdamond);
if (err)
return err;
+ ctx = damon_lru_sort_ctx();
ctx->callback.after_wmarks_check = damon_lru_sort_after_wmarks_check;
ctx->callback.after_aggregation = damon_lru_sort_after_aggregation;
diff --git a/mm/damon/modules-common.c b/mm/damon/modules-common.c
index 7cf96574c..a70b4fc7a 100644
--- a/mm/damon/modules-common.c
+++ b/mm/damon/modules-common.c
@@ -9,13 +9,7 @@
#include "modules-common.h"
-/*
- * Allocate, set, and return a DAMON context for the physical address space.
- * @ctxp: Pointer to save the point to the newly created context
- * @targetp: Pointer to save the point to the newly created target
- */
-int damon_modules_new_paddr_ctx_target(struct damon_ctx **ctxp,
- struct damon_target **targetp)
+static int __damon_modules_new_paddr_kdamond(struct kdamond_struct *kdamond)
{
struct damon_ctx *ctx;
struct damon_target *target;
@@ -34,9 +28,33 @@ int damon_modules_new_paddr_ctx_target(struct damon_ctx **ctxp,
damon_destroy_ctx(ctx);
return -ENOMEM;
}
+
damon_add_target(ctx, target);
+ damon_add_ctx(kdamond, ctx);
+
+ return 0;
+}
+
+/*
+ * Allocate, set, and return a DAMON daemon for the physical address space.
+ * @kdamondp: Pointer to save the point to the newly created kdamond
+ */
+int damon_modules_new_paddr_kdamond(struct kdamond_struct **kdamondp)
+{
+ int err;
+ struct kdamond_struct *kdamond;
+
+ kdamond = damon_new_kdamond();
+ if (!kdamond)
+ return -ENOMEM;
+
+ err = __damon_modules_new_paddr_kdamond(kdamond);
+ if (err) {
+ damon_destroy_kdamond(kdamond);
+ return err;
+ }
+ kdamond->nr_ctxs = 1;
- *ctxp = ctx;
- *targetp = target;
+ *kdamondp = kdamond;
return 0;
}
diff --git a/mm/damon/modules-common.h b/mm/damon/modules-common.h
index f49cdb417..eeb5a06b9 100644
--- a/mm/damon/modules-common.h
+++ b/mm/damon/modules-common.h
@@ -45,5 +45,4 @@
module_param_named(nr_##qt_exceed_name, stat.qt_exceeds, ulong, \
0400);
-int damon_modules_new_paddr_ctx_target(struct damon_ctx **ctxp,
- struct damon_target **targetp);
+int damon_modules_new_paddr_kdamond(struct kdamond_struct **kdamondp);
--
2.42.0
next prev parent reply other threads:[~2024-05-15 15:25 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-15 15:24 [RFC PATCH v1 0/7] DAMON multiple contexts support Alex Rusuf
2024-05-15 15:24 ` [RFC PATCH v1 1/7] mm/damon/core: kdamond_struct abstraction layer Alex Rusuf
2024-05-15 15:24 ` [RFC PATCH v1 2/7] mm/damon/core: list-based contexts organization Alex Rusuf
2024-05-15 15:24 ` Alex Rusuf [this message]
2024-05-15 15:24 ` [RFC PATCH v1 4/7] mm/damon/reclaim: kdamon_struct abstraction layer Alex Rusuf
2024-05-15 15:24 ` [RFC PATCH v1 5/7] mm/damon/core: rename nr_running_ctxs -> nr_running_kdamonds Alex Rusuf
2024-05-15 15:24 ` [RFC PATCH v1 6/7] mm/damon/core: multi-context support Alex Rusuf
2024-05-15 15:24 ` [RFC PATCH v1 7/7] mm/damon/core: multi-context awarness for trace events Alex Rusuf
2024-05-16 22:17 ` [RFC PATCH v1 0/7] DAMON multiple contexts support SeongJae Park
2024-05-17 8:51 ` Alex Rusuf
2024-05-17 22:59 ` SeongJae Park
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240515152457.603724-4-yorha.op@gmail.com \
--to=yorha.op@gmail.com \
--cc=damon@lists.linux.dev \
--cc=sj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).