diff options
authorMichal Hocko <>2013-07-31 13:53:51 -0700
committerChanho Park <>2014-03-21 16:53:38 +0900
commit466d997d9667896c0012e5767516b98a32c00991 (patch)
parent4528b0d883bcec9913cb2576bc2e547c6001f4cc (diff)
vmpressure: make sure there are no events queued after memcg is offlined
vmpressure is called synchronously from reclaim where the target_memcg is guaranteed to be alive but the eventfd is signaled from the work queue context. This means that memcg (along with vmpressure structure which is embedded into it) might go away while the work item is pending which would result in use-after-release bug. We have two possible ways how to fix this. Either vmpressure pins memcg before it schedules vmpr->work and unpin it in vmpressure_work_fn or explicitely flush the work item from the css_offline context (as suggested by Tejun). This patch implements the later one and it introduces vmpressure_cleanup which flushes the vmpressure work queue item item. It hooks into mem_cgroup_css_offline after the memcg itself is cleaned up. [ coding-style fixes] Signed-off-by: Michal Hocko <> Reported-by: Tejun Heo <> Cc: Anton Vorontsov <> Cc: Johannes Weiner <> Cc: KAMEZAWA Hiroyuki <> Cc: KOSAKI Motohiro <> Cc: Li Zefan <> Acked-by: Tejun Heo <> Signed-off-by: Andrew Morton <> Signed-off-by: Linus Torvalds <> Change-Id: I1deefca16b6e243f86bd78b84c561db02e7a20e8
3 files changed, 18 insertions, 0 deletions
diff --git a/include/linux/vmpressure.h b/include/linux/vmpressure.h
index 2081680e015..7dc17e2456d 100644
--- a/include/linux/vmpressure.h
+++ b/include/linux/vmpressure.h
@@ -30,6 +30,7 @@ extern void vmpressure(gfp_t gfp, struct mem_cgroup *memcg,
extern void vmpressure_prio(gfp_t gfp, struct mem_cgroup *memcg, int prio);
extern void vmpressure_init(struct vmpressure *vmpr);
+extern void vmpressure_cleanup(struct vmpressure *vmpr);
extern struct vmpressure *memcg_to_vmpressure(struct mem_cgroup *memcg);
extern struct cgroup_subsys_state *vmpressure_to_css(struct vmpressure *vmpr);
extern struct vmpressure *css_to_vmpressure(struct cgroup_subsys_state *css);
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 6115b2bbd6e..1b8397835ee 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -6330,6 +6330,7 @@ static void mem_cgroup_css_offline(struct cgroup *cont)
+ vmpressure_cleanup(&memcg->vmpressure);
static void mem_cgroup_css_free(struct cgroup *cont)
diff --git a/mm/vmpressure.c b/mm/vmpressure.c
index 192f9731931..0c1e37d829f 100644
--- a/mm/vmpressure.c
+++ b/mm/vmpressure.c
@@ -372,3 +372,19 @@ void vmpressure_init(struct vmpressure *vmpr)
INIT_WORK(&vmpr->work, vmpressure_work_fn);
+ * vmpressure_cleanup() - shuts down vmpressure control structure
+ * @vmpr: Structure to be cleaned up
+ *
+ * This function should be called before the structure in which it is
+ * embedded is cleaned up.
+ */
+void vmpressure_cleanup(struct vmpressure *vmpr)
+ /*
+ * Make sure there is no pending work before eventfd infrastructure
+ * goes away.
+ */
+ flush_work(&vmpr->work);