From: SeongJae Park <sj@kernel.org>
To: Usama Arif <usamaarif642@gmail.com>
Cc: SeongJae Park <sj@kernel.org>,
akpm@linux-foundation.org, damon@lists.linux.dev,
linux-mm@kvack.org, hannes@cmpxchg.org, david@redhat.com,
kernel-team@meta.com
Subject: Re: [PATCH v4 3/6] mm/damon/sysfs-schemes: add files for setting damos_filter->folio_size
Date: Tue, 4 Feb 2025 15:10:40 -0800 [thread overview]
Message-ID: <20250204231040.2655-1-sj@kernel.org> (raw)
In-Reply-To: <20250203225604.44742-4-usamaarif642@gmail.com>
On Mon, 3 Feb 2025 22:55:30 +0000 Usama Arif <usamaarif642@gmail.com> wrote:
> Add min and max files for damon filters to let the userspace decide
> the min/max folio size to operate on. This will be needed to decide
> what folio sizes to give pa_stat for.
I'd prefer implementing the logic with API interface first, and then
implementing sysfs interface on top of the API.
>
> Signed-off-by: Usama Arif <usamaarif642@gmail.com>
> ---
> include/linux/damon.h | 11 +++++++++
> mm/damon/core.c | 3 +++
> mm/damon/sysfs-schemes.c | 53 ++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 67 insertions(+)
>
> diff --git a/include/linux/damon.h b/include/linux/damon.h
> index af525252b853..6f30ceeff215 100644
> --- a/include/linux/damon.h
> +++ b/include/linux/damon.h
> @@ -35,6 +35,16 @@ struct damon_addr_range {
> unsigned long end;
> };
>
> +/**
> + * struct damon_folio_size - Represents size of folio filter on [@min, @max].
> + * @min: Min size of the folio (inclusive).
> + * @max: Max size of the folio (inclusive).
> + */
> +struct damon_folio_size {
> + unsigned long min;
> + unsigned long max;
> +};
> +
I'd suggest giving a more general name, say, damon_size_range, so that we can
reuse this for any possible future size range based filters or whatever.
> /**
> * struct damon_region - Represents a monitoring target region.
> * @ar: The address range of the region.
> @@ -377,6 +387,7 @@ struct damos_filter {
> struct damon_addr_range addr_range;
> int target_idx;
> };
> + struct damon_folio_size folio_size;
As this will be used depending on damos_filter->type, let's add this field in
the above union, together with addr_range and target_idx.
Also, I'd prefer calling this hugepage_size, as we discussed on the previous
version of this patch series.
> struct list_head list;
> };
>
> diff --git a/mm/damon/core.c b/mm/damon/core.c
> index c7b981308862..27323e3a800d 100644
> --- a/mm/damon/core.c
> +++ b/mm/damon/core.c
> @@ -776,6 +776,9 @@ static void damos_commit_filter_arg(
> case DAMOS_FILTER_TYPE_TARGET:
> dst->target_idx = src->target_idx;
> break;
> + case DAMOS_FILTER_TYPE_HUGEPAGE:
> + dst->folio_size = src->folio_size;
> + break;
> default:
> break;
> }
> diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c
> index 98f93ae9f59e..bc7ca43ca9c4 100644
> --- a/mm/damon/sysfs-schemes.c
> +++ b/mm/damon/sysfs-schemes.c
> @@ -316,6 +316,7 @@ struct damon_sysfs_scheme_filter {
> bool allow;
> char *memcg_path;
> struct damon_addr_range addr_range;
> + struct damon_folio_size folio_size;
Again, I'd prefer calling this hugepage_size.
> int target_idx;
> };
>
> @@ -469,6 +470,43 @@ static ssize_t addr_end_store(struct kobject *kobj,
> struct damon_sysfs_scheme_filter *filter = container_of(kobj,
> struct damon_sysfs_scheme_filter, kobj);
> int err = kstrtoul(buf, 0, &filter->addr_range.end);
> + return err ? err : count;
> +}
Let's keep the blank line before 'return' so that this is not unnecessarily
marked as a diff.
> +
> +static ssize_t min_show(struct kobject *kobj,
> + struct kobj_attribute *attr, char *buf)
> +{
> + struct damon_sysfs_scheme_filter *filter = container_of(kobj,
> + struct damon_sysfs_scheme_filter, kobj);
> +
> + return sysfs_emit(buf, "%lu\n", filter->folio_size.min);
> +}
> +
> +static ssize_t min_store(struct kobject *kobj,
> + struct kobj_attribute *attr, const char *buf, size_t count)
> +{
> + struct damon_sysfs_scheme_filter *filter = container_of(kobj,
> + struct damon_sysfs_scheme_filter, kobj);
> + int err = kstrtoul(buf, 0, &filter->folio_size.min);
> +
> + return err ? err : count;
> +}
> +
> +static ssize_t max_show(struct kobject *kobj,
> + struct kobj_attribute *attr, char *buf)
> +{
> + struct damon_sysfs_scheme_filter *filter = container_of(kobj,
> + struct damon_sysfs_scheme_filter, kobj);
> +
> + return sysfs_emit(buf, "%lu\n", filter->folio_size.max);
> +}
> +
> +static ssize_t max_store(struct kobject *kobj,
> + struct kobj_attribute *attr, const char *buf, size_t count)
> +{
> + struct damon_sysfs_scheme_filter *filter = container_of(kobj,
> + struct damon_sysfs_scheme_filter, kobj);
> + int err = kstrtoul(buf, 0, &filter->folio_size.max);
>
> return err ? err : count;
> }
> @@ -519,6 +557,12 @@ static struct kobj_attribute damon_sysfs_scheme_filter_addr_start_attr =
> static struct kobj_attribute damon_sysfs_scheme_filter_addr_end_attr =
> __ATTR_RW_MODE(addr_end, 0600);
>
> +static struct kobj_attribute damon_sysfs_scheme_filter_min_attr =
> + __ATTR_RW_MODE(min, 0600);
> +
> +static struct kobj_attribute damon_sysfs_scheme_filter_max_attr =
> + __ATTR_RW_MODE(max, 0600);
> +
> static struct kobj_attribute damon_sysfs_scheme_filter_damon_target_idx_attr =
> __ATTR_RW_MODE(damon_target_idx, 0600);
>
> @@ -529,6 +573,8 @@ static struct attribute *damon_sysfs_scheme_filter_attrs[] = {
> &damon_sysfs_scheme_filter_memcg_path_attr.attr,
> &damon_sysfs_scheme_filter_addr_start_attr.attr,
> &damon_sysfs_scheme_filter_addr_end_attr.attr,
> + &damon_sysfs_scheme_filter_min_attr.attr,
> + &damon_sysfs_scheme_filter_max_attr.attr,
> &damon_sysfs_scheme_filter_damon_target_idx_attr.attr,
> NULL,
> };
> @@ -1953,6 +1999,13 @@ static int damon_sysfs_add_scheme_filters(struct damos *scheme,
> filter->addr_range = sysfs_filter->addr_range;
> } else if (filter->type == DAMOS_FILTER_TYPE_TARGET) {
> filter->target_idx = sysfs_filter->target_idx;
> + } else if (filter->type == DAMOS_FILTER_TYPE_HUGEPAGE) {
> + if (sysfs_filter->folio_size.min >
> + sysfs_filter->folio_size.max) {
> + damos_destroy_filter(filter);
> + return -EINVAL;
> + }
I don't think letting users set invalid min/max is a real problem, as long as
the implementation will handle the case (no memory matches the filter). Let's
just allow it, like addr_range case. If we really need to disallow this, it
would better to do that from damos_commit_filter() like central point.
> + filter->folio_size = sysfs_filter->folio_size;
> }
>
> damos_add_filter(scheme, filter);
> --
> 2.43.5
Thanks,
SJ
next prev parent reply other threads:[~2025-02-04 23:10 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-03 22:55 [PATCH v4 0/6] mm/damon: add support for hugepages Usama Arif
2025-02-03 22:55 ` [PATCH v4 1/6] mm/damon: have damon_get_folio return folio even for tail pages Usama Arif
2025-02-03 22:55 ` [PATCH v4 2/6] mm/damon/paddr: use damon_get_folio_in_region to obtain folio Usama Arif
2025-02-04 23:06 ` SeongJae Park
2025-02-05 12:46 ` Usama Arif
2025-02-05 21:40 ` SeongJae Park
2025-02-03 22:55 ` [PATCH v4 3/6] mm/damon/sysfs-schemes: add files for setting damos_filter->folio_size Usama Arif
2025-02-04 23:10 ` SeongJae Park [this message]
2025-02-05 13:57 ` Usama Arif
2025-02-05 21:44 ` SeongJae Park
2025-02-03 22:55 ` [PATCH v4 4/6] mm/damon: introduce DAMOS filter type hugepage Usama Arif
2025-02-04 23:12 ` SeongJae Park
2025-02-05 13:52 ` Usama Arif
2025-02-05 22:05 ` SeongJae Park
2025-02-07 18:22 ` Usama Arif
2025-02-07 18:52 ` SeongJae Park
2025-02-03 22:55 ` [PATCH v4 5/6] Docs/ABI/damon: document DAMOS sysfs files to set the min/max folio_size Usama Arif
2025-02-04 23:13 ` SeongJae Park
2025-02-03 22:55 ` [PATCH v4 6/6] Docs/admin-guide/mm/damon/usage: Document hugepage filter type Usama Arif
2025-02-04 23:13 ` SeongJae Park
2025-02-04 23:20 ` [PATCH v4 0/6] mm/damon: add support for hugepages SeongJae Park
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250204231040.2655-1-sj@kernel.org \
--to=sj@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=damon@lists.linux.dev \
--cc=david@redhat.com \
--cc=hannes@cmpxchg.org \
--cc=kernel-team@meta.com \
--cc=linux-mm@kvack.org \
--cc=usamaarif642@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox