From: Johannes Weiner Subject: Re: [PATCH 11/51] memcg: implement mem_cgroup_css_from_page() Date: Fri, 22 May 2015 19:28:31 -0400 Message-ID: <20150522232831.GB6485@cmpxchg.org> References: <1432329245-5844-1-git-send-email-tj@kernel.org> <1432329245-5844-12-git-send-email-tj@kernel.org> Mime-Version: 1.0 Return-path: Content-Disposition: inline In-Reply-To: <1432329245-5844-12-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> Sender: cgroups-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org List-ID: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Tejun Heo Cc: axboe-tSWWG44O7X1aa/9Udqfwiw@public.gmane.org, linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, jack-AlSwsSmVLrQ@public.gmane.org, hch-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org, linux-fsdevel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, vgoyal-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org, lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.org, cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org, mhocko-AlSwsSmVLrQ@public.gmane.org, clm-b10kYP2dOMg@public.gmane.org, fengguang.wu-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org, david-FqsqvQoI3Ljby3iVrkZq2A@public.gmane.org, gthelen-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org, khlebnikov-XoJtRXgx1JseBXzfvpsJ4g@public.gmane.org On Fri, May 22, 2015 at 05:13:25PM -0400, Tejun Heo wrote: > +/** > + * mem_cgroup_css_from_page - css of the memcg associated with a page > + * @page: page of interest > + * > + * This function is guaranteed to return a valid cgroup_subsys_state and > + * the returned css remains accessible until @page is released. > + */ > +struct cgroup_subsys_state *mem_cgroup_css_from_page(struct page *page) > +{ > + if (page->mem_cgroup) > + return &page->mem_cgroup->css; > + return &root_mem_cgroup->css; > +} replace_page_cache() can clear page->mem_cgroup even when the page still has references, so unfortunately you must hold the page lock when calling this function. I haven't checked how you use this - chances are you always have the page locked anyways - but it probably needs a comment.