Re: [PATCH v17 03/15] mm/damon: Implement region based sampling

From: SeongJae Park
Date: Tue Jul 07 2020 - 03:55:43 EST


On Mon, 6 Jul 2020 13:53:10 +0200 SeongJae Park <sjpark@xxxxxxxxxx> wrote:

> From: SeongJae Park <sjpark@xxxxxxxxx>
>
> This commit implements DAMON's target address space independent high
> level logics for basic access check and region based sampling. This
> doesn't work alone, but needs the target address space specific low
> level pritimives implementation for the monitoring target address ranges
> construction and the access check, though. A reference implementation
> of those will be provided by a later commit. Nevertheless, users can
> implement and use their own versions for their specific use cases.
>
[...]
> +/**
> + * damon_start() - Starts monitoring with given context.
> + * @ctx: monitoring context
> + *
> + * Return: 0 on success, negative error code otherwise.
> + */
> +int damon_start(struct damon_ctx *ctx)
> +{
> + int err = -EBUSY;
> +
> + mutex_lock(&ctx->kdamond_lock);
> + if (!ctx->kdamond) {
> + err = 0;
> + ctx->kdamond_stop = false;
> + ctx->kdamond = kthread_run(kdamond_fn, ctx, "kdamond");

Oops, this means 'kdamond_fn' could see the unset '->kdamond'. I will use
'kthread_create()' and 'wake_up_process()' in the next spin.

> + if (IS_ERR(ctx->kdamond))
> + err = PTR_ERR(ctx->kdamond);
> + }
> + mutex_unlock(&ctx->kdamond_lock);
> +
> + return err;
> +}

So, the change would be something like below:

--- a/mm/damon.c
+++ b/mm/damon.c
@@ -1464,9 +1464,11 @@ int damon_start(struct damon_ctx *ctx)
if (!ctx->kdamond) {
err = 0;
ctx->kdamond_stop = false;
- ctx->kdamond = kthread_run(kdamond_fn, ctx, "kdamond");
+ ctx->kdamond = kthread_create(kdamond_fn, ctx, "kdamond");
if (IS_ERR(ctx->kdamond))
err = PTR_ERR(ctx->kdamond);
+ else
+ wake_up_process(ctx->kdamond);
}
mutex_unlock(&ctx->kdamond_lock);


Thanks,
SeongJae Park