linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: <xu.xin16@zte.com.cn>
To: <shakeel.butt@linux.dev>
Cc: <akpm@linux-foundation.org>, <david@redhat.com>,
	<linux-kernel@vger.kernel.org>, <wang.yaxin@zte.com.cn>,
	<linux-mm@kvack.org>, <linux-fsdevel@vger.kernel.org>,
	<yang.yang29@zte.com.cn>
Subject: Re: [PATCH v2 0/9] support ksm_stat showing at cgroup level
Date: Mon, 2 Jun 2025 22:14:58 +0800 (CST)	[thread overview]
Message-ID: <20250602221458798de-eCxDE3QgOIkg0WG1nB@zte.com.cn> (raw)
In-Reply-To: <t7q2d73nxdd75sghobnpmzi7bsbvden6lbrtejkxyoqfl2xilv@4ewvm2od2sf3>

> > > > Users can obtain the KSM information 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_process_profit 309657600
> > > > 
> > > > Current implementation supports both cgroup v2 and cgroup v1.
> > > > 
> > > 
> > > Before adding these stats to memcg, add global stats for them in
> > > enum node_stat_item and then you can expose them in memcg through
> > > memory.stat instead of a new interface.
> > 
> > Dear shakeel.butt,
> > 
> > If adding these ksm-related items to enum node_stat_item and bringing extra counters-updating
> > code like __lruvec_stat_add_folio()... embedded into KSM procudure, it increases extra
> > CPU-consuming while normal KSM procedures happen.
> 
> How is it more expensive than traversing all processes?
> __lruvec_stat_add_folio() and related functions are already called in many
> performance critical code paths, so I don't see any issue to call in the
> ksm.
> 
> > Or, we can just traversal all processes of
> > this memcg and sum their ksm'counters like the current patche set implmentation.
> > 
> > If only including a single "KSM merged pages" entry in memory.stat, I think it is reasonable as
> > it reflects this memcg's KSM page count. However, adding the other three KSM-related metrics is
> > less advisable since they are strongly coupled with KSM internals and would primarily interest
> > users monitoring KSM-specific behavior.
> 
> We can discuss and decide each individual ksm stat if it makes sense to
> added to memcg or not.
> 
> > 
> > Last but not least, the rationale for adding a ksm_stat entry to memcg also lies in maintaining
> > structural consistency with the existing /proc/<pid>/ksm_stat interface.
> 
> Sorry, I don't agree with this rationale. This is a separate interface
> and can be different from exisiting ksm interface. We can define however
> we think is right way to do for memcg and yes there can be stats overlap
> with older interface.
> 
> For now I would say start with the ksm metrics that are appropriate to
> be exposed globally and then we can see if those are fine for memcg as
> well.

Thank you very much for your suggestion, and I'm sorry for the delayed reply
as last month I was exceptionally busy. 

Upon further consideration, I agree that adding entries to the existing memory.stat
interface is indeed preferable to arbitrarily creating new interfaces.  Therefore, my
next step is to plan adding the following global KSM metrics to memory.stat,  such as
ksm_merged, ksm_unmergable, ksm_zero, and ksm_profit. (These represent the
total amount of merged pages, unmergable pages, zero pages merged by KSM, and
the overall profit, respectively.) However, please note that ksm_merging_pages and
ksm_unshared need to be converted to be represented in bytes.”


      reply	other threads:[~2025-06-02 14:15 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-01  4:08 xu.xin16
2025-05-01  4:11 ` [PATCH v2 1/9] memcontrol: rename mem_cgroup_scan_tasks() xu.xin.sc
2025-05-01  4:13 ` [PATCH v2 2/9] memcontrol: introduce the new mem_cgroup_scan_tasks() xu.xin.sc
2025-05-01  4:14 ` [PATCH v2 3/9] memcontrol: introduce ksm_stat at memcg-v2 xu.xin.sc
2025-05-01  4:14 ` [PATCH v2 4/9] memcontrol: add ksm_zero_pages in cgroup/memory.ksm_stat xu.xin.sc
2025-05-01  4:15 ` [PATCH v2 5/9] memcontrol: add ksm_merging_pages " xu.xin.sc
2025-05-01  4:15 ` [PATCH v2 6/9] memcontrol: add ksm_profit " xu.xin.sc
2025-05-01  4:16 ` [PATCH v2 7/9] memcontrol-v1: add ksm_stat at memcg-v1 xu.xin.sc
2025-05-01  4:17 ` [PATCH v2 8/9] Documentation: add ksm_stat description in cgroup-v1/memory.rst xu.xin.sc
2025-05-01  4:17 ` [PATCH v2 9/9] Documentation: add ksm_stat description in cgroup-v2.rst xu.xin.sc
2025-05-01 20:27 ` [PATCH v2 0/9] support ksm_stat showing at cgroup level Andrew Morton
2025-05-05 21:30 ` Shakeel Butt
2025-05-06  5:09   ` xu.xin16
2025-05-08 18:56     ` Shakeel Butt
2025-06-02 14:14       ` xu.xin16 [this message]

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=20250602221458798de-eCxDE3QgOIkg0WG1nB@zte.com.cn \
    --to=xu.xin16@zte.com.cn \
    --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=shakeel.butt@linux.dev \
    --cc=wang.yaxin@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