mm: slab: make page_cgroup_ino() to recognize non-compound slab pages properly
Subsystems (3)
PATCH v2 1/1 mm: slab: make page_cgroup_ino() to recognize non-compound slab pages properly
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/[email protected]/ | grep slab0x0000000000000080 38 0 _______S___________________________________ slab
After this patch:
[root@localhost ~]# ./page-types -c /sys/fs/cgroup/user.slice/user-0.slice/[email protected]/ | grep slab0x0000000000000080 147 0 _______S___________________________________ slab
--- mm/memcontrol.c | 2 +- mm/slab.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
mm/memcontrol.c +1 -1
@@ -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);
mm/slab.h +2 -2
@@ -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.
Signature · 1 line
2.17.1
Andrew Morton
maintainerQuoted 16 lines · On Wed, 30 Oct 2019 18:21:51 -0700 Roman Gushchin <[email protected]> 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 thekmem_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/[email protected]/| grep slab0x000000000000008038 0_______S___________________________________slabAfter this patch:
[root@localhost ~]# ./page-types -c/sys/fs/cgroup/user.slice/user-0.slice/[email protected]/| grep slab0x0000000000000080147 0_______S___________________________________slab
Quoted 5 lines
Fixes 4d96ba353075 ("mm: memcg/slab: stop setting page->mem_cgroup pointer for slab pages")Signed-off-by Roman Gushchin <[email protected]>Reviewed-by Shakeel Butt <[email protected]>Cc Vladimir Davydov <[email protected]>Cc Daniel Jordan <[email protected]>
Affects /proc/kpagecgroup, but page_cgroup_ino() is also used in the memory-failure code - I wonder what effect this bug has there?
IOW, should we backport this into -stable?
Quoted 18 lines · Andrew Morton
Quoted 16 lines · On Wed, 30 Oct 2019 18:21:51 -0700 Roman Gushchin <[email protected]> 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 thekmem_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/[email protected]/| grep slab0x000000000000008038 0_______S___________________________________slabAfter this patch:
[root@localhost ~]# ./page-types -c/sys/fs/cgroup/user.slice/user-0.slice/[email protected]/| grep slab0x0000000000000080147 0_______S___________________________________slab
Quoted 8 lines
Quoted 5 lines
Fixes 4d96ba353075 ("mm: memcg/slab: stop setting page->mem_cgroup pointer for slab pages")Signed-off-by Roman Gushchin <[email protected]>Reviewed-by Shakeel Butt <[email protected]>Cc Vladimir Davydov <[email protected]>Cc Daniel Jordan <[email protected]>Affects
/proc/kpagecgroup, butpage_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.
Quoted 2 lines
IOW, should we backport this into -stable?
I think yes, because the patch is small enough and clearly fixes a bug.
Thanks,
Naoya Horiguchi
Quoted 35 lines · Naoya Horiguchi
Quoted 18 lines · Andrew Morton
Quoted 16 lines · On Wed, 30 Oct 2019 18:21:51 -0700 Roman Gushchin <[email protected]> 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 thekmem_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/[email protected]/| grep slab0x000000000000008038 0_______S___________________________________slabAfter this patch:
[root@localhost ~]# ./page-types -c/sys/fs/cgroup/user.slice/user-0.slice/[email protected]/| grep slab0x0000000000000080147 0_______S___________________________________slabQuoted 8 lines
Quoted 5 lines
Fixes 4d96ba353075 ("mm: memcg/slab: stop setting page->mem_cgroup pointer for slab pages")Signed-off-by Roman Gushchin <[email protected]>Reviewed-by Shakeel Butt <[email protected]>Cc Vladimir Davydov <[email protected]>Cc Daniel Jordan <[email protected]>Affects
/proc/kpagecgroup, butpage_cgroup_ino()is also used in the memory-failure code - I wonder what effect this bug has there?
hwpoison_filter_task()uses output ofpage_cgroup_ino()in order to filter error injection events based on memcg.
So ifpage_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.Quoted 1 line
Quoted 3 lines
Quoted 1 line
IOW, should we backport this into -stable?
I think yes, because the patch is small enough and clearly fixes a bug.
I agree.
Thanks!
Quoted 16 lines · Roman Gushchin
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 thekmem_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/[email protected]/| grep slab0x000000000000008038 0_______S___________________________________slabAfter this patch:
[root@localhost ~]# ./page-types -c/sys/fs/cgroup/user.slice/user-0.slice/[email protected]/| grep slab0x0000000000000080147 0_______S___________________________________slab
Quoted 5 lines
Fixes 4d96ba353075 ("mm: memcg/slab: stop setting page->mem_cgroup pointer for slab pages")Signed-off-by Roman Gushchin <[email protected]>Reviewed-by Shakeel Butt <[email protected]>Cc Vladimir Davydov <[email protected]>Cc Daniel Jordan <[email protected]>