Skip to content

Commit

Permalink
mm/damon/{dbgfs,sysfs}: move target_has_pid() from dbgfs to damon.h
Browse files Browse the repository at this point in the history
The function for knowing if given monitoring context's targets will have
pid or not is defined and used in dbgfs only.  However, the logic is also
needed for sysfs.  This commit moves the code to damon.h and makes both
dbgfs and sysfs to use it.

Link: https://lkml.kernel.org/r/20220606182310.48781-3-sj@kernel.org
Signed-off-by: SeongJae Park <sj@kernel.org>
Cc: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
  • Loading branch information
SeongJae Park authored and akpm committed Jul 4, 2022
1 parent 2054980 commit c9e124e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
6 changes: 6 additions & 0 deletions include/linux/damon.h
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,12 @@ bool damon_is_registered_ops(enum damon_ops_id id);
int damon_register_ops(struct damon_operations *ops);
int damon_select_ops(struct damon_ctx *ctx, enum damon_ops_id id);

static inline bool damon_target_has_pid(const struct damon_ctx *ctx)
{
return ctx->ops.id == DAMON_OPS_VADDR || ctx->ops.id == DAMON_OPS_FVADDR;
}


int damon_start(struct damon_ctx **ctxs, int nr_ctxs, bool exclusive);
int damon_stop(struct damon_ctx **ctxs, int nr_ctxs);

Expand Down
15 changes: 5 additions & 10 deletions mm/damon/dbgfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,6 @@ static ssize_t dbgfs_schemes_write(struct file *file, const char __user *buf,
return ret;
}

static inline bool target_has_pid(const struct damon_ctx *ctx)
{
return ctx->ops.id == DAMON_OPS_VADDR;
}

static ssize_t sprint_target_ids(struct damon_ctx *ctx, char *buf, ssize_t len)
{
struct damon_target *t;
Expand All @@ -288,7 +283,7 @@ static ssize_t sprint_target_ids(struct damon_ctx *ctx, char *buf, ssize_t len)
int rc;

damon_for_each_target(t, ctx) {
if (target_has_pid(ctx))
if (damon_target_has_pid(ctx))
/* Show pid numbers to debugfs users */
id = pid_vnr(t->pid);
else
Expand Down Expand Up @@ -415,7 +410,7 @@ static int dbgfs_set_targets(struct damon_ctx *ctx, ssize_t nr_targets,
struct damon_target *t, *next;

damon_for_each_target_safe(t, next, ctx) {
if (target_has_pid(ctx))
if (damon_target_has_pid(ctx))
put_pid(t->pid);
damon_destroy_target(t);
}
Expand All @@ -425,11 +420,11 @@ static int dbgfs_set_targets(struct damon_ctx *ctx, ssize_t nr_targets,
if (!t) {
damon_for_each_target_safe(t, next, ctx)
damon_destroy_target(t);
if (target_has_pid(ctx))
if (damon_target_has_pid(ctx))
dbgfs_put_pids(pids, nr_targets);
return -ENOMEM;
}
if (target_has_pid(ctx))
if (damon_target_has_pid(ctx))
t->pid = pids[i];
damon_add_target(ctx, t);
}
Expand Down Expand Up @@ -722,7 +717,7 @@ static void dbgfs_before_terminate(struct damon_ctx *ctx)
{
struct damon_target *t, *next;

if (!target_has_pid(ctx))
if (!damon_target_has_pid(ctx))
return;

mutex_lock(&ctx->kdamond_lock);
Expand Down
8 changes: 3 additions & 5 deletions mm/damon/sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2136,8 +2136,7 @@ static void damon_sysfs_destroy_targets(struct damon_ctx *ctx)
struct damon_target *t, *next;

damon_for_each_target_safe(t, next, ctx) {
if (ctx->ops.id == DAMON_OPS_VADDR ||
ctx->ops.id == DAMON_OPS_FVADDR)
if (damon_target_has_pid(ctx))
put_pid(t->pid);
damon_destroy_target(t);
}
Expand Down Expand Up @@ -2181,8 +2180,7 @@ static int damon_sysfs_add_target(struct damon_sysfs_target *sys_target,

if (!t)
return -ENOMEM;
if (ctx->ops.id == DAMON_OPS_VADDR ||
ctx->ops.id == DAMON_OPS_FVADDR) {
if (damon_target_has_pid(ctx)) {
t->pid = find_get_pid(sys_target->pid);
if (!t->pid)
goto destroy_targets_out;
Expand Down Expand Up @@ -2210,7 +2208,7 @@ static struct damon_target *damon_sysfs_existing_target(
struct pid *pid;
struct damon_target *t;

if (ctx->ops.id == DAMON_OPS_PADDR) {
if (!damon_target_has_pid(ctx)) {
/* Up to only one target for paddr could exist */
damon_for_each_target(t, ctx)
return t;
Expand Down

0 comments on commit c9e124e

Please sign in to comment.