* [PATCH] mm: memcg: yield cpu when we fail to charge pages
@ 2020-09-08 18:50 Julius Hemanth Pitti
2020-09-08 19:21 ` Roman Gushchin
2020-09-14 4:15 ` Xunlei Pang
0 siblings, 2 replies; 4+ messages in thread
From: Julius Hemanth Pitti @ 2020-09-08 18:50 UTC (permalink / raw)
To: hannes, mhocko, vdavydov.dev, akpm
Cc: cgroups, linux-mm, linux-kernel, xe-linux-external, Julius Hemanth Pitti
For non root CG, in try_charge(), we keep trying
to charge until we succeed. On non-preemptive
kernel, when we are OOM, this results in holding
CPU forever.
On SMP systems, this doesn't create a big problem
because oom_reaper get a change to kill victim
and make some free pages. However on a single-core
CPU (or cases where oom_reaper pinned to same CPU
where try_charge is executing), oom_reaper shall
never get scheduled and we stay in try_charge forever.
Steps to repo this on non-smp:
1. mount -t tmpfs none /sys/fs/cgroup
2. mkdir /sys/fs/cgroup/memory
3. mount -t cgroup none /sys/fs/cgroup/memory -o memory
4. mkdir /sys/fs/cgroup/memory/0
5. echo 40M > /sys/fs/cgroup/memory/0/memory.limit_in_bytes
6. echo $$ > /sys/fs/cgroup/memory/0/tasks
7. stress -m 5 --vm-bytes 10M --vm-hang 0
Signed-off-by: Julius Hemanth Pitti <jpitti@cisco.com>
---
mm/memcontrol.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 0d6f3ea86738..4620d70267cb 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -2652,6 +2652,8 @@ static int try_charge(struct mem_cgroup *memcg, gfp_t gfp_mask,
if (fatal_signal_pending(current))
goto force;
+ cond_resched();
+
/*
* keep retrying as long as the memcg oom killer is able to make
* a forward progress or bypass the charge if the oom killer
--
2.17.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] mm: memcg: yield cpu when we fail to charge pages
2020-09-08 18:50 [PATCH] mm: memcg: yield cpu when we fail to charge pages Julius Hemanth Pitti
@ 2020-09-08 19:21 ` Roman Gushchin
2020-09-08 19:28 ` Julius Hemanth Pitti (jpitti)
2020-09-14 4:15 ` Xunlei Pang
1 sibling, 1 reply; 4+ messages in thread
From: Roman Gushchin @ 2020-09-08 19:21 UTC (permalink / raw)
To: Julius Hemanth Pitti
Cc: hannes, mhocko, vdavydov.dev, akpm, cgroups, linux-mm,
linux-kernel, xe-linux-external
On Tue, Sep 08, 2020 at 11:50:51AM -0700, Julius Hemanth Pitti wrote:
> For non root CG, in try_charge(), we keep trying
> to charge until we succeed. On non-preemptive
> kernel, when we are OOM, this results in holding
> CPU forever.
>
> On SMP systems, this doesn't create a big problem
> because oom_reaper get a change to kill victim
> and make some free pages. However on a single-core
> CPU (or cases where oom_reaper pinned to same CPU
> where try_charge is executing), oom_reaper shall
> never get scheduled and we stay in try_charge forever.
>
> Steps to repo this on non-smp:
> 1. mount -t tmpfs none /sys/fs/cgroup
> 2. mkdir /sys/fs/cgroup/memory
> 3. mount -t cgroup none /sys/fs/cgroup/memory -o memory
> 4. mkdir /sys/fs/cgroup/memory/0
> 5. echo 40M > /sys/fs/cgroup/memory/0/memory.limit_in_bytes
> 6. echo $$ > /sys/fs/cgroup/memory/0/tasks
> 7. stress -m 5 --vm-bytes 10M --vm-hang 0
>
> Signed-off-by: Julius Hemanth Pitti <jpitti@cisco.com>
> ---
> mm/memcontrol.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 0d6f3ea86738..4620d70267cb 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -2652,6 +2652,8 @@ static int try_charge(struct mem_cgroup *memcg, gfp_t gfp_mask,
> if (fatal_signal_pending(current))
> goto force;
>
> + cond_resched();
> +
Can you, please, add a short comment here?
Something like "give oom_reaper a chance on a non-SMP system"?
> /*
> * keep retrying as long as the memcg oom killer is able to make
> * a forward progress or bypass the charge if the oom killer
> --
> 2.17.1
>
The patch makes total sense to me. Please, feel free to add
Acked-by: Roman Gushchin <guro@fb.com> after adding a comment.
Thank you!
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mm: memcg: yield cpu when we fail to charge pages
2020-09-08 19:21 ` Roman Gushchin
@ 2020-09-08 19:28 ` Julius Hemanth Pitti (jpitti)
0 siblings, 0 replies; 4+ messages in thread
From: Julius Hemanth Pitti (jpitti) @ 2020-09-08 19:28 UTC (permalink / raw)
To: guro
Cc: vdavydov.dev, linux-kernel, cgroups, linux-mm, hannes,
xe-linux-external(mailer list),
akpm, mhocko
On Tue, 2020-09-08 at 12:21 -0700, Roman Gushchin wrote:
> On Tue, Sep 08, 2020 at 11:50:51AM -0700, Julius Hemanth Pitti wrote:
> > For non root CG, in try_charge(), we keep trying
> > to charge until we succeed. On non-preemptive
> > kernel, when we are OOM, this results in holding
> > CPU forever.
> >
> > On SMP systems, this doesn't create a big problem
> > because oom_reaper get a change to kill victim
> > and make some free pages. However on a single-core
> > CPU (or cases where oom_reaper pinned to same CPU
> > where try_charge is executing), oom_reaper shall
> > never get scheduled and we stay in try_charge forever.
> >
> > Steps to repo this on non-smp:
> > 1. mount -t tmpfs none /sys/fs/cgroup
> > 2. mkdir /sys/fs/cgroup/memory
> > 3. mount -t cgroup none /sys/fs/cgroup/memory -o memory
> > 4. mkdir /sys/fs/cgroup/memory/0
> > 5. echo 40M > /sys/fs/cgroup/memory/0/memory.limit_in_bytes
> > 6. echo $$ > /sys/fs/cgroup/memory/0/tasks
> > 7. stress -m 5 --vm-bytes 10M --vm-hang 0
> >
> > Signed-off-by: Julius Hemanth Pitti <jpitti@cisco.com>
> > ---
> > mm/memcontrol.c | 2 ++
> > 1 file changed, 2 insertions(+)
> >
> > diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> > index 0d6f3ea86738..4620d70267cb 100644
> > --- a/mm/memcontrol.c
> > +++ b/mm/memcontrol.c
> > @@ -2652,6 +2652,8 @@ static int try_charge(struct mem_cgroup
> > *memcg, gfp_t gfp_mask,
> > if (fatal_signal_pending(current))
> > goto force;
> >
> > + cond_resched();
> > +
>
> Can you, please, add a short comment here?
> Something like "give oom_reaper a chance on a non-SMP system"?
Sure.
>
> > /*
> > * keep retrying as long as the memcg oom killer is able to
> > make
> > * a forward progress or bypass the charge if the oom killer
> > --
> > 2.17.1
> >
>
> The patch makes total sense to me. Please, feel free to add
> Acked-by: Roman Gushchin <guro@fb.com> after adding a comment.
Thanks, I shall add.
>
> Thank you!
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mm: memcg: yield cpu when we fail to charge pages
2020-09-08 18:50 [PATCH] mm: memcg: yield cpu when we fail to charge pages Julius Hemanth Pitti
2020-09-08 19:21 ` Roman Gushchin
@ 2020-09-14 4:15 ` Xunlei Pang
1 sibling, 0 replies; 4+ messages in thread
From: Xunlei Pang @ 2020-09-14 4:15 UTC (permalink / raw)
To: Julius Hemanth Pitti, hannes, mhocko, vdavydov.dev, akpm
Cc: cgroups, linux-mm, linux-kernel, xe-linux-external
On 2020/9/9 AM2:50, Julius Hemanth Pitti wrote:
> For non root CG, in try_charge(), we keep trying
> to charge until we succeed. On non-preemptive
> kernel, when we are OOM, this results in holding
> CPU forever.
>
> On SMP systems, this doesn't create a big problem
> because oom_reaper get a change to kill victim
> and make some free pages. However on a single-core
> CPU (or cases where oom_reaper pinned to same CPU
> where try_charge is executing), oom_reaper shall
> never get scheduled and we stay in try_charge forever.
>
> Steps to repo this on non-smp:
> 1. mount -t tmpfs none /sys/fs/cgroup
> 2. mkdir /sys/fs/cgroup/memory
> 3. mount -t cgroup none /sys/fs/cgroup/memory -o memory
> 4. mkdir /sys/fs/cgroup/memory/0
> 5. echo 40M > /sys/fs/cgroup/memory/0/memory.limit_in_bytes
> 6. echo $$ > /sys/fs/cgroup/memory/0/tasks
> 7. stress -m 5 --vm-bytes 10M --vm-hang 0
>
> Signed-off-by: Julius Hemanth Pitti <jpitti@cisco.com>
> ---
> mm/memcontrol.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 0d6f3ea86738..4620d70267cb 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -2652,6 +2652,8 @@ static int try_charge(struct mem_cgroup *memcg, gfp_t gfp_mask,
> if (fatal_signal_pending(current))
> goto force;
>
> + cond_resched();
> +
> /*
> * keep retrying as long as the memcg oom killer is able to make
> * a forward progress or bypass the charge if the oom killer
>
This should be fixed by:
https://lkml.org/lkml/2020/8/26/1440
Thanks,
Xunlei
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-09-14 4:15 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-08 18:50 [PATCH] mm: memcg: yield cpu when we fail to charge pages Julius Hemanth Pitti
2020-09-08 19:21 ` Roman Gushchin
2020-09-08 19:28 ` Julius Hemanth Pitti (jpitti)
2020-09-14 4:15 ` Xunlei Pang
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).