Skip to content

Commit

Permalink
mm/damon/sysfs: avoid empty scheme tried regions for large apply inte…
Browse files Browse the repository at this point in the history
…rval

DAMON_SYSFS assumes all schemes will be applied for at least one DAMON
monitoring results snapshot within one aggregation interval, or makes no
sense to wait for it while DAMON is deactivated by the watermarks.  That
for deactivated status still makes sense, but the aggregation interval
based assumption is invalid now because each scheme can has its own apply
interval.  For schemes having larger than the aggregation or watermarks
check interval, DAMOS tried regions update request can be finished without
the update.  Avoid the case by explicitly checking the status of the
schemes tried regions update and watermarks based DAMON deactivation.

Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: SeongJae Park <[email protected]>
Cc: Jonathan Corbet <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
  • Loading branch information
sjp38 authored and akpm00 committed Oct 18, 2023
1 parent 4d4e41b commit 7612633
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
2 changes: 2 additions & 0 deletions mm/damon/sysfs-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ int damon_sysfs_schemes_update_regions_start(
struct damon_sysfs_schemes *sysfs_schemes,
struct damon_ctx *ctx, bool total_bytes_only);

bool damos_sysfs_regions_upd_done(void);

int damon_sysfs_schemes_update_regions_stop(struct damon_ctx *ctx);

int damon_sysfs_schemes_clear_regions(
Expand Down
16 changes: 16 additions & 0 deletions mm/damon/sysfs-schemes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1904,6 +1904,22 @@ int damon_sysfs_schemes_update_regions_start(
return 0;
}

bool damos_sysfs_regions_upd_done(void)
{
struct damon_sysfs_schemes *sysfs_schemes =
damon_sysfs_schemes_for_damos_callback;
struct damon_sysfs_scheme_regions *sysfs_regions;
int i;

for (i = 0; i < sysfs_schemes->nr; i++) {
sysfs_regions = sysfs_schemes->schemes_arr[i]->tried_regions;
if (sysfs_regions->upd_status !=
DAMOS_TRIED_REGIONS_UPD_FINISHED)
return false;
}
return true;
}

/*
* Called from damon_sysfs_cmd_request_callback under damon_sysfs_lock. Caller
* should unlock damon_sysfs_lock which held before
Expand Down
34 changes: 30 additions & 4 deletions mm/damon/sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1336,12 +1336,13 @@ static int damon_sysfs_commit_input(struct damon_sysfs_kdamond *kdamond)

/*
* damon_sysfs_cmd_request_callback() - DAMON callback for handling requests.
* @c: The DAMON context of the callback.
* @c: The DAMON context of the callback.
* @active: Whether @c is not deactivated due to watermarks.
*
* This function is periodically called back from the kdamond thread for @c.
* Then, it checks if there is a waiting DAMON sysfs request and handles it.
*/
static int damon_sysfs_cmd_request_callback(struct damon_ctx *c)
static int damon_sysfs_cmd_request_callback(struct damon_ctx *c, bool active)
{
struct damon_sysfs_kdamond *kdamond;
bool total_bytes_only = false;
Expand Down Expand Up @@ -1373,6 +1374,13 @@ static int damon_sysfs_cmd_request_callback(struct damon_ctx *c)
goto keep_lock_out;
}
} else {
/*
* Continue regions updating if DAMON is till
* active and the update for all schemes is not
* finished.
*/
if (active && !damos_sysfs_regions_upd_done())
goto keep_lock_out;
err = damon_sysfs_upd_schemes_regions_stop(kdamond);
damon_sysfs_schemes_regions_updating = false;
}
Expand All @@ -1392,6 +1400,24 @@ static int damon_sysfs_cmd_request_callback(struct damon_ctx *c)
return err;
}

static int damon_sysfs_after_wmarks_check(struct damon_ctx *c)
{
/*
* after_wmarks_check() is called back while the context is deactivated
* by watermarks.
*/
return damon_sysfs_cmd_request_callback(c, false);
}

static int damon_sysfs_after_aggregation(struct damon_ctx *c)
{
/*
* after_aggregation() is called back only while the context is not
* deactivated by watermarks.
*/
return damon_sysfs_cmd_request_callback(c, true);
}

static struct damon_ctx *damon_sysfs_build_ctx(
struct damon_sysfs_context *sys_ctx)
{
Expand All @@ -1407,8 +1433,8 @@ static struct damon_ctx *damon_sysfs_build_ctx(
return ERR_PTR(err);
}

ctx->callback.after_wmarks_check = damon_sysfs_cmd_request_callback;
ctx->callback.after_aggregation = damon_sysfs_cmd_request_callback;
ctx->callback.after_wmarks_check = damon_sysfs_after_wmarks_check;
ctx->callback.after_aggregation = damon_sysfs_after_aggregation;
ctx->callback.before_terminate = damon_sysfs_before_terminate;
return ctx;
}
Expand Down

0 comments on commit 7612633

Please sign in to comment.