From: xu xin <xu.xin.sc@gmail.com>
To: xu.xin16@zte.com.cn
Cc: akpm@linux-foundation.org, david@redhat.com,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, wang.yaxin@zte.com.cn,
yang.yang29@zte.com.cn
Subject: [PATCH RESEND 2/6] memcontrol: introduce the new mem_cgroup_scan_tasks()
Date: Tue, 22 Apr 2025 11:20:34 +0000 [thread overview]
Message-ID: <20250422112034.3231352-1-xu.xin16@zte.com.cn> (raw)
In-Reply-To: <20250422191407770210-193JBD0Fgeu5zqE2K@zte.com.cn>
Introduce a new mem_cgroup_scan_tasks function that strictly iterates
processes only within the current memcgroup, aligning its behavior with
its name.
Signed-off-by: xu xin <xu.xin16@zte.com.cn>
---
include/linux/memcontrol.h | 7 +++++++
mm/memcontrol.c | 24 ++++++++++++++++++++++++
2 files changed, 31 insertions(+)
diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 1c1ce25fae4c..f9d663a7ccde 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -795,6 +795,8 @@ struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *,
struct mem_cgroup *,
struct mem_cgroup_reclaim_cookie *);
void mem_cgroup_iter_break(struct mem_cgroup *, struct mem_cgroup *);
+void mem_cgroup_scan_tasks(struct mem_cgroup *memcg,
+ int (*)(struct task_struct *, void *), void *arg);
void mem_cgroup_tree_scan_tasks(struct mem_cgroup *memcg,
int (*)(struct task_struct *, void *), void *arg);
@@ -1289,6 +1291,11 @@ static inline void mem_cgroup_iter_break(struct mem_cgroup *root,
{
}
+static inline void mem_cgroup_scan_tasks(struct mem_cgroup *memcg,
+ int (*fn)(struct task_struct *, void *), void *arg)
+{
+}
+
static inline void mem_cgroup_tree_scan_tasks(struct mem_cgroup *memcg,
int (*fn)(struct task_struct *, void *), void *arg)
{
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 3baf0a4e0674..629e2ce2d830 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -1163,6 +1163,30 @@ static void invalidate_reclaim_iterators(struct mem_cgroup *dead_memcg)
dead_memcg);
}
+/* *
+ * mem_cgroup_scan_tasks - iterate over tasks of only this memory cgroup.
+ * @memcg: the specified memory cgroup.
+ * @fn: function to call for each task
+ * @arg: argument passed to @fn
+ *
+ * Unlike mem_cgroup_tree_scan_tasks(), this function only iterate over
+ * these tasks attached to @memcg, not including any of its descendants
+ * memcg. And this could be called for the root memory cgroup.
+ */
+void mem_cgroup_scan_tasks(struct mem_cgroup *memcg,
+ int (*fn)(struct task_struct *, void *), void *arg)
+{
+ int ret = 0;
+ struct css_task_iter it;
+ struct task_struct *task;
+
+ css_task_iter_start(&memcg->css, CSS_TASK_ITER_PROCS, &it);
+ while (!ret && (task = css_task_iter_next(&it)))
+ ret = fn(task, arg);
+
+ css_task_iter_end(&it);
+}
+
/**
* mem_cgroup_tree_scan_tasks - iterate over tasks of a memory cgroup hierarchy
* @memcg: hierarchy root
--
2.39.3
next prev parent reply other threads:[~2025-04-22 11:20 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-22 11:14 [PATCH RESEND 0/6] support ksm_stat showing at cgroup level xu.xin16
2025-04-22 11:19 ` [PATCH RESEND 1/6] memcontrol: rename mem_cgroup_scan_tasks() xu xin
2025-04-22 23:29 ` Andrew Morton
2025-04-23 12:22 ` Matthew Wilcox
2025-04-25 14:30 ` Michal Hocko
2025-04-22 11:20 ` xu xin [this message]
2025-04-22 11:21 ` [PATCH RESEND 3/6] memcontrol-v1: introduce ksm_stat at cgroup level xu xin
2025-04-22 11:21 ` [PATCH RESEND 4/6] memcontrol-v1: add ksm_zero_pages in cgroup/memory.ksm_stat xu xin
2025-04-22 11:22 ` [PATCH RESEND 5/6] memcontrol-v1: add ksm_merging_pages " xu xin
2025-04-22 11:22 ` [PATCH RESEND 6/6] memcontrol-v1: add ksm_profit " xu xin
2025-04-23 8:21 ` kernel test robot
2025-04-23 13:08 ` [PATCH RESEND 0/6] support ksm_stat showing at cgroup level David Hildenbrand
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=20250422112034.3231352-1-xu.xin16@zte.com.cn \
--to=xu.xin.sc@gmail.com \
--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=wang.yaxin@zte.com.cn \
--cc=xu.xin16@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