hulk inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8S9BY CVE: NA
--------------------------------
Introduce mem_cgroup_scan_cgroups to iterate over memcgs of a memory cgroup hierarchy.
Signed-off-by: Liu Shixin liushixin2@huawei.com --- include/linux/memcontrol.h | 3 +++ mm/memcontrol.c | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+)
diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 287d130ee969..19a6d34992b0 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -883,6 +883,9 @@ struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *, 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_scan_cgroups(struct mem_cgroup *memcg, + void (*fn)(struct mem_cgroup *, void *), + void *arg);
static inline unsigned short mem_cgroup_id(struct mem_cgroup *memcg) { diff --git a/mm/memcontrol.c b/mm/memcontrol.c index b037c313f4a4..ad006adec9c7 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1310,6 +1310,24 @@ void mem_cgroup_scan_tasks(struct mem_cgroup *memcg, } }
+/** + * mem_cgroup_scan_cgroups - iterate over memcgs of a memory cgroup hierarchy + * @memcg: hierarchy root + * @fn: function to call for each memcg + * @arg: argument passed to @fn + * + * This function iterates over memcg attached to @memcg or to any of its + * descendants and calls @fn for each memcgs. + */ +void mem_cgroup_scan_cgroups(struct mem_cgroup *memcg, + void (*fn)(struct mem_cgroup *, void *), void *arg) +{ + struct mem_cgroup *iter; + + for_each_mem_cgroup_tree(iter, memcg) + fn(iter, arg); +} + #ifdef CONFIG_DEBUG_VM void lruvec_memcg_debug(struct lruvec *lruvec, struct folio *folio) {