[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250914180543238RmGhd2wFVDA1pXX_I9Rrb@zte.com.cn>
Date: Sun, 14 Sep 2025 18:05:43 +0800 (CST)
From: <xu.xin16@....com.cn>
To: <akpm@...ux-foundation.org>
Cc: <akpm@...ux-foundation.org>, <shakeel.butt@...ux.dev>,
<hannes@...xchg.org>, <mhocko@...nel.org>, <roman.gushchin@...ux.dev>,
<david@...hat.com>, <chengming.zhou@...ux.dev>,
<muchun.song@...ux.dev>, <linux-kernel@...r.kernel.org>,
<linux-mm@...ck.org>, <cgroups@...r.kernel.org>, <xu.xin16@....com.cn>
Subject: [PATCH v2 2/5] memcg: show ksm_zero_pages count in memory.stat
From: xu xin <xu.xin16@....com.cn>
Users can obtain ksm_zero_pages of a cgroup just by:
'cat /sys/fs/cgroup/memory.stat | grep ksm_zero_pages
Signed-off-by: xu xin <xu.xin16@....com.cn>
---
mm/ksm.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/mm/ksm.c b/mm/ksm.c
index b533f0edaf96..5832159214f8 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -3311,6 +3311,7 @@ long ksm_process_profit(struct mm_struct *mm)
#ifdef CONFIG_MEMCG
struct memcg_ksm_stat {
unsigned long ksm_rmap_items;
+ long ksm_zero_pages;
};
static int evaluate_memcg_ksm_stat(struct task_struct *task, void *arg)
@@ -3321,6 +3322,7 @@ static int evaluate_memcg_ksm_stat(struct task_struct *task, void *arg)
mm = get_task_mm(task);
if (mm) {
ksm_stat->ksm_rmap_items += mm->ksm_rmap_items;
+ ksm_stat->ksm_zero_pages += mm_ksm_zero_pages(mm);
mmput(mm);
}
@@ -3335,14 +3337,17 @@ void memcg_stat_ksm_show(struct mem_cgroup *memcg, struct seq_buf *s)
if (mem_cgroup_is_root(memcg)) {
/* Just use the global counters when root memcg */
ksm_stat.ksm_rmap_items = ksm_rmap_items;
+ ksm_stat.ksm_zero_pages = atomic_long_read(&ksm_zero_pages);
} else {
/* Initialization */
ksm_stat.ksm_rmap_items = 0;
+ ksm_stat.ksm_zero_pages = 0;
/* Summing all processes'ksm statistic items */
mem_cgroup_scan_tasks(memcg, evaluate_memcg_ksm_stat, &ksm_stat);
}
/* Print memcg ksm statistic items */
seq_buf_printf(s, "ksm_rmap_items %lu\n", ksm_stat.ksm_rmap_items);
+ seq_buf_printf(s, "ksm_zero_pages %lu\n", ksm_stat.ksm_zero_pages);
}
#endif
--
2.25.1
Powered by blists - more mailing lists