* [PATCH] mm: slab: make page_cgroup_ino() to recognize non-compound slab pages properly
@ 2019-10-25 23:27 Roman Gushchin
2019-10-30 19:40 ` Roman Gushchin
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Roman Gushchin @ 2019-10-25 23:27 UTC (permalink / raw)
To: linux-mm
Cc: Michal Hocko, Johannes Weiner, linux-kernel, kernel-team,
Roman Gushchin, Vladimir Davydov, Shakeel Butt
page_cgroup_ino() doesn't return a valid memcg pointer for non-compund
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>
Cc: Vladimir Davydov <vdavydov.dev@gmail.com>
Cc: Shakeel Butt <shakeelb@google.com>
---
mm/memcontrol.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
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);
--
2.17.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] mm: slab: make page_cgroup_ino() to recognize non-compound slab pages properly
2019-10-25 23:27 [PATCH] mm: slab: make page_cgroup_ino() to recognize non-compound slab pages properly Roman Gushchin
@ 2019-10-30 19:40 ` Roman Gushchin
2019-10-30 20:40 ` Shakeel Butt
2019-10-30 21:03 ` Daniel Jordan
2 siblings, 0 replies; 5+ messages in thread
From: Roman Gushchin @ 2019-10-30 19:40 UTC (permalink / raw)
To: linux-mm, akpm
Cc: Michal Hocko, Johannes Weiner, linux-kernel, Kernel Team,
Vladimir Davydov, Shakeel Butt
On Fri, Oct 25, 2019 at 04:27:10PM -0700, Roman Gushchin wrote:
> page_cgroup_ino() doesn't return a valid memcg pointer for non-compund
> 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>
> Cc: Vladimir Davydov <vdavydov.dev@gmail.com>
> Cc: Shakeel Butt <shakeelb@google.com>
Ping?
> ---
> mm/memcontrol.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> 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);
> --
> 2.17.1
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] mm: slab: make page_cgroup_ino() to recognize non-compound slab pages properly
2019-10-25 23:27 [PATCH] mm: slab: make page_cgroup_ino() to recognize non-compound slab pages properly Roman Gushchin
2019-10-30 19:40 ` Roman Gushchin
@ 2019-10-30 20:40 ` Shakeel Butt
2019-10-30 21:03 ` Daniel Jordan
2 siblings, 0 replies; 5+ messages in thread
From: Shakeel Butt @ 2019-10-30 20:40 UTC (permalink / raw)
To: Roman Gushchin
Cc: Linux MM, Michal Hocko, Johannes Weiner, LKML, Kernel Team,
Vladimir Davydov
On Fri, Oct 25, 2019 at 4:28 PM Roman Gushchin <guro@fb.com> wrote:
>
> page_cgroup_ino() doesn't return a valid memcg pointer for non-compund
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: Shakeel Butt <shakeelb@google.com>
> ---
> mm/memcontrol.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> 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);
> --
> 2.17.1
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] mm: slab: make page_cgroup_ino() to recognize non-compound slab pages properly
2019-10-25 23:27 [PATCH] mm: slab: make page_cgroup_ino() to recognize non-compound slab pages properly Roman Gushchin
2019-10-30 19:40 ` Roman Gushchin
2019-10-30 20:40 ` Shakeel Butt
@ 2019-10-30 21:03 ` Daniel Jordan
2019-10-30 21:35 ` Roman Gushchin
2 siblings, 1 reply; 5+ messages in thread
From: Daniel Jordan @ 2019-10-30 21:03 UTC (permalink / raw)
To: Roman Gushchin
Cc: linux-mm, Michal Hocko, Johannes Weiner, linux-kernel,
kernel-team, Vladimir Davydov, Shakeel Butt
Hi Roman,
On Fri, Oct 25, 2019 at 04:27:10PM -0700, Roman Gushchin wrote:
> page_cgroup_ino() doesn't return a valid memcg pointer for non-compund
> 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().
You may also want to update the comment above memcg_from_slab_page():
* So this function assumes that the page can pass PageHead() and PageSlab()
* checks.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] mm: slab: make page_cgroup_ino() to recognize non-compound slab pages properly
2019-10-30 21:03 ` Daniel Jordan
@ 2019-10-30 21:35 ` Roman Gushchin
0 siblings, 0 replies; 5+ messages in thread
From: Roman Gushchin @ 2019-10-30 21:35 UTC (permalink / raw)
To: Daniel Jordan
Cc: linux-mm, Michal Hocko, Johannes Weiner, linux-kernel,
Kernel Team, Vladimir Davydov, Shakeel Butt
On Wed, Oct 30, 2019 at 05:03:14PM -0400, Daniel Jordan wrote:
> Hi Roman,
>
> On Fri, Oct 25, 2019 at 04:27:10PM -0700, Roman Gushchin wrote:
> > page_cgroup_ino() doesn't return a valid memcg pointer for non-compund
> > 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().
>
> You may also want to update the comment above memcg_from_slab_page():
>
> * So this function assumes that the page can pass PageHead() and PageSlab()
> * checks.
Good catch, thank you! Will send v2 in no time.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-10-30 21:35 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-25 23:27 [PATCH] mm: slab: make page_cgroup_ino() to recognize non-compound slab pages properly Roman Gushchin
2019-10-30 19:40 ` Roman Gushchin
2019-10-30 20:40 ` Shakeel Butt
2019-10-30 21:03 ` Daniel Jordan
2019-10-30 21:35 ` Roman Gushchin
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).