Message ID | 20220824124615.223158-1-xu.xin16@zte.com.cn (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | ksm: count allocated rmap_items and update documentation | expand |
On Wed, Aug 24, 2022 at 12:46:15PM +0000, xu xin wrote: > #ifdef CONFIG_KSM > ONE("ksm_merging_pages", S_IRUSR, proc_pid_ksm_merging_pages), > + ONE("ksm_rmp_items", S_IRUSR, proc_pid_ksm_rmp_items), You misspelled "rmap" in the file name. > + /* > + * Represent how many pages are checked for ksm merging > + * including merged and not merged. > + */ > + unsigned long ksm_rmp_items; Also here.
On Wed, Aug 24, 2022 at 12:46:15PM +0000, xu xin wrote: > +static int proc_pid_ksm_rmp_items(struct seq_file *m, struct pid_namespace *ns, > + struct pid *pid, struct task_struct *task) > +{ > + struct mm_struct *mm; > + > + mm = get_task_mm(task); > + if (mm) { > + seq_printf(m, "%lu\n", mm->ksm_rmp_items); > + mmput(mm); > + } > + > + return 0; > +} > #endif /* CONFIG_KSM */ > > #ifdef CONFIG_STACKLEAK_METRICS > @@ -3334,6 +3347,7 @@ static const struct pid_entry tgid_base_stuff[] = { > #endif > #ifdef CONFIG_KSM > ONE("ksm_merging_pages", S_IRUSR, proc_pid_ksm_merging_pages), > + ONE("ksm_rmp_items", S_IRUSR, proc_pid_ksm_rmp_items), > #endif Another tiny /proc/$pid/ file? Guys, this problem with "find /proc" instantiating megabytes is not getting better only worse. How did KSM didn't get its own /proc/*/ksm file with many values? Maybe add /proc/*/ksm and start filling it with stuff leaving /proc/*/ksm_merging_pages alone?
diff --git a/fs/proc/base.c b/fs/proc/base.c index 4ead8cf654e4..9977e17885c2 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -3199,6 +3199,19 @@ static int proc_pid_ksm_merging_pages(struct seq_file *m, struct pid_namespace * return 0; } +static int proc_pid_ksm_rmp_items(struct seq_file *m, struct pid_namespace *ns, + struct pid *pid, struct task_struct *task) +{ + struct mm_struct *mm; + + mm = get_task_mm(task); + if (mm) { + seq_printf(m, "%lu\n", mm->ksm_rmp_items); + mmput(mm); + } + + return 0; +} #endif /* CONFIG_KSM */ #ifdef CONFIG_STACKLEAK_METRICS @@ -3334,6 +3347,7 @@ static const struct pid_entry tgid_base_stuff[] = { #endif #ifdef CONFIG_KSM ONE("ksm_merging_pages", S_IRUSR, proc_pid_ksm_merging_pages), + ONE("ksm_rmp_items", S_IRUSR, proc_pid_ksm_rmp_items), #endif }; @@ -3671,6 +3685,7 @@ static const struct pid_entry tid_base_stuff[] = { #endif #ifdef CONFIG_KSM ONE("ksm_merging_pages", S_IRUSR, proc_pid_ksm_merging_pages), + ONE("ksm_rmp_items", S_IRUSR, proc_pid_ksm_rmp_items), #endif }; diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index d6ec33438dc1..a2a8da1ccb31 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -656,6 +656,11 @@ struct mm_struct { * merging. */ unsigned long ksm_merging_pages; + /* + * Represent how many pages are checked for ksm merging + * including merged and not merged. + */ + unsigned long ksm_rmp_items; #endif #ifdef CONFIG_LRU_GEN struct { diff --git a/mm/ksm.c b/mm/ksm.c index a98bc3beb874..66d686039010 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -387,6 +387,7 @@ static inline struct rmap_item *alloc_rmap_item(void) static inline void free_rmap_item(struct rmap_item *rmap_item) { ksm_rmap_items--; + rmap_item->mm->ksm_rmp_items--; rmap_item->mm = NULL; /* debug safety */ kmem_cache_free(rmap_item_cache, rmap_item); } @@ -2231,6 +2232,7 @@ static struct rmap_item *get_next_rmap_item(struct mm_slot *mm_slot, if (rmap_item) { /* It has already been zeroed */ rmap_item->mm = mm_slot->mm; + rmap_item->mm->ksm_rmp_items++; rmap_item->address = addr; rmap_item->rmap_list = *rmap_list; *rmap_list = rmap_item;