From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk0-f181.google.com (mail-qk0-f181.google.com [209.85.220.181]) by kanga.kvack.org (Postfix) with ESMTP id 66EA3829A8 for ; Fri, 22 May 2015 17:14:35 -0400 (EDT) Received: by qkgx75 with SMTP id x75so22199370qkg.1 for ; Fri, 22 May 2015 14:14:35 -0700 (PDT) Received: from mail-qg0-x229.google.com (mail-qg0-x229.google.com. [2607:f8b0:400d:c04::229]) by mx.google.com with ESMTPS id me9si3737643qcb.11.2015.05.22.14.14.34 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 May 2015 14:14:34 -0700 (PDT) Received: by qget53 with SMTP id t53so16178334qge.3 for ; Fri, 22 May 2015 14:14:34 -0700 (PDT) From: Tejun Heo Subject: [PATCH 11/51] memcg: implement mem_cgroup_css_from_page() Date: Fri, 22 May 2015 17:13:25 -0400 Message-Id: <1432329245-5844-12-git-send-email-tj@kernel.org> In-Reply-To: <1432329245-5844-1-git-send-email-tj@kernel.org> References: <1432329245-5844-1-git-send-email-tj@kernel.org> Sender: owner-linux-mm@kvack.org List-ID: To: axboe@kernel.dk Cc: linux-kernel@vger.kernel.org, jack@suse.cz, hch@infradead.org, hannes@cmpxchg.org, linux-fsdevel@vger.kernel.org, vgoyal@redhat.com, lizefan@huawei.com, cgroups@vger.kernel.org, linux-mm@kvack.org, mhocko@suse.cz, clm@fb.com, fengguang.wu@intel.com, david@fromorbit.com, gthelen@google.com, khlebnikov@yandex-team.ru, Tejun Heo Implement mem_cgroup_css_from_page() which returns the cgroup_subsys_state of the memcg associated with a given page. This will be used by cgroup writeback support. Signed-off-by: Tejun Heo Cc: Johannes Weiner Cc: Michal Hocko --- include/linux/memcontrol.h | 1 + mm/memcontrol.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 294498f..637ef62 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -115,6 +115,7 @@ static inline bool mm_match_cgroup(struct mm_struct *mm, } extern struct cgroup_subsys_state *mem_cgroup_css(struct mem_cgroup *memcg); +extern struct cgroup_subsys_state *mem_cgroup_css_from_page(struct page *page); struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *, struct mem_cgroup *, diff --git a/mm/memcontrol.c b/mm/memcontrol.c index b22a92b..763f8f3 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -598,6 +598,20 @@ struct cgroup_subsys_state *mem_cgroup_css(struct mem_cgroup *memcg) return &memcg->css; } +/** + * 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; +} + static struct mem_cgroup_per_zone * mem_cgroup_page_zoneinfo(struct mem_cgroup *memcg, struct page *page) { -- 2.4.0 -- 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: email@kvack.org