mm/damon: Do some small changes
Subsystems (3)
PATCH v4 1/4 mm/damon: Unified access_check function naming rules
In reply to Xin HaoIn damon/paddr.c file, two functions names start with underscore,
static void __damon_pa_prepare_access_check(struct damon_ctx *ctx,
struct damon_region *r)
static void __damon_pa_prepare_access_check(struct damon_ctx *ctx,
struct damon_region *r)
In damon/vaddr.c file, there are also two functions with the same function,
static void damon_va_prepare_access_check(struct damon_ctx *ctx,
struct mm_struct *mm, struct damon_region *r)
static void damon_va_check_access(struct damon_ctx *ctx,
struct mm_struct *mm, struct damon_region *r)
It makes sense to keep consistent, and it is not easy to be confused with the function that call them.
--- mm/damon/vaddr.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
mm/damon/vaddr.c +4 -4
@@ -409,7 +409,7 @@ static void damon_va_mkold(struct mm_struct *mm, unsigned long addr)* Functions for the access checking of the regions */ -static void damon_va_prepare_access_check (struct damon_ctx *ctx, +static void __damon_va_prepare_access_check (struct damon_ctx *ctx,struct mm_struct *mm,struct damon_region *r) { r->sampling_addr =damon_rand (r->ar.start, r->ar.end);
@@ -428,7 +428,7 @@ void damon_va_prepare_access_checks(struct damon_ctx *ctx)if (!mm)continue ;damon_for_each_region (r, t) -damon_va_prepare_access_check (ctx, mm, r); +__damon_va_prepare_access_check (ctx, mm, r);mmput (mm); } }
@@ -514,7 +514,7 @@ static bool damon_va_young(struct mm_struct *mm, unsigned long addr,* mm 'mm_struct' for the given virtual address space * r the region to be checked */ -static void damon_va_check_access (struct damon_ctx *ctx, +static void __damon_va_check_access (struct damon_ctx *ctx,struct mm_struct *mm,struct damon_region *r) {static struct mm_struct *last_mm;
@@ -550,7 +550,7 @@ unsigned int damon_va_check_accesses(struct damon_ctx *ctx)if (!mm)continue ;damon_for_each_region (r, t) { -damon_va_check_access (ctx, mm, r); +__damon_va_check_access (ctx, mm, r); max_nr_accesses =max (r->nr_accesses, max_nr_accesses); }mmput (mm);
Signature · 1 line
2.31.0
v4 cover mm/damon: Do some small changes
V3 -> V4
Fix kernel test compile warning of patch[4]
V2 -> V3
Fix commit information patch[2], as suggested by SeongJae Park Add reviewed by SeongJae Park
https://lore.kernel.org/linux-mm/[email protected]/
V1 -> V2
Add reviewed by SeongJae Park
Add two new patches
V1:
https://lore.kernel.org/linux-mm/[email protected]/
Xin Hao (4):
mm/damon: Unified access_check function naming rules mm/damon: Add 'age' of region tracepoint support mm/damon/core: Using function abs() instead of diff_of() mm/damon: Remove some no need func definitions in damon.h file
include/linux/damon.h | 25 ++----------------------- include/trace/events/damon.h | 7 +++++-- mm/damon/core.c | 6 ++---- mm/damon/paddr.c | 8 ++++---- mm/damon/vaddr.c | 20 ++++++++++---------- 5 files changed, 23 insertions(+), 43 deletions(-)
--
2.31.0
PATCH v4 2/4 mm/damon: Add 'age' of region tracepoint support
In Damon, we can get age information by analyzing the nr_access change, But short time sampling is not effective, we have to obtain enough data for analysis through long time trace, this also means that we need to consume more cpu resources and storage space.
Now the region add a new 'age' variable, we only need to get the change of age value through a little time trace, for example, age has been increasing to 141, but nr_access shows a value of 0 at the same time, Through this,we can conclude that the region has a very low nr_access value for a long time.
--- include/trace/events/damon.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
include/trace/events/damon.h +5 -2
@@ -22,6 +22,7 @@ TRACE_EVENT(damon_aggregated, __field(unsigned long, start) __field(unsigned long, end) __field(unsigned int, nr_accesses) + __field(unsigned int, age) ), TP_fast_assign(
@@ -30,11 +31,13 @@ TRACE_EVENT(damon_aggregated, __entry->start = r->ar.start; __entry->end = r->ar.end; __entry->nr_accesses = r->nr_accesses; + __entry->age = r->age; ), -TP_printk ("target_id=%lu nr_regions=%u %lu-%lu: %u" , +TP_printk ("target_id=%lu nr_regions=%u %lu-%lu: %u %u" , __entry->target_id, __entry->nr_regions, - __entry->start, __entry->end, __entry->nr_accesses) + __entry->start, __entry->end, + __entry->nr_accesses, __entry->age) );#endif /* _TRACE_DAMON_H */
--
2.31.0
PATCH v4 3/4 mm/damon/core: Using function abs() instead of diff_of()
In reply to Xin HaoIn kernel, we can use abs(a - b) to get the absolute value, So there is no need to redefine a new one.
--- mm/damon/core.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
mm/damon/core.c +2 -4
@@ -757,8 +757,6 @@ static void damon_merge_two_regions(struct damon_target *t,damon_destroy_region (r, t); } -#define diff_of (a, b) (a > b ? a - b : b - a) -/* * Merge adjacent regions having similar access frequencies *
@@ -772,13 +770,13 @@ static void damon_merge_regions_of(struct damon_target *t, unsigned int thres,struct damon_region *r, *prev =NULL , *next;damon_for_each_region_safe (r, next, t) { -if (diff_of (r->nr_accesses, r->last_nr_accesses) > thres) +if (abs (r->nr_accesses - r->last_nr_accesses) > thres) r->age =0 ;else r->age++;if (prev && prev->ar.end == r->ar.start && -diff_of (prev->nr_accesses, r->nr_accesses) <= thres && +abs (prev->nr_accesses - r->nr_accesses) <= thres &&sz_damon_region (prev) +sz_damon_region (r) <= sz_limit)damon_merge_two_regions (t, prev, r);else
Signature · 1 line
2.31.0
PATCH v4 4/4 mm/damon: Remove some no need func definitions in damon.h file
In reply to Xin HaoIn the damon.h header file, some func definitions about VA & PA can only be used in its own file, so there no need to define in the header file, and the header file will looks cleaner.
If other files later call these functions, then put them to the header file will not be late.
--- include/linux/damon.h | 25 ++----------------------- mm/damon/paddr.c | 8 ++++---- mm/damon/vaddr.c | 12 ++++++------ 3 files changed, 12 insertions(+), 33 deletions(-)
include/linux/damon.h +2 -23
@@ -461,34 +461,13 @@ int damon_stop(struct damon_ctx **ctxs, int nr_ctxs);#endif /* CONFIG_DAMON */ #ifdef CONFIG_DAMON_VADDR - -/* Monitoring primitives for virtual memory address spaces */ -void damon_va_init (struct damon_ctx *ctx); -void damon_va_update (struct damon_ctx *ctx); -void damon_va_prepare_access_checks (struct damon_ctx *ctx); -unsigned int damon_va_check_accesses (struct damon_ctx *ctx); -bool damon_va_target_valid (void *t); -void damon_va_cleanup (struct damon_ctx *ctx); -int damon_va_apply_scheme (struct damon_ctx *context,struct damon_target *t, -struct damon_region *r,struct damos *scheme); -int damon_va_scheme_score (struct damon_ctx *context,struct damon_target *t, -struct damon_region *r,struct damos *scheme);void damon_va_set_primitives (struct damon_ctx *ctx); - +bool damon_va_target_valid (void *t);#endif /* CONFIG_DAMON_VADDR */ #ifdef CONFIG_DAMON_PADDR - -/* Monitoring primitives for the physical memory address space */ -void damon_pa_prepare_access_checks (struct damon_ctx *ctx); -unsigned int damon_pa_check_accesses (struct damon_ctx *ctx); -bool damon_pa_target_valid (void *t); -int damon_pa_apply_scheme (struct damon_ctx *context,struct damon_target *t, -struct damon_region *r,struct damos *scheme); -int damon_pa_scheme_score (struct damon_ctx *context,struct damon_target *t, -struct damon_region *r,struct damos *scheme);void damon_pa_set_primitives (struct damon_ctx *ctx); - +bool damon_pa_target_valid (void *t);#endif /* CONFIG_DAMON_PADDR */ #endif /* _DAMON_H */
mm/damon/paddr.c +4 -4
@@ -73,7 +73,7 @@ static void __damon_pa_prepare_access_check(struct damon_ctx *ctx,damon_pa_mkold (r->sampling_addr); } -void damon_pa_prepare_access_checks (struct damon_ctx *ctx) +static void damon_pa_prepare_access_checks (struct damon_ctx *ctx) {struct damon_target *t;struct damon_region *r;
@@ -192,7 +192,7 @@ static void __damon_pa_check_access(struct damon_ctx *ctx, last_addr = r->sampling_addr; } -unsigned int damon_pa_check_accesses (struct damon_ctx *ctx) +static unsigned int damon_pa_check_accesses (struct damon_ctx *ctx) {struct damon_target *t;struct damon_region *r;
@@ -213,7 +213,7 @@ bool damon_pa_target_valid(void *t)return true; } -int damon_pa_apply_scheme (struct damon_ctx *ctx,struct damon_target *t, +static int damon_pa_apply_scheme (struct damon_ctx *ctx,struct damon_target *t,struct damon_region *r,struct damos *scheme) {unsigned long addr;
@@ -246,7 +246,7 @@ int damon_pa_apply_scheme(struct damon_ctx *ctx, struct damon_target *t,return 0 ; } -int damon_pa_scheme_score (struct damon_ctx *context,struct damon_target *t, +static int damon_pa_scheme_score (struct damon_ctx *context,struct damon_target *t,struct damon_region *r,struct damos *scheme) {switch (scheme->action) {
mm/damon/vaddr.c +6 -6
@@ -271,7 +271,7 @@ static void __damon_va_init_regions(struct damon_ctx *ctx, }/* Initialize '->regions_list' of every target (task) */ -void damon_va_init (struct damon_ctx *ctx) +static void damon_va_init (struct damon_ctx *ctx) {struct damon_target *t;
@@ -355,7 +355,7 @@ static void damon_va_apply_three_regions(struct damon_target *t,/* * Update regions for current memory mappings */ -void damon_va_update (struct damon_ctx *ctx) +static void damon_va_update (struct damon_ctx *ctx) {struct damon_addr_range three_regions[3 ];struct damon_target *t;
@@ -417,7 +417,7 @@ static void __damon_va_prepare_access_check(struct damon_ctx *ctx,damon_va_mkold (mm, r->sampling_addr); } -void damon_va_prepare_access_checks (struct damon_ctx *ctx) +static void damon_va_prepare_access_checks (struct damon_ctx *ctx) {struct damon_target *t;struct mm_struct *mm;
@@ -538,7 +538,7 @@ static void __damon_va_check_access(struct damon_ctx *ctx, last_addr = r->sampling_addr; } -unsigned int damon_va_check_accesses (struct damon_ctx *ctx) +static unsigned int damon_va_check_accesses (struct damon_ctx *ctx) {struct damon_target *t;struct mm_struct *mm;
@@ -602,7 +602,7 @@ static int damos_madvise(struct damon_target *target, struct damon_region *r, }#endif /* CONFIG_ADVISE_SYSCALLS */ -int damon_va_apply_scheme (struct damon_ctx *ctx,struct damon_target *t, +static int damon_va_apply_scheme (struct damon_ctx *ctx,struct damon_target *t,struct damon_region *r,struct damos *scheme) {int madv_action;
@@ -633,7 +633,7 @@ int damon_va_apply_scheme(struct damon_ctx *ctx, struct damon_target *t,return damos_madvise (t, r, madv_action); } -int damon_va_scheme_score (struct damon_ctx *context,struct damon_target *t, +static int damon_va_scheme_score (struct damon_ctx *context,struct damon_target *t,struct damon_region *r,struct damos *scheme) {
--
2.31.0