mm/damon: add support for hugepage_size DAMOS filter
Subsystems (4)
v5 cover mm/damon: add support for hugepage_size DAMOS filter
Patches 1-2 from v4 which are a requirement for this series were sent separately by SJ and are merged in mm-unstable.
hugepage_size DAMOS filter can be used to gather statistics to check if memory regions of specific access tempratures are backed by hugepages of a size in a specific range. This filter can help to observe and prove the effectivenes of different schemes for shrinking/collapsing hugepages.
v4 -> v5: (SJ)
- Drop patches 1-2 which were merged.
- change filter name from 'hugepage' -> 'hugepage_size'.
- change struct name from damon_folio_size to damon_size_range.
v3 -> v4:
- Add support for large folios of all sizes, and not just PMD mapped hugepages (David and SJ).
- only get folio while checking access/ applying DAMOS scheme if the head page is also part of that region.
v2 -> v3:
- expose hugepage via sysfs even if the kernel is
built without hugepage support. DAMON will just
just return 0. (SJ Park)
v1 -> v2:
- Wrap DAMOS_FILTER_TYPE_HUGEPAGE case with
CONFIG_PGTABLE_HAS_HUGE_LEAVES (SJ Park)
Usama Arif (4):
mm/damon: introduce DAMOS filter type hugepage_size mm/damon/sysfs-schemes: add files for setting damos_filter->sz_range Docs/ABI/damon: document DAMOS sysfs files to set the min/max
folio_size
Docs/admin-guide/mm/damon/usage: Document hugepage_size filter type
.../ABI/testing/sysfs-kernel-mm-damon | 14 +++++ Documentation/admin-guide/mm/damon/usage.rst | 17 +++--- include/linux/damon.h | 13 +++++ mm/damon/core.c | 3 + mm/damon/paddr.c | 6 ++ mm/damon/sysfs-schemes.c | 55 +++++++++++++++++++ 6 files changed, 100 insertions(+), 8 deletions(-)
Signature · 1 line
2.43.5
PATCH v5 1/4 mm/damon: introduce DAMOS filter type hugepage_size
This is to gather statistics to check if memory regions of specific access tempratures are backed by pages of a size in a specific range.
This filter can help to observe and prove the effectivenes of different schemes for shrinking/collapsing hugepages.
--- include/linux/damon.h | 13 +++++++++++++ mm/damon/core.c | 3 +++ mm/damon/paddr.c | 6 ++++++ mm/damon/sysfs-schemes.c | 1 + 4 files changed, 23 insertions(+)
include/linux/damon.h +13 -0
@@ -35,6 +35,16 @@ struct damon_addr_range {unsigned long end; }; +/** +* struct damon_size_range - Represents size for filter to operate on [@min, @max]. +* @min: Min size (inclusive). +* @max: Max size (inclusive). +*/ +struct damon_size_range { +unsigned long min; +unsigned long max; +}; +/** * struct damon_region - Represents a monitoring target region. * @ar: The address range of the region.
@@ -326,6 +336,7 @@ struct damos_stat {* @DAMOS_FILTER_TYPE_ANON: Anonymous pages. * @DAMOS_FILTER_TYPE_MEMCG: Specific memcg's pages. * @DAMOS_FILTER_TYPE_YOUNG: Recently accessed pages. +* @DAMOS_FILTER_TYPE_HUGEPAGE_SIZE: Page is part of a hugepage. * @DAMOS_FILTER_TYPE_ADDR: Address range. * @DAMOS_FILTER_TYPE_TARGET: Data Access Monitoring target. * @NR_DAMOS_FILTER_TYPES: Number of filter types.
@@ -345,6 +356,7 @@ enum damos_filter_type {DAMOS_FILTER_TYPE_ANON ,DAMOS_FILTER_TYPE_MEMCG ,DAMOS_FILTER_TYPE_YOUNG , +DAMOS_FILTER_TYPE_HUGEPAGE_SIZE ,DAMOS_FILTER_TYPE_ADDR ,DAMOS_FILTER_TYPE_TARGET , NR_DAMOS_FILTER_TYPES,
@@ -376,6 +388,7 @@ struct damos_filter {unsigned short memcg_id;struct damon_addr_range addr_range;int target_idx; +struct damon_size_range sz_range; };struct list_head list; };
mm/damon/core.c +3 -0
@@ -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_SIZE : + dst->sz_range = src->sz_range; +break ;default :break ; }
mm/damon/paddr.c +6 -0
@@ -203,6 +203,7 @@ static bool damos_pa_filter_match(struct damos_filter *filter, {bool matched = false;struct mem_cgroup *memcg; +size_t folio_sz;switch (filter->type) {case DAMOS_FILTER_TYPE_ANON :
@@ -222,6 +223,11 @@ static bool damos_pa_filter_match(struct damos_filter *filter,if (matched)damon_folio_mkold (folio);break ; +case DAMOS_FILTER_TYPE_HUGEPAGE_SIZE : + folio_sz =folio_size (folio); + matched = filter->sz_range.min <= folio_sz && + folio_sz <= filter->sz_range.max; +break ;default :break ; }
mm/damon/sysfs-schemes.c +1 -0
@@ -329,6 +329,7 @@ static const char * const damon_sysfs_scheme_filter_type_strs[] = {"anon" ,"memcg" ,"young" , +"hugepage_size" ,"addr" , "target", };
Signature · 1 line
2.43.5
Re: [PATCH v5 1/4] mm/damon: introduce DAMOS filter type hugepage_size
Quoted 7 lines · On Tue, 11 Feb 2025 12:43:40 +0000 Usama Arif <[email protected]> wrote:
This is to gather statistics to check if memory regions of specific access tempratures are backed by pages of a size in a specific range.
This filter can help to observe and prove the effectivenes of different schemes for shrinking/collapsing hugepages.Signed-off-by Usama Arif <[email protected]>
Thanks,
SJ
[...]
PATCH v5 2/4 mm/damon/sysfs-schemes: add files for setting damos_filter->sz_range
In reply to Usama ArifAdd 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.
--- mm/damon/sysfs-schemes.c | 54 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+)
mm/damon/sysfs-schemes.c +54 -0
@@ -316,6 +316,7 @@ struct damon_sysfs_scheme_filter {bool allow;char *memcg_path;struct damon_addr_range addr_range; +struct damon_size_range sz_range;int target_idx; };
@@ -474,6 +475,44 @@ static ssize_t addr_end_store(struct kobject *kobj,return err ? err : count; } +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->sz_range.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->sz_range.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->sz_range.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->sz_range.max); + +return err ? err : count; +} +static ssize_t damon_target_idx_show (struct kobject *kobj,struct kobj_attribute *attr,char *buf) {
@@ -520,6 +559,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 );
@@ -530,6 +575,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, };
@@ -1954,6 +2001,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_SIZE ) { +if (sysfs_filter->sz_range.min > + sysfs_filter->sz_range.max) { +damos_destroy_filter (filter); +return -EINVAL ; + } + filter->sz_range = sysfs_filter->sz_range; }damos_add_filter (scheme, filter);
Signature · 1 line
2.43.5
Re: [PATCH v5 2/4] mm/damon/sysfs-schemes: add files for setting damos_filter->sz_range
Quoted 5 lines · On Tue, 11 Feb 2025 12:43:41 +0000 Usama Arif <[email protected]> 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_statfor.Signed-off-by Usama Arif <[email protected]>
Thanks,
SJ
[...]
PATCH v5 3/4 Docs/ABI/damon: document DAMOS sysfs files to set the min/max folio_size
In reply to Usama ArifThis will be used to decide the min and max folio size to operate on for pa_stat.
--- Documentation/ABI/testing/sysfs-kernel-mm-damon | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
Documentation/ABI/testing/sysfs-kernel-mm-damon +14 -0
@@ -345,6 +345,20 @@ Description: If 'addr' is written to the 'type' file, writing to or reading from this file sets or gets the end address of the address range for the filter. +What: /sys/kernel/mm/damon/admin/kdamonds/<K>/contexts/<C>/schemes/<S>/filters/<F>/min +Date: Feb 2025 +Contact: SeongJae Park <[email protected]> +Description: If 'hugepage_size' is written to the 'type' file, writing to + or reading from this file sets or gets the minimum size of the + hugepage for the filter. + +What: /sys/kernel/mm/damon/admin/kdamonds/<K>/contexts/<C>/schemes/<S>/filters/<F>/max +Date: Feb 2025 +Contact: SeongJae Park <[email protected]> +Description: If 'hugepage_size' is written to the 'type' file, writing to + or reading from this file sets or gets the maximum size of the + hugepage for the filter. + What: /sys/kernel/mm/damon/admin/kdamonds/<K>/contexts/<C>/schemes/<S>/filters/<F>/target_idx Date: Dec 2022 Contact: SeongJae Park <[email protected]>
Signature · 1 line
2.43.5
PATCH v5 4/4 Docs/admin-guide/mm/damon/usage: Document hugepage_size filter type
In reply to Usama ArifThis includes both the 'hugepage_size' filter type and the min/max files used to decide range of sizes to filter on.
--- Documentation/admin-guide/mm/damon/usage.rst | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
Documentation/admin-guide/mm/damon/usage.rst +9 -8
@@ -83,7 +83,7 @@ comma (","). │ │ │ │ │ │ │ │ │ 0/target_metric,target_value,current_value │ │ │ │ │ │ │ :ref:`watermarks <sysfs_watermarks>`/metric,interval_us,high,mid,low │ │ │ │ │ │ │ :ref:`filters <sysfs_filters>`/nr_filters - │ │ │ │ │ │ │ │ 0/type,matching,allow,memcg_path,addr_start,addr_end,target_idx + │ │ │ │ │ │ │ │ 0/type,matching,allow,memcg_path,addr_start,addr_end,target_idx,min,max │ │ │ │ │ │ │ :ref:`stats <sysfs_schemes_stats>`/nr_tried,sz_tried,nr_applied,sz_applied,sz_ops_filter_passed,qt_exceeds │ │ │ │ │ │ │ :ref:`tried_regions <sysfs_schemes_tried_regions>`/total_bytes │ │ │ │ │ │ │ │ 0/start,end,nr_accesses,age,sz_filter_passed
@@ -406,13 +406,14 @@ number (``N``) to the file creates the number of child directories named ``0`` to ``N-1``. Each directory represents each filter. The filters are evaluated in the numeric order. -Each filter directory contains seven files, namely ``type``, ``matching``, -``allow``, ``memcg_path``, ``addr_start``, ``addr_end``, and ``target_idx``. -To ``type`` file, you can write one of five special keywords: ``anon`` for -anonymous pages, ``memcg`` for specific memory cgroup, ``young`` for young -pages, ``addr`` for specific address range (an open-ended interval), or -``target`` for specific DAMON monitoring target filtering. Meaning of the -types are same to the description on the :ref:`design doc +Each filter directory contains nine files, namely ``type``, ``matching``, +``allow``, ``memcg_path``, ``addr_start``, ``addr_end``, ``min``, ``max`` +and ``target_idx``. To ``type`` file, you can write one of six special +keywords: ``anon`` for anonymous pages, ``memcg`` for specific memory cgroup, +``young`` for young pages, ``addr`` for specific address range (an open-ended +interval), ``hugepage_size`` for large folios of a specific size range [``min``, +``max``] or ``target`` for specific DAMON monitoring target filtering. Meaning +of the types are same to the description on the :ref:`design doc <damon_design_damos_filters>`. In case of the memory cgroup filtering, you can specify the memory cgroup of
Signature · 1 line
2.43.5
Re: [PATCH v5 4/4] Docs/admin-guide/mm/damon/usage: Document hugepage_size filter type
Quoted 4 lines · On Tue, 11 Feb 2025 12:43:43 +0000 Usama Arif <[email protected]> wrote:
This includes both the '
hugepage_size' filter type and the min/max files used to decide range of sizes to filter on.Signed-off-by Usama Arif <[email protected]>
Thanks,
SJ
[...]
SeongJae Park
maintainerHi Usama,
Quoted 9 lines · On Tue, 11 Feb 2025 12:43:39 +0000 Usama Arif <[email protected]> wrote:
Patches 1-2 from v4 which are a requirement for this series were sent separately by SJ and are merged in mm-unstable.
hugepage_sizeDAMOS filter can be used to gather statistics to check if memory regions of specific access tempratures are backed by hugepages of a size in a specific range. This filter can help to observe and prove the effectivenes of different schemes for shrinking/collapsing hugepages.
Quoted 4 lines
v4 -> v5: (SJ)
- Drop patches 1-2 which were merged.
- change filter name from 'hugepage' -> 'hugepage_size'.
- change struct name fromdamon_folio_sizetodamon_size_range.
Thank you again for continuing this great work. All patches of this series look good to me, so I added my Reviewed-by: tags to the whole.
Also Cc-ing Andrew, since I think this patch series may better to be queued on mm-unstable for wider testing.
Thanks,
SJ
[...]