[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250501041647.3324541-1-xu.xin16@zte.com.cn>
Date: Thu, 1 May 2025 04:16:47 +0000
From: xu.xin.sc@...il.com
To: xu.xin16@....com.cn
Cc: akpm@...ux-foundation.org,
david@...hat.com,
linux-fsdevel@...r.kernel.org,
linux-kernel@...r.kernel.org,
linux-mm@...ck.org,
wang.yaxin@....com.cn,
yang.yang29@....com.cn
Subject: [PATCH v2 7/9] memcontrol-v1: add ksm_stat at memcg-v1
From: xu xin <xu.xin16@....com.cn>
With the enablement of container-level KSM (e.g., via prctl), there is a
growing demand for container-level observability of KSM behavior. However,
current cgroup implementations lack support for exposing KSM-related
metrics.
This patch introduces a new interface named ksm_stat
at the cgroup hierarchy level, enabling users to monitor KSM merging
statistics specifically for containers where this feature has been
activated, eliminating the need to manually inspect KSM information for
each individual process within the cgroup-v1.
Since the implementation of ksm_stat has been added into memcg-v2, this
just add it back to memcg-v1 with the same function of traversing the
process of the memcg.
Users can obtain the KSM information of a cgroup just by:
`cat /sys/fs/cgroup/memory.ksm_stat`
Signed-off-by: xu xin <xu.xin16@....com.cn>
---
include/linux/memcontrol.h | 7 +++++++
mm/memcontrol-v1.c | 6 ++++++
mm/memcontrol.c | 2 +-
3 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index f9d663a7ccde..880ed3619f57 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -939,6 +939,8 @@ unsigned long lruvec_page_state(struct lruvec *lruvec, enum node_stat_item idx);
unsigned long lruvec_page_state_local(struct lruvec *lruvec,
enum node_stat_item idx);
+int memcg_ksm_stat_show(struct seq_file *m, void *v);
+
void mem_cgroup_flush_stats(struct mem_cgroup *memcg);
void mem_cgroup_flush_stats_ratelimited(struct mem_cgroup *memcg);
@@ -1415,6 +1417,11 @@ static inline unsigned long lruvec_page_state_local(struct lruvec *lruvec,
return node_page_state(lruvec_pgdat(lruvec), idx);
}
+static inline int memcg_ksm_stat_show(struct seq_file *m, void *v)
+{
+ return 0;
+}
+
static inline void mem_cgroup_flush_stats(struct mem_cgroup *memcg)
{
}
diff --git a/mm/memcontrol-v1.c b/mm/memcontrol-v1.c
index 4a9cf27a70af..0891ae3dae78 100644
--- a/mm/memcontrol-v1.c
+++ b/mm/memcontrol-v1.c
@@ -2079,6 +2079,12 @@ struct cftype mem_cgroup_legacy_files[] = {
.name = "numa_stat",
.seq_show = memcg_numa_stat_show,
},
+#endif
+#ifdef CONFIG_KSM
+ {
+ .name = "ksm_stat",
+ .seq_show = memcg_ksm_stat_show,
+ },
#endif
{
.name = "kmem.limit_in_bytes",
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 8ab21420ebb8..cf4e9d47bb40 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -4414,7 +4414,7 @@ static int evaluate_memcg_ksm_stat(struct task_struct *task, void *arg)
return 0;
}
-static int memcg_ksm_stat_show(struct seq_file *m, void *v)
+int memcg_ksm_stat_show(struct seq_file *m, void *v)
{
struct memcg_ksm_stat ksm_stat;
struct mem_cgroup *memcg = mem_cgroup_from_seq(m);
--
2.15.2
Powered by blists - more mailing lists