Re: [PATCH v5 29/32] mm: memcontrol: prepare for reparenting non-hierarchical stats

From: Qi Zheng

Date: Thu Feb 26 2026 - 01:43:23 EST



On 2/26/26 8:25 AM, Shakeel Butt wrote:
On Wed, Feb 25, 2026 at 06:58:59AM -0800, Yosry Ahmed wrote:
@@ -473,6 +493,29 @@ unsigned long lruvec_page_state_local(struct lruvec *lruvec,
return x;
}

+#ifdef CONFIG_MEMCG_V1
+void reparent_memcg_lruvec_state_local(struct mem_cgroup *memcg,
+ struct mem_cgroup *parent, int idx)
+{
+ int i = memcg_stats_index(idx);
+ int nid;
+
+ if (WARN_ONCE(BAD_STAT_IDX(i), "%s: missing stat item %d\n", __func__, idx))
+ return;
+
+ for_each_node(nid) {
+ struct lruvec *child_lruvec = mem_cgroup_lruvec(memcg, NODE_DATA(nid));
+ struct lruvec *parent_lruvec = mem_cgroup_lruvec(parent, NODE_DATA(nid));
+ struct mem_cgroup_per_node *parent_pn;
+ unsigned long value = lruvec_page_state_local(child_lruvec, idx);
+
+ parent_pn = container_of(parent_lruvec, struct mem_cgroup_per_node, lruvec);
+
+ atomic_long_add(value, &(parent_pn->lruvec_stats->state_local[i]));
+ }
+}

Did you measure the impact of making state_local atomic on the flush
path? It's a slow path but we've seen pain from it being too slow
before, because it extends the critical section of the rstat flush
lock.

Qi, please measure the impact on flushing and if no impact then no need to do

OK, will try to do it.

anything as I don't want anymore churn in this series.

Agree.