linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Michal Hocko <mhocko@suse.cz>
To: cgroups@vger.kernel.org
Cc: Tejun Heo <tj@kernel.org>, Li Zefan <lizefan@huawei.com>,
	Anton Vorontsov <anton.vorontsov@linaro.org>,
	Johannes Weiner <hannes@cmpxchg.org>,
	KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>,
	KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>,
	linux-mm@kvack.org
Subject: [PATCH 1/3] vmpressure: document why css_get/put is not necessary for work queue based signaling
Date: Fri, 12 Jul 2013 11:24:56 +0200	[thread overview]
Message-ID: <1373621098-15261-1-git-send-email-mhocko@suse.cz> (raw)
In-Reply-To: <20130712084039.GA13224@dhcp22.suse.cz>

Tejun raised a concern that vmpressure() doesn't take any reference to
memcg which embeds vmpressure structure when it schedules work item so
there is no guarantee that memcg (thus vmpr) is still valid when the
work item is processed.

Normally we should take a css reference on memcg before scheduling the
work and release it in vmpressure_work_fn but this doesn't seem to be
necessary because of the way how eventfd is implemented at cgroup level.

Cgroup events are unregistered from the workqueue context by
cgroup_event_remove scheduled by cgroup_destroy_locked (when a cgroup is
removed by rmdir).

cgroup_event_remove removes the eventfd wait queue from the work
queue, then it unregisters all the registered events and finally
puts a reference to the cgroup dentry. css_free which triggers memcg
deallocation is called after the last reference is dropped.

The scheduled vmpressure work item either happens before
cgroup_event_remove or it is not triggered at all so it always happen
_before_ the last dput thus css_free.

This patch just documents this trickiness.

Brought-up-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Michal Hocko <mhocko@suse.cz>
---
 mm/vmpressure.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/mm/vmpressure.c b/mm/vmpressure.c
index 736a601..eb2bcf9 100644
--- a/mm/vmpressure.c
+++ b/mm/vmpressure.c
@@ -165,6 +165,13 @@ static bool vmpressure_event(struct vmpressure *vmpr,
 
 static void vmpressure_work_fn(struct work_struct *work)
 {
+	/*
+	 * vmpr which is embedded inside memcg is safe to use from
+	 * this context because cgroup_event_remove which unregisters
+	 * vmpressure events and removes work item from the queue is
+	 * called before dput on the cgroup so css_free is called
+	 * later. So css_get/put on memcg is not necessary.
+	 */
 	struct vmpressure *vmpr = work_to_vmpressure(work);
 	unsigned long scanned;
 	unsigned long reclaimed;
-- 
1.8.3.2

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  parent reply	other threads:[~2013-07-12  9:25 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20130710184254.GA16979@mtj.dyndns.org>
     [not found] ` <20130711083110.GC21667@dhcp22.suse.cz>
     [not found]   ` <51DE701C.6010800@huawei.com>
     [not found]     ` <20130711092542.GD21667@dhcp22.suse.cz>
     [not found]       ` <51DE7AAF.6070004@huawei.com>
2013-07-11  9:33         ` [PATCH v2] vmpressure: make sure memcg stays alive until all users are signaled Michal Hocko
2013-07-11 15:44           ` Tejun Heo
2013-07-11 16:22             ` Michal Hocko
2013-07-11 16:32               ` Tejun Heo
2013-07-12  8:40                 ` Michal Hocko
2013-07-12  9:20                   ` Li Zefan
2013-07-12  9:29                     ` Michal Hocko
2013-07-12  9:54                       ` Li Zefan
2013-07-12 10:37                         ` Michal Hocko
2013-07-15  3:07                           ` Li Zefan
2013-07-15  9:20                             ` Michal Hocko
2013-07-15  9:53                               ` Li Zefan
2013-07-12  9:24                   ` Michal Hocko [this message]
2013-07-12  9:24                     ` [PATCH 2/3] vmpressure: change vmpressure::sr_lock to spinlock Michal Hocko
2013-07-12  9:24                     ` [PATCH 3/3] vmpressure: do not check for pending work to prevent from new work Michal Hocko
2013-07-12 18:48                     ` [PATCH 1/3] vmpressure: document why css_get/put is not necessary for work queue based signaling Tejun Heo
2013-07-15 10:27                       ` Michal Hocko
2013-07-12 18:34                   ` [PATCH v2] vmpressure: make sure memcg stays alive until all users are signaled Tejun Heo
2013-07-12 18:40                     ` Tejun Heo
2013-07-12  6:03               ` Li Zefan
2013-07-15 10:30             ` [PATCH v3 1/3] vmpressure: change vmpressure::sr_lock to spinlock Michal Hocko
2013-07-15 10:30               ` [PATCH v3 2/3] vmpressure: do not check for pending work to prevent from new work Michal Hocko
2013-07-15 10:30               ` [PATCH v3 3/3] vmpressure: Make sure there are no events queued after memcg is offlined Michal Hocko

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=1373621098-15261-1-git-send-email-mhocko@suse.cz \
    --to=mhocko@suse.cz \
    --cc=anton.vorontsov@linaro.org \
    --cc=cgroups@vger.kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=kamezawa.hiroyu@jp.fujitsu.com \
    --cc=kosaki.motohiro@jp.fujitsu.com \
    --cc=linux-mm@kvack.org \
    --cc=lizefan@huawei.com \
    --cc=tj@kernel.org \
    /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