From: xu xin <xu.xin.sc@gmail.com>
To: xu.xin16@zte.com.cn
Cc: akpm@linux-foundation.org, david@redhat.com,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, wang.yaxin@zte.com.cn,
yang.yang29@zte.com.cn
Subject: [PATCH RESEND 6/6] memcontrol-v1: add ksm_profit in cgroup/memory.ksm_stat
Date: Tue, 22 Apr 2025 11:22:51 +0000 [thread overview]
Message-ID: <20250422112251.3231599-1-xu.xin16@zte.com.cn> (raw)
In-Reply-To: <20250422191407770210-193JBD0Fgeu5zqE2K@zte.com.cn>
Users can obtain ksm_profit of a cgroup just by:
/ # cat /sys/fs/cgroup/memory.ksm_stat
ksm_rmap_items 76800
ksm_zero_pages 0
ksm_merging_pages 76800
ksm_profit 309657600
Current implementation supports cgroup v1 temporarily; cgroup v2
compatibility is planned for future versions.
Signed-off-by: xu xin <xu.xin16@zte.com.cn>
---
mm/memcontrol-v1.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/mm/memcontrol-v1.c b/mm/memcontrol-v1.c
index 7ee38d633d85..2cf2823c5514 100644
--- a/mm/memcontrol-v1.c
+++ b/mm/memcontrol-v1.c
@@ -1827,6 +1827,7 @@ struct memcg_ksm_stat {
unsigned long ksm_rmap_items;
long ksm_zero_pages;
unsigned long ksm_merging_pages;
+ long ksm_profit;
};
static int evaluate_memcg_ksm_stat(struct task_struct *task, void *arg)
@@ -1839,6 +1840,7 @@ static int evaluate_memcg_ksm_stat(struct task_struct *task, void *arg)
ksm_stat->ksm_rmap_items += mm->ksm_rmap_items;
ksm_stat->ksm_zero_pages += mm_ksm_zero_pages(mm);
ksm_stat->ksm_merging_pages += mm->ksm_merging_pages;
+ ksm_stat->ksm_profit += ksm_process_profit(mm);
mmput(mm);
}
@@ -1854,6 +1856,7 @@ static int memcg_ksm_stat_show(struct seq_file *m, void *v)
ksm_stat.ksm_rmap_items = 0;
ksm_stat.ksm_zero_pages = 0;
ksm_stat.ksm_merging_pages = 0;
+ ksm_stat.ksm_profit = 0;
/* summing all processes'ksm statistic items of this cgroup hierarchy */
mem_cgroup_scan_tasks(memcg, evaluate_memcg_ksm_stat, &ksm_stat);
@@ -1861,6 +1864,7 @@ static int memcg_ksm_stat_show(struct seq_file *m, void *v)
seq_printf(m, "ksm_rmap_items %lu\n", ksm_stat.ksm_rmap_items);
seq_printf(m, "ksm_zero_pages %ld\n", ksm_stat.ksm_zero_pages);
seq_printf(m, "ksm_merging_pages %ld\n", ksm_stat.ksm_merging_pages);
+ seq_printf(m, "ksm_profit %ld\n", ksm_stat.ksm_profit);
return 0;
}
--
2.39.3
next prev parent reply other threads:[~2025-04-22 11:23 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-22 11:14 [PATCH RESEND 0/6] support ksm_stat showing at cgroup level xu.xin16
2025-04-22 11:19 ` [PATCH RESEND 1/6] memcontrol: rename mem_cgroup_scan_tasks() xu xin
2025-04-22 23:29 ` Andrew Morton
2025-04-23 12:22 ` Matthew Wilcox
2025-04-25 14:30 ` Michal Hocko
2025-04-22 11:20 ` [PATCH RESEND 2/6] memcontrol: introduce the new mem_cgroup_scan_tasks() xu xin
2025-04-22 11:21 ` [PATCH RESEND 3/6] memcontrol-v1: introduce ksm_stat at cgroup level xu xin
2025-04-22 11:21 ` [PATCH RESEND 4/6] memcontrol-v1: add ksm_zero_pages in cgroup/memory.ksm_stat xu xin
2025-04-22 11:22 ` [PATCH RESEND 5/6] memcontrol-v1: add ksm_merging_pages " xu xin
2025-04-22 11:22 ` xu xin [this message]
2025-04-23 8:21 ` [PATCH RESEND 6/6] memcontrol-v1: add ksm_profit " kernel test robot
2025-04-23 13:08 ` [PATCH RESEND 0/6] support ksm_stat showing at cgroup level David Hildenbrand
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250422112251.3231599-1-xu.xin16@zte.com.cn \
--to=xu.xin.sc@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=david@redhat.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=wang.yaxin@zte.com.cn \
--cc=xu.xin16@zte.com.cn \
--cc=yang.yang29@zte.com.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox