diff options
Diffstat (limited to 'mm/memcontrol.c')
-rw-r--r-- | mm/memcontrol.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/mm/memcontrol.c b/mm/memcontrol.c index bf9cf738c836..c071af193986 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -714,6 +714,28 @@ struct mem_cgroup *get_mem_cgroup_from_mm(struct mm_struct *mm) EXPORT_SYMBOL(get_mem_cgroup_from_mm); /** + * get_mem_cgroup_from_page: Obtain a reference on given page's memcg. + * @page: page from which memcg should be extracted. + * + * Obtain a reference on page->memcg and returns it if successful. Otherwise + * root_mem_cgroup is returned. + */ +struct mem_cgroup *get_mem_cgroup_from_page(struct page *page) +{ + struct mem_cgroup *memcg = page->mem_cgroup; + + if (mem_cgroup_disabled()) + return NULL; + + rcu_read_lock(); + if (!memcg || !css_tryget_online(&memcg->css)) + memcg = root_mem_cgroup; + rcu_read_unlock(); + return memcg; +} +EXPORT_SYMBOL(get_mem_cgroup_from_page); + +/** * If current->active_memcg is non-NULL, do not fallback to current->mm->memcg. */ static __always_inline struct mem_cgroup *get_mem_cgroup_from_current(void) |