mm/damon: Remove duplicate get_monitoring_region() definitions
Subsystems (2)
PATCH v4 1/1 mm/damon: Remove duplicate get_monitoring_region() definitions
In lru_sort.c and reclaim.c, they are all defining get_monitoring_region() function, there is no need to define it separately.
As 'get_monitoring_region()' is not a 'static' function anymore, we try to use a prefix to distinguish with other functions, so there rename it to 'damon_find_biggest_system_ram'.
--- include/linux/damon.h | 11 +++++++++++ mm/damon/core.c | 29 +++++++++++++++++++++++++++++ mm/damon/lru_sort.c | 37 ++----------------------------------- mm/damon/reclaim.c | 37 ++----------------------------------- 4 files changed, 44 insertions(+), 70 deletions(-)
include/linux/damon.h +11 -0
@@ -448,6 +448,16 @@ struct damon_ctx {struct list_head schemes; }; +/** +* struct damon_system_ram_region - System RAM resource address region of [@start, @end). +* @start: Start address of the (inclusive). +* @end: End address of the region (exclusive). +*/ +struct damon_system_ram_region { +unsigned long start; +unsigned long end; +}; +static inline struct damon_region *damon_next_region (struct damon_region *r) { return container_of(r->list.next, struct damon_region, list);
@@ -500,6 +510,7 @@ void damon_add_region(struct damon_region *r, struct damon_target *t);void damon_destroy_region (struct damon_region *r,struct damon_target *t);int damon_set_regions (struct damon_target *t,struct damon_addr_range *ranges,unsigned int nr_ranges); +bool damon_find_biggest_system_ram (unsigned long *start,unsigned long *end); struct damos *damon_new_scheme( unsigned long min_sz_region, unsigned long max_sz_region,
mm/damon/core.c +29 -0
@@ -276,6 +276,35 @@ struct damos *damon_new_scheme(return scheme; } +static int walk_system_ram (struct resource *res,void *arg) +{ +struct damon_system_ram_region *a = arg; + +if (a->end - a->start <resource_size (res)) { + a->start = res->start; + a->end = res->end; + } +return 0 ; +} + +/* +* Find biggest 'System RAM' resource and store its start and end address in +* @start and @end, respectively. If no System RAM is found, returns false. +*/ +bool damon_find_biggest_system_ram (unsigned long *start,unsigned long *end) + +{ +struct damon_system_ram_region arg = {}; + +walk_system_ram_res (0 ,ULONG_MAX , &arg, walk_system_ram); +if (arg.end <= arg.start) +return false; + + *start = arg.start; + *end = arg.end; +return true; +} +void damon_add_scheme (struct damon_ctx *ctx,struct damos *s) {list_add_tail (&s->list, &ctx->schemes);
mm/damon/lru_sort.c +2 -35
@@ -257,39 +257,6 @@ module_param(nr_cold_quota_exceeds, ulong, 0400);static struct damon_ctx *ctx;static struct damon_target *target; -struct damon_lru_sort_ram_walk_arg { -unsigned long start; -unsigned long end; -}; - -static int walk_system_ram (struct resource *res,void *arg) -{ -struct damon_lru_sort_ram_walk_arg *a = arg; - -if (a->end - a->start <resource_size (res)) { - a->start = res->start; - a->end = res->end; - } -return 0 ; -} - -/* -* Find biggest 'System RAM' resource and store its start and end address in -* @start and @end, respectively. If no System RAM is found, returns false. -*/ -static bool get_monitoring_region (unsigned long *start,unsigned long *end) -{ -struct damon_lru_sort_ram_walk_arg arg = {}; - -walk_system_ram_res (0 ,ULONG_MAX , &arg, walk_system_ram); -if (arg.end <= arg.start) -return false; - - *start = arg.start; - *end = arg.end; -return true; -} -/* Create a DAMON-based operation scheme for hot memory regions */ static struct damos *damon_lru_sort_new_hot_scheme (unsigned int hot_thres) {
@@ -404,8 +371,8 @@ static int damon_lru_sort_apply_parameters(void)if (monitor_region_start > monitor_region_end)return -EINVAL ;if (!monitor_region_start && !monitor_region_end && - !get_monitoring_region (&monitor_region_start, - &monitor_region_end)) + !damon_find_biggest_system_ram (&monitor_region_start, + &monitor_region_end))return -EINVAL ; addr_range.start = monitor_region_start; addr_range.end = monitor_region_end;
mm/damon/reclaim.c +2 -35
@@ -229,39 +229,6 @@ module_param(nr_quota_exceeds, ulong, 0400);static struct damon_ctx *ctx;static struct damon_target *target; -struct damon_reclaim_ram_walk_arg { -unsigned long start; -unsigned long end; -}; - -static int walk_system_ram (struct resource *res,void *arg) -{ -struct damon_reclaim_ram_walk_arg *a = arg; - -if (a->end - a->start <resource_size (res)) { - a->start = res->start; - a->end = res->end; - } -return 0 ; -} - -/* -* Find biggest 'System RAM' resource and store its start and end address in -* @start and @end, respectively. If no System RAM is found, returns false. -*/ -static bool get_monitoring_region (unsigned long *start,unsigned long *end) -{ -struct damon_reclaim_ram_walk_arg arg = {}; - -walk_system_ram_res (0 ,ULONG_MAX , &arg, walk_system_ram); -if (arg.end <= arg.start) -return false; - - *start = arg.start; - *end = arg.end; -return true; -} -static struct damos *damon_reclaim_new_scheme (void ) {struct damos_watermarks wmarks = {
@@ -323,8 +290,8 @@ static int damon_reclaim_apply_parameters(void)if (monitor_region_start > monitor_region_end)return -EINVAL ;if (!monitor_region_start && !monitor_region_end && - !get_monitoring_region (&monitor_region_start, - &monitor_region_end)) + !damon_find_biggest_system_ram (&monitor_region_start, + &monitor_region_end))return -EINVAL ; addr_range.start = monitor_region_start; addr_range.end = monitor_region_end;
Signature · 1 line
2.31.0
SeongJae Park
maintainerQuoted 21 lines · On Fri, 9 Sep 2022 10:41:05 +0800 Xin Hao <[email protected]> wrote:
In
lru_sort.candreclaim.c, they are all definingget_monitoring_region()function, there is no need to define it separately.As '
get_monitoring_region()' is not a 'static' function anymore, we try to use a prefix to distinguish with other functions, so there rename it to 'damon_find_biggest_system_ram'.Suggested-by SeongJae Park <[email protected]>Signed-off-by Xin Hao <[email protected]>--- include/linux/damon.h | 11 +++++++++++ mm/damon/core.c | 29 +++++++++++++++++++++++++++++ mm/damon/lru_sort.c | 37 ++----------------------------------- mm/damon/reclaim.c | 37 ++----------------------------------- 4 files changed, 44 insertions(+), 70 deletions(-)include/linux/damon.h +0
-0
include/linux/damon.h struct damon_ctx { · line 452
Quoted 5 lines
include/linux/damon.h +2
-0@@ -448,6 +448,16 @@ struct damon_ctx {struct list_head schemes; }; +/** +* struct damon_system_ram_region - System RAM resource address region of [@start, @end).
I prefer 80 columns, let's break down this line.
https://docs.kernel.org/process/coding-style.html#breaking-long-lines-and-strings
Also this struct is gonna be used by only damon_find_biggest_system_ram(), so I think it might make more sense to move this into core.c.
And, as this is not aimed to directly be used by external API users, I think it would make more sense to hide from kernel doc (/* instead of /**).
include/linux/damon.h struct damon_ctx { · line 453
Quoted 1 line
include/linux/damon.h +1
-0+* @start: Start address of the (inclusive).
of the 'region'?
include/linux/damon.h struct damon_ctx { · line 454
Quoted 1 line
include/linux/damon.h +1
-0+* @end: End address of the region (exclusive).
I like the nice explanation: whether its inclusive or exclusive.
include/linux/damon.h struct damon_ctx { · line 460
Quoted 6 lines
include/linux/damon.h +6
-0+*/ +struct damon_system_ram_region { +unsigned long start; +unsigned long end; +}; +
As this struct is only used by damon_find_biggest_system_ram(), I think it might make more sense to move this into core.c?
Below parts all look good.
Also, this patch seems cannot cleanly applied on top of the latest mm/mm-unstable branch. Would need rebase.
Thanks,
SJ
[...]
SeongJae Park
maintainerAs my previous comments are almost only cosmetic trivial nits and I don't want to make this unnecessarily delayed long, I made the changes on my own and posted it:
https://lore.kernel.org/damon/[email protected]/
Xin, if there was anything I missed or there is anything you disagree about my changes, please let me know.
Thanks,
SJ
Quoted 67 lines · On Fri, 9 Sep 2022 20:45:20 +0000 SeongJae Park <[email protected]> wrote:
Quoted 21 lines · On Fri, 9 Sep 2022 10:41:05 +0800 Xin Hao <[email protected]> wrote:
In
lru_sort.candreclaim.c, they are all definingget_monitoring_region()function, there is no need to define it separately.As '
get_monitoring_region()' is not a 'static' function anymore, we try to use a prefix to distinguish with other functions, so there rename it to 'damon_find_biggest_system_ram'.Suggested-by SeongJae Park <[email protected]>Signed-off-by Xin Hao <[email protected]>--- include/linux/damon.h | 11 +++++++++++ mm/damon/core.c | 29 +++++++++++++++++++++++++++++ mm/damon/lru_sort.c | 37 ++----------------------------------- mm/damon/reclaim.c | 37 ++----------------------------------- 4 files changed, 44 insertions(+), 70 deletions(-)include/linux/damon.h +0
-0include/linux/damon.h struct damon_ctx { · line 452
Quoted 5 lines
include/linux/damon.h +2
-0@@ -448,6 +448,16 @@ struct damon_ctx {struct list_head schemes; }; +/** +* struct damon_system_ram_region - System RAM resource address region of [@start, @end). I prefer 80 columns, let's break down this line.
https://docs.kernel.org/process/coding-style.html#breaking-long-lines-and-stringsAlso this struct is gonna be used by only
damon_find_biggest_system_ram(), so I think it might make more sense to move this intocore.c.And, as this is not aimed to directly be used by external API users, I think it would make more sense to hide from kernel doc (/* instead of /**).
include/linux/damon.h struct damon_ctx { · line 453
Quoted 1 line
include/linux/damon.h +1
-0+* @start: Start address of the (inclusive). of the 'region'?
include/linux/damon.h struct damon_ctx { · line 454
Quoted 1 line
include/linux/damon.h +1
-0+* @end: End address of the region (exclusive). I like the nice explanation: whether its inclusive or exclusive.
include/linux/damon.h struct damon_ctx { · line 460
Quoted 6 lines
include/linux/damon.h +6
-0+*/ +struct damon_system_ram_region { +unsigned long start; +unsigned long end; +}; +As this struct is only used by
damon_find_biggest_system_ram(), I think it might make more sense to move this intocore.c?Below parts all look good.
Also, this patch seems cannot cleanly applied on top of the latest
mm/mm-unstablebranch. Would need rebase.Thanks,
SJ[...]
Quoted 4 lines · SeongJae Park
As my previous comments are almost only cosmetic trivial nits and I don't want to make this unnecessarily delayed long, I made the changes on my own and posted it:
https://lore.kernel.org/damon/[email protected]/
Thanks a lot for your modification,your suggestion is reasonable too.
Quoted 73 lines
Xin, if there was anything I missed or there is anything you disagree about my changes, please let me know.
Thanks,
SJQuoted 63 lines · On Fri, 9 Sep 2022 20:45:20 +0000 SeongJae Park <[email protected]> wrote:
Quoted 21 lines · On Fri, 9 Sep 2022 10:41:05 +0800 Xin Hao <[email protected]> wrote:
In
lru_sort.candreclaim.c, they are all definingget_monitoring_region()function, there is no need to define it separately.As '
get_monitoring_region()' is not a 'static' function anymore, we try to use a prefix to distinguish with other functions, so there rename it to 'damon_find_biggest_system_ram'.Suggested-by SeongJae Park <[email protected]>Signed-off-by Xin Hao <[email protected]>--- include/linux/damon.h | 11 +++++++++++ mm/damon/core.c | 29 +++++++++++++++++++++++++++++ mm/damon/lru_sort.c | 37 ++----------------------------------- mm/damon/reclaim.c | 37 ++----------------------------------- 4 files changed, 44 insertions(+), 70 deletions(-)include/linux/damon.h +0
-0include/linux/damon.h struct damon_ctx { · line 452
Quoted 5 lines
include/linux/damon.h +2
-0@@ -448,6 +448,16 @@ struct damon_ctx {struct list_head schemes; }; +/** +* struct damon_system_ram_region - System RAM resource address region of [@start, @end). I prefer 80 columns, let's break down this line.
https://docs.kernel.org/process/coding-style.html#breaking-long-lines-and-stringsAlso this struct is gonna be used by only
damon_find_biggest_system_ram(), so I think it might make more sense to move this intocore.c.And, as this is not aimed to directly be used by external API users, I think it would make more sense to hide from kernel doc (/* instead of /**).
include/linux/damon.h struct damon_ctx { · line 453
Quoted 1 line
include/linux/damon.h +1
-0+* @start: Start address of the (inclusive). of the 'region'?
include/linux/damon.h struct damon_ctx { · line 454
Quoted 1 line
include/linux/damon.h +1
-0+* @end: End address of the region (exclusive). I like the nice explanation: whether its inclusive or exclusive.
include/linux/damon.h struct damon_ctx { · line 460
Quoted 6 lines
include/linux/damon.h +6
-0+*/ +struct damon_system_ram_region { +unsigned long start; +unsigned long end; +}; +As this struct is only used by
damon_find_biggest_system_ram(), I think it might make more sense to move this intocore.c?Below parts all look good.
Also, this patch seems cannot cleanly applied on top of the latest
mm/mm-unstablebranch. Would need rebase.Thanks,
SJ[...]