lkml.org 
[lkml]   [2021]   [Oct]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 1/7] mm/damon/dbgfs: Allow users to set initial monitoring target regions
On Tue, 12 Oct 2021 20:57:05 +0000 SeongJae Park <sj@kernel.org> wrote:

> Some 'damon-dbgfs' users would want to monitor only a part of the entire
> virtual memory address space. The program interface users in the kernel
> space could use '->before_start()' callback or set the regions inside
> the context struct as they want, but 'damon-dbgfs' users cannot.
>
> For the reason, this commit introduces a new debugfs file called
> 'init_region'. 'damon-dbgfs' users can specify which initial monitoring
> target address regions they want by writing special input to the file.
> The input should describe each region in each line in the below form:
>
> <pid> <start address> <end address>
>
> Note that the regions will be updated to cover entire memory mapped
> regions after a 'regions update interval' is passed. If you want the
> regions to not be updated after the initial setting, you could set the
> interval as a very long time, say, a few decades.
>
> ...
>
> +static int add_init_region(struct damon_ctx *c,
> + unsigned long target_id, struct damon_addr_range *ar)
> +{
> + struct damon_target *t;
> + struct damon_region *r, *prev;
> + unsigned long id;
> + int rc = -EINVAL;
> +
> + if (ar->start >= ar->end)
> + return -EINVAL;
> +
> + damon_for_each_target(t, c) {
> + id = t->id;
> + if (targetid_is_pid(c))
> + id = (unsigned long)pid_vnr((struct pid *)id);

This is a bit ugly. Did you consider making damon_target.id a union of
all the possible types it can contain? This will avoid typecasts, has
documentation value and reflacts what is actually going on.

> + if (id == target_id) {
> + r = damon_new_region(ar->start, ar->end);
> + if (!r)
> + return -ENOMEM;
> + damon_add_region(r, t);
> + if (damon_nr_regions(t) > 1) {
> + prev = damon_prev_region(r);
> + if (prev->ar.end > r->ar.start) {
> + damon_destroy_region(r, t);
> + return -EINVAL;
> + }
> + }
> + rc = 0;
> + }
> + }
> + return rc;
> +}
> +

\
 
 \ /
  Last update: 2021-10-14 00:46    [W:0.088 / U:0.148 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site