Move get_mem_cgroup_from_current() to memcontrol.h to make it
available for use outside of the memcontrol.c. The function is
small and marked as __always_inline, so it's better to place
it into memcontrol.h.

Signed-off-by: Roman Gushchin <[email protected]>
---
 include/linux/memcontrol.h | 17 +++++++++++++++++
 mm/memcontrol.c            | 17 -----------------
 2 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index bf1fcf85abd8..a75980559a47 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -453,6 +453,23 @@ struct mem_cgroup *get_mem_cgroup_from_mm(struct mm_struct 
*mm);
 
 struct mem_cgroup *get_mem_cgroup_from_page(struct page *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)
+{
+       if (unlikely(current->active_memcg)) {
+               struct mem_cgroup *memcg = root_mem_cgroup;
+
+               rcu_read_lock();
+               if (css_tryget_online(&current->active_memcg->css))
+                       memcg = current->active_memcg;
+               rcu_read_unlock();
+               return memcg;
+       }
+       return get_mem_cgroup_from_mm(current->mm);
+}
+
 static inline
 struct mem_cgroup *mem_cgroup_from_css(struct cgroup_subsys_state *css){
        return css ? container_of(css, struct mem_cgroup, css) : NULL;
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index ebaa4ff36e0c..8a753a336efd 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -1074,23 +1074,6 @@ struct mem_cgroup *get_mem_cgroup_from_page(struct page 
*page)
 }
 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)
-{
-       if (unlikely(current->active_memcg)) {
-               struct mem_cgroup *memcg = root_mem_cgroup;
-
-               rcu_read_lock();
-               if (css_tryget_online(&current->active_memcg->css))
-                       memcg = current->active_memcg;
-               rcu_read_unlock();
-               return memcg;
-       }
-       return get_mem_cgroup_from_mm(current->mm);
-}
-
 /**
  * mem_cgroup_iter - iterate over memory cgroup hierarchy
  * @root: hierarchy root
-- 
2.21.0

Reply via email to