From: <xu.xin16@zte.com.cn>
To: <akpm@linux-foundation.org>
Cc: <akpm@linux-foundation.org>, <shakeel.butt@linux.dev>,
<hannes@cmpxchg.org>, <mhocko@kernel.org>,
<roman.gushchin@linux.dev>, <david@redhat.com>,
<chengming.zhou@linux.dev>, <muchun.song@linux.dev>,
<linux-kernel@vger.kernel.org>, <linux-mm@kvack.org>,
<cgroups@vger.kernel.org>, <xu.xin16@zte.com.cn>
Subject: [PATCH v2 2/5] memcg: show ksm_zero_pages count in memory.stat
Date: Sun, 14 Sep 2025 18:05:43 +0800 (CST) [thread overview]
Message-ID: <20250914180543238RmGhd2wFVDA1pXX_I9Rrb@zte.com.cn> (raw)
In-Reply-To: <20250914180031197jk6ngo5pQjpXkNtNsjzSo@zte.com.cn>
From: xu xin <xu.xin16@zte.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@zte.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
next prev parent reply other threads:[~2025-09-14 10:06 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-14 10:00 [PATCH v2 0/5] memcg: Support per-memcg KSM metrics xu.xin16
2025-09-14 10:03 ` [PATCH v2 1/5] memcg: add per-memcg ksm_rmap_items stat xu.xin16
2025-09-14 13:54 ` kernel test robot
2025-09-14 10:05 ` xu.xin16 [this message]
2025-09-14 10:06 ` [PATCH v2 3/5] memcg: show ksm_merging_pages in memory.stat xu.xin16
2025-09-14 10:07 ` [PATCH v2 4/5] memcg: add per-memcg ksm_profit xu.xin16
2025-09-14 13:02 ` kernel test robot
2025-09-14 10:09 ` [PATCH v2 5/5] Documentation: add KSM statistic counters description in cgroup-v2.rst xu.xin16
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=20250914180543238RmGhd2wFVDA1pXX_I9Rrb@zte.com.cn \
--to=xu.xin16@zte.com.cn \
--cc=akpm@linux-foundation.org \
--cc=cgroups@vger.kernel.org \
--cc=chengming.zhou@linux.dev \
--cc=david@redhat.com \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=muchun.song@linux.dev \
--cc=roman.gushchin@linux.dev \
--cc=shakeel.butt@linux.dev \
/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