aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVladimir Davydov <vdavydov@virtuozzo.com>2015-11-05 21:49:04 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2015-11-05 22:34:48 -0500
commitdf4065516b0dbfa35ac0e9b8124d441221c0a285 (patch)
tree4b96cb7cbe15db5bb219c107904d2ed495b63a87
parentf3ccb2c42297757d2e9b820ad37960462df7b7c1 (diff)
memcg: simplify and inline __mem_cgroup_from_kmem
Before the previous patch ("memcg: unify slab and other kmem pages charging"), __mem_cgroup_from_kmem had to handle two types of kmem - slab pages and pages allocated with alloc_kmem_pages - memcg in the page struct. Now we can unify it. Since after it, this function becomes tiny we can fold it into mem_cgroup_from_kmem. [hughd@google.com: move mem_cgroup_from_kmem into list_lru.c] Signed-off-by: Vladimir Davydov <vdavydov@virtuozzo.com> Acked-by: Michal Hocko <mhocko@suse.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Hugh Dickins <hughd@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--include/linux/memcontrol.h15
-rw-r--r--mm/list_lru.c10
-rw-r--r--mm/memcontrol.c18
3 files changed, 10 insertions, 33 deletions
diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 0ba4c86d3b40..998311e0c70c 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -770,8 +770,6 @@ static inline int memcg_cache_id(struct mem_cgroup *memcg)
770struct kmem_cache *__memcg_kmem_get_cache(struct kmem_cache *cachep); 770struct kmem_cache *__memcg_kmem_get_cache(struct kmem_cache *cachep);
771void __memcg_kmem_put_cache(struct kmem_cache *cachep); 771void __memcg_kmem_put_cache(struct kmem_cache *cachep);
772 772
773struct mem_cgroup *__mem_cgroup_from_kmem(void *ptr);
774
775static inline bool __memcg_kmem_bypass(gfp_t gfp) 773static inline bool __memcg_kmem_bypass(gfp_t gfp)
776{ 774{
777 if (!memcg_kmem_enabled()) 775 if (!memcg_kmem_enabled())
@@ -830,13 +828,6 @@ static __always_inline void memcg_kmem_put_cache(struct kmem_cache *cachep)
830 if (memcg_kmem_enabled()) 828 if (memcg_kmem_enabled())
831 __memcg_kmem_put_cache(cachep); 829 __memcg_kmem_put_cache(cachep);
832} 830}
833
834static __always_inline struct mem_cgroup *mem_cgroup_from_kmem(void *ptr)
835{
836 if (!memcg_kmem_enabled())
837 return NULL;
838 return __mem_cgroup_from_kmem(ptr);
839}
840#else 831#else
841#define for_each_memcg_cache_index(_idx) \ 832#define for_each_memcg_cache_index(_idx) \
842 for (; NULL; ) 833 for (; NULL; )
@@ -882,11 +873,5 @@ memcg_kmem_get_cache(struct kmem_cache *cachep, gfp_t gfp)
882static inline void memcg_kmem_put_cache(struct kmem_cache *cachep) 873static inline void memcg_kmem_put_cache(struct kmem_cache *cachep)
883{ 874{
884} 875}
885
886static inline struct mem_cgroup *mem_cgroup_from_kmem(void *ptr)
887{
888 return NULL;
889}
890#endif /* CONFIG_MEMCG_KMEM */ 876#endif /* CONFIG_MEMCG_KMEM */
891#endif /* _LINUX_MEMCONTROL_H */ 877#endif /* _LINUX_MEMCONTROL_H */
892
diff --git a/mm/list_lru.c b/mm/list_lru.c
index 28237476b055..afc71ea9a381 100644
--- a/mm/list_lru.c
+++ b/mm/list_lru.c
@@ -63,6 +63,16 @@ list_lru_from_memcg_idx(struct list_lru_node *nlru, int idx)
63 return &nlru->lru; 63 return &nlru->lru;
64} 64}
65 65
66static __always_inline struct mem_cgroup *mem_cgroup_from_kmem(void *ptr)
67{
68 struct page *page;
69
70 if (!memcg_kmem_enabled())
71 return NULL;
72 page = virt_to_head_page(ptr);
73 return page->mem_cgroup;
74}
75
66static inline struct list_lru_one * 76static inline struct list_lru_one *
67list_lru_from_kmem(struct list_lru_node *nlru, void *ptr) 77list_lru_from_kmem(struct list_lru_node *nlru, void *ptr)
68{ 78{
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 9575cff544fa..c0111cb667b5 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -2430,24 +2430,6 @@ void __memcg_kmem_uncharge(struct page *page, int order)
2430 page->mem_cgroup = NULL; 2430 page->mem_cgroup = NULL;
2431 css_put_many(&memcg->css, nr_pages); 2431 css_put_many(&memcg->css, nr_pages);
2432} 2432}
2433
2434struct mem_cgroup *__mem_cgroup_from_kmem(void *ptr)
2435{
2436 struct mem_cgroup *memcg = NULL;
2437 struct kmem_cache *cachep;
2438 struct page *page;
2439
2440 page = virt_to_head_page(ptr);
2441 if (PageSlab(page)) {
2442 cachep = page->slab_cache;
2443 if (!is_root_cache(cachep))
2444 memcg = cachep->memcg_params.memcg;
2445 } else
2446 /* page allocated by alloc_kmem_pages */
2447 memcg = page->mem_cgroup;
2448
2449 return memcg;
2450}
2451#endif /* CONFIG_MEMCG_KMEM */ 2433#endif /* CONFIG_MEMCG_KMEM */
2452 2434
2453#ifdef CONFIG_TRANSPARENT_HUGEPAGE 2435#ifdef CONFIG_TRANSPARENT_HUGEPAGE