Re: [RFC PATCH 08/11] mm/damon/sysfs-schemes: implement scheme filters

From: SeongJae Park
Date: Wed Nov 30 2022 - 14:26:44 EST


On Thu, 24 Nov 2022 21:21:11 +0000 SeongJae Park <sj@xxxxxxxxxx> wrote:

> Implement scheme filters functionality of DAMON sysfs interface by
> making the code reads the values of files under the filter directories
> and pass that to DAMON using DAMON kernel API.
>
> Signed-off-by: SeongJae Park <sj@xxxxxxxxxx>
> ---
> mm/damon/sysfs-schemes.c | 85 +++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 84 insertions(+), 1 deletion(-)
>
> diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c
> index 7f2bab617156..6f014b328e6f 100644
> --- a/mm/damon/sysfs-schemes.c
> +++ b/mm/damon/sysfs-schemes.c
[...]
> +static int damon_sysfs_memcg_path_to_id(char *memcg_path, unsigned short *id)
> +{
> + struct mem_cgroup *memcg;
> + char *path;
> +
> + if (!memcg_path)
> + return -EINVAL;
> +
> + path = kmalloc(sizeof(*path) * PATH_MAX, GFP_KERNEL);
> + if (!path)
> + return -ENOMEM;
> +
> + for (memcg = mem_cgroup_iter(NULL, NULL, NULL); memcg;
> + memcg = mem_cgroup_iter(NULL, memcg, NULL)) {
> + if (damon_sysfs_memcg_path_eq(memcg, path, memcg_path)) {
> + *id = mem_cgroup_id(memcg);

Forgot mentioning this. Removed memcgs can still be iterated, so this can
result in getting id of already removed cgroup. If the user input is valid but
there is a removed memcg that has same path, this could be confused.

Removed memcg would have id 0. The next version of this will handle the case.


Thanks,
SJ

> + break;
> + }
> + }
> +
> + kfree(path);
> + return 0;
> +}