Extedn DAMOS filters for address ranges and
Subsystems (5)
SeongJae Park
maintainercover Extedn DAMOS filters for address ranges and
There are use cases that need to apply DAMOS schemes to specific address ranges or DAMON monitoring targets. NUMA nodes in the physical address space, special memory objects in the virtual address space, and monitoring target specific efficient monitoring results snapshot retrieval could be examples of such use cases. This patchset extends DAMOS filters feature for such cases, by implementing two more filter types, namely address ranges and DAMON monitoring types.
Patches sequence
----------------
The first seven patches are for the address ranges based DAMOS filter. The first patch implements the filter feature and expose it via DAMON kernel API. The second patch further expose the feature to users via DAMON sysfs interface. The third and fourth patches implement unit tests and selftests for the feature. Three patches (fifth to seventh) updating the documents follow.
The following six patches are for the DAMON monitoring target based DAMOS filter. The eighth patch implements the feature in the core layer and expose it via DAMON's kernel API. The ninth patch further expose it to users via DAMON sysfs interface. Tenth patch add a selftest, and two patches (eleventh and twelfth) update documents.
SeongJae Park (13):
mm/damon/core: introduce address range type damos filter mm/damon/sysfs-schemes: support address range type DAMOS filter mm/damon/core-test: add a unit test for __damos_filter_out() selftests/damon/sysfs: test address range damos filter Docs/mm/damon/design: update for address range filters Docs/ABI/damon: update for address range DAMOS filter Docs/admin-guide/mm/damon/usage: update for address range type DAMOS
filter
mm/damon/core: implement target type damos filter mm/damon/sysfs-schemes: support target damos filter selftests/damon/sysfs: test damon_target filter Docs/mm/damon/design: update for DAMON monitoring target type DAMOS
filter
Docs/ABI/damon: update for DAMON monitoring target type DAMOS filter Docs/admin-guide/mm/damon/usage: update for DAMON monitoring target
type DAMOS filter
.../ABI/testing/sysfs-kernel-mm-damon | 27 +++++- Documentation/admin-guide/mm/damon/usage.rst | 34 +++++--- Documentation/mm/damon/design.rst | 24 ++++-- include/linux/damon.h | 28 +++++-- mm/damon/core-test.h | 61 ++++++++++++++ mm/damon/core.c | 62 ++++++++++++++ mm/damon/sysfs-schemes.c | 83 +++++++++++++++++++ tools/testing/selftests/damon/sysfs.sh | 5 ++ 8 files changed, 299 insertions(+), 25 deletions(-)
Signature · 1 line
2.25.1
SeongJae Park
maintainerRFC PATCH 1/13 mm/damon/core: introduce address range type damos filter
Users can know special characteristic of specific address ranges. NUMA nodes or special objects or buffers in virtual address space could be such examples. For such cases, DAMOS schemes could required to be applied to only specific address ranges. Implement yet another type of DAMOS filter for the purpose.
Note that the existing filter types, namely anon pages and memcg DAMOS filters needed page level type check. Because such check can be done efficiently in the opertions set layer, those filters are handled in operations set layer. Specifically, only paddr operations set implementation supports these filters. Also, because statistics counting is done in the DAMON core layer, the regions that filtered out by these filters are counted as tried but failed to the statistics.
Unlike those, address range based filters can efficiently handled in the core layer. Hence, do the handling in the layer, and count the regions that filtered out by those as the scheme has not tried for the region. This difference should clearly documented.
--- include/linux/damon.h | 22 +++++++++++++----- mm/damon/core.c | 52 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 6 deletions(-)
include/linux/damon.h +16 -6
@@ -226,16 +226,24 @@ struct damos_stat {* enum damos_filter_type - Type of memory for &struct damos_filter * @DAMOS_FILTER_TYPE_ANON: Anonymous pages. * @DAMOS_FILTER_TYPE_MEMCG: Specific memcg's pages. +* @DAMOS_FILTER_TYPE_ADDR: Address range. * @NR_DAMOS_FILTER_TYPES: Number of filter types. * -* The support of each filter type is up to running &struct damon_operations. -* &enum DAMON_OPS_PADDR is supporting all filter types, while -* &enum DAMON_OPS_VADDR and &enum DAMON_OPS_FVADDR are not supporting any -* filter types. +* The anon pages type and memcg type filters are handled by underlying +* &struct damon_operations as a part of scheme action trying, and therefore +* accounted as 'tried'. In contrast, other types are handled by core layer +* before trying of the action and therefore not accounted as 'tried'. +* +* The support of the filters that handled by &struct damon_operations depend +* on the running &struct damon_operations. +* &enum DAMON_OPS_PADDR supports both anon pages type and memcg type filters, +* while &enum DAMON_OPS_VADDR and &enum DAMON_OPS_FVADDR don't support any of +* the two types. */ enum damos_filter_type {DAMOS_FILTER_TYPE_ANON ,DAMOS_FILTER_TYPE_MEMCG , +DAMOS_FILTER_TYPE_ADDR ,NR_DAMOS_FILTER_TYPES , };
@@ -244,18 +252,20 @@ enum damos_filter_type {* @type: Type of the page. * @matching: If the matching page should filtered out or in. * @memcg_id: Memcg id of the question if @type is DAMOS_FILTER_MEMCG. +* @addr_range: Address range if @type is DAMOS_FILTER_TYPE_ADDR. * @list: List head for siblings. * * Before applying the &damos->action to a memory region, DAMOS checks if each * page of the region matches to this and avoid applying the action if so. -* Note that the check support is up to &struct damon_operations -* implementation. +* Support of each filter type depends on the running &struct damon_operations +* and the type. Refer to &enum damos_filter_type for more detai. */ struct damos_filter {enum damos_filter_type type;bool matching;union {unsigned short memcg_id; +struct damon_addr_range addr_range; };struct list_head list; };
mm/damon/core.c +52 -0
64 lines not on this page · raw message
Signature · 1 line
2.25.1
SeongJae Park
maintainerRFC PATCH 2/13 mm/damon/sysfs-schemes: support address range type DAMOS filter
In reply to SeongJae ParkExtend DAMON sysfs interface to support address range based DAMOS filters, by adding a special keyword for the filter/<N>/type file, namely 'addr', and two files under filter/<N>/ for specifying the start and the end addresses of the range, namely 'addr_start' and 'addr_end'.
--- mm/damon/sysfs-schemes.c | 56 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+)
mm/damon/sysfs-schemes.c +56 -0
@@ -282,6 +282,7 @@ struct damon_sysfs_scheme_filter {enum damos_filter_type type;bool matching;char *memcg_path; +struct damon_addr_range addr_range; };static struct damon_sysfs_scheme_filter *damon_sysfs_scheme_filter_alloc (void )
@@ -293,6 +294,7 @@ static struct damon_sysfs_scheme_filter *damon_sysfs_scheme_filter_alloc(void)static const char *const damon_sysfs_scheme_filter_type_strs[] = {"anon" ,"memcg" , +"addr" , }; static ssize_t type_show(struct kobject *kobj,
@@ -373,6 +375,44 @@ static ssize_t memcg_path_store(struct kobject *kobj,return count; } +static ssize_t addr_start_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->addr_range.start); +} + +static ssize_t addr_start_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->addr_range.start); + +return err ? err : count; +} + +static ssize_t addr_end_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->addr_range.end); +} + +static ssize_t addr_end_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->addr_range.end); + +return err ? err : count; +} +static void damon_sysfs_scheme_filter_release (struct kobject *kobj) { struct damon_sysfs_scheme_filter *filter = container_of(kobj,
@@ -391,10 +431,18 @@ static struct kobj_attribute damon_sysfs_scheme_filter_matching_attr =static struct kobj_attribute damon_sysfs_scheme_filter_memcg_path_attr =__ATTR_RW_MODE (memcg_path,0600 ); +static struct kobj_attribute damon_sysfs_scheme_filter_addr_start_attr = +__ATTR_RW_MODE (addr_start,0600 ); + +static struct kobj_attribute damon_sysfs_scheme_filter_addr_end_attr = +__ATTR_RW_MODE (addr_end,0600 ); +static struct attribute *damon_sysfs_scheme_filter_attrs[] = { &damon_sysfs_scheme_filter_type_attr.attr, &damon_sysfs_scheme_filter_matching_attr.attr, &damon_sysfs_scheme_filter_memcg_path_attr.attr, + &damon_sysfs_scheme_filter_addr_start_attr.attr, + &damon_sysfs_scheme_filter_addr_end_attr.attr,NULL , };ATTRIBUTE_GROUPS (damon_sysfs_scheme_filter);
@@ -1484,7 +1532,15 @@ static int damon_sysfs_set_scheme_filters(struct damos *scheme,damos_destroy_filter (filter);return err; } + }else if (filter->type ==DAMOS_FILTER_TYPE_ADDR ) { +if (sysfs_filter->addr_range.end < + sysfs_filter->addr_range.start) { +damos_destroy_filter (filter); +return -EINVAL ; + } + filter->addr_range = sysfs_filter->addr_range; } +damos_add_filter (scheme, filter); }return 0 ;
Signature · 1 line
2.25.1
SeongJae Park
maintainerRFC PATCH 2/13 mm/damon/sysfs-schemes: support address range type DAMOS filter
In reply to SeongJae ParkDate: Sat, 22 Jul 2023 19:45:58 +0000
Subject: [RFC PATCH 03/13] mm/damon/core-test: add a unit test for
__damos_filter_out()
Implement a kunit test for the core of address range DAMOS filter handling, namely __damos_filter_out(). The test especially focus on regions that overlap with given filter's target address range.
--- mm/damon/core-test.h | 61 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+)
mm/damon/core-test.h +61 -0
@@ -341,6 +341,66 @@ static void damon_test_set_attrs(struct kunit *test)KUNIT_EXPECT_EQ (test,damon_set_attrs (c, &invalid_attrs), -EINVAL ); } +static void damos_test_filter_out (struct kunit *test) +{ +struct damon_target *t; +struct damon_region *r, *r2; +struct damos_filter *f; + + f =damos_new_filter (DAMOS_FILTER_TYPE_ADDR , true); + f->addr_range = (struct damon_addr_range ){ + .start =DAMON_MIN_REGION *2 , .end =DAMON_MIN_REGION *6 }; + + t =damon_new_target (); + r =damon_new_region (DAMON_MIN_REGION *3 ,DAMON_MIN_REGION *5 ); +damon_add_region (r, t); + +/* region in the range */ +KUNIT_EXPECT_TRUE (test,__damos_filter_out (NULL , t, r, f)); +KUNIT_EXPECT_EQ (test,damon_nr_regions (t),1 ); + +/* region before the range */ + r->ar.start =DAMON_MIN_REGION *1 ; + r->ar.end =DAMON_MIN_REGION *2 ; +KUNIT_EXPECT_FALSE (test,__damos_filter_out (NULL , t, r, f)); +KUNIT_EXPECT_EQ (test,damon_nr_regions (t),1 ); + +/* region after the range */ + r->ar.start =DAMON_MIN_REGION *6 ; + r->ar.end =DAMON_MIN_REGION *8 ; +KUNIT_EXPECT_FALSE (test,__damos_filter_out (NULL , t, r, f)); +KUNIT_EXPECT_EQ (test,damon_nr_regions (t),1 ); + +/* region started before the range */ + r->ar.start =DAMON_MIN_REGION *1 ; + r->ar.end =DAMON_MIN_REGION *4 ; +KUNIT_EXPECT_FALSE (test,__damos_filter_out (NULL , t, r, f)); +/* filter should have split the region */ +KUNIT_EXPECT_EQ (test, r->ar.start,DAMON_MIN_REGION *1 ); +KUNIT_EXPECT_EQ (test, r->ar.end,DAMON_MIN_REGION *2 ); +KUNIT_EXPECT_EQ (test,damon_nr_regions (t),2 ); + r2 =damon_next_region (r); +KUNIT_EXPECT_EQ (test, r2->ar.start,DAMON_MIN_REGION *2 ); +KUNIT_EXPECT_EQ (test, r2->ar.end,DAMON_MIN_REGION *4 ); +damon_destroy_region (r2, t); + +/* region started in the range */ + r->ar.start =DAMON_MIN_REGION *2 ; + r->ar.end =DAMON_MIN_REGION *8 ; +KUNIT_EXPECT_TRUE (test,__damos_filter_out (NULL , t, r, f)); +/* filter should have split the region */ +KUNIT_EXPECT_EQ (test, r->ar.start,DAMON_MIN_REGION *2 ); +KUNIT_EXPECT_EQ (test, r->ar.end,DAMON_MIN_REGION *6 ); +KUNIT_EXPECT_EQ (test,damon_nr_regions (t),2 ); + r2 =damon_next_region (r); +KUNIT_EXPECT_EQ (test, r2->ar.start,DAMON_MIN_REGION *6 ); +KUNIT_EXPECT_EQ (test, r2->ar.end,DAMON_MIN_REGION *8 ); +damon_destroy_region (r2, t); + +damon_free_target (t); +damos_free_filter (f); +} +static struct kunit_case damon_test_cases[] = {KUNIT_CASE (damon_test_target),KUNIT_CASE (damon_test_regions),
@@ -353,6 +413,7 @@ static struct kunit_case damon_test_cases[] = {KUNIT_CASE (damon_test_set_regions),KUNIT_CASE (damon_test_update_monitoring_result),KUNIT_CASE (damon_test_set_attrs), + KUNIT_CASE(damos_test_filter_out), {}, };
Signature · 1 line
2.25.1
SeongJae Park
maintainerRFC PATCH 4/13 selftests/damon/sysfs: test address range damos filter
In reply to SeongJae ParkAdd a selftest for checking existence of addr_{start,end} files under DAMOS filter directory, and 'addr' damos filter type input of DAMON sysfs interface.
--- tools/testing/selftests/damon/sysfs.sh | 3 +++ 1 file changed, 3 insertions(+)
tools/testing/selftests/damon/sysfs.sh +3 -0
@@ -103,9 +103,12 @@ test_filter() ensure_file "$filter_dir/type" "exist" "600" ensure_write_succ "$filter_dir/type" "anon" "valid input" ensure_write_succ "$filter_dir/type" "memcg" "valid input" + ensure_write_succ "$filter_dir/type" "addr" "valid input" ensure_write_fail "$filter_dir/type" "foo" "invalid input" ensure_file "$filter_dir/matching" "exist" "600" ensure_file "$filter_dir/memcg_path" "exist" "600" + ensure_file "$filter_dir/addr_start" "exist" "600" + ensure_file "$filter_dir/addr_end" "exist" "600" } test_filters()
Signature · 1 line
2.25.1
SeongJae Park
maintainerRFC PATCH 5/13 Docs/mm/damon/design: update for address range filters
In reply to SeongJae ParkUpdate DAMON design document's DAMOS filters section for address range DAMOS filters. Because address range filters are handled by the core layer and it makes difference in schemes tried regions and schemes statistics, clearly describe it.
--- Documentation/mm/damon/design.rst | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)
Documentation/mm/damon/design.rst +15 -6
@@ -380,12 +380,21 @@ number of filters for each scheme. Each filter specifies the type of target memory, and whether it should exclude the memory of the type (filter-out), or all except the memory of the type (filter-in). -As of this writing, anonymous page type and memory cgroup type are supported by -the feature. Some filter target types can require additional arguments. For -example, the memory cgroup filter type asks users to specify the file path of -the memory cgroup for the filter. Hence, users can apply specific schemes to -only anonymous pages, non-anonymous pages, pages of specific cgroups, all pages -excluding those of specific cgroups, and any combination of those. +Currently, anonymous page, memory cgroup, and address range type filters are +supported by the feature. Some filter target types can require additional +arguments. For example, the memory cgroup filter type asks users to specify +the file path of the memory cgroup for the filter, while the address range type +asks the start and end addresses of the range. Hence, users can apply specific +schemes to only anonymous pages, non-anonymous pages, pages of specific +cgroups, all pages excluding those of specific cgroups, pages in specific +address range, and any combination of those. + +To handle filters efficiently, the address range type filter is handled by the +core layer, while others are handled by operations set. If a memory region is +filtered by the core layer-handled filter, it is not counted as the scheme has +tried to the region. In contrast, if a memory regions is filtered by an +operations set layer-handled filter, it is counted as the scheme has tried. +The difference in accounting leads to changes in the statistics. Application Programming Interface
Signature · 1 line
2.25.1
SeongJae Park
maintainerRFC PATCH 6/13 Docs/ABI/damon: update for address range DAMOS filter
In reply to SeongJae ParkUpdate DAMON ABI document for address ranges type DAMOS filter files.
--- .../ABI/testing/sysfs-kernel-mm-damon | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)
Documentation/ABI/testing/sysfs-kernel-mm-damon +18 -2
@@ -271,8 +271,9 @@ What: /sys/kernel/mm/damon/admin/kdamonds/<K>/contexts/<C>/schemes/<S>/filters/ Date: Dec 2022 Contact: SeongJae Park <[email protected]> Description: Writing to and reading from this file sets and gets the type of - the memory of the interest. 'anon' for anonymous pages, or - 'memcg' for specific memory cgroup can be written and read. + the memory of the interest. 'anon' for anonymous pages, + 'memcg' for specific memory cgroup, or 'addr' for address range + (an open-ended interval) can be written and read. What: /sys/kernel/mm/damon/admin/kdamonds/<K>/contexts/<C>/schemes/<S>/filters/<F>/memcg_path Date: Dec 2022
@@ -281,6 +282,21 @@ Description: If 'memcg' is written to the 'type' file, writing to and reading from this file sets and gets the path to the memory cgroup of the interest. +What: /sys/kernel/mm/damon/admin/kdamonds/<K>/contexts/<C>/schemes/<S>/filters/<F>/addr_start +Date: Jul 2023 +Contact: SeongJae Park <[email protected]> +Description: If 'addr' is written to the 'type' file, writing to or reading + from this file sets or gets the start address of the address + range for the filter. + +What: /sys/kernel/mm/damon/admin/kdamonds/<K>/contexts/<C>/schemes/<S>/filters/<F>/addr_end +Date: Jul 2023 +Contact: SeongJae Park <[email protected]> +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>/matching Date: Dec 2022 Contact: SeongJae Park <[email protected]>
Signature · 1 line
2.25.1
SeongJae Park
maintainerRFC PATCH 7/13 Docs/admin-guide/mm/damon/usage: update for address range type DAMOS filter
In reply to SeongJae ParkUpdate DAMON usage document for the newly added address range type DAMOS filter.
--- Documentation/admin-guide/mm/damon/usage.rst | 31 +++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-)
Documentation/admin-guide/mm/damon/usage.rst +20 -11
@@ -363,15 +363,18 @@ 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 three files, namely ``type``, ``matcing``, and -``memcg_path``. You can write one of two special keywords, ``anon`` for -anonymous pages, or ``memcg`` for specific memory cgroup filtering. In case of -the memory cgroup filtering, you can specify the memory cgroup of the interest -by writing the path of the memory cgroup from the cgroups mount point to -``memcg_path`` file. You can write ``Y`` or ``N`` to ``matching`` file to -filter out pages that does or does not match to the type, respectively. Then, -the scheme's action will not be applied to the pages that specified to be -filtered out. +Each filter directory contains five files, namely ``type``, ``matcing``, +``memcg_path``, ``addr_start``, and ``addr_end``. To ``type`` file, you can +write one of three special keywords: ``anon`` for anonymous pages, ``memcg`` +for specific memory cgroup, or ``addr`` for specific address range (an +open-ended interval) filtering. In case of the memory cgroup filtering, you +can specify the memory cgroup of the interest by writing the path of the memory +cgroup from the cgroups mount point to ``memcg_path`` file. In case of the +address range filtering, you can specify the start and end address of the range +to ``addr_start`` and ``addr_end`` files, respectively. You can write ``Y`` or +``N`` to ``matching`` file to filter out pages that does or does not match to +the type, respectively. Then, the scheme's action will not be applied to the +pages that specified to be filtered out. For example, below restricts a DAMOS action to be applied to only non-anonymous pages of all memory cgroups except ``/having_care_already``.::
@@ -385,8 +388,14 @@ pages of all memory cgroups except ``/having_care_already``.:: echo /having_care_already > 1/memcg_path echo N > 1/matching -Note that filters are currently supported only when ``paddr`` -`implementation <sysfs_contexts>` is being used. +Note that ``anon`` and ``memcg`` filters are currently supported only when +``paddr`` `implementation <sysfs_contexts>` is being used. + +Also, memory regions that are filtered out by ``addr`` filters are not counted +as the scheme has tried to those, while regions that filtered out by other type +filters are counted as the scheme has tried to. The difference is applied to +:ref:`stats <damos_stats>` and :ref:`tried regions +<sysfs_schemes_tried_regions>`. .. _sysfs_schemes_stats:
Signature · 1 line
2.25.1
SeongJae Park
maintainerRFC PATCH 8/13 mm/damon/core: implement target type damos filter
In reply to SeongJae ParkOne DAMON context can have multiple monitoring targets, and DAMOS schemes are applied to all targets. In some cases, users need to apply different scheme to different targets. Retrieving monitoring results via DAMON sysfs interface' 'tried_regions' directory could be one good example. Also, there could be cases that cgroup DAMOS filter is not enough. All such use cases can be worked around by having multiple DAMON contexts having only single target, but it is inefficient in terms of resource usage, thogh the overhead is not estimated to be huge.
Implement DAMON monitoring target based DAMOS filter for the case. Like address range target DAMOS filter, handle these filters in the DAMON core layer, since it is more efficient than doing in operations set layer. This also means that regions that filtered out by monitoring target type DAMOS filters are counted as not tried by the scheme. Hence, target granularity monitoring results retrieval via DAMON sysfs interface becomes available.
--- include/linux/damon.h | 6 ++++++ mm/damon/core.c | 22 ++++++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-)
include/linux/damon.h +6 -0
@@ -227,6 +227,7 @@ struct damos_stat {* @DAMOS_FILTER_TYPE_ANON: Anonymous pages. * @DAMOS_FILTER_TYPE_MEMCG: Specific memcg's pages. * @DAMOS_FILTER_TYPE_ADDR: Address range. +* @DAMOS_FILTER_TYPE_TARGET: Data Access Monitoring target. * @NR_DAMOS_FILTER_TYPES: Number of filter types. * * The anon pages type and memcg type filters are handled by underlying
@@ -244,6 +245,7 @@ enum damos_filter_type {DAMOS_FILTER_TYPE_ANON ,DAMOS_FILTER_TYPE_MEMCG ,DAMOS_FILTER_TYPE_ADDR , +DAMOS_FILTER_TYPE_TARGET , NR_DAMOS_FILTER_TYPES, };
@@ -253,6 +255,9 @@ enum damos_filter_type {* @matching: If the matching page should filtered out or in. * @memcg_id: Memcg id of the question if @type is DAMOS_FILTER_MEMCG. * @addr_range: Address range if @type is DAMOS_FILTER_TYPE_ADDR. +* @target_idx: Index of the &struct damon_target of +* &damon_ctx->adaptive_targets if @type is +* DAMOS_FILTER_TYPE_TARGET. * @list: List head for siblings. * * Before applying the &damos->action to a memory region, DAMOS checks if each
@@ -266,6 +271,7 @@ struct damos_filter {union {unsigned short memcg_id;struct damon_addr_range addr_range; +int target_idx; };struct list_head list; };
mm/damon/core.c +16 -6
@@ -906,13 +906,23 @@ static void damos_update_stat(struct damos *s, s->stat.sz_applied += sz_applied; } -static bool __damos_filter_out (struct damon_target *t,struct damon_region *r, -struct damos_filter *filter) +static bool __damos_filter_out (struct damon_ctx *ctx,struct damon_target *t, +struct damon_region *r,struct damos_filter *filter) {bool matched = false; +struct damon_target *ti; +int target_idx =0 ;unsigned long start, end;switch (filter->type) { +case DAMOS_FILTER_TYPE_TARGET : +damon_for_each_target (ti, ctx) { +if (ti == t) +break ; + target_idx++; + } + matched = target_idx == filter->target_idx; +break ;case DAMOS_FILTER_TYPE_ADDR : start =ALIGN_DOWN (filter->addr_range.start,DAMON_MIN_REGION ); end =ALIGN_DOWN (filter->addr_range.end,DAMON_MIN_REGION );
@@ -944,13 +954,13 @@ static bool __damos_filter_out(struct damon_target *t, struct damon_region *r,return matched == filter->matching; } -static bool damos_filter_out (struct damon_target *t,struct damon_region *r, -struct damos *s) +static bool damos_filter_out (struct damon_ctx *ctx,struct damon_target *t, +struct damon_region *r,struct damos *s) {struct damos_filter *filter;damos_for_each_filter (filter, s) { -if (__damos_filter_out (t, r, filter)) +if (__damos_filter_out (ctx, t, r, filter))return true; }return false;
@@ -982,7 +992,7 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t, }damon_split_region_at (t, r, sz); } -if (damos_filter_out (t, r, s)) +if (damos_filter_out (c, t, r, s))return ;ktime_get_coarse_ts64 (&begin);if (c->callback.before_damos_apply)
Signature · 1 line
2.25.1
SeongJae Park
maintainerRFC PATCH 9/13 mm/damon/sysfs-schemes: support target damos filter
In reply to SeongJae ParkExtend DAMON sysfs interface to support the DAMON monitoring target based DAMOS filter. Users can use it via writing 'target' to the filter's 'type' file and specifying the index of the target from the corresponding DAMON context's monitoring targets list to 'target_idx' sysfs file.
--- mm/damon/sysfs-schemes.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
mm/damon/sysfs-schemes.c +27 -0
@@ -283,6 +283,7 @@ struct damon_sysfs_scheme_filter {bool matching;char *memcg_path;struct damon_addr_range addr_range; +int target_idx; };static struct damon_sysfs_scheme_filter *damon_sysfs_scheme_filter_alloc (void )
@@ -295,6 +296,7 @@ static const char * const damon_sysfs_scheme_filter_type_strs[] = {"anon" ,"memcg" ,"addr" , + "target", }; static ssize_t type_show(struct kobject *kobj,
@@ -413,6 +415,25 @@ static ssize_t addr_end_store(struct kobject *kobj,return err ? err : count; } +static ssize_t damon_target_idx_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,"%d\n" , filter->target_idx); +} + +static ssize_t damon_target_idx_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 =kstrtoint (buf,0 , &filter->target_idx); + +return err ? err : count; +} +static void damon_sysfs_scheme_filter_release (struct kobject *kobj) { struct damon_sysfs_scheme_filter *filter = container_of(kobj,
@@ -437,12 +458,16 @@ 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_damon_target_idx_attr = +__ATTR_RW_MODE (damon_target_idx,0600 ); +static struct attribute *damon_sysfs_scheme_filter_attrs[] = { &damon_sysfs_scheme_filter_type_attr.attr, &damon_sysfs_scheme_filter_matching_attr.attr, &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_damon_target_idx_attr.attr,NULL , };ATTRIBUTE_GROUPS (damon_sysfs_scheme_filter);
@@ -1539,6 +1564,8 @@ static int damon_sysfs_set_scheme_filters(struct damos *scheme,return -EINVAL ; } filter->addr_range = sysfs_filter->addr_range; + }else if (filter->type ==DAMOS_FILTER_TYPE_TARGET ) { + filter->target_idx = sysfs_filter->target_idx; }damos_add_filter (scheme, filter);
Signature · 1 line
2.25.1
SeongJae Park
maintainerRFC PATCH 10/13 selftests/damon/sysfs: test damon_target filter
In reply to SeongJae ParkTest existence of files and validity of input keyword for DAMON monitoring target based DAMOS filter on DAMON sysfs interface.
--- tools/testing/selftests/damon/sysfs.sh | 2 ++ 1 file changed, 2 insertions(+)
tools/testing/selftests/damon/sysfs.sh +2 -0
@@ -104,11 +104,13 @@ test_filter() ensure_write_succ "$filter_dir/type" "anon" "valid input" ensure_write_succ "$filter_dir/type" "memcg" "valid input" ensure_write_succ "$filter_dir/type" "addr" "valid input" + ensure_write_succ "$filter_dir/type" "target" "valid input" ensure_write_fail "$filter_dir/type" "foo" "invalid input" ensure_file "$filter_dir/matching" "exist" "600" ensure_file "$filter_dir/memcg_path" "exist" "600" ensure_file "$filter_dir/addr_start" "exist" "600" ensure_file "$filter_dir/addr_end" "exist" "600" + ensure_file "$filter_dir/damon_target_idx" "exist" "600" } test_filters()
Signature · 1 line
2.25.1
SeongJae Park
maintainerRFC PATCH 11/13 Docs/mm/damon/design: update for DAMON monitoring target type DAMOS filter
In reply to SeongJae ParkUpdate DAMON design document for the newly added DAMON monitoring target type DAMOS filter.
--- Documentation/mm/damon/design.rst | 33 +++++++++++++++++-------------- 1 file changed, 18 insertions(+), 15 deletions(-)
Documentation/mm/damon/design.rst +18 -15
@@ -380,21 +380,24 @@ number of filters for each scheme. Each filter specifies the type of target memory, and whether it should exclude the memory of the type (filter-out), or all except the memory of the type (filter-in). -Currently, anonymous page, memory cgroup, and address range type filters are -supported by the feature. Some filter target types can require additional -arguments. For example, the memory cgroup filter type asks users to specify -the file path of the memory cgroup for the filter, while the address range type -asks the start and end addresses of the range. Hence, users can apply specific -schemes to only anonymous pages, non-anonymous pages, pages of specific -cgroups, all pages excluding those of specific cgroups, pages in specific -address range, and any combination of those. - -To handle filters efficiently, the address range type filter is handled by the -core layer, while others are handled by operations set. If a memory region is -filtered by the core layer-handled filter, it is not counted as the scheme has -tried to the region. In contrast, if a memory regions is filtered by an -operations set layer-handled filter, it is counted as the scheme has tried. -The difference in accounting leads to changes in the statistics. +Currently, anonymous page, memory cgroup, address range, and DAMON monitoring +target type filters are supported by the feature. Some filter target types +require additional arguments. The memory cgroup filter type asks users to +specify the file path of the memory cgroup for the filter. The address range +type asks the start and end addresses of the range. The DAMON monitoring +target type asks the index of the target from the context's monitoring targets +list. Hence, users can apply specific schemes to only anonymous pages, +non-anonymous pages, pages of specific cgroups, all pages excluding those of +specific cgroups, pages in specific address range, pages in specific DAMON +monitoring targets, and any combination of those. + +To handle filters efficiently, the address range and DAMON monitoring target +type filters are handled by the core layer, while others are handled by +operations set. If a memory region is filtered by a core layer-handled filter, +it is not counted as the scheme has tried to the region. In contrast, if a +memory regions is filtered by an operations set layer-handled filter, it is +counted as the scheme has tried. The difference in accounting leads to changes +in the statistics. Application Programming Interface
Signature · 1 line
2.25.1
SeongJae Park
maintainerRFC PATCH 12/13 Docs/ABI/damon: update for DAMON monitoring target type DAMOS filter
In reply to SeongJae ParkUpdate DAMON ABI document for the newly added DAMON monitoring target type DAMOS filter.
--- Documentation/ABI/testing/sysfs-kernel-mm-damon | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
Documentation/ABI/testing/sysfs-kernel-mm-damon +9 -2
@@ -272,8 +272,9 @@ Date: Dec 2022 Contact: SeongJae Park <[email protected]> Description: Writing to and reading from this file sets and gets the type of the memory of the interest. 'anon' for anonymous pages, - 'memcg' for specific memory cgroup, or 'addr' for address range - (an open-ended interval) can be written and read. + 'memcg' for specific memory cgroup, 'addr' for address range + (an open-ended interval), or 'target' for DAMON monitoring + target can be written and read. What: /sys/kernel/mm/damon/admin/kdamonds/<K>/contexts/<C>/schemes/<S>/filters/<F>/memcg_path Date: Dec 2022
@@ -296,6 +297,12 @@ 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>/target_idx +Date: Dec 2022 +Contact: SeongJae Park <[email protected]> +Description: If 'target' is written to the 'type' file, writing to or + reading from this file sets or gets the index of the DAMON + monitoring target of the interest. What: /sys/kernel/mm/damon/admin/kdamonds/<K>/contexts/<C>/schemes/<S>/filters/<F>/matching Date: Dec 2022
Signature · 1 line
2.25.1
SeongJae Park
maintainerRFC PATCH 13/13 Docs/admin-guide/mm/damon/usage: update for DAMON monitoring target type DAMOS filter
In reply to SeongJae ParkUpdate DAMON usage document for newly added DAMON monitoring target type DAMOS filter.
--- Documentation/admin-guide/mm/damon/usage.rst | 37 +++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-)
Documentation/admin-guide/mm/damon/usage.rst +20 -17
@@ -363,18 +363,21 @@ 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 five files, namely ``type``, ``matcing``, -``memcg_path``, ``addr_start``, and ``addr_end``. To ``type`` file, you can -write one of three special keywords: ``anon`` for anonymous pages, ``memcg`` -for specific memory cgroup, or ``addr`` for specific address range (an -open-ended interval) filtering. In case of the memory cgroup filtering, you -can specify the memory cgroup of the interest by writing the path of the memory -cgroup from the cgroups mount point to ``memcg_path`` file. In case of the -address range filtering, you can specify the start and end address of the range -to ``addr_start`` and ``addr_end`` files, respectively. You can write ``Y`` or -``N`` to ``matching`` file to filter out pages that does or does not match to -the type, respectively. Then, the scheme's action will not be applied to the -pages that specified to be filtered out. +Each filter directory contains six files, namely ``type``, ``matcing``, +``memcg_path``, ``addr_start``, ``addr_end``, and ``target_idx``. To ``type`` +file, you can write one of four special keywords: ``anon`` for anonymous pages, +``memcg`` for specific memory cgroup, ``addr`` for specific address range (an +open-ended interval), or ``target`` for specific DAMON monitoring target +filtering. In case of the memory cgroup filtering, you can specify the memory +cgroup of the interest by writing the path of the memory cgroup from the +cgroups mount point to ``memcg_path`` file. In case of the address range +filtering, you can specify the start and end address of the range to +``addr_start`` and ``addr_end`` files, respectively. For the DAMON monitoring +target filtering, you can specify the index of the target between the list of +the DAMON context's monitoring targets list to ``target_idx`` file. You can +write ``Y`` or ``N`` to ``matching`` file to filter out pages that does or does +not match to the type, respectively. Then, the scheme's action will not be +applied to the pages that specified to be filtered out. For example, below restricts a DAMOS action to be applied to only non-anonymous pages of all memory cgroups except ``/having_care_already``.::
@@ -391,11 +394,11 @@ pages of all memory cgroups except ``/having_care_already``.:: Note that ``anon`` and ``memcg`` filters are currently supported only when ``paddr`` `implementation <sysfs_contexts>` is being used. -Also, memory regions that are filtered out by ``addr`` filters are not counted -as the scheme has tried to those, while regions that filtered out by other type -filters are counted as the scheme has tried to. The difference is applied to -:ref:`stats <damos_stats>` and :ref:`tried regions -<sysfs_schemes_tried_regions>`. +Also, memory regions that are filtered out by ``addr`` or ``target`` filters +are not counted as the scheme has tried to those, while regions that filtered +out by other type filters are counted as the scheme has tried to. The +difference is applied to :ref:`stats <damos_stats>` and +:ref:`tried regions <sysfs_schemes_tried_regions>`. .. _sysfs_schemes_stats:
Signature · 1 line
2.25.1