memcg: accounting for allocations called with disabled BH
Subsystems (3)
PATCH 1/9 memcg: accounting for allocations called with disabled BH
in_interrupt() check in memcg_kmem_bypass() is incorrect because it does not allow to account memory allocation called from task context with disabled BH, i.e. inside spin_lock_bh()/spin_unlock_bh() sections
--- mm/memcontrol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/memcontrol.c +1 -1
@@ -1076,7 +1076,7 @@ static __always_inline bool memcg_kmem_bypass(void)return false;/* Memcg to charge can't be determined. */ -if (in_interrupt () || !current->mm || (current->flags &PF_KTHREAD )) +if (!in_task () || !current->mm || (current->flags &PF_KTHREAD ))return true;return false;
Signature · 1 line
1.8.3.1
Quoted 3 lines · Vasily Averin
in_interrupt()check inmemcg_kmem_bypass()is incorrect because it does not allow to account memory allocation called from task context with disabled BH, i.e. inside spin_lock_bh()/spin_unlock_bh() sections
Is there any existing user in the tree? Or is this more of a preparatory patch for a later one which will need it? In other words, is this a bug fix or a preparatory work.
Quoted 20 lines
Signed-off-by Vasily Averin <[email protected]>--- mm/memcontrol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/memcontrol.c +1
-1@@ -1076,7 +1076,7 @@ static __always_inline bool memcg_kmem_bypass(void)return false;/* Memcg to charge can't be determined. */ -if (in_interrupt () || !current->mm || (current->flags &PF_KTHREAD )) +if (!in_task () || !current->mm || (current->flags &PF_KTHREAD ))return true;return false;Signature · 1 line
1.8.3.1
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 8 lines · Michal Hocko
Quoted 3 lines · Vasily Averin
in_interrupt()check inmemcg_kmem_bypass()is incorrect because it does not allow to account memory allocation called from task context with disabled BH, i.e. inside spin_lock_bh()/spin_unlock_bh() sectionsIs there any existing user in the tree? Or is this more of a preparatory patch for a later one which will need it? In other words, is this a bug fix or a preparatory work.
struct fib6_node objects are allocated by this way net/ipv6/route.c::__ip6_ins_rt()
... write_lock_bh(&table->tb6_lock);
err = fib6_add(&table->tb6_root, rt, info, mxc);
write_unlock_bh(&table->tb6_lock);I spend some time to understand why properly entries from properly configured cache was not accounted to container's memcg.
Thank you,
Vasily Averin
Quoted 10 lines · Vasily Averin
Quoted 8 lines · Michal Hocko
Quoted 3 lines · Vasily Averin
in_interrupt()check inmemcg_kmem_bypass()is incorrect because it does not allow to account memory allocation called from task context with disabled BH, i.e. inside spin_lock_bh()/spin_unlock_bh() sectionsIs there any existing user in the tree? Or is this more of a preparatory patch for a later one which will need it? In other words, is this a bug fix or a preparatory work.
Quoted 8 lines
struct
fib6_nodeobjects are allocated by this way net/ipv6/route.c::__ip6_ins_rt()... write_lock_bh(&table->tb6_lock); err = fib6_add(&table->tb6_root, rt, info, mxc); write_unlock_bh(&table->tb6_lock);I spend some time to understand why properly entries from properly configured cache was not accounted to container's memcg.
OK, that is a valuable information. If there are no other users currently then I would recommend squashing this patch into the one which introduces accounting for fib6_node cache (patch 2, IIUC).
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 6 lines · Vasily Averin
in_interrupt()check inmemcg_kmem_bypass()is incorrect because it does not allow to account memory allocation called from task context with disabled BH, i.e. inside spin_lock_bh()/spin_unlock_bh() sectionsSigned-off-by Vasily Averin <[email protected]>
In that file in_interrupt() is used at other places too. Should we change those too?
Quoted 20 lines
--- mm/memcontrol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/memcontrol.c +1
-2@@ -1076,7 +1076,7 @@ static __always_inline bool memcg_kmem_bypass(void)return false;/* Memcg to charge can't be determined. */ -if (in_interrupt () || !current->mm || (current->flags &PF_KTHREAD )) +if (!in_task () || !current->mm || (current->flags &PF_KTHREAD ))return true;return false; --1.8.3.1
Quoted 10 lines · Shakeel Butt
Quoted 6 lines · Vasily Averin
in_interrupt()check inmemcg_kmem_bypass()is incorrect because it does not allow to account memory allocation called from task context with disabled BH, i.e. inside spin_lock_bh()/spin_unlock_bh() sectionsSigned-off-by Vasily Averin <[email protected]>In that file
in_interrupt()is used at other places too. Should we change those too?
Yes, it seems so. Let me prepare a fix (it seems like most of them were introduced by me).
Thanks!
Quoted 7 lines · Roman Gushchin
Quoted 6 lines · Shakeel Butt
Quoted 5 lines · Vasily Averin
in_interrupt()check inmemcg_kmem_bypass()is incorrect because it does not allow to account memory allocation called from task context with disabled BH, i.e. inside spin_lock_bh()/spin_unlock_bh() sections
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Vasily Averin <[email protected]>In that file
in_interrupt()is used at other places too. Should we change those too?Yes, it seems so. Let me prepare a fix (it seems like most of them were introduced by me).
No objects from my side, just keep me informed and add me in "Reported-by:" in your patches.
Thank you,
Vasily Averin
Quoted 7 lines · Roman Gushchin
Quoted 6 lines · Shakeel Butt
Quoted 5 lines · Vasily Averin
in_interrupt()check inmemcg_kmem_bypass()is incorrect because it does not allow to account memory allocation called from task context with disabled BH, i.e. inside spin_lock_bh()/spin_unlock_bh() sections
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Vasily Averin <[email protected]>In that file
in_interrupt()is used at other places too. Should we change those too?Yes, it seems so. Let me prepare a fix (it seems like most of them were introduced by me).
Does this affect any existing in-tree users?
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 10 lines · Michal Hocko
Quoted 9 lines · Roman Gushchin
Quoted 8 lines · Shakeel Butt
Quoted 6 lines · Vasily Averin
in_interrupt()check inmemcg_kmem_bypass()is incorrect because it does not allow to account memory allocation called from task context with disabled BH, i.e. inside spin_lock_bh()/spin_unlock_bh() sectionsSigned-off-by Vasily Averin <[email protected]>
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
In that file
in_interrupt()is used at other places too. Should we change those too?Yes, it seems so. Let me prepare a fix (it seems like most of them were introduced by me).
Does this affect any existing in-tree users?
I'll double check this, but I doubt. We should fix it anyway, but I don't think we need any stable backports.
Quoted 10 lines · Shakeel Butt
Quoted 6 lines · Vasily Averin
in_interrupt()check inmemcg_kmem_bypass()is incorrect because it does not allow to account memory allocation called from task context with disabled BH, i.e. inside spin_lock_bh()/spin_unlock_bh() sectionsSigned-off-by Vasily Averin <[email protected]>In that file
in_interrupt()is used at other places too. Should we change those too?
Yes, you're right, in_interrupt() is used incorrectly in other places too, but
1) these cases are not so critical as this one,
2) and are not related to current patch set
They can be replaced later without urgency
(unless I missed something imporant).
thank you,
Vasily Averin
Quoted 20 lines
Quoted 20 lines
--- mm/memcontrol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/memcontrol.c +1
-2@@ -1076,7 +1076,7 @@ static __always_inline bool memcg_kmem_bypass(void)return false;/* Memcg to charge can't be determined. */ -if (in_interrupt () || !current->mm || (current->flags &PF_KTHREAD )) +if (!in_task () || !current->mm || (current->flags &PF_KTHREAD ))return true;return false; --1.8.3.1
Quoted 5 lines · Vasily Averin
in_interrupt()check inmemcg_kmem_bypass()is incorrect because it does not allow to account memory allocation called from task context with disabled BH, i.e. inside spin_lock_bh()/spin_unlock_bh() sectionsSigned-off-by Vasily Averin <[email protected]>
Good catch!
It looks like the bug was there for years: in_interrupt() was there since the commit 7ae1e1d0f8ac ("memcg: kmem controller infrastructure") from 2012! So I guess there is no point for a stable fix, but it's definitely nice to have it fixed.
for this patch and the rest of the series.
Thank you!
Quoted 20 lines
--- mm/memcontrol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/memcontrol.c +1
-1@@ -1076,7 +1076,7 @@ static __always_inline bool memcg_kmem_bypass(void)return false;/* Memcg to charge can't be determined. */ -if (in_interrupt () || !current->mm || (current->flags &PF_KTHREAD )) +if (!in_task () || !current->mm || (current->flags &PF_KTHREAD ))return true;return false;Signature · 1 line
1.8.3.1
Quoted 5 lines · Roman Gushchin
Quoted 4 lines · Vasily Averin
in_interrupt()check inmemcg_kmem_bypass()is incorrect because it does not allow to account memory allocation called from task context with disabled BH, i.e. inside spin_lock_bh()/spin_unlock_bh() sections
Quoted 8 lines
Quoted 1 line
Signed-off-by Vasily Averin <[email protected]>Good catch!
It looks like the bug was there for years:
in_interrupt()was there since the commit7ae1e1d0f8ac("memcg: kmem controller infrastructure") from 2012! So I guess there is no point for a stable fix, but it's definitely nice to have it fixed.
I did not noticed that this problem affect existing allocation,
I just found that it blocked accounting of "struct fib6_node" in __ip6_ins_rt() added in my current patch set. So I do not think it should went to stable@.
Thank you,
Vasily Averin