[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20250403134013749X6VVdhQope3TRpBQF_qia@zte.com.cn>
Date: Thu, 3 Apr 2025 13:40:13 +0800 (CST)
From: <xu.xin16@....com.cn>
To: <akpm@...ux-foundation.org>, <mhocko@...nel.org>
Cc: <hannes@...xchg.org>, <roman.gushchin@...ux.dev>, <muchun.song@...ux.dev>,
<shakeel.butt@...ux.dev>, <cgroups@...r.kernel.org>,
<linux-mm@...ck.org>, <linux-kernel@...r.kernel.org>,
<yang.yang29@....com.cn>, <chen.haonan2@....com.cn>,
<wang.yaxin@....com.cn>, <xu.xin16@....com.cn>
Subject: [PATCH linux-next 6/6] memcontrol-v1: add ksm_profit in cgroup/memory.ksm_stat
From: xu xin <xu.xin16@....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@....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 b52f728af963..3e7a653e3df1 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.15.2
Powered by blists - more mailing lists