Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1248747 > unrolled thread

Re: [PATCH 3/3] memcg: simplify and inline __mem_cgroup_from_kmem

Started by"Kirill A. Shutemov" <kirill@shutemov.name>
First post2015-10-16 15:20 +0200
Last post2015-10-16 16:40 +0200
Articles 7 — 6 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [PATCH 3/3] memcg: simplify and inline __mem_cgroup_from_kmem "Kirill A. Shutemov" <kirill@shutemov.name> - 2015-10-16 15:20 +0200
    Re: [PATCH 3/3] memcg: simplify and inline __mem_cgroup_from_kmem Vladimir Davydov <vdavydov@virtuozzo.com> - 2015-10-16 16:00 +0200
      Re: [PATCH 3/3] memcg: simplify and inline __mem_cgroup_from_kmem Hugh Dickins <hughd@google.com> - 2015-10-17 00:20 +0200
        Re: [PATCH 3/3] memcg: simplify and inline __mem_cgroup_from_kmem Johannes Weiner <hannes@cmpxchg.org> - 2015-10-17 00:30 +0200
        Re: [PATCH 3/3] memcg: simplify and inline __mem_cgroup_from_kmem Andrew Morton <akpm@linux-foundation.org> - 2015-10-17 00:30 +0200
        Re: [PATCH 3/3] memcg: simplify and inline __mem_cgroup_from_kmem Vladimir Davydov <vdavydov@virtuozzo.com> - 2015-10-17 17:00 +0200
    Re: [PATCH 3/3] memcg: simplify and inline __mem_cgroup_from_kmem Michal Hocko <mhocko@kernel.org> - 2015-10-16 16:40 +0200

#1248747 — Re: [PATCH 3/3] memcg: simplify and inline __mem_cgroup_from_kmem

From"Kirill A. Shutemov" <kirill@shutemov.name>
Date2015-10-16 15:20 +0200
SubjectRe: [PATCH 3/3] memcg: simplify and inline __mem_cgroup_from_kmem
Message-ID<qkd5o-7oE-11@gated-at.bofh.it>
On Mon, Oct 05, 2015 at 01:21:43AM +0300, Vladimir Davydov wrote:
> Before the previous patch, __mem_cgroup_from_kmem had to handle two
> types of kmem - slab pages and pages allocated with alloc_kmem_pages -
> differently, because slab pages did not store information about owner
> 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.
> 
> Signed-off-by: Vladimir Davydov <vdavydov@virtuozzo.com>
> ---
>  include/linux/memcontrol.h |  7 ++++---
>  mm/memcontrol.c            | 18 ------------------
>  2 files changed, 4 insertions(+), 21 deletions(-)
> 
> diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
> index 8a9b7a798f14..0e2e039609d1 100644
> --- a/include/linux/memcontrol.h
> +++ b/include/linux/memcontrol.h
> @@ -769,8 +769,6 @@ static inline int memcg_cache_id(struct mem_cgroup *memcg)
>  struct kmem_cache *__memcg_kmem_get_cache(struct kmem_cache *cachep);
>  void __memcg_kmem_put_cache(struct kmem_cache *cachep);
>  
> -struct mem_cgroup *__mem_cgroup_from_kmem(void *ptr);
> -
>  static inline bool __memcg_kmem_bypass(gfp_t gfp)
>  {
>  	if (!memcg_kmem_enabled())
> @@ -832,9 +830,12 @@ static __always_inline void memcg_kmem_put_cache(struct kmem_cache *cachep)
>  
>  static __always_inline struct mem_cgroup *mem_cgroup_from_kmem(void *ptr)
>  {
> +	struct page *page;
> +
>  	if (!memcg_kmem_enabled())
>  		return NULL;
> -	return __mem_cgroup_from_kmem(ptr);
> +	page = virt_to_head_page(ptr);
> +	return page->mem_cgroup;
>  }

virt_to_head_page() is defined in <linux/mm.h> but you don't include it,
and the commit breaks build for me (on v4.3-rc5-mmotm-2015-10-15-15-20).

  CC      arch/x86/kernel/asm-offsets.s
In file included from /home/kas/linux/mm/include/linux/swap.h:8:0,
                 from /home/kas/linux/mm/include/linux/suspend.h:4,
                 from /home/kas/linux/mm/arch/x86/kernel/asm-offsets.c:12:
/home/kas/linux/mm/include/linux/memcontrol.h: In function ‘mem_cgroup_from_kmem’:
/home/kas/linux/mm/include/linux/memcontrol.h:841:9: error: implicit declaration of function ‘virt_to_head_page’ [-Werror=implicit-function-declaration]
  page = virt_to_head_page(ptr);
         ^
/home/kas/linux/mm/include/linux/memcontrol.h:841:7: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
  page = virt_to_head_page(ptr);
       ^
In file included from /home/kas/linux/mm/include/linux/suspend.h:8:0,
                 from /home/kas/linux/mm/arch/x86/kernel/asm-offsets.c:12:
/home/kas/linux/mm/include/linux/mm.h: At top level:
/home/kas/linux/mm/include/linux/mm.h:452:28: error: conflicting types for ‘virt_to_head_page’
 static inline struct page *virt_to_head_page(const void *x)
                            ^
In file included from /home/kas/linux/mm/include/linux/swap.h:8:0,
                 from /home/kas/linux/mm/include/linux/suspend.h:4,
                 from /home/kas/linux/mm/arch/x86/kernel/asm-offsets.c:12:
/home/kas/linux/mm/include/linux/memcontrol.h:841:9: note: previous implicit declaration of ‘virt_to_head_page’ was here
  page = virt_to_head_page(ptr);
         ^
cc1: some warnings being treated as errors

The patch below fixes it for me (and for allmodconfig on x86-64), but I'm not
sure if it have any side effects on other configurations.

diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 47677acb4516..e8e52e502c20 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -26,6 +26,7 @@
 #include <linux/page_counter.h>
 #include <linux/vmpressure.h>
 #include <linux/eventfd.h>
+#include <linux/mm.h>
 #include <linux/mmzone.h>
 #include <linux/writeback.h>
 
-- 
 Kirill A. Shutemov
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1248772

FromVladimir Davydov <vdavydov@virtuozzo.com>
Date2015-10-16 16:00 +0200
Message-ID<qkdI5-89o-7@gated-at.bofh.it>
In reply to#1248747
On Fri, Oct 16, 2015 at 04:17:26PM +0300, Kirill A. Shutemov wrote:
> On Mon, Oct 05, 2015 at 01:21:43AM +0300, Vladimir Davydov wrote:
> > Before the previous patch, __mem_cgroup_from_kmem had to handle two
> > types of kmem - slab pages and pages allocated with alloc_kmem_pages -
> > differently, because slab pages did not store information about owner
> > 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.
> > 
> > Signed-off-by: Vladimir Davydov <vdavydov@virtuozzo.com>
> > ---
> >  include/linux/memcontrol.h |  7 ++++---
> >  mm/memcontrol.c            | 18 ------------------
> >  2 files changed, 4 insertions(+), 21 deletions(-)
> > 
> > diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
> > index 8a9b7a798f14..0e2e039609d1 100644
> > --- a/include/linux/memcontrol.h
> > +++ b/include/linux/memcontrol.h
> > @@ -769,8 +769,6 @@ static inline int memcg_cache_id(struct mem_cgroup *memcg)
> >  struct kmem_cache *__memcg_kmem_get_cache(struct kmem_cache *cachep);
> >  void __memcg_kmem_put_cache(struct kmem_cache *cachep);
> >  
> > -struct mem_cgroup *__mem_cgroup_from_kmem(void *ptr);
> > -
> >  static inline bool __memcg_kmem_bypass(gfp_t gfp)
> >  {
> >  	if (!memcg_kmem_enabled())
> > @@ -832,9 +830,12 @@ static __always_inline void memcg_kmem_put_cache(struct kmem_cache *cachep)
> >  
> >  static __always_inline struct mem_cgroup *mem_cgroup_from_kmem(void *ptr)
> >  {
> > +	struct page *page;
> > +
> >  	if (!memcg_kmem_enabled())
> >  		return NULL;
> > -	return __mem_cgroup_from_kmem(ptr);
> > +	page = virt_to_head_page(ptr);
> > +	return page->mem_cgroup;
> >  }
> 
> virt_to_head_page() is defined in <linux/mm.h> but you don't include it,
> and the commit breaks build for me (on v4.3-rc5-mmotm-2015-10-15-15-20).
> 
>   CC      arch/x86/kernel/asm-offsets.s
> In file included from /home/kas/linux/mm/include/linux/swap.h:8:0,
>                  from /home/kas/linux/mm/include/linux/suspend.h:4,
>                  from /home/kas/linux/mm/arch/x86/kernel/asm-offsets.c:12:
> /home/kas/linux/mm/include/linux/memcontrol.h: In function â?~mem_cgroup_from_kmemâ?T:
> /home/kas/linux/mm/include/linux/memcontrol.h:841:9: error: implicit declaration of function â?~virt_to_head_pageâ?T [-Werror=implicit-function-declaration]
>   page = virt_to_head_page(ptr);
>          ^
> /home/kas/linux/mm/include/linux/memcontrol.h:841:7: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
>   page = virt_to_head_page(ptr);
>        ^
> In file included from /home/kas/linux/mm/include/linux/suspend.h:8:0,
>                  from /home/kas/linux/mm/arch/x86/kernel/asm-offsets.c:12:
> /home/kas/linux/mm/include/linux/mm.h: At top level:
> /home/kas/linux/mm/include/linux/mm.h:452:28: error: conflicting types for â?~virt_to_head_pageâ?T
>  static inline struct page *virt_to_head_page(const void *x)
>                             ^
> In file included from /home/kas/linux/mm/include/linux/swap.h:8:0,
>                  from /home/kas/linux/mm/include/linux/suspend.h:4,
>                  from /home/kas/linux/mm/arch/x86/kernel/asm-offsets.c:12:
> /home/kas/linux/mm/include/linux/memcontrol.h:841:9: note: previous implicit declaration of â?~virt_to_head_pageâ?T was here
>   page = virt_to_head_page(ptr);
>          ^
> cc1: some warnings being treated as errors

Oops, in my config I have CONFIG_CGROUP_WRITEBACK enabled, which results
in including mm.h to memcontrol.h indirectly:

 linux/memcontrol.h
  linux/writeback.h
   linux/bio.h
    linux/highmem.h
     linux/mm.h

That's why I didn't notice this. Sorry about that.

> 
> The patch below fixes it for me (and for allmodconfig on x86-64), but I'm not
> sure if it have any side effects on other configurations.

It should work OK with any config, otherwise CONFIG_CGROUP_WRITEBACK
would be broken too.

Andrew, could you please merge the fix by Kirill into
memcg-simplify-and-inline-__mem_cgroup_from_kmem.patch

Thanks,
Vladimir

> 
> diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
> index 47677acb4516..e8e52e502c20 100644
> --- a/include/linux/memcontrol.h
> +++ b/include/linux/memcontrol.h
> @@ -26,6 +26,7 @@
>  #include <linux/page_counter.h>
>  #include <linux/vmpressure.h>
>  #include <linux/eventfd.h>
> +#include <linux/mm.h>
>  #include <linux/mmzone.h>
>  #include <linux/writeback.h>
>  
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1249183

FromHugh Dickins <hughd@google.com>
Date2015-10-17 00:20 +0200
Message-ID<qklvX-2Tu-11@gated-at.bofh.it>
In reply to#1248772

[Multipart message — attachments visible in raw view] — view raw

On Fri, 16 Oct 2015, Vladimir Davydov wrote:
> On Fri, Oct 16, 2015 at 04:17:26PM +0300, Kirill A. Shutemov wrote:
> > On Mon, Oct 05, 2015 at 01:21:43AM +0300, Vladimir Davydov wrote:
> > > Before the previous patch, __mem_cgroup_from_kmem had to handle two
> > > types of kmem - slab pages and pages allocated with alloc_kmem_pages -
> > > differently, because slab pages did not store information about owner
> > > 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.
> > > 
> > > Signed-off-by: Vladimir Davydov <vdavydov@virtuozzo.com>
> > > ---
> > >  include/linux/memcontrol.h |  7 ++++---
> > >  mm/memcontrol.c            | 18 ------------------
> > >  2 files changed, 4 insertions(+), 21 deletions(-)
> > > 
> > > diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
> > > index 8a9b7a798f14..0e2e039609d1 100644
> > > --- a/include/linux/memcontrol.h
> > > +++ b/include/linux/memcontrol.h
> > > @@ -769,8 +769,6 @@ static inline int memcg_cache_id(struct mem_cgroup *memcg)
> > >  struct kmem_cache *__memcg_kmem_get_cache(struct kmem_cache *cachep);
> > >  void __memcg_kmem_put_cache(struct kmem_cache *cachep);
> > >  
> > > -struct mem_cgroup *__mem_cgroup_from_kmem(void *ptr);
> > > -
> > >  static inline bool __memcg_kmem_bypass(gfp_t gfp)
> > >  {
> > >  	if (!memcg_kmem_enabled())
> > > @@ -832,9 +830,12 @@ static __always_inline void memcg_kmem_put_cache(struct kmem_cache *cachep)
> > >  
> > >  static __always_inline struct mem_cgroup *mem_cgroup_from_kmem(void *ptr)
> > >  {
> > > +	struct page *page;
> > > +
> > >  	if (!memcg_kmem_enabled())
> > >  		return NULL;
> > > -	return __mem_cgroup_from_kmem(ptr);
> > > +	page = virt_to_head_page(ptr);
> > > +	return page->mem_cgroup;
> > >  }
> > 
> > virt_to_head_page() is defined in <linux/mm.h> but you don't include it,
> > and the commit breaks build for me (on v4.3-rc5-mmotm-2015-10-15-15-20).
> > 
> >   CC      arch/x86/kernel/asm-offsets.s
> > In file included from /home/kas/linux/mm/include/linux/swap.h:8:0,
> >                  from /home/kas/linux/mm/include/linux/suspend.h:4,
> >                  from /home/kas/linux/mm/arch/x86/kernel/asm-offsets.c:12:
> > /home/kas/linux/mm/include/linux/memcontrol.h: In function â?~mem_cgroup_from_kmemâ?T:
> > /home/kas/linux/mm/include/linux/memcontrol.h:841:9: error: implicit declaration of function â?~virt_to_head_pageâ?T [-Werror=implicit-function-declaration]
> >   page = virt_to_head_page(ptr);
> >          ^
> > /home/kas/linux/mm/include/linux/memcontrol.h:841:7: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
> >   page = virt_to_head_page(ptr);
> >        ^
> > In file included from /home/kas/linux/mm/include/linux/suspend.h:8:0,
> >                  from /home/kas/linux/mm/arch/x86/kernel/asm-offsets.c:12:
> > /home/kas/linux/mm/include/linux/mm.h: At top level:
> > /home/kas/linux/mm/include/linux/mm.h:452:28: error: conflicting types for â?~virt_to_head_pageâ?T
> >  static inline struct page *virt_to_head_page(const void *x)
> >                             ^
> > In file included from /home/kas/linux/mm/include/linux/swap.h:8:0,
> >                  from /home/kas/linux/mm/include/linux/suspend.h:4,
> >                  from /home/kas/linux/mm/arch/x86/kernel/asm-offsets.c:12:
> > /home/kas/linux/mm/include/linux/memcontrol.h:841:9: note: previous implicit declaration of â?~virt_to_head_pageâ?T was here
> >   page = virt_to_head_page(ptr);
> >          ^
> > cc1: some warnings being treated as errors
> 
> Oops, in my config I have CONFIG_CGROUP_WRITEBACK enabled, which results
> in including mm.h to memcontrol.h indirectly:
> 
>  linux/memcontrol.h
>   linux/writeback.h
>    linux/bio.h
>     linux/highmem.h
>      linux/mm.h
> 
> That's why I didn't notice this. Sorry about that.
> 
> > 
> > The patch below fixes it for me (and for allmodconfig on x86-64), but I'm not
> > sure if it have any side effects on other configurations.
> 
> It should work OK with any config, otherwise CONFIG_CGROUP_WRITEBACK
> would be broken too.
> 
> Andrew, could you please merge the fix by Kirill into
> memcg-simplify-and-inline-__mem_cgroup_from_kmem.patch
> 
> Thanks,
> Vladimir
> 
> > 
> > diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
> > index 47677acb4516..e8e52e502c20 100644
> > --- a/include/linux/memcontrol.h
> > +++ b/include/linux/memcontrol.h
> > @@ -26,6 +26,7 @@
> >  #include <linux/page_counter.h>
> >  #include <linux/vmpressure.h>
> >  #include <linux/eventfd.h>
> > +#include <linux/mm.h>
> >  #include <linux/mmzone.h>
> >  #include <linux/writeback.h>
> >  

Are you expecting to use mem_cgroup_from_kmem() from other places
in future?  Seems possible; but at present it's called from only
one place, and (given how memcontrol.h has somehow managed to avoid
including mm.h all these years), I thought it would be nice to avoid
it for just this; and fixed my build with the patch below last night.
Whatever you all think best: just wanted to point out an alternative.

Hugh

--- 4035m/include/linux/memcontrol.h	2015-10-15 15:26:59.503568644 -0700
+++ 4035M/include/linux/memcontrol.h	2015-10-16 03:09:10.000000000 -0700
@@ -831,16 +831,6 @@ static __always_inline void memcg_kmem_p
 	if (memcg_kmem_enabled())
 		__memcg_kmem_put_cache(cachep);
 }
-
-static __always_inline struct mem_cgroup *mem_cgroup_from_kmem(void *ptr)
-{
-	struct page *page;
-
-	if (!memcg_kmem_enabled())
-		return NULL;
-	page = virt_to_head_page(ptr);
-	return page->mem_cgroup;
-}
 #else
 #define for_each_memcg_cache_index(_idx)	\
 	for (; NULL; )
@@ -886,11 +876,5 @@ memcg_kmem_get_cache(struct kmem_cache *
 static inline void memcg_kmem_put_cache(struct kmem_cache *cachep)
 {
 }
-
-static inline struct mem_cgroup *mem_cgroup_from_kmem(void *ptr)
-{
-	return NULL;
-}
 #endif /* CONFIG_MEMCG_KMEM */
 #endif /* _LINUX_MEMCONTROL_H */
-
--- 4035m/mm/list_lru.c	2015-10-15 15:26:59.835572128 -0700
+++ 4035M/mm/list_lru.c	2015-10-16 03:11:51.000000000 -0700
@@ -63,6 +63,16 @@ list_lru_from_memcg_idx(struct list_lru_
 	return &nlru->lru;
 }
 
+static __always_inline struct mem_cgroup *mem_cgroup_from_kmem(void *ptr)
+{
+	struct page *page;
+
+	if (!memcg_kmem_enabled())
+		return NULL;
+	page = virt_to_head_page(ptr);
+	return page->mem_cgroup;
+}
+
 static inline struct list_lru_one *
 list_lru_from_kmem(struct list_lru_node *nlru, void *ptr)
 {

[toc] | [prev] | [next] | [standalone]


#1249188

FromJohannes Weiner <hannes@cmpxchg.org>
Date2015-10-17 00:30 +0200
Message-ID<qklFE-35c-13@gated-at.bofh.it>
In reply to#1249183
On Fri, Oct 16, 2015 at 03:12:23PM -0700, Hugh Dickins wrote:
> --- 4035m/mm/list_lru.c	2015-10-15 15:26:59.835572128 -0700
> +++ 4035M/mm/list_lru.c	2015-10-16 03:11:51.000000000 -0700
> @@ -63,6 +63,16 @@ list_lru_from_memcg_idx(struct list_lru_
>  	return &nlru->lru;
>  }
>  
> +static __always_inline struct mem_cgroup *mem_cgroup_from_kmem(void *ptr)
> +{
> +	struct page *page;
> +
> +	if (!memcg_kmem_enabled())
> +		return NULL;
> +	page = virt_to_head_page(ptr);
> +	return page->mem_cgroup;
> +}
> +
>  static inline struct list_lru_one *
>  list_lru_from_kmem(struct list_lru_node *nlru, void *ptr)
>  {

I like this better than the mm.h include, too.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1249189

FromAndrew Morton <akpm@linux-foundation.org>
Date2015-10-17 00:30 +0200
Message-ID<qklFE-35c-21@gated-at.bofh.it>
In reply to#1249183
On Fri, 16 Oct 2015 15:12:23 -0700 (PDT) Hugh Dickins <hughd@google.com> wrote:

> > > --- a/include/linux/memcontrol.h
> > > +++ b/include/linux/memcontrol.h
> > > @@ -26,6 +26,7 @@
> > >  #include <linux/page_counter.h>
> > >  #include <linux/vmpressure.h>
> > >  #include <linux/eventfd.h>
> > > +#include <linux/mm.h>
> > >  #include <linux/mmzone.h>
> > >  #include <linux/writeback.h>
> > >  
> 
> Are you expecting to use mem_cgroup_from_kmem() from other places
> in future?  Seems possible; but at present it's called from only
> one place, and (given how memcontrol.h has somehow managed to avoid
> including mm.h all these years), I thought it would be nice to avoid
> it for just this;

Yes, I was wondering about that.  I figured that anything which
includes memcontrol.h is already including mm.h and gcc is pretty
efficient with handling the #ifdef FOO_H_INCLUDED guards.

> and fixed my build with the patch below last night.
> Whatever you all think best: just wanted to point out an alternative.

Yes, that's neater - let's go that way.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1249334

FromVladimir Davydov <vdavydov@virtuozzo.com>
Date2015-10-17 17:00 +0200
Message-ID<qkB7I-DX-15@gated-at.bofh.it>
In reply to#1249183
On Fri, Oct 16, 2015 at 03:12:23PM -0700, Hugh Dickins wrote:
...
> Are you expecting to use mem_cgroup_from_kmem() from other places
> in future?  Seems possible; but at present it's called from only

Not in the near future. At least, currently I can't think of any other
use for it except list_lru_from_kmem.

> one place, and (given how memcontrol.h has somehow managed to avoid
> including mm.h all these years), I thought it would be nice to avoid
> it for just this; and fixed my build with the patch below last night.
> Whatever you all think best: just wanted to point out an alternative.

Makes sense, thanks!

I would even inline mem_cgroup_from_kmem to list_lru_from_kmem:

diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 47677acb4516..2077b9bb4883 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -831,16 +831,6 @@ static __always_inline void memcg_kmem_put_cache(struct kmem_cache *cachep)
 	if (memcg_kmem_enabled())
 		__memcg_kmem_put_cache(cachep);
 }
-
-static __always_inline struct mem_cgroup *mem_cgroup_from_kmem(void *ptr)
-{
-	struct page *page;
-
-	if (!memcg_kmem_enabled())
-		return NULL;
-	page = virt_to_head_page(ptr);
-	return page->mem_cgroup;
-}
 #else
 #define for_each_memcg_cache_index(_idx)	\
 	for (; NULL; )
@@ -886,11 +876,6 @@ memcg_kmem_get_cache(struct kmem_cache *cachep, gfp_t gfp)
 static inline void memcg_kmem_put_cache(struct kmem_cache *cachep)
 {
 }
-
-static inline struct mem_cgroup *mem_cgroup_from_kmem(void *ptr)
-{
-	return NULL;
-}
 #endif /* CONFIG_MEMCG_KMEM */
 #endif /* _LINUX_MEMCONTROL_H */
 
diff --git a/mm/list_lru.c b/mm/list_lru.c
index 28237476b055..00d0a70af70a 100644
--- a/mm/list_lru.c
+++ b/mm/list_lru.c
@@ -68,10 +68,10 @@ list_lru_from_kmem(struct list_lru_node *nlru, void *ptr)
 {
 	struct mem_cgroup *memcg;
 
-	if (!nlru->memcg_lrus)
+	if (!memcg_kmem_enabled() || !nlru->memcg_lrus)
 		return &nlru->lru;
 
-	memcg = mem_cgroup_from_kmem(ptr);
+	memcg = virt_to_head_page(ptr)->mem_cgroup;
 	if (!memcg)
 		return &nlru->lru;
 
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1248820

FromMichal Hocko <mhocko@kernel.org>
Date2015-10-16 16:40 +0200
Message-ID<qkekN-GU-5@gated-at.bofh.it>
In reply to#1248747
On Fri 16-10-15 16:17:26, Kirill A. Shutemov wrote:
[...]

I've just encountered the same while updating mmotm git tree. Thanks for
the fix. All other configs which I am testing are good as well.

> virt_to_head_page() is defined in <linux/mm.h> but you don't include it,
> and the commit breaks build for me (on v4.3-rc5-mmotm-2015-10-15-15-20).
> 
>   CC      arch/x86/kernel/asm-offsets.s
> In file included from /home/kas/linux/mm/include/linux/swap.h:8:0,
>                  from /home/kas/linux/mm/include/linux/suspend.h:4,
>                  from /home/kas/linux/mm/arch/x86/kernel/asm-offsets.c:12:
> /home/kas/linux/mm/include/linux/memcontrol.h: In function ‘mem_cgroup_from_kmem’:
> /home/kas/linux/mm/include/linux/memcontrol.h:841:9: error: implicit declaration of function ‘virt_to_head_page’ [-Werror=implicit-function-declaration]
>   page = virt_to_head_page(ptr);
>          ^
> /home/kas/linux/mm/include/linux/memcontrol.h:841:7: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
>   page = virt_to_head_page(ptr);
>        ^
> In file included from /home/kas/linux/mm/include/linux/suspend.h:8:0,
>                  from /home/kas/linux/mm/arch/x86/kernel/asm-offsets.c:12:
> /home/kas/linux/mm/include/linux/mm.h: At top level:
> /home/kas/linux/mm/include/linux/mm.h:452:28: error: conflicting types for ‘virt_to_head_page’
>  static inline struct page *virt_to_head_page(const void *x)
>                             ^
> In file included from /home/kas/linux/mm/include/linux/swap.h:8:0,
>                  from /home/kas/linux/mm/include/linux/suspend.h:4,
>                  from /home/kas/linux/mm/arch/x86/kernel/asm-offsets.c:12:
> /home/kas/linux/mm/include/linux/memcontrol.h:841:9: note: previous implicit declaration of ‘virt_to_head_page’ was here
>   page = virt_to_head_page(ptr);
>          ^
> cc1: some warnings being treated as errors
> 
> The patch below fixes it for me (and for allmodconfig on x86-64), but I'm not
> sure if it have any side effects on other configurations.
> 
> diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
> index 47677acb4516..e8e52e502c20 100644
> --- a/include/linux/memcontrol.h
> +++ b/include/linux/memcontrol.h
> @@ -26,6 +26,7 @@
>  #include <linux/page_counter.h>
>  #include <linux/vmpressure.h>
>  #include <linux/eventfd.h>
> +#include <linux/mm.h>
>  #include <linux/mmzone.h>
>  #include <linux/writeback.h>
>  
> -- 
>  Kirill A. Shutemov
> 
> --
> 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: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

-- 
Michal Hocko
SUSE Labs
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web