-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
samples/damon: introduce a skeleton of a smaple DAMON module for proa…
…ctive reclamation DAMON is not only for monitoring of access patterns, but also for access-aware system operations. For the system operations, DAMON provides a feature called DAMOS (Data Access Monitoring-based Operation Schemes). There is no sample API usage of DAMOS, though. Copy the working set size estimation sample modules with changed names of the module and symbols, to use it as a skeleton for a sample module showing the DAMOS API usage. The following commit will make it proactively reclaim cold memory of the given process, using DAMOS. Link: https://lkml.kernel.org/r/20241210215030.85675-5-sj@kernel.org Signed-off-by: SeongJae Park <sj@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
- Loading branch information
SeongJae Park
authored and
Andrew Morton
committed
Jan 14, 2025
1 parent
65cc56d
commit 2aca254
Showing
4 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# SPDX-License-Identifier: GPL-2.0 | ||
|
||
obj-$(CONFIG_SAMPLE_DAMON_WSSE) += wsse.o | ||
obj-$(CONFIG_SAMPLE_DAMON_PRCL) += prcl.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
/* | ||
* proactive reclamation: monitor access pattern of a given process, find | ||
* regiosn that seems not accessed, and proactively page out the regions. | ||
*/ | ||
|
||
#define pr_fmt(fmt) "damon_sample_prcl: " fmt | ||
|
||
#include <linux/damon.h> | ||
#include <linux/init.h> | ||
#include <linux/kernel.h> | ||
#include <linux/module.h> | ||
|
||
static int target_pid __read_mostly; | ||
module_param(target_pid, int, 0600); | ||
|
||
static int damon_sample_prcl_enable_store( | ||
const char *val, const struct kernel_param *kp); | ||
|
||
static const struct kernel_param_ops enable_param_ops = { | ||
.set = damon_sample_prcl_enable_store, | ||
.get = param_get_bool, | ||
}; | ||
|
||
static bool enable __read_mostly; | ||
module_param_cb(enable, &enable_param_ops, &enable, 0600); | ||
MODULE_PARM_DESC(enable, "Enable of disable DAMON_SAMPLE_WSSE"); | ||
|
||
static struct damon_ctx *ctx; | ||
static struct pid *target_pidp; | ||
|
||
static int damon_sample_prcl_after_aggregate(struct damon_ctx *c) | ||
{ | ||
struct damon_target *t; | ||
|
||
damon_for_each_target(t, c) { | ||
struct damon_region *r; | ||
unsigned long wss = 0; | ||
|
||
damon_for_each_region(r, t) { | ||
if (r->nr_accesses > 0) | ||
wss += r->ar.end - r->ar.start; | ||
} | ||
pr_info("wss: %lu\n", wss); | ||
} | ||
return 0; | ||
} | ||
|
||
static int damon_sample_prcl_start(void) | ||
{ | ||
struct damon_target *target; | ||
|
||
pr_info("start\n"); | ||
|
||
ctx = damon_new_ctx(); | ||
if (!ctx) | ||
return -ENOMEM; | ||
if (damon_select_ops(ctx, DAMON_OPS_VADDR)) { | ||
damon_destroy_ctx(ctx); | ||
return -EINVAL; | ||
} | ||
|
||
target = damon_new_target(); | ||
if (!target) { | ||
damon_destroy_ctx(ctx); | ||
return -ENOMEM; | ||
} | ||
damon_add_target(ctx, target); | ||
target_pidp = find_get_pid(target_pid); | ||
if (!target_pidp) { | ||
damon_destroy_ctx(ctx); | ||
return -EINVAL; | ||
} | ||
target->pid = target_pidp; | ||
|
||
ctx->callback.after_aggregation = damon_sample_prcl_after_aggregate; | ||
|
||
return damon_start(&ctx, 1, true); | ||
} | ||
|
||
static void damon_sample_prcl_stop(void) | ||
{ | ||
pr_info("stop\n"); | ||
if (ctx) { | ||
damon_stop(&ctx, 1); | ||
damon_destroy_ctx(ctx); | ||
} | ||
if (target_pidp) | ||
put_pid(target_pidp); | ||
} | ||
|
||
static int damon_sample_prcl_enable_store( | ||
const char *val, const struct kernel_param *kp) | ||
{ | ||
bool enabled = enable; | ||
int err; | ||
|
||
err = kstrtobool(val, &enable); | ||
if (err) | ||
return err; | ||
|
||
if (enable == enabled) | ||
return 0; | ||
|
||
if (enable) | ||
return damon_sample_prcl_start(); | ||
damon_sample_prcl_stop(); | ||
return 0; | ||
} | ||
|
||
static int __init damon_sample_prcl_init(void) | ||
{ | ||
return 0; | ||
} | ||
|
||
module_init(damon_sample_prcl_init); |