* [PATCH v2] mm: slab: make page_cgroup_ino() to recognize non-compound slab pages properly
@ 2019-10-31 1:21 Roman Gushchin
[not found] ` <20191030211608.29f8fc92e07fd2ac2ef4d1d3@linux-foundation.org>
2019-10-31 18:16 ` David Rientjes
0 siblings, 2 replies; 4+ messages in thread
From: Roman Gushchin @ 2019-10-31 1:21 UTC (permalink / raw)
To: linux-mm, Andrew Morton
Cc: Michal Hocko, Johannes Weiner, linux-kernel, kernel-team,
Roman Gushchin, Vladimir Davydov, Daniel Jordan
page_cgroup_ino() doesn't return a valid memcg pointer for non-compound
slab pages, because it depends on PgHead AND PgSlab flags to be set
to determine the memory cgroup from the kmem_cache.
It's correct for compound pages, but not for generic small pages. Those
don't have PgHead set, so it ends up returning zero.
Fix this by replacing the condition to PageSlab() && !PageTail().
Before this patch:
[root@localhost ~]# ./page-types -c /sys/fs/cgroup/user.slice/user-0.slice/user@0.service/ | grep slab
0x0000000000000080 38 0 _______S___________________________________ slab
After this patch:
[root@localhost ~]# ./page-types -c /sys/fs/cgroup/user.slice/user-0.slice/user@0.service/ | grep slab
0x0000000000000080 147 0 _______S___________________________________ slab
Fixes: 4d96ba353075 ("mm: memcg/slab: stop setting page->mem_cgroup pointer for slab pages")
Signed-off-by: Roman Gushchin <guro@fb.com>
Reviewed-by: Shakeel Butt <shakeelb@google.com>
Cc: Vladimir Davydov <vdavydov.dev@gmail.com>
Cc: Daniel Jordan <daniel.m.jordan@oracle.com>
---
mm/memcontrol.c | 2 +-
mm/slab.h | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index ea085877c548..00b4188b1bed 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -476,7 +476,7 @@ ino_t page_cgroup_ino(struct page *page)
unsigned long ino = 0;
rcu_read_lock();
- if (PageHead(page) && PageSlab(page))
+ if (PageSlab(page) && !PageTail(page))
memcg = memcg_from_slab_page(page);
else
memcg = READ_ONCE(page->mem_cgroup);
diff --git a/mm/slab.h b/mm/slab.h
index 3eb29ae75743..8b77f973a6ab 100644
--- a/mm/slab.h
+++ b/mm/slab.h
@@ -323,8 +323,8 @@ static inline struct kmem_cache *memcg_root_cache(struct kmem_cache *s)
* Expects a pointer to a slab page. Please note, that PageSlab() check
* isn't sufficient, as it returns true also for tail compound slab pages,
* which do not have slab_cache pointer set.
- * So this function assumes that the page can pass PageHead() and PageSlab()
- * checks.
+ * So this function assumes that the page can pass PageSlab() && !PageTail()
+ * check.
*
* The kmem_cache can be reparented asynchronously. The caller must ensure
* the memcg lifetime, e.g. by taking rcu_read_lock() or cgroup_mutex.
--
2.17.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] mm: slab: make page_cgroup_ino() to recognize non-compound slab pages properly
[not found] ` <20191030211608.29f8fc92e07fd2ac2ef4d1d3@linux-foundation.org>
@ 2019-10-31 9:38 ` Naoya Horiguchi
2019-10-31 15:49 ` Roman Gushchin
0 siblings, 1 reply; 4+ messages in thread
From: Naoya Horiguchi @ 2019-10-31 9:38 UTC (permalink / raw)
To: Andrew Morton
Cc: Roman Gushchin, linux-mm, Michal Hocko, Johannes Weiner,
linux-kernel, kernel-team, Vladimir Davydov, Daniel Jordan
On Wed, Oct 30, 2019 at 09:16:08PM -0700, Andrew Morton wrote:
> On Wed, 30 Oct 2019 18:21:51 -0700 Roman Gushchin <guro@fb.com> wrote:
>
> > page_cgroup_ino() doesn't return a valid memcg pointer for non-compound
> > slab pages, because it depends on PgHead AND PgSlab flags to be set
> > to determine the memory cgroup from the kmem_cache.
> > It's correct for compound pages, but not for generic small pages. Those
> > don't have PgHead set, so it ends up returning zero.
> >
> > Fix this by replacing the condition to PageSlab() && !PageTail().
> >
> > Before this patch:
> > [root@localhost ~]# ./page-types -c /sys/fs/cgroup/user.slice/user-0.slice/user@0.service/ | grep slab
> > 0x0000000000000080 38 0 _______S___________________________________ slab
> >
> > After this patch:
> > [root@localhost ~]# ./page-types -c /sys/fs/cgroup/user.slice/user-0.slice/user@0.service/ | grep slab
> > 0x0000000000000080 147 0 _______S___________________________________ slab
> >
> > Fixes: 4d96ba353075 ("mm: memcg/slab: stop setting page->mem_cgroup pointer for slab pages")
> > Signed-off-by: Roman Gushchin <guro@fb.com>
> > Reviewed-by: Shakeel Butt <shakeelb@google.com>
> > Cc: Vladimir Davydov <vdavydov.dev@gmail.com>
> > Cc: Daniel Jordan <daniel.m.jordan@oracle.com>
>
> Affects /proc/kpagecgroup, but page_cgroup_ino() is also used in the
> memory-failure code - I wonder what effect this bug has there?
hwpoison_filter_task() uses output of page_cgroup_ino() in order to
filter error injection events based on memcg.
So if page_cgroup_ino() fails to return memcg pointer, we just fail
to inject memory error. Considering that hwpoison filter is for testing,
affected users are limited and the impact should be marginal.
>
> IOW, should we backport this into -stable?
I think yes, because the patch is small enough and clearly fixes a bug.
Thanks,
Naoya Horiguchi
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] mm: slab: make page_cgroup_ino() to recognize non-compound slab pages properly
2019-10-31 9:38 ` Naoya Horiguchi
@ 2019-10-31 15:49 ` Roman Gushchin
0 siblings, 0 replies; 4+ messages in thread
From: Roman Gushchin @ 2019-10-31 15:49 UTC (permalink / raw)
To: Naoya Horiguchi
Cc: Andrew Morton, linux-mm, Michal Hocko, Johannes Weiner,
linux-kernel, Kernel Team, Vladimir Davydov, Daniel Jordan
On Thu, Oct 31, 2019 at 09:38:40AM +0000, Naoya Horiguchi wrote:
> On Wed, Oct 30, 2019 at 09:16:08PM -0700, Andrew Morton wrote:
> > On Wed, 30 Oct 2019 18:21:51 -0700 Roman Gushchin <guro@fb.com> wrote:
> >
> > > page_cgroup_ino() doesn't return a valid memcg pointer for non-compound
> > > slab pages, because it depends on PgHead AND PgSlab flags to be set
> > > to determine the memory cgroup from the kmem_cache.
> > > It's correct for compound pages, but not for generic small pages. Those
> > > don't have PgHead set, so it ends up returning zero.
> > >
> > > Fix this by replacing the condition to PageSlab() && !PageTail().
> > >
> > > Before this patch:
> > > [root@localhost ~]# ./page-types -c /sys/fs/cgroup/user.slice/user-0.slice/user@0.service/ | grep slab
> > > 0x0000000000000080 38 0 _______S___________________________________ slab
> > >
> > > After this patch:
> > > [root@localhost ~]# ./page-types -c /sys/fs/cgroup/user.slice/user-0.slice/user@0.service/ | grep slab
> > > 0x0000000000000080 147 0 _______S___________________________________ slab
> > >
> > > Fixes: 4d96ba353075 ("mm: memcg/slab: stop setting page->mem_cgroup pointer for slab pages")
> > > Signed-off-by: Roman Gushchin <guro@fb.com>
> > > Reviewed-by: Shakeel Butt <shakeelb@google.com>
> > > Cc: Vladimir Davydov <vdavydov.dev@gmail.com>
> > > Cc: Daniel Jordan <daniel.m.jordan@oracle.com>
> >
> > Affects /proc/kpagecgroup, but page_cgroup_ino() is also used in the
> > memory-failure code - I wonder what effect this bug has there?
>
> hwpoison_filter_task() uses output of page_cgroup_ino() in order to
> filter error injection events based on memcg.
> So if page_cgroup_ino() fails to return memcg pointer, we just fail
> to inject memory error. Considering that hwpoison filter is for testing,
> affected users are limited and the impact should be marginal.
>
> >
> > IOW, should we backport this into -stable?
>
> I think yes, because the patch is small enough and clearly fixes a bug.
I agree.
Thanks!
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] mm: slab: make page_cgroup_ino() to recognize non-compound slab pages properly
2019-10-31 1:21 [PATCH v2] mm: slab: make page_cgroup_ino() to recognize non-compound slab pages properly Roman Gushchin
[not found] ` <20191030211608.29f8fc92e07fd2ac2ef4d1d3@linux-foundation.org>
@ 2019-10-31 18:16 ` David Rientjes
1 sibling, 0 replies; 4+ messages in thread
From: David Rientjes @ 2019-10-31 18:16 UTC (permalink / raw)
To: Roman Gushchin
Cc: linux-mm, Andrew Morton, Michal Hocko, Johannes Weiner,
linux-kernel, kernel-team, Vladimir Davydov, Daniel Jordan
On Wed, 30 Oct 2019, Roman Gushchin wrote:
> page_cgroup_ino() doesn't return a valid memcg pointer for non-compound
> slab pages, because it depends on PgHead AND PgSlab flags to be set
> to determine the memory cgroup from the kmem_cache.
> It's correct for compound pages, but not for generic small pages. Those
> don't have PgHead set, so it ends up returning zero.
>
> Fix this by replacing the condition to PageSlab() && !PageTail().
>
> Before this patch:
> [root@localhost ~]# ./page-types -c /sys/fs/cgroup/user.slice/user-0.slice/user@0.service/ | grep slab
> 0x0000000000000080 38 0 _______S___________________________________ slab
>
> After this patch:
> [root@localhost ~]# ./page-types -c /sys/fs/cgroup/user.slice/user-0.slice/user@0.service/ | grep slab
> 0x0000000000000080 147 0 _______S___________________________________ slab
>
> Fixes: 4d96ba353075 ("mm: memcg/slab: stop setting page->mem_cgroup pointer for slab pages")
> Signed-off-by: Roman Gushchin <guro@fb.com>
> Reviewed-by: Shakeel Butt <shakeelb@google.com>
> Cc: Vladimir Davydov <vdavydov.dev@gmail.com>
> Cc: Daniel Jordan <daniel.m.jordan@oracle.com>
Acked-by: David Rientjes <rientjes@google.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-10-31 18:16 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-31 1:21 [PATCH v2] mm: slab: make page_cgroup_ino() to recognize non-compound slab pages properly Roman Gushchin
[not found] ` <20191030211608.29f8fc92e07fd2ac2ef4d1d3@linux-foundation.org>
2019-10-31 9:38 ` Naoya Horiguchi
2019-10-31 15:49 ` Roman Gushchin
2019-10-31 18:16 ` David Rientjes
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).