Re: [PATCH v23 10/15] mm/damon/dbgfs: Support multiple contexts

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 15 Dec 2020 12:54:43 +0100 SeongJae Park <sjpark@xxxxxxxxxx> wrote:

> From: SeongJae Park <sjpark@xxxxxxxxx>
> 
> In some use cases, users would want to run multiple monitoring context.
> For example, if a user wants a high precision monitoring and dedicating
> multiple CPUs for the job is ok, because DAMON creates one monitoring
> thread per one context, the user can split the monitoring target regions
> into multiple small regions and create one context for each region.  Or,
> someone might want to simultaneously monitor different address spaces,
> e.g., both virtual address space and physical address space.
> 
> The DAMON's API allows such usage, but 'damon-dbgfs' does not.
> Therefore, only kernel space DAMON users can do multiple contexts
> monitoring.
> 
> This commit allows the user space DAMON users to use multiple contexts
> monitoring by introducing two new 'damon-dbgfs' debugfs files,
> 'mk_context' and 'rm_context'.  Users can create a new monitoring
> context by writing the desired name of the new context to 'mk_context'.
> Then, a new directory with the name and having the files for setting of
> the context ('attrs', 'target_ids' and 'record') will be created under
> the debugfs directory.  Writing the name of the context to remove to
> 'rm_context' will remove the related context and directory.
> 
> Signed-off-by: SeongJae Park <sjpark@xxxxxxxxx>
> ---
>  mm/damon/dbgfs.c | 213 ++++++++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 211 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/damon/dbgfs.c b/mm/damon/dbgfs.c
> index a1512d3e5afe..46186b057e1a 100644
> --- a/mm/damon/dbgfs.c
> +++ b/mm/damon/dbgfs.c
[...]
> +/*
> + * Remove a context of @name and its debugfs directory.
> + *
> + * This function should be called while holding damon_dbgfs_lock.
> + *
> + * Return 0 on success, negative error code otherwise.
> + */
> +static int dbgfs_rm_context(char *name)
> +{
> +	struct dentry *root, *dir, **new_dirs;
> +	struct damon_ctx **new_ctxs;
> +	int i, j;
> +
> +	if (damon_nr_running_ctxs())
> +		return -EBUSY;
> +
> +	root = dbgfs_dirs[0];
> +	if (!root)
> +		return -ENOENT;
> +
> +	dir = debugfs_lookup(name, root);
> +	if (!dir)
> +		return -ENOENT;
> +
> +	new_dirs = kmalloc_array(dbgfs_nr_ctxs - 1, sizeof(*dbgfs_dirs),
> +			GFP_KERNEL);
> +	if (!new_dirs)
> +		return -ENOMEM;
> +
> +	new_ctxs = kmalloc_array(dbgfs_nr_ctxs - 1, sizeof(*dbgfs_ctxs),
> +			GFP_KERNEL);
> +	if (!new_ctxs) {
> +		kfree(new_dirs);
> +		return -ENOMEM;
> +	}
> +
> +	for (i = 0, j = 0; i < dbgfs_nr_ctxs; i++) {
> +		if (dbgfs_dirs[i] == dir) {
> +			debugfs_remove(dbgfs_dirs[i]);
> +			dbgfs_destroy_ctx(dbgfs_ctxs[i]);

In case of virtual address monitoring, dbgfs_destroy_ctx() calls
damon_destroy_ctx() and damon_destroy_ctx() doesn't put the target pids.  I
will fix this in the next version.

> +			continue;
> +		}
> +		new_dirs[j] = dbgfs_dirs[i];
> +		new_ctxs[j++] = dbgfs_ctxs[i];
> +	}
> +
> +	kfree(dbgfs_dirs);
> +	kfree(dbgfs_ctxs);
> +
> +	dbgfs_dirs = new_dirs;
> +	dbgfs_ctxs = new_ctxs;
> +	dbgfs_nr_ctxs--;
> +
> +	return 0;
> +}

Thanks,
SeongJae Park
[...]




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux