Skip to contentSkip to conversation

mm: memcg: yield cpu when we fail to charge pages

PATCH In review Julius Hemanth Pitti 3 participants 4 messages Sep 8, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 mm: memcg: yield cpu when we fail to charge pages

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

---

Changes in v2:
- Added comments.
- Added "Acked-by: Roman Gushchin <[email protected]>".

---
 mm/memcontrol.c | 9 +++++++++
 1 file changed, 9 insertions(+)
mm/memcontrol.c +9 -0
index cfa6cbad21d5..4f293bf8c7ed 100644
@@ -2745,6 +2745,15 @@ static int try_charge(struct mem_cgroup *memcg, gfp_t gfp_mask,
 	if (fatal_signal_pending(current))
 		goto force;
 
+	/*
+	 * We failed to charge even after retries, give oom_reaper or
+	 * other process a change to make some free pages.
+	 *
+	 * On non-preemptive, Non-SMP system, this is critical, else
+	 * we keep retrying with no success, forever.
+	 */
+	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
Signature · 1 line
2.17.1
#1 lore raw
Quoted 13 lines · 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.

Quoted 8 lines

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

Isn't it the same problem solved by e3336cab2579 ("mm: memcg: fix memcg reclaim soft lockup")? It has been in Linus's tree.

Quoted 36 lines

---

Changes in v2:
- Added comments.
- Added "Acked-by: Roman Gushchin <[email protected]>".

---
 mm/memcontrol.c | 9 +++++++++
 1 file changed, 9 insertions(+)
mm/memcontrol.c +9 -1
index cfa6cbad21d5..4f293bf8c7ed 100644
@@ -2745,6 +2745,15 @@ static int try_charge(struct mem_cgroup *memcg, gfp_t gfp_mask,
        if (fatal_signal_pending(current))
                goto force;
 
+       /*
+        * We failed to charge even after retries, give oom_reaper or
+        * other process a change to make some free pages.
+        *
+        * On non-preemptive, Non-SMP system, this is critical, else
+        * we keep retrying with no success, forever.
+        */
+       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

#2 lore raw
Quoted 23 lines · Yang Shi
Quoted 13 lines · 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.

Quoted 8 lines

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

Quoted 2 lines

Isn't it the same problem solved by e3336cab2579 ("mm: memcg: fix memcg reclaim soft lockup")? It has been in Linus's tree.

Yes it should because it adds a scheduling point regardless of reclaimability.

Quoted 35 lines
Quoted 35 lines

---

Changes in v2:
- Added comments.
- Added "Acked-by: Roman Gushchin <[email protected]>".

---
 mm/memcontrol.c | 9 +++++++++
 1 file changed, 9 insertions(+)
mm/memcontrol.c +9 -1
index cfa6cbad21d5..4f293bf8c7ed 100644
@@ -2745,6 +2745,15 @@ static int try_charge(struct mem_cgroup *memcg, gfp_t gfp_mask,
        if (fatal_signal_pending(current))
                goto force;
 
+       /*
+        * We failed to charge even after retries, give oom_reaper or
+        * other process a change to make some free pages.
+        *
+        * On non-preemptive, Non-SMP system, this is critical, else
+        * we keep retrying with no success, forever.
+        */
+       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

Signature · 2 lines
Michal Hocko
SUSE Labs
#3 lore raw
In reply to Yang Shi
Quoted 24 lines · Yang Shi

On Tue, Sep 8, 2020 at 1:14 PM Julius Hemanth Pitti <[email protected]

Quoted 14 lines

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.

Quoted 8 lines

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

Quoted 2 lines

Isn't it the same problem solved by e3336cab2579 ("mm: memcg: fix memcg reclaim soft lockup")? It has been in Linus's tree.

Yes, indeed.
I just tested with e3336cab2579, and it solved this problem. Thanks for pointing it out.

Quoted 42 lines
Quoted 42 lines

---

Changes in v2:
- Added comments.
- Added "Acked-by: Roman Gushchin <[email protected]>".

---
 mm/memcontrol.c | 9 +++++++++
 1 file changed, 9 insertions(+)
mm/memcontrol.c +2 -0
index cfa6cbad21d5..4f293bf8c7ed 100644
@@ -2745,6 +2745,15 @@ static int try_charge(struct mem_cgroup
 *memcg, gfp_t gfp_mask,
        if (fatal_signal_pending(current))
                goto force;
 
+       /*
+        * We failed to charge even after retries, give oom_reaper

or

mm/memcontrol.c +3 -0
+        * other process a change to make some free pages.
+        *
+        * On non-preemptive, Non-SMP system, this is critical,

else

mm/memcontrol.c +4 -0
+        * we keep retrying with no success, forever.
+        */
+       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