mm/damon: Remove duplicate get_monitoring_region() definitions
Subsystems (2)
PATCH v3 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.
BTW, this patch removes two struct 'damon_lru_sort_ram_walk_arg' and 'damon_reclaim_ram_walk_arg', though the two structs are removed, if we want to add more fields to these structs for other purposes later, it will not too late for us to use them again.
For example:
struct damon_reclaim_ram_walk_arg {
struct damon_addr_range raw_walk;
xxx A;
xxx B;
}
struct damon_lru_sort_ram_walk_arg {
struct damon_addr_range raw_walk;
xxx A;
xxx B;
}--- include/linux/damon.h | 1 + mm/damon/core.c | 28 ++++++++++++++++++++++++++++ mm/damon/lru_sort.c | 37 ++----------------------------------- mm/damon/reclaim.c | 37 ++----------------------------------- 4 files changed, 33 insertions(+), 70 deletions(-)
include/linux/damon.h +1 -0
@@ -500,6 +500,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_get_sram_monitoring_region (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 +28 -0
@@ -276,6 +276,34 @@ struct damos *damon_new_scheme(return scheme; } +static inline int walk_system_ram (struct resource *res,void *arg) +{ +struct damon_addr_range *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_get_sram_monitoring_region (unsigned long *start,unsigned long *end) +{ +struct damon_addr_range 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_get_sram_monitoring_region (&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_get_sram_monitoring_region (&monitor_region_start, + &monitor_region_end))return -EINVAL ; addr_range.start = monitor_region_start; addr_range.end = monitor_region_end;
--
2.31.0
SeongJae Park
maintainerHi Xin,
Thanks for your efforts! But, please answer to some more comments below.
Quoted 8 lines
In
lru_sort.candreclaim.c, they are all definingget_monitoring_region()function, there is no need to define it separately.BTW, this patch removes two struct '
damon_lru_sort_ram_walk_arg' and 'damon_reclaim_ram_walk_arg', though the two structs are removed, if we want to add more fields to these structs for other purposes later, it will not too late for us to use them again.
For example:
Quoted 10 lines
struct damon_reclaim_ram_walk_arg {
struct damon_addr_range raw_walk;
xxx A;
xxx B;
}
struct damon_lru_sort_ram_walk_arg {
struct damon_addr_range raw_walk;
xxx A;
xxx B;
}Sorry, seems I didn't make my words clear enough. What I'm concerning[1] is, any possible future change to 'struct damon_addr_range', not to 'struct damon_{reclaim,lru_sort}_ram_walk_arg'.
Also, after all, as mentioned before, the purpose of 'struct damon_addr_range' is not saving the 'start' and 'end' fields of 'struct resource'. Let's use different types for different purposes to avoid any unneeded dependencies.
[1] https://lore.kernel.org/damon/[email protected]/
Quoted 26 lines
Signed-off-by Xin Hao <[email protected]>--- include/linux/damon.h | 1 + mm/damon/core.c | 28 ++++++++++++++++++++++++++++ mm/damon/lru_sort.c | 37 ++----------------------------------- mm/damon/reclaim.c | 37 ++----------------------------------- 4 files changed, 33 insertions(+), 70 deletions(-)include/linux/damon.h +1
-0@@ -500,6 +500,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_get_sram_monitoring_region (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 +0
-0
mm/damon/core.c struct damos *damon_new_scheme( · line 279
Quoted 4 lines
mm/damon/core.c +1
-0@@ -276,6 +276,34 @@ struct damos *damon_new_scheme(return scheme; } +static inline int walk_system_ram (struct resource *res,void *arg)
We will pass pointer to this function. I guess 'inline' makes no sense?
Quoted 5 lines
mm/damon/core.c +5
-0+{ +struct damon_addr_range *a = arg; + +if (a->end - a->start <resource_size (res)) { + a->start = res->start;
mm/damon/core.c struct damos *damon_new_scheme( · line 294
Quoted 10 lines
mm/damon/core.c +10
-0+ 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_get_sram_monitoring_region (unsigned long *start,unsigned long *end)
We should avoid too verbose name, so 'sram' looks nice, but it might be able to be more clear to let readers know what it does. For an example, how about 'damon_find_biggest_system_ram()'?
Below parts all look good.
Thanks,
SJ
[...]
Quoted 23 lines · SeongJae Park
Hi Xin,
Thanks for your efforts! But, please answer to some more comments below.
Quoted 8 lines
In
lru_sort.candreclaim.c, they are all definingget_monitoring_region()function, there is no need to define it separately.BTW, this patch removes two struct '
damon_lru_sort_ram_walk_arg' and 'damon_reclaim_ram_walk_arg', though the two structs are removed, if we want to add more fields to these structs for other purposes later, it will not too late for us to use them again.
For example:Quoted 10 lines
struct damon_reclaim_ram_walk_arg { struct damon_addr_range raw_walk; xxx A; xxx B; } struct damon_lru_sort_ram_walk_arg { struct damon_addr_range raw_walk; xxx A; xxx B; }
Quoted 7 lines
Sorry, seems I didn't make my words clear enough. What I'm concerning[1] is, any possible future change to 'struct
damon_addr_range', not to 'struct damon_{reclaim,lru_sort}_ram_walk_arg'.Also, after all, as mentioned before, the purpose of 'struct
damon_addr_range' is not saving the 'start' and 'end' fields of 'struct resource'. Let's use different types for different purposes to avoid any unneeded dependencies.
Ok, i will define another struct.
Quoted 31 lines
[1] https://lore.kernel.org/damon/[email protected]/
Quoted 28 lines
Signed-off-by Xin Hao <[email protected]>--- include/linux/damon.h | 1 + mm/damon/core.c | 28 ++++++++++++++++++++++++++++ mm/damon/lru_sort.c | 37 ++----------------------------------- mm/damon/reclaim.c | 37 ++----------------------------------- 4 files changed, 33 insertions(+), 70 deletions(-)include/linux/damon.h +1
-0@@ -500,6 +500,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_get_sram_monitoring_region (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 +0
-0@@ -276,6 +276,34 @@ struct damos *damon_new_scheme(return scheme; }
Quoted 2 lines
mm/damon/core.c struct damos *damon_new_scheme( · line 279
Quoted 1 line
mm/damon/core.c +1
-0+static inline int walk_system_ram (struct resource *res,void *arg)We will pass pointer to this function. I guess 'inline' makes no sense?
Ok, i will remove it.
Quoted 10 lines
Quoted 10 lines
mm/damon/core.c +10
-0+{ +struct damon_addr_range *a = arg; + +if (a->end - a->start <resource_size (res)) { + a->start = res->start; + a->end = res->end; + } +return 0 ; +} +
Quoted 8 lines
mm/damon/core.c struct damos *damon_new_scheme( · line 294
Quoted 5 lines
mm/damon/core.c +5
-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_get_sram_monitoring_region (unsigned long *start,unsigned long *end)We should avoid too verbose name, so 'sram' looks nice, but it might be able to be more clear to let readers know what it does. For an example, how about '
damon_find_biggest_system_ram()'?
Ok.
Quoted 8 lines
Below parts all look good.
Thanks,
SJ[...]