[RFC PATCH 6/7] memcg: charge high_work reclaim to the memcg
From: Shakeel Butt
Date: Thu Sep 24 2026 - 14:55:30 EST
When a charge from IRQ context puts a memcg over memory.high, the
reclaim runs later from high_work on a kworker. The kworker is in the
root cgroup, so the reclaim does not show up in the memcg's cpu.stat
or memory.pressure, and does not count against its cpu.max.
Run the reclaim under set_active_cgroup(). Its CPU time and memory
stalls are then charged to the memcg's cgroup, and its CPU time comes
out of that cgroup's cpu.max quota.
Signed-off-by: Shakeel Butt <shakeel.butt@xxxxxxxxx>
---
mm/memcontrol.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 4d00748c8a5b..f1d0ba8b48cb 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -2456,9 +2456,14 @@ static unsigned long reclaim_high(struct mem_cgroup *memcg,
static void high_work_func(struct work_struct *work)
{
struct mem_cgroup *memcg;
+ struct cgroup *old;
memcg = container_of(work, struct mem_cgroup, high_work);
+
+ /* Charge the reclaim to the memcg's cgroup, not to the root. */
+ old = set_active_cgroup(memcg->css.cgroup);
reclaim_high(memcg, MEMCG_CHARGE_BATCH, GFP_KERNEL);
+ set_active_cgroup(old);
}
static void high_irq_work_func(struct irq_work *work)
--
2.53.0-Meta