Skip to contentSkip to conversation

oom: skip frozen tasks

PATCH In review Konstantin Khlebnikov 7 participants 44 messages Aug 23, 2011 – Sep 27, 2011

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

PATCH 1/1 oom: skip frozen tasks

All frozen tasks are unkillable, and if one of them has TIF_MEMDIE we must kill something else to avoid deadlock. After this patch select_bad_process() will skip frozen task before checking TIF_MEMDIE.

---
 mm/oom_kill.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
mm/oom_kill.c +2 -0
index 626303b..931ab20 100644
@@ -138,6 +138,8 @@ static bool oom_unkillable_task(struct task_struct *p,
 		return true;
 	if (p->flags & PF_KTHREAD)
 		return true;
+	if (p->flags & PF_FROZEN)
+		return true;
 
 	/* When mem_cgroup_out_of_memory() and p is not member of the group */
 	if (mem && !task_in_mem_cgroup(p, mem))
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · On Tue, 23 Aug 2011 11:31:01 +0300 Konstantin Khlebnikov…

All frozen tasks are unkillable, and if one of them has TIF_MEMDIE we must kill something else to avoid deadlock. After this patch select_bad_process() will skip frozen task before checking TIF_MEMDIE.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

Reviewed-by on v1 1/1
#2 lore raw
In reply to Konstantin Khlebnikov
Quoted 2 lines · Konstantin Khlebnikov

All frozen tasks are unkillable, and if one of them has TIF_MEMDIE we must kill something else to avoid deadlock.

This is a livelock rather than a deadlock, isn't it? We are picking the same process all the time and cannot do any progress.

Quoted 4 lines

After this patch select_bad_process() will skip frozen task before checking TIF_MEMDIE.

Anyway the patch looks good to me.

Quoted 24 lines
---
 mm/oom_kill.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
mm/oom_kill.c +2 -1
index 626303b..931ab20 100644
@@ -138,6 +138,8 @@ static bool oom_unkillable_task(struct task_struct *p,
 		return true;
 	if (p->flags & PF_KTHREAD)
 		return true;
+	if (p->flags & PF_FROZEN)
+		return true;
 
 	/* When mem_cgroup_out_of_memory() and p is not member of the group */
 	if (mem && !task_in_mem_cgroup(p, mem))
 
--

To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

Signature · 13 lines
Michal Hocko
SUSE Labs
SUSE LINUX s.r.o.
Lihovarska 1060/12
190 00 Praha 9    
Czech Republic

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#3 lore raw
In reply to Konstantin Khlebnikov
Quoted 4 lines · Konstantin Khlebnikov

All frozen tasks are unkillable, and if one of them has TIF_MEMDIE we must kill something else to avoid deadlock. After this patch select_bad_process() will skip frozen task before checking TIF_MEMDIE.

The caveat is that if the task in the refrigerator is not OOM_DISABLE and there are no other eligible tasks (system wide, in the cpuset, or in the memcg) to kill, then the machine will panic as a result of this when, in the past, we would simply issue the SIGKILL and keep looping in the page allocator until it is thawed.

So you may actually be trading a stall waiting for this thread to thaw for what would now be a panic, and that's not clearly better to me.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#4 lore raw
Quoted 7 lines · David Rientjes
Quoted 4 lines · Konstantin Khlebnikov

All frozen tasks are unkillable, and if one of them has TIF_MEMDIE we must kill something else to avoid deadlock. After this patch select_bad_process() will skip frozen task before checking TIF_MEMDIE.

Quoted 5 lines

The caveat is that if the task in the refrigerator is not OOM_DISABLE and there are no other eligible tasks (system wide, in the cpuset, or in the memcg) to kill, then the machine will panic as a result of this when, in the past, we would simply issue the SIGKILL and keep looping in the page allocator until it is thawed.

mem_cgroup_out_of_memory doesn't panic if nothing has been selected. We will loop in the charge&reclaim path until somebody frees some memory.

Quoted 2 lines

So you may actually be trading a stall waiting for this thread to thaw for what would now be a panic, and that's not clearly better to me.

When we are in the global OOM condition then you are right, we have a higher chance to panic. I still find the patch an improvement because encountering a frozen task and looping over it without any progress (even though there are other tasks that could be killed) is more probable than having no killable task at all.
On non-NUMA machines there is even not a big chance that somebody would be able to thaw a task as the system is already on knees.

Signature · 13 lines
Michal Hocko
SUSE Labs
SUSE LINUX s.r.o.
Lihovarska 1060/12
190 00 Praha 9    
Czech Republic

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#5 lore raw
Quoted 8 lines · Michal Hocko

When we are in the global OOM condition then you are right, we have a higher chance to panic. I still find the patch an improvement because encountering a frozen task and looping over it without any progress (even though there are other tasks that could be killed) is more probable than having no killable task at all.
On non-NUMA machines there is even not a big chance that somebody would be able to thaw a task as the system is already on knees.

That's obviously false since we call oom_killer_disable() in freeze_processes() to disable the oom killer from ever being called in the first place, so this is something you need to resolve with Rafael before you cause more machines to panic.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#6 lore raw
Quoted 11 lines · David Rientjes
Quoted 8 lines · Michal Hocko

When we are in the global OOM condition then you are right, we have a higher chance to panic. I still find the patch an improvement because encountering a frozen task and looping over it without any progress (even though there are other tasks that could be killed) is more probable than having no killable task at all.
On non-NUMA machines there is even not a big chance that somebody would be able to thaw a task as the system is already on knees.

Quoted 4 lines

That's obviously false since we call oom_killer_disable() in freeze_processes() to disable the oom killer from ever being called in the first place, so this is something you need to resolve with Rafael before you cause more machines to panic.

I didn't mean suspend/resume path (that is protected by oom_killer_disabled) so the patch doesn't make any change.

Other than that you may end up with all tasks frozen by freezer cgroup (assuming that others, that are killable, would be already killed by OOM). But in that case who can thaw those processes when we are already in OOM? If there is no chance to move forward then panic is more suitable than a livelock IMO.
OK, we might be in OOM on a nodemask (cpuset or mempol) on NUMA and an allocation on a different nodemask might still succeed and so we can thaw those processes. This should be addressed.
What if we panicked only if constraint == CONSTRAINT_NONE?

Or am I missing something?

Signature · 13 lines
Michal Hocko
SUSE Labs
SUSE LINUX s.r.o.
Lihovarska 1060/12
190 00 Praha 9    
Czech Republic

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#7 lore raw
Quoted 10 lines · Michal Hocko
Quoted 5 lines · David Rientjes

That's obviously false since we call oom_killer_disable() in freeze_processes() to disable the oom killer from ever being called in the first place, so this is something you need to resolve with Rafael before you cause more machines to panic.

I didn't mean suspend/resume path (that is protected by oom_killer_disabled) so the patch doesn't make any change.

Confused... freeze_processes() does try_to_freeze_tasks() before oom_killer_disable() ?

Oleg.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#8 lore raw
Quoted 9 lines · Oleg Nesterov
Quoted 8 lines · Michal Hocko
Quoted 5 lines · David Rientjes

That's obviously false since we call oom_killer_disable() in freeze_processes() to disable the oom killer from ever being called in the first place, so this is something you need to resolve with Rafael before you cause more machines to panic.

Quoted 5 lines
Quoted 2 lines

I didn't mean suspend/resume path (that is protected by oom_killer_disabled) so the patch doesn't make any change.

Confused... freeze_processes() does try_to_freeze_tasks() before oom_killer_disable() ?

Yes you are right, I must have been blind.

Now I see the point. We do not want to panic while we are suspending and the memory is really low just because all the userspace is already in the the fridge.
Sorry for confusion.

I still do not follow the oom_killer_disable note from David, though.

Quoted 2 lines

Oleg.

Signature · 13 lines
Michal Hocko
SUSE Labs
SUSE LINUX s.r.o.
Lihovarska 1060/12
190 00 Praha 9    
Czech Republic

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#9 lore raw
Quoted 11 lines · Michal Hocko
Quoted 10 lines
Quoted 7 lines
Quoted 4 lines

That's obviously false since we call oom_killer_disable() in freeze_processes() to disable the oom killer from ever being called in the first place, so this is something you need to resolve with Rafael before you cause more machines to panic.

I didn't mean suspend/resume path (that is protected by oom_killer_disabled) so the patch doesn't make any change.

Confused... freeze_processes() does try_to_freeze_tasks() before oom_killer_disable() ?

Quoted 9 lines

Yes you are right, I must have been blind.

Now I see the point. We do not want to panic while we are suspending and the memory is really low just because all the userspace is already in the the fridge.
Sorry for confusion.

I still do not follow the oom_killer_disable note from David, though.

oom_killer_disable() was added to that path for a reason when all threads are frozen: memory allocations still occur in the suspend path in an oom condition and adding the oom_killer_disable() will cause those allocations to fail rather than sending pointless SIGKILLs to frozen threads.

Now consider if the only _eligible_ threads for oom kill (because of cpusets or mempolicies) are those that are frozen. We certainly do not want to panic because other cpusets are still getting work done. We'd either want to add a mem to the cpuset or thaw the processes because the cpuset is oom.

You can't just selectively skip certain threads when their state can be temporary without risking a panic. That's why this patch is a non-starter.

A much better solution would be to lower the badness score that the oom killer uses for PF_FROZEN threads so that they aren't considered a priority for kill unless there's nothing else left to kill.

#10 lore raw
Quoted 29 lines · David Rientjes
Quoted 11 lines · Michal Hocko
Quoted 10 lines
Quoted 7 lines
Quoted 4 lines

That's obviously false since we call oom_killer_disable() in freeze_processes() to disable the oom killer from ever being called in the first place, so this is something you need to resolve with Rafael before you cause more machines to panic.

I didn't mean suspend/resume path (that is protected by oom_killer_disabled) so the patch doesn't make any change.

Confused... freeze_processes() does try_to_freeze_tasks() before oom_killer_disable() ?

Quoted 9 lines

Yes you are right, I must have been blind.

Now I see the point. We do not want to panic while we are suspending and the memory is really low just because all the userspace is already in the the fridge.
Sorry for confusion.

I still do not follow the oom_killer_disable note from David, though.

oom_killer_disable() was added to that path for a reason when all threads are frozen: memory allocations still occur in the suspend path in an oom condition and adding the oom_killer_disable() will cause those allocations to fail rather than sending pointless SIGKILLs to frozen threads.

Quoted 5 lines

Now consider if the only _eligible_ threads for oom kill (because of cpusets or mempolicies) are those that are frozen. We certainly do not want to panic because other cpusets are still getting work done. We'd either want to add a mem to the cpuset or thaw the processes because the cpuset is oom.

Sure.

Quoted 8 lines

You can't just selectively skip certain threads when their state can be temporary without risking a panic. That's why this patch is a non-starter.

A much better solution would be to lower the badness score that the oom killer uses for PF_FROZEN threads so that they aren't considered a priority for kill unless there's nothing else left to kill.

Yes, sounds better.

Thanks

Signature · 13 lines
Michal Hocko
SUSE Labs
SUSE LINUX s.r.o.
Lihovarska 1060/12
190 00 Praha 9    
Czech Republic

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#11 lore raw
Quoted 43 lines · Michal Hocko
Quoted 29 lines · David Rientjes
Quoted 11 lines · Michal Hocko
Quoted 10 lines
Quoted 7 lines
Quoted 4 lines

That's obviously false since we call oom_killer_disable() in freeze_processes() to disable the oom killer from ever being called in the first place, so this is something you need to resolve with Rafael before you cause more machines to panic.

I didn't mean suspend/resume path (that is protected by oom_killer_disabled) so the patch doesn't make any change.

Confused... freeze_processes() does try_to_freeze_tasks() before oom_killer_disable() ?

Quoted 9 lines

Yes you are right, I must have been blind.

Now I see the point. We do not want to panic while we are suspending and the memory is really low just because all the userspace is already in the the fridge.
Sorry for confusion.

I still do not follow the oom_killer_disable note from David, though.

oom_killer_disable() was added to that path for a reason when all threads are frozen: memory allocations still occur in the suspend path in an oom condition and adding the oom_killer_disable() will cause those allocations to fail rather than sending pointless SIGKILLs to frozen threads.

Quoted 5 lines

Now consider if the only _eligible_ threads for oom kill (because of cpusets or mempolicies) are those that are frozen. We certainly do not want to panic because other cpusets are still getting work done. We'd either want to add a mem to the cpuset or thaw the processes because the cpuset is oom.

Sure.

Quoted 5 lines

You can't just selectively skip certain threads when their state can be temporary without risking a panic. That's why this patch is a non-starter.

Quoted 5 lines
Quoted 3 lines

A much better solution would be to lower the badness score that the oom killer uses for PF_FROZEN threads so that they aren't considered a priority for kill unless there's nothing else left to kill.

Yes, sounds better.

.. but still not sufficient. We also have to thaw the process as well. Just a quick hacked up patch (not tested, just for an illustration).
Would something like this work?
---

#12 lore raw
Quoted 4 lines · Michal Hocko

Let's give all frozen tasks a bonus (OOM_SCORE_ADJ_MAX/2) so that we do not consider them unless really necessary and if we really pick up one then thaw its threads before we try to kill it.

I don't like arbitrary heuristics like this because they polluted the old oom killer before it was rewritten and made it much more unpredictable. The only heuristic it includes right now is a bonus for root tasks so that when two processes have nearly the same amount of memory usage (within 3% of available memory), the non-root task is chosen instead.

This bonus is actually saying that a single frozen task can use up to 50% more of the machine's capacity in a system-wide oom condition than the task that will now be killed instead. That seems excessive.

I do like the idea of automatically thawing the task though and if that's possible then I don't think we need to manipulate the badness heuristic at all. I know that wouldn't be feasible when we've frozen _all_ threads and that's why we have oom_killer_disable(), but we'll have to check with Rafael to see if something like this could work. Rafael?

Quoted 35 lines

TODO
- given bonus might be too big?
- aren't we racing with try_to_freeze_tasks?

---
 mm/oom_kill.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)
mm/oom_kill.c +9 -0
index 626303b..fd194bc 100644
@@ -32,6 +32,7 @@
 #include <linux/mempolicy.h>
 #include <linux/security.h>
 #include <linux/ptrace.h>
+#include <linux/freezer.h>
 
 int sysctl_panic_on_oom;
 int sysctl_oom_kill_allocating_task;
@@ -214,6 +215,14 @@ unsigned int oom_badness(struct task_struct *p, struct mem_cgroup *mem,
 	points += p->signal->oom_score_adj;
 
 	/*
+	 * Do not try to kill frozen tasks unless there is nothing else to kill.
+	 * We do not want to give it 1 point because we still want to select a good
+	 * candidate among all frozen tasks. Let's give it a reasonable bonus.
+	 */
+	if (frozen(p))
+		points -= OOM_SCORE_ADJ_MAX/2;
+
+	/*
 	 * Never return 0 for an eligible task that may be killed since it's
 	 * possible that no single user task uses more than 0.1% of memory and
 	 * no single admin tasks uses more than 3.0%.

mm/oom_kill.c static int oom_kill_task(struct task_struct *p, struct mem_cgroup *mem) · line 468

Quoted 10 lines
mm/oom_kill.c +4 -0
@@ -450,6 +459,10 @@ static int oom_kill_task(struct task_struct *p, struct mem_cgroup *mem)
 			pr_err("Kill process %d (%s) sharing same memory\n",
 				task_pid_nr(q), q->comm);
 			task_unlock(q);
+
+			if (frozen(q))
+				thaw_process(q);
+
 			force_sig(SIGKILL, q);
 		}
 

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#13 lore raw
Quoted 13 lines · David Rientjes
Quoted 4 lines · Michal Hocko

Let's give all frozen tasks a bonus (OOM_SCORE_ADJ_MAX/2) so that we do not consider them unless really necessary and if we really pick up one then thaw its threads before we try to kill it.

I don't like arbitrary heuristics like this because they polluted the old oom killer before it was rewritten and made it much more unpredictable. The only heuristic it includes right now is a bonus for root tasks so that when two processes have nearly the same amount of memory usage (within 3% of available memory), the non-root task is chosen instead.

Quoted 3 lines

This bonus is actually saying that a single frozen task can use up to 50% more of the machine's capacity in a system-wide oom condition than the task that will now be killed instead. That seems excessive.

Yes, the number is probably too high. I just wanted to start up with something. Maybe we can give it another root bonus. But I agree whatever we use it will be just a random value...

Quoted 4 lines

I do like the idea of automatically thawing the task though and if that's possible then I don't think we need to manipulate the badness heuristic at all. I know that wouldn't be feasible when we've frozen _all_ threads and

Why it wouldn't be feasible for all threads? If you have all tasks frozen (suspend going on, whole cgroup or all tasks in a cpuset/nodemask are frozen) then the selection is more natural because all of them are equal (with or without a bonus). The bonus tries to reduce thawing if not all of them are frozen.
I am not saying the bonus is necessary, though. It depends on what the freezer is used for (e.g. freeze a process which went wild and debug what went wrong wouldn't welcome that somebody killed it or other (mis)use which relies on D state).

Quoted 48 lines

that's why we have oom_killer_disable(), but we'll have to check with Rafael to see if something like this could work. Rafael?

Quoted 45 lines

TODO
- given bonus might be too big?
- aren't we racing with try_to_freeze_tasks?

---
 mm/oom_kill.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)
mm/oom_kill.c +13 -0
index 626303b..fd194bc 100644
@@ -32,6 +32,7 @@
 #include <linux/mempolicy.h>
 #include <linux/security.h>
 #include <linux/ptrace.h>
+#include <linux/freezer.h>
 
 int sysctl_panic_on_oom;
 int sysctl_oom_kill_allocating_task;
@@ -214,6 +215,14 @@ unsigned int oom_badness(struct task_struct *p, struct mem_cgroup *mem,
 	points += p->signal->oom_score_adj;
 
 	/*
+	 * Do not try to kill frozen tasks unless there is nothing else to kill.
+	 * We do not want to give it 1 point because we still want to select a good
+	 * candidate among all frozen tasks. Let's give it a reasonable bonus.
+	 */
+	if (frozen(p))
+		points -= OOM_SCORE_ADJ_MAX/2;
+
+	/*
 	 * Never return 0 for an eligible task that may be killed since it's
 	 * possible that no single user task uses more than 0.1% of memory and
 	 * no single admin tasks uses more than 3.0%.
@@ -450,6 +459,10 @@ static int oom_kill_task(struct task_struct *p, struct mem_cgroup *mem)
 			pr_err("Kill process %d (%s) sharing same memory\n",
 				task_pid_nr(q), q->comm);
 			task_unlock(q);
+
+			if (frozen(q))
+				thaw_process(q);
+
 			force_sig(SIGKILL, q);
 		}
 
Signature · 13 lines
Michal Hocko
SUSE Labs
SUSE LINUX s.r.o.
Lihovarska 1060/12
190 00 Praha 9    
Czech Republic

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#14 lore raw
Quoted 27 lines · Michal Hocko
Quoted 13 lines · David Rientjes
Quoted 4 lines · Michal Hocko

Let's give all frozen tasks a bonus (OOM_SCORE_ADJ_MAX/2) so that we do not consider them unless really necessary and if we really pick up one then thaw its threads before we try to kill it.

I don't like arbitrary heuristics like this because they polluted the old oom killer before it was rewritten and made it much more unpredictable. The only heuristic it includes right now is a bonus for root tasks so that when two processes have nearly the same amount of memory usage (within 3% of available memory), the non-root task is chosen instead.

Quoted 3 lines

This bonus is actually saying that a single frozen task can use up to 50% more of the machine's capacity in a system-wide oom condition than the task that will now be killed instead. That seems excessive.

Yes, the number is probably too high. I just wanted to start up with something. Maybe we can give it another root bonus. But I agree whatever we use it will be just a random value...

Quoted 4 lines

I do like the idea of automatically thawing the task though and if that's possible then I don't think we need to manipulate the badness heuristic at all. I know that wouldn't be feasible when we've frozen _all_ threads and

Quoted 9 lines

Why it wouldn't be feasible for all threads? If you have all tasks frozen (suspend going on, whole cgroup or all tasks in a cpuset/nodemask are frozen) then the selection is more natural because all of them are equal (with or without a bonus). The bonus tries to reduce thawing if not all of them are frozen.
I am not saying the bonus is necessary, though. It depends on what the freezer is used for (e.g. freeze a process which went wild and debug what went wrong wouldn't welcome that somebody killed it or other (mis)use which relies on D state).

Anyway, I do agree, the two things (bonus and thaw during oom_kill) should be handled separately.

Signature · 6 lines
Michal Hocko
SUSE Labs
SUSE LINUX s.r.o.
Lihovarska 1060/12
190 00 Praha 9    
Czech Republic
#15 lore raw
In reply to Michal Hocko
Quoted 9 lines · Michal Hocko
Quoted 3 lines

I do like the idea of automatically thawing the task though and if that's possible then I don't think we need to manipulate the badness heuristic at all. I know that wouldn't be feasible when we've frozen _all_ threads and

Why it wouldn't be feasible for all threads? If you have all tasks frozen (suspend going on, whole cgroup or all tasks in a cpuset/nodemask are frozen) then the selection is more natural because all of them are equal (with or without a bonus). The bonus tries to reduce thawing if not all of them are frozen.

Yeah, this comment wasn't in reference to your heuristic change, it was in reference to the fact that if all threads are frozen then there is little hope for us recovering from the situation without a user response. I think that's why we want oom_killer_disable() so that we avoid looping forever and can actually fail allocations in the hope that we'll bring ourselves out of suspend.

Quoted 5 lines

I am not saying the bonus is necessary, though. It depends on what the freezer is used for (e.g. freeze a process which went wild and debug what went wrong wouldn't welcome that somebody killed it or other (mis)use which relies on D state).

I'd love to be able to do a thaw on a PF_FROZEN task in the oom killer followed by a SIGKILL if that task is selected for oom kill without an heuristic change. Not sure if that's possible, so we'll wait for Rafael to chime in.

If it actually does come down to a heuristic change, then it need not happen in the oom killer: the freezing code would need to use test_set_oom_score_adj() to temporarily reduce the oom_score_adj for that task until it comes out of the refrigerator. We already use that in ksm and swapoff to actually prefer threads, but we can use it to bias against threads as well.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#16 lore raw

PATCH 1/2 oom: do not live lock on frozen tasks

[Let's add some more people to CC list]

Sorry it took so long but I was quite bussy recently.

Quoted 1 line · David Rientjes

On Fri, 26 Aug 2011, Michal Hocko wrote:

[...]

Quoted 10 lines
Quoted 5 lines

I am not saying the bonus is necessary, though. It depends on what the freezer is used for (e.g. freeze a process which went wild and debug what went wrong wouldn't welcome that somebody killed it or other (mis)use which relies on D state).

I'd love to be able to do a thaw on a PF_FROZEN task in the oom killer followed by a SIGKILL if that task is selected for oom kill without an heuristic change. Not sure if that's possible, so we'll wait for Rafael to chime in.

We have discussed that with Rafael and it should be safe to do that. See the patch bellow.
The only place I am not entirely sure about is run_guest (drivers/lguest/core.c). It seems that the code is able to cope with signals but it also calls lguest_arch_run_guest after try_to_freeze.
---

Quoted 1 line

From aea3c3fba1e172373877df03a335848cae4b717e Mon Sep 17 00:00:00 2001

From: Michal Hocko <[email protected]>
Date: Fri, 16 Sep 2011 11:23:15 +0200
Subject: [PATCH 1/2] oom: do not live lock on frozen tasks

Konstantin Khlebnikov has reported (https://lkml.org/lkml/2011/8/23/45)
that OOM can end up in a live lock if select_bad_process picks up a frozen task.
Unfortunately we cannot mark such processes as unkillable to ignore them because we could panic the system even though there is a chance that somebody could thaw the process so we can make a forward process (e.g. a process from another cpuset or with a different nodemask).

Let's thaw an OOM selected frozen process right after we've sent fatal signal from oom_kill_task.
Thawing is safe if the frozen task doesn't access any suspended device (e.g. by ioctl) on the way out to the userspace where we handle the signal and die. Note, we are not interested in the kernel threads because they are not oom killable.

Accessing suspended devices by a userspace processes shouldn't be an issue because devices are suspended only after userspace is already frozen and oom is disabled at that time.

run_guest (drivers/lguest/core.c) calls try_to_freeze with an user context but it seems it is able to cope with signals because it explicitly checks for pending signals so we should be safe.

Other than that userspace accesses the fridge only from the signal handling routines so we are able to handle SIGKILL without any negative side effects.

---
 mm/oom_kill.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
mm/oom_kill.c +4 -0
index 626303b..b9774f3 100644
@@ -32,6 +32,7 @@
 #include <linux/mempolicy.h>
 #include <linux/security.h>
 #include <linux/ptrace.h>
+#include <linux/freezer.h>
 
 int sysctl_panic_on_oom;
 int sysctl_oom_kill_allocating_task;
@@ -451,6 +452,9 @@ static int oom_kill_task(struct task_struct *p, struct mem_cgroup *mem)
 				task_pid_nr(q), q->comm);
 			task_unlock(q);
 			force_sig(SIGKILL, q);
+
+			if (frozen(q))
+				thaw_process(q);
 		}
 
 	set_tsk_thread_flag(p, TIF_MEMDIE);
Signature · 9 lines
1.7.5.4

-- 
Michal Hocko
SUSE Labs
SUSE LINUX s.r.o.
Lihovarska 1060/12
190 00 Praha 9    
Czech Republic
reviewer Acked-by on v1 1/2
#17 lore raw

Re: [PATCH 1/2] oom: do not live lock on frozen tasks

Quoted 13 lines · Michal Hocko
mm/oom_kill.c +1 -0
index 626303b..b9774f3 100644
@@ -32,6 +32,7 @@
 #include <linux/mempolicy.h>
 #include <linux/security.h>
 #include <linux/ptrace.h>
+#include <linux/freezer.h>
 
 int sysctl_panic_on_oom;
 int sysctl_oom_kill_allocating_task;

mm/oom_kill.c static int oom_kill_task(struct task_struct *p, struct mem_cgroup *mem) · line 460

Quoted 9 lines
mm/oom_kill.c +3 -0
@@ -451,6 +452,9 @@ static int oom_kill_task(struct task_struct *p, struct mem_cgroup *mem)
 				task_pid_nr(q), q->comm);
 			task_unlock(q);
 			force_sig(SIGKILL, q);
+
+			if (frozen(q))
+				thaw_process(q);
 		}
 
 	set_tsk_thread_flag(p, TIF_MEMDIE);

This is in the wrong place, oom_kill_task() iterates over all threads that are _not_ in the same thread group as the chosen thread and kills them without giving them access to memory reserves. The chosen task, p, could still be frozen and may not exit.

Once that's fixed, feel free to add my

once Rafael sends his acked-by or reviewed-by.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#18 lore raw

Re: [PATCH 1/2] oom: do not live lock on frozen tasks

Quoted 23 lines · David Rientjes
Quoted 21 lines · Michal Hocko
mm/oom_kill.c +4 -0
index 626303b..b9774f3 100644
@@ -32,6 +32,7 @@
 #include <linux/mempolicy.h>
 #include <linux/security.h>
 #include <linux/ptrace.h>
+#include <linux/freezer.h>
 
 int sysctl_panic_on_oom;
 int sysctl_oom_kill_allocating_task;
@@ -451,6 +452,9 @@ static int oom_kill_task(struct task_struct *p, struct mem_cgroup *mem)
 				task_pid_nr(q), q->comm);
 			task_unlock(q);
 			force_sig(SIGKILL, q);
+
+			if (frozen(q))
+				thaw_process(q);
 		}
 
Quoted 6 lines

mm/oom_kill.c static int oom_kill_task(struct task_struct *p, struct mem_cgroup *mem) · line 460

Quoted 1 line
mm/oom_kill.c +0 -0
 	set_tsk_thread_flag(p, TIF_MEMDIE);

This is in the wrong place, oom_kill_task() iterates over all threads that are _not_ in the same thread group as the chosen thread and kills them without giving them access to memory reserves. The chosen task, p, could still be frozen and may not exit.

Ahh, right you are. I ave missed that one. Updated patch bellow.

Quoted 4 lines

Once that's fixed, feel free to add my

Thanks

Quoted 2 lines

once Rafael sends his acked-by or reviewed-by.

---

Quoted 1 line

From f935ed4558c2fb033ef5c14e02b28e12a615f80e Mon Sep 17 00:00:00 2001

From: Michal Hocko <[email protected]>
Date: Fri, 16 Sep 2011 11:23:15 +0200
Subject: [PATCH] oom: do not live lock on frozen tasks

Konstantin Khlebnikov has reported (https://lkml.org/lkml/2011/8/23/45)
that OOM can end up in a live lock if select_bad_process picks up a frozen task.
Unfortunately we cannot mark such processes as unkillable to ignore them because we could panic the system even though there is a chance that somebody could thaw the process so we can make a forward process (e.g. a process from another cpuset or with a different nodemask).

Let's thaw an OOM selected frozen process right after we've sent fatal signal from oom_kill_task.
Thawing is safe if the frozen task doesn't access any suspended device (e.g. by ioctl) on the way out to the userspace where we handle the signal and die. Note, we are not interested in the kernel threads because they are not oom killable.

Accessing suspended devices by a userspace processes shouldn't be an issue because devices are suspended only after userspace is already frozen and oom is disabled at that time.

run_guest (drivers/lguest/core.c) calls try_to_freeze with an user context but it seems it is able to cope with signals because it explicitly checks for pending signals so we should be safe.

Other than that userspace accesses the fridge only from the signal handling routines so we are able to handle SIGKILL without any negative side effects.

---
 mm/oom_kill.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
mm/oom_kill.c +6 -0
index 626303b..c419a7e 100644
@@ -32,6 +32,7 @@
 #include <linux/mempolicy.h>
 #include <linux/security.h>
 #include <linux/ptrace.h>
+#include <linux/freezer.h>
 
 int sysctl_panic_on_oom;
 int sysctl_oom_kill_allocating_task;
@@ -451,10 +452,15 @@ static int oom_kill_task(struct task_struct *p, struct mem_cgroup *mem)
 				task_pid_nr(q), q->comm);
 			task_unlock(q);
 			force_sig(SIGKILL, q);
+
+			if (frozen(q))
+				thaw_process(q);
 		}
 
 	set_tsk_thread_flag(p, TIF_MEMDIE);
 	force_sig(SIGKILL, p);
+	if (frozen(p))
+		thaw_process(p);
 
 	return 0;
 }
Signature · 9 lines
1.7.5.4

-- 
Michal Hocko
SUSE Labs
SUSE LINUX s.r.o.
Lihovarska 1060/12
190 00 Praha 9    
Czech Republic
Reviewed-by
#19 lore raw

Re: [PATCH 1/2] oom: do not live lock on frozen tasks

Quoted 71 lines · On Mon, 26 Sep 2011 11:14:40 +0200 Michal Hocko <[email protected]> wrote:
Quoted 23 lines · David Rientjes
Quoted 21 lines · Michal Hocko
mm/oom_kill.c +4 -0
index 626303b..b9774f3 100644
@@ -32,6 +32,7 @@
 #include <linux/mempolicy.h>
 #include <linux/security.h>
 #include <linux/ptrace.h>
+#include <linux/freezer.h>
 
 int sysctl_panic_on_oom;
 int sysctl_oom_kill_allocating_task;
@@ -451,6 +452,9 @@ static int oom_kill_task(struct task_struct *p, struct mem_cgroup *mem)
 				task_pid_nr(q), q->comm);
 			task_unlock(q);
 			force_sig(SIGKILL, q);
+
+			if (frozen(q))
+				thaw_process(q);
 		}
 
Quoted 6 lines

mm/oom_kill.c static int oom_kill_task(struct task_struct *p, struct mem_cgroup *mem) · line 460

Quoted 1 line
mm/oom_kill.c +0 -0
 	set_tsk_thread_flag(p, TIF_MEMDIE);

This is in the wrong place, oom_kill_task() iterates over all threads that are _not_ in the same thread group as the chosen thread and kills them without giving them access to memory reserves. The chosen task, p, could still be frozen and may not exit.

Ahh, right you are. I ave missed that one. Updated patch bellow.

Quoted 4 lines

Once that's fixed, feel free to add my

Thanks

Quoted 2 lines

once Rafael sends his acked-by or reviewed-by.

---
From f935ed4558c2fb033ef5c14e02b28e12a615f80e Mon Sep 17 00:00:00 2001
From: Michal Hocko <[email protected]>
Date: Fri, 16 Sep 2011 11:23:15 +0200
Subject: [PATCH] oom: do not live lock on frozen tasks

Konstantin Khlebnikov has reported (https://lkml.org/lkml/2011/8/23/45)
that OOM can end up in a live lock if select_bad_process picks up a frozen task.
Unfortunately we cannot mark such processes as unkillable to ignore them because we could panic the system even though there is a chance that somebody could thaw the process so we can make a forward process (e.g. a process from another cpuset or with a different nodemask).

Let's thaw an OOM selected frozen process right after we've sent fatal signal from oom_kill_task.
Thawing is safe if the frozen task doesn't access any suspended device (e.g. by ioctl) on the way out to the userspace where we handle the signal and die. Note, we are not interested in the kernel threads because they are not oom killable.

Accessing suspended devices by a userspace processes shouldn't be an issue because devices are suspended only after userspace is already frozen and oom is disabled at that time.

run_guest (drivers/lguest/core.c) calls try_to_freeze with an user context but it seems it is able to cope with signals because it explicitly checks for pending signals so we should be safe.

Quoted 6 lines

Other than that userspace accesses the fridge only from the signal handling routines so we are able to handle SIGKILL without any negative side effects.

#20 lore raw

Re: [PATCH 1/2] oom: do not live lock on frozen tasks

Quoted 74 lines · KAMEZAWA Hiroyuki
Quoted 71 lines · On Mon, 26 Sep 2011 11:14:40 +0200 Michal Hocko <[email protected]> wrote:
Quoted 23 lines · David Rientjes
Quoted 21 lines · Michal Hocko
mm/oom_kill.c +4 -0
index 626303b..b9774f3 100644
@@ -32,6 +32,7 @@
 #include <linux/mempolicy.h>
 #include <linux/security.h>
 #include <linux/ptrace.h>
+#include <linux/freezer.h>
 
 int sysctl_panic_on_oom;
 int sysctl_oom_kill_allocating_task;
@@ -451,6 +452,9 @@ static int oom_kill_task(struct task_struct *p, struct mem_cgroup *mem)
 				task_pid_nr(q), q->comm);
 			task_unlock(q);
 			force_sig(SIGKILL, q);
+
+			if (frozen(q))
+				thaw_process(q);
 		}
 
Quoted 6 lines

mm/oom_kill.c static int oom_kill_task(struct task_struct *p, struct mem_cgroup *mem) · line 460

Quoted 1 line
mm/oom_kill.c +0 -0
 	set_tsk_thread_flag(p, TIF_MEMDIE);

This is in the wrong place, oom_kill_task() iterates over all threads that are _not_ in the same thread group as the chosen thread and kills them without giving them access to memory reserves. The chosen task, p, could still be frozen and may not exit.

Ahh, right you are. I ave missed that one. Updated patch bellow.

Quoted 4 lines

Once that's fixed, feel free to add my

Thanks

Quoted 2 lines

once Rafael sends his acked-by or reviewed-by.

---
From f935ed4558c2fb033ef5c14e02b28e12a615f80e Mon Sep 17 00:00:00 2001
From: Michal Hocko <[email protected]>
Date: Fri, 16 Sep 2011 11:23:15 +0200
Subject: [PATCH] oom: do not live lock on frozen tasks

Konstantin Khlebnikov has reported (https://lkml.org/lkml/2011/8/23/45)
that OOM can end up in a live lock if select_bad_process picks up a frozen task.
Unfortunately we cannot mark such processes as unkillable to ignore them because we could panic the system even though there is a chance that somebody could thaw the process so we can make a forward process (e.g. a process from another cpuset or with a different nodemask).

Let's thaw an OOM selected frozen process right after we've sent fatal signal from oom_kill_task.
Thawing is safe if the frozen task doesn't access any suspended device (e.g. by ioctl) on the way out to the userspace where we handle the signal and die. Note, we are not interested in the kernel threads because they are not oom killable.

Accessing suspended devices by a userspace processes shouldn't be an issue because devices are suspended only after userspace is already frozen and oom is disabled at that time.

run_guest (drivers/lguest/core.c) calls try_to_freeze with an user context but it seems it is able to cope with signals because it explicitly checks for pending signals so we should be safe.

Quoted 8 lines
Quoted 6 lines

Other than that userspace accesses the fridge only from the signal handling routines so we are able to handle SIGKILL without any negative side effects.

Thanks

Signature · 13 lines
Michal Hocko
SUSE Labs
SUSE LINUX s.r.o.
Lihovarska 1060/12
190 00 Praha 9    
Czech Republic

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#21 lore raw

Re: [PATCH 1/2] oom: do not live lock on frozen tasks

In reply to Michal Hocko
Quoted 71 lines · Michal Hocko
Quoted 23 lines · David Rientjes
Quoted 21 lines · Michal Hocko
mm/oom_kill.c +4 -0
index 626303b..b9774f3 100644
@@ -32,6 +32,7 @@
 #include <linux/mempolicy.h>
 #include <linux/security.h>
 #include <linux/ptrace.h>
+#include <linux/freezer.h>
 
 int sysctl_panic_on_oom;
 int sysctl_oom_kill_allocating_task;
@@ -451,6 +452,9 @@ static int oom_kill_task(struct task_struct *p, struct mem_cgroup *mem)
 				task_pid_nr(q), q->comm);
 			task_unlock(q);
 			force_sig(SIGKILL, q);
+
+			if (frozen(q))
+				thaw_process(q);
 		}
 
Quoted 6 lines

mm/oom_kill.c static int oom_kill_task(struct task_struct *p, struct mem_cgroup *mem) · line 460

Quoted 1 line
mm/oom_kill.c +0 -0
 	set_tsk_thread_flag(p, TIF_MEMDIE);

This is in the wrong place, oom_kill_task() iterates over all threads that are _not_ in the same thread group as the chosen thread and kills them without giving them access to memory reserves. The chosen task, p, could still be frozen and may not exit.

Ahh, right you are. I ave missed that one. Updated patch bellow.

Quoted 4 lines

Once that's fixed, feel free to add my

Thanks

Quoted 2 lines

once Rafael sends his acked-by or reviewed-by.

---
From f935ed4558c2fb033ef5c14e02b28e12a615f80e Mon Sep 17 00:00:00 2001
From: Michal Hocko <[email protected]>
Date: Fri, 16 Sep 2011 11:23:15 +0200
Subject: [PATCH] oom: do not live lock on frozen tasks

Konstantin Khlebnikov has reported (https://lkml.org/lkml/2011/8/23/45)
that OOM can end up in a live lock if select_bad_process picks up a frozen task.
Unfortunately we cannot mark such processes as unkillable to ignore them because we could panic the system even though there is a chance that somebody could thaw the process so we can make a forward process (e.g. a process from another cpuset or with a different nodemask).

Let's thaw an OOM selected frozen process right after we've sent fatal signal from oom_kill_task.
Thawing is safe if the frozen task doesn't access any suspended device (e.g. by ioctl) on the way out to the userspace where we handle the signal and die. Note, we are not interested in the kernel threads because they are not oom killable.

Accessing suspended devices by a userspace processes shouldn't be an issue because devices are suspended only after userspace is already frozen and oom is disabled at that time.

run_guest (drivers/lguest/core.c) calls try_to_freeze with an user context but it seems it is able to cope with signals because it explicitly checks for pending signals so we should be safe.

Quoted 6 lines

Other than that userspace accesses the fridge only from the signal handling routines so we are able to handle SIGKILL without any negative side effects.

Quoted 33 lines
---
 mm/oom_kill.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
mm/oom_kill.c +6 -0
index 626303b..c419a7e 100644
@@ -32,6 +32,7 @@
 #include <linux/mempolicy.h>
 #include <linux/security.h>
 #include <linux/ptrace.h>
+#include <linux/freezer.h>
 
 int sysctl_panic_on_oom;
 int sysctl_oom_kill_allocating_task;
@@ -451,10 +452,15 @@ static int oom_kill_task(struct task_struct *p, struct mem_cgroup *mem)
 				task_pid_nr(q), q->comm);
 			task_unlock(q);
 			force_sig(SIGKILL, q);
+
+			if (frozen(q))
+				thaw_process(q);
 		}
 
 	set_tsk_thread_flag(p, TIF_MEMDIE);
 	force_sig(SIGKILL, p);
+	if (frozen(p))
+		thaw_process(p);
 
 	return 0;
 }
#22 lore raw

Re: [PATCH 1/2] oom: do not live lock on frozen tasks

Quoted 1 line · Rafael J. Wysocki

On Monday, September 26, 2011, Michal Hocko wrote:

[...]

Quoted 28 lines
Quoted 28 lines

From f935ed4558c2fb033ef5c14e02b28e12a615f80e Mon Sep 17 00:00:00 2001
From: Michal Hocko <[email protected]>
Date: Fri, 16 Sep 2011 11:23:15 +0200
Subject: [PATCH] oom: do not live lock on frozen tasks

Konstantin Khlebnikov has reported (https://lkml.org/lkml/2011/8/23/45)
that OOM can end up in a live lock if select_bad_process picks up a frozen task.
Unfortunately we cannot mark such processes as unkillable to ignore them because we could panic the system even though there is a chance that somebody could thaw the process so we can make a forward process (e.g. a process from another cpuset or with a different nodemask).

Let's thaw an OOM selected frozen process right after we've sent fatal signal from oom_kill_task.
Thawing is safe if the frozen task doesn't access any suspended device (e.g. by ioctl) on the way out to the userspace where we handle the signal and die. Note, we are not interested in the kernel threads because they are not oom killable.

Accessing suspended devices by a userspace processes shouldn't be an issue because devices are suspended only after userspace is already frozen and oom is disabled at that time.

run_guest (drivers/lguest/core.c) calls try_to_freeze with an user context but it seems it is able to cope with signals because it explicitly checks for pending signals so we should be safe.

Quoted 8 lines
Quoted 6 lines

Other than that userspace accesses the fridge only from the signal handling routines so we are able to handle SIGKILL without any negative side effects.

Thanks.

Signature · 13 lines
Michal Hocko
SUSE Labs
SUSE LINUX s.r.o.
Lihovarska 1060/12
190 00 Praha 9    
Czech Republic

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
reviewer Acked-by
#23 lore raw

Re: [PATCH 1/2] oom: do not live lock on frozen tasks

In reply to Rafael J. Wysocki
Quoted 23 lines · Rafael J. Wysocki
Quoted 23 lines

Konstantin Khlebnikov has reported (https://lkml.org/lkml/2011/8/23/45)
that OOM can end up in a live lock if select_bad_process picks up a frozen task.
Unfortunately we cannot mark such processes as unkillable to ignore them because we could panic the system even though there is a chance that somebody could thaw the process so we can make a forward process (e.g. a process from another cpuset or with a different nodemask).

Let's thaw an OOM selected frozen process right after we've sent fatal signal from oom_kill_task.
Thawing is safe if the frozen task doesn't access any suspended device (e.g. by ioctl) on the way out to the userspace where we handle the signal and die. Note, we are not interested in the kernel threads because they are not oom killable.

Accessing suspended devices by a userspace processes shouldn't be an issue because devices are suspended only after userspace is already frozen and oom is disabled at that time.

run_guest (drivers/lguest/core.c) calls try_to_freeze with an user context but it seems it is able to cope with signals because it explicitly checks for pending signals so we should be safe.

Quoted 9 lines
Quoted 6 lines

Other than that userspace accesses the fridge only from the signal handling routines so we are able to handle SIGKILL without any negative side effects.

Although this still seems to be problematic if the chosen thread gets frozen before the SIGKILL can be handled. We don't have any checks for fatal_signal_pending() when freezing threads and waiting for them to exit?

Michal, could you send Andrew your revised patch with all the acked-bys?

Thanks!

#24 lore raw

Re: [PATCH 1/2] oom: do not live lock on frozen tasks

Quoted 29 lines · David Rientjes
Quoted 27 lines · Rafael J. Wysocki
Quoted 27 lines

Konstantin Khlebnikov has reported (https://lkml.org/lkml/2011/8/23/45)
that OOM can end up in a live lock if select_bad_process picks up a frozen task.
Unfortunately we cannot mark such processes as unkillable to ignore them because we could panic the system even though there is a chance that somebody could thaw the process so we can make a forward process (e.g. a process from another cpuset or with a different nodemask).

Let's thaw an OOM selected frozen process right after we've sent fatal signal from oom_kill_task.
Thawing is safe if the frozen task doesn't access any suspended device (e.g. by ioctl) on the way out to the userspace where we handle the signal and die. Note, we are not interested in the kernel threads because they are not oom killable.

Accessing suspended devices by a userspace processes shouldn't be an issue because devices are suspended only after userspace is already frozen and oom is disabled at that time.

run_guest (drivers/lguest/core.c) calls try_to_freeze with an user context but it seems it is able to cope with signals because it explicitly checks for pending signals so we should be safe.

Other than that userspace accesses the fridge only from the signal handling routines so we are able to handle SIGKILL without any negative side effects.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Thanks!

Quoted 4 lines

Although this still seems to be problematic if the chosen thread gets frozen before the SIGKILL can be handled. We don't have any checks for fatal_signal_pending() when freezing threads and waiting for them to exit?

I guess you mean a situation when select_bad_process picks up a process which is not marked as frozen yet but we send SIGKILL right before schedule is called in refrigerator.
In that case either schedule should catch it by signal_pending_state check or we will pick it up next OOM round when we pick up the same process (if nothing else is eligible). Or am I missing something?

Quoted 1 line

Michal, could you send Andrew your revised patch with all the acked-bys?

Yes I will. I would just like to hear back from Konstantin who originally reported the issue. Maybe he has a test case.

Quoted 7 lines

Thanks!
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Signature · 6 lines
Michal Hocko
SUSE Labs
SUSE LINUX s.r.o.
Lihovarska 1060/12
190 00 Praha 9    
Czech Republic
#25 lore raw

Re: [PATCH 1/2] oom: do not live lock on frozen tasks

Quoted 7 lines · Michal Hocko

I guess you mean a situation when select_bad_process picks up a process which is not marked as frozen yet but we send SIGKILL right before schedule is called in refrigerator.
In that case either schedule should catch it by signal_pending_state check or we will pick it up next OOM round when we pick up the same process (if nothing else is eligible). Or am I missing something?

That doesn't close the race, the oom killer will see the presence of an eligible TIF_MEMDIE thread in select_bad_process() and simply return to the page allocator. You'd need to thaw it there as well and hope that nothing now or in the future will get into an endless thaw-freeze-thaw loop in the exit path.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#26 lore raw

Re: [PATCH 1/2] oom: do not live lock on frozen tasks

In reply to Michal Hocko
Quoted 11 lines · Michal Hocko
Quoted 4 lines · David Rientjes

I'd love to be able to do a thaw on a PF_FROZEN task in the oom killer followed by a SIGKILL if that task is selected for oom kill without an heuristic change. Not sure if that's possible, so we'll wait for Rafael to chime in.

We have discussed that with Rafael and it should be safe to do that. See the patch bellow.
The only place I am not entirely sure about is run_guest (drivers/lguest/core.c). It seems that the code is able to cope with signals but it also calls lguest_arch_run_guest after try_to_freeze.

Yes; if you want to kill things in the refrigerator(), then will a

		if (cpu->lg->dead || task_is_dead(current))
                        break;

Work? That break means we return to the read() syscall pretty much immediately.

Thanks for the CC,
Rusty.

#27 lore raw

Re: [PATCH 1/2] oom: do not live lock on frozen tasks

Quoted 13 lines · Rusty Russell
Quoted 11 lines · Michal Hocko
Quoted 4 lines · David Rientjes

I'd love to be able to do a thaw on a PF_FROZEN task in the oom killer followed by a SIGKILL if that task is selected for oom kill without an heuristic change. Not sure if that's possible, so we'll wait for Rafael to chime in.

We have discussed that with Rafael and it should be safe to do that. See the patch bellow.
The only place I am not entirely sure about is run_guest (drivers/lguest/core.c). It seems that the code is able to cope with signals but it also calls lguest_arch_run_guest after try_to_freeze.

Quoted 6 lines

Yes; if you want to kill things in the refrigerator(), then will a

		if (cpu->lg->dead || task_is_dead(current))
                        break;

Work?

The task is not dead yet. We should rather check for pending signals. Can we just move try_to_freeze up before the pending signals check?

drivers/lguest/core.c +6 -7
index 2535933..a513509 100644
@@ -232,6 +232,12 @@ int run_guest(struct lg_cpu *cpu, unsigned long __user *user)
 			}
 		}
 
+		/*
+		 * All long-lived kernel loops need to check with this horrible
+		 * thing called the freezer.  If the Host is trying to suspend,
+		 * it stops us.
+		 */
+		try_to_freeze();
 		/* Check for signals */
 		if (signal_pending(current))
 			return -ERESTARTSYS;
@@ -246,13 +252,6 @@ int run_guest(struct lg_cpu *cpu, unsigned long __user *user)
 			try_deliver_interrupt(cpu, irq, more);
 
 		/*
-		 * All long-lived kernel loops need to check with this horrible
-		 * thing called the freezer.  If the Host is trying to suspend,
-		 * it stops us.
-		 */
-		try_to_freeze();
-
-		/*
 		 * Just make absolutely sure the Guest is still alive.  One of
 		 * those hypercalls could have been fatal, for example.
 		 */
Quoted 5 lines

That break means we return to the read() syscall pretty much immediately.

Thanks for the CC,
Rusty.

Signature · 13 lines
Michal Hocko
SUSE Labs
SUSE LINUX s.r.o.
Lihovarska 1060/12
190 00 Praha 9    
Czech Republic

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Acked-by
#28 lore raw

Re: [PATCH 1/2] oom: do not live lock on frozen tasks

Quoted 16 lines · Michal Hocko
Quoted 15 lines · Rusty Russell
Quoted 11 lines · Michal Hocko
Quoted 4 lines · David Rientjes

I'd love to be able to do a thaw on a PF_FROZEN task in the oom killer followed by a SIGKILL if that task is selected for oom kill without an heuristic change. Not sure if that's possible, so we'll wait for Rafael to chime in.

We have discussed that with Rafael and it should be safe to do that. See the patch bellow.
The only place I am not entirely sure about is run_guest (drivers/lguest/core.c). It seems that the code is able to cope with signals but it also calls lguest_arch_run_guest after try_to_freeze.

Yes; if you want to kill things in the refrigerator(), then will a

Quoted 7 lines
Quoted 4 lines
		if (cpu->lg->dead || task_is_dead(current))
                        break;

Work?

The task is not dead yet. We should rather check for pending signals. Can we just move try_to_freeze up before the pending signals check?

Yep, that works.

Cheers,
Rusty.

#29 lore raw

PATCH 1/1 lguest: move process freezing before pending signals check

Quoted 20 lines · Rusty Russell
Quoted 19 lines · Michal Hocko
Quoted 18 lines · Rusty Russell
Quoted 11 lines · Michal Hocko
Quoted 4 lines · David Rientjes

I'd love to be able to do a thaw on a PF_FROZEN task in the oom killer followed by a SIGKILL if that task is selected for oom kill without an heuristic change. Not sure if that's possible, so we'll wait for Rafael to chime in.

We have discussed that with Rafael and it should be safe to do that. See the patch bellow.
The only place I am not entirely sure about is run_guest (drivers/lguest/core.c). It seems that the code is able to cope with signals but it also calls lguest_arch_run_guest after try_to_freeze.

Yes; if you want to kill things in the refrigerator(), then will a

		if (cpu->lg->dead || task_is_dead(current))
                        break;
Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Work?

The task is not dead yet. We should rather check for pending signals. Can we just move try_to_freeze up before the pending signals check?

Yep, that works.

Thanks.
The full patch bellow:
---

#30 lore raw

PATCH 2/2 oom: give bonus to frozen processes

In reply to David Rientjes
Quoted 1 line · David Rientjes

On Fri, 26 Aug 2011, Michal Hocko wrote:

[...]

Quoted 4 lines
Quoted 4 lines

I am not saying the bonus is necessary, though. It depends on what the freezer is used for (e.g. freeze a process which went wild and debug what went wrong wouldn't welcome that somebody killed it or other (mis)use which relies on D state).

[...]

Quoted 6 lines

If it actually does come down to a heuristic change, then it need not happen in the oom killer: the freezing code would need to use test_set_oom_score_adj() to temporarily reduce the oom_score_adj for that task until it comes out of the refrigerator. We already use that in ksm and swapoff to actually prefer threads, but we can use it to bias against threads as well.

Let's try it with a heuristic change first. If you really do not like it, we can move to oom_scode_adj. I like the heuristic change little bit more because it is at the same place as the root bonus.
---

Quoted 1 line

From 2f8fbab922f353eebaa9fa1c5fcb59a59cf2f441 Mon Sep 17 00:00:00 2001

From: Michal Hocko <[email protected]>
Date: Fri, 16 Sep 2011 15:51:25 +0200
Subject: [PATCH 2/2] oom: give bonus to frozen processes

We do not want to kill frozen processes if there are some processes that could be killed instead. Frozen tasks are in uninterruptible sleep and somebody might rely on that.
Let's give those tasks a bonus so that they would be selected only when really necessary. The size of the bonus is questionable but let's start with the same bonus we give to root processes.

---
 include/linux/oom.h |    6 ++++++
 mm/oom_kill.c       |   10 +++++++++-
 2 files changed, 15 insertions(+), 1 deletions(-)
include/linux/oom.h +6 -0
index 13b7b02e..960e2de 100644
@@ -13,6 +13,12 @@
 #define OOM_ADJUST_MAX 15
 
 /*
+ * Bonus (3%) for a task that shouldn't be killed unless necessary.
+ * We give this bonus to root and frozen tasks currently.
+ */
+#define OOM_BONUS 30
+
+/*
  * /proc/<pid>/oom_score_adj set to OOM_SCORE_ADJ_MIN disables oom killing for
  * pid.
  */
mm/oom_kill.c +9 -1
index b9774f3..4aea1b3 100644
@@ -205,7 +205,15 @@ unsigned int oom_badness(struct task_struct *p, struct mem_cgroup *mem,
 	 * implementation used by LSMs.
 	 */
 	if (has_capability_noaudit(p, CAP_SYS_ADMIN))
-		points -= 30;
+		points -= OOM_BONUS;
+
+	/*
+	 * Do not try to kill frozen tasks unless there is nothing else to kill.
+	 * We do not want to give it 1 point because we still want to select a good
+	 * candidate among all frozen tasks. Let's give it a reasonable bonus.
+	 */
+	if (frozen(p))
+		points -= OOM_BONUS;
 
 	/*
 	 * /proc/pid/oom_score_adj ranges from -1000 to +1000 such that it may
Signature · 10 lines
1.7.5.4


-- 
Michal Hocko
SUSE Labs
SUSE LINUX s.r.o.
Lihovarska 1060/12
190 00 Praha 9    
Czech Republic
#31 lore raw

Re: [PATCH 2/2] oom: give bonus to frozen processes

Quoted 3 lines · Michal Hocko

Let's try it with a heuristic change first. If you really do not like it, we can move to oom_scode_adj. I like the heuristic change little bit more because it is at the same place as the root bonus.

The problem with the bonus is that, as mentioned previously, it doesn't protect against ANYTHING for the case you're trying to fix. This won't panic the machine because all killable threads are guaranteed to have a non-zero badness score, but it's a very valid configuration to have either

- all eligible threads (system-wide, shared cpuset, shared mempolicy nodes) are frozen, or

- all eligible frozen threads use <5% of memory whereas all other eligible killable threads use 1% of available memory.

and that means the oom killer will repeatedly select those threads and the livelock still exists unless you can guarantee that they are successfully thawed, that thawing them in all situations is safe, and that once thawed they will make a timely exit.

Additionally, I don't think biasing against frozen tasks makes sense from a heusritic standpoint of the oom killer. Why would we want give non-frozen tasks that are actually getting work done a preference over a task that is frozen and doing absolutely nothing? It seems like that's backwards and that we'd actually prefer killing the task doing nothing so it can free its memory.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#32 lore raw

Re: [PATCH 2/2] oom: give bonus to frozen processes

Quoted 22 lines · On Mon, 26 Sep 2011 02:02:59 -0700 (PDT) David Rientjes <[email protected]>…
Quoted 3 lines · Michal Hocko

Let's try it with a heuristic change first. If you really do not like it, we can move to oom_scode_adj. I like the heuristic change little bit more because it is at the same place as the root bonus.

The problem with the bonus is that, as mentioned previously, it doesn't protect against ANYTHING for the case you're trying to fix. This won't panic the machine because all killable threads are guaranteed to have a non-zero badness score, but it's a very valid configuration to have either

- all eligible threads (system-wide, shared cpuset, shared mempolicy nodes) are frozen, or

- all eligible frozen threads use <5% of memory whereas all other eligible killable threads use 1% of available memory.

and that means the oom killer will repeatedly select those threads and the livelock still exists unless you can guarantee that they are successfully thawed, that thawing them in all situations is safe, and that once thawed they will make a timely exit.

Quoted 7 lines

Additionally, I don't think biasing against frozen tasks makes sense from a heusritic standpoint of the oom killer. Why would we want give non-frozen tasks that are actually getting work done a preference over a task that is frozen and doing absolutely nothing? It seems like that's backwards and that we'd actually prefer killing the task doing nothing so it can free its memory.

I agree with David.
Why don't you set oom_score_adj as -1000 for processes which never should die ? You don't freeze processes via user-land using cgroup ?

Thanks,
-Kame

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#33 lore raw

Re: [PATCH 2/2] oom: give bonus to frozen processes

Quoted 11 lines · KAMEZAWA Hiroyuki
Quoted 8 lines · On Mon, 26 Sep 2011 02:02:59 -0700 (PDT) David Rientjes <[email protected]>…
Quoted 3 lines · Michal Hocko

Let's try it with a heuristic change first. If you really do not like it, we can move to oom_scode_adj. I like the heuristic change little bit more because it is at the same place as the root bonus.

The problem with the bonus is that, as mentioned previously, it doesn't protect against ANYTHING for the case you're trying to fix.

Yes, it just makes this less probable.

Quoted 7 lines
Quoted 7 lines

This won't panic the machine because all killable threads are guaranteed to have a non-zero badness score, but it's a very valid configuration to have either

- all eligible threads (system-wide, shared cpuset, shared mempolicy nodes) are frozen, or

Quoted 7 lines
Quoted 7 lines

- all eligible frozen threads use <5% of memory whereas all other eligible killable threads use 1% of available memory.

and that means the oom killer will repeatedly select those threads and the livelock still exists unless you can guarantee that they are successfully thawed, that thawing them in all situations is safe, and that once thawed they will make a timely exit.

Yes, this is what the first patch is fixing. Thawed tasks should die almost immediately because they are on the way to userspace anyway.

Quoted 5 lines
Quoted 5 lines

Additionally, I don't think biasing against frozen tasks makes sense from a heusritic standpoint of the oom killer. Why would we want give non-frozen tasks that are actually getting work done a preference over a task that is frozen and doing absolutely nothing?

Because frozen tasks are in that state usually (not considering suspend path which has OOM disabled) based on an user request (via freezer cgroup e.g.). I wouldn't be surprised if somebody relied on the D state and that the task will not get killer.

Quoted 6 lines
Quoted 3 lines

It seems like that's backwards and that we'd actually prefer killing the task doing nothing so it can free its memory.

I agree with David.
Why don't you set oom_score_adj as -1000 for processes which never should die ?

It is little bit unintuitive to think about OOM killer when you just want to debug your frozen application.
On the other hand I agree that adding a new heuristic for an use case that is not entirely clear and which is not 100% anyway is not good.

So, please scratch this patch and let's wait for somebody with a valid use case.

Quoted 1 line

You don't freeze processes via user-land using cgroup ?

That was exactly the use case I had in mind. Somebody using freezer cgroup to freeze a task to debug it.

Quoted 12 lines

Thanks,
-Kame

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

Signature · 13 lines
Michal Hocko
SUSE Labs
SUSE LINUX s.r.o.
Lihovarska 1060/12
190 00 Praha 9    
Czech Republic

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#34 lore raw
In reply to David Rientjes
Quoted 17 lines · David Rientjes
Quoted 4 lines · Michal Hocko

Let's give all frozen tasks a bonus (OOM_SCORE_ADJ_MAX/2) so that we do not consider them unless really necessary and if we really pick up one then thaw its threads before we try to kill it.

I don't like arbitrary heuristics like this because they polluted the old oom killer before it was rewritten and made it much more unpredictable. The only heuristic it includes right now is a bonus for root tasks so that when two processes have nearly the same amount of memory usage (within 3% of available memory), the non-root task is chosen instead.

This bonus is actually saying that a single frozen task can use up to 50% more of the machine's capacity in a system-wide oom condition than the task that will now be killed instead. That seems excessive.

Quoted 5 lines

I do like the idea of automatically thawing the task though and if that's possible then I don't think we need to manipulate the badness heuristic at all. I know that wouldn't be feasible when we've frozen _all_ threads and that's why we have oom_killer_disable(), but we'll have to check with Rafael to see if something like this could work. Rafael?

That depends a good deal on when the thawing happens and what the thawed task can do before being killed. For example, if the thawing happens while devices are suspended and the thawed task accesses a driver through ioctl(), for example, the purpose of freezing will be defeated.

Thanks,
Rafael

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#35 lore raw
In reply to Michal Hocko

Review static int oom_kill_task(struct task_struct *p, struct mem_cgroup *mem) · line 465

Quoted 8 lines · Michal Hocko
(quoted diff) +4 -0
@@ -450,6 +459,10 @@ static int oom_kill_task(struct task_struct *p, struct mem_cgroup *mem)
  			pr_err("Kill process %d (%s) sharing same memory\n",
  				task_pid_nr(q), q->comm);
  			task_unlock(q);
+
+			if (frozen(q))
+				thaw_process(q);
+

We must thaw task strictly after sending SIGKILL.
But anyway I think this is a bad idea.

Quoted 3 lines
(quoted diff) +0 -0
  			force_sig(SIGKILL, q);
  		}
 
#36 lore raw
Quoted 12 lines · Konstantin Khlebnikov

Review static int oom_kill_task(struct task_struct *p, struct mem_cgroup *mem) · line 465

Quoted 8 lines · Michal Hocko
(quoted diff) +4 -0
@@ -450,6 +459,10 @@ static int oom_kill_task(struct task_struct *p, struct mem_cgroup *mem)
 			pr_err("Kill process %d (%s) sharing same memory\n",
 				task_pid_nr(q), q->comm);
 			task_unlock(q);
+
+			if (frozen(q))
+				thaw_process(q);
+

We must thaw task strictly after sending SIGKILL.

Sounds reasonable.

Quoted 1 line

But anyway I think this is a bad idea.

Why?

Quoted 4 lines
Quoted 4 lines
(quoted diff) +0 -0
 			force_sig(SIGKILL, q);
 		}
 
Signature · 13 lines
Michal Hocko
SUSE Labs
SUSE LINUX s.r.o.
Lihovarska 1060/12
190 00 Praha 9    
Czech Republic

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#37 lore raw
Quoted 14 lines · Michal Hocko
Quoted 12 lines · Konstantin Khlebnikov

Review static int oom_kill_task(struct task_struct *p, struct mem_cgroup *mem) · line 465

Quoted 8 lines · Michal Hocko
(quoted diff) +4 -0
@@ -450,6 +459,10 @@ static int oom_kill_task(struct task_struct *p, struct mem_cgroup *mem)
  			pr_err("Kill process %d (%s) sharing same memory\n",
  				task_pid_nr(q), q->comm);
  			task_unlock(q);
+
+			if (frozen(q))
+				thaw_process(q);
+

We must thaw task strictly after sending SIGKILL.

Quoted 5 lines

Sounds reasonable.

Quoted 1 line

But anyway I think this is a bad idea.

Why?

Refrigerator may be used for digging in task's internal structures, so such digger may be very surprised if somebody suddenly thaws this task.

Quoted 6 lines
Quoted 5 lines
Quoted 5 lines
(quoted diff) +0 -0
  			force_sig(SIGKILL, q);
  		}
 
#38 lore raw
Quoted 15 lines · Konstantin Khlebnikov
Quoted 14 lines · Michal Hocko
Quoted 12 lines · Konstantin Khlebnikov

Review static int oom_kill_task(struct task_struct *p, struct mem_cgroup *mem) · line 465

Quoted 8 lines · Michal Hocko
(quoted diff) +4 -0
@@ -450,6 +459,10 @@ static int oom_kill_task(struct task_struct *p, struct mem_cgroup *mem)
 			pr_err("Kill process %d (%s) sharing same memory\n",
 				task_pid_nr(q), q->comm);
 			task_unlock(q);
+
+			if (frozen(q))
+				thaw_process(q);
+

We must thaw task strictly after sending SIGKILL.

Quoted 8 lines
Quoted 5 lines

Sounds reasonable.

Quoted 1 line

But anyway I think this is a bad idea.

Why?

Refrigerator may be used for digging in task's internal structures, so such digger may be very surprised if somebody suddenly thaws this task.

That is something similar why I mentioned that we probably want to give it some oom bonus. Nevertheless we have to be carefull about that. Someone could freeze a memory hog just to hide it from OOM which would have much worse consequences than if such app disappeared while somebody is looking at it while it is frozen.
This has to be balanced somehow.

Quoted 13 lines
Quoted 7 lines
Quoted 6 lines

Review static int oom_kill_task(struct task_struct *p, struct mem_cgroup *mem) · line 468

Quoted 6 lines
(quoted diff) +0 -0
 			force_sig(SIGKILL, q);
 		}
 

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Signature · 13 lines
Michal Hocko
SUSE Labs
SUSE LINUX s.r.o.
Lihovarska 1060/12
190 00 Praha 9    
Czech Republic

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#39 lore raw
In reply to David Rientjes
Quoted 35 lines · David Rientjes
Quoted 11 lines · Michal Hocko
Quoted 10 lines
Quoted 7 lines
Quoted 4 lines

That's obviously false since we call oom_killer_disable() in freeze_processes() to disable the oom killer from ever being called in the first place, so this is something you need to resolve with Rafael before you cause more machines to panic.

I didn't mean suspend/resume path (that is protected by oom_killer_disabled) so the patch doesn't make any change.

Confused... freeze_processes() does try_to_freeze_tasks() before oom_killer_disable() ?

Quoted 9 lines

Yes you are right, I must have been blind.

Now I see the point. We do not want to panic while we are suspending and the memory is really low just because all the userspace is already in the the fridge.
Sorry for confusion.

I still do not follow the oom_killer_disable note from David, though.

oom_killer_disable() was added to that path for a reason when all threads are frozen: memory allocations still occur in the suspend path in an oom condition and adding the oom_killer_disable() will cause those allocations to fail rather than sending pointless SIGKILLs to frozen threads.

Now consider if the only _eligible_ threads for oom kill (because of cpusets or mempolicies) are those that are frozen. We certainly do not want to panic because other cpusets are still getting work done. We'd either want to add a mem to the cpuset or thaw the processes because the cpuset is oom.

Quoted 7 lines

You can't just selectively skip certain threads when their state can be temporary without risking a panic. That's why this patch is a non-starter.

A much better solution would be to lower the badness score that the oom killer uses for PF_FROZEN threads so that they aren't considered a priority for kill unless there's nothing else left to kill.

Anyway, oom killer shouldn't loop endlessly if it see TIF_MEMDIE on frozen task, it must go on and try to kill somebody else. We cannot wait for thawing this task.

#40 lore raw
Quoted 9 lines · Konstantin Khlebnikov
Quoted 3 lines

A much better solution would be to lower the badness score that the oom killer uses for PF_FROZEN threads so that they aren't considered a priority for kill unless there's nothing else left to kill.

Anyway, oom killer shouldn't loop endlessly if it see TIF_MEMDIE on frozen task,
it must go on and try to kill somebody else. We cannot wait for thawing this task.

Did you read my suggestion? I quoted it above again for you. The badness heuristic would only select those tasks to kill as a last resort in the hopes they will eventually be thawed and may exit. Panicking the entire machine for what could be isolated by a cgroup is insanity.

#41 lore raw
Quoted 12 lines · David Rientjes
Quoted 9 lines · Konstantin Khlebnikov
Quoted 3 lines

A much better solution would be to lower the badness score that the oom killer uses for PF_FROZEN threads so that they aren't considered a priority for kill unless there's nothing else left to kill.

Anyway, oom killer shouldn't loop endlessly if it see TIF_MEMDIE on frozen task,
it must go on and try to kill somebody else. We cannot wait for thawing this task.

Quoted 4 lines

Did you read my suggestion? I quoted it above again for you. The badness heuristic would only select those tasks to kill as a last resort in the hopes they will eventually be thawed and may exit. Panicking the entire machine for what could be isolated by a cgroup is insanity.

Maybe just fix this "panic" logic? OOM killer should panic only on global memory shortage.

#42 lore raw
Quoted 3 lines · Konstantin Khlebnikov

Maybe just fix this "panic" logic? OOM killer should panic only on global memory shortage.

NO, it shouldn't, we actually rely quite extensively on cpusets filled with OOM_DISABLE threads to panic because the job scheduler would be unresponsive in such a condition and it'd much better to panic and reboot than to brick the machine. I'm not sure where you're getting all your information from, but please don't pass it off as principles.

You can set the panic logic to be whatever you want with /proc/sys/vm/panic_on_oom. See Documentation/filesystems/proc.txt for more information.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#43 lore raw
In reply to Oleg Nesterov
Quoted 9 lines · Oleg Nesterov
Quoted 8 lines · Michal Hocko
Quoted 5 lines · David Rientjes

That's obviously false since we call oom_killer_disable() in freeze_processes() to disable the oom killer from ever being called in the first place, so this is something you need to resolve with Rafael before you cause more machines to panic.

Quoted 5 lines
Quoted 2 lines

I didn't mean suspend/resume path (that is protected by oom_killer_disabled) so the patch doesn't make any change.

Confused... freeze_processes() does try_to_freeze_tasks() before oom_killer_disable() ?

Yes, it does.

Thanks,
Rafael