[RFC 3/3] oom: Do not try to sacrifice small children

From: Michal Hocko
Date: Tue Jan 12 2016 - 16:00:44 EST


From: Michal Hocko <mhocko@xxxxxxxx>

try_to_sacrifice_child will select the largest child of the selected OOM
victim to protect it and potentially save some work done by the parent.
We can however select a small child which has barely touched any memory
and killing it wouldn't lead to OOM recovery and only prolong the OOM
condition which is not desirable.

This patch simply ignores the largest child selection and falls back to
the parent (original victim) if the child hasn't accumulated even 1MB
worth of oom score. We are not checking the memory consumption directly
as we want to honor the oom_score_adj here because this would be the
only way to protect children from this heuristic in case they are more
important than the parent.

Signed-off-by: Michal Hocko <mhocko@xxxxxxxx>
---
mm/oom_kill.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index 8bca0b1e97f7..b5c0021c6462 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -721,8 +721,16 @@ try_to_sacrifice_child(struct oom_control *oc, struct task_struct *victim,
if (!child_victim)
goto out;

- put_task_struct(victim);
- victim = child_victim;
+ /*
+ * Protecting the parent makes sense only if killing the child
+ * would release at least some memory (at least 1MB).
+ */
+ if (K(victim_points) >= 1024) {
+ put_task_struct(victim);
+ victim = child_victim;
+ } else {
+ put_task_struct(child_victim);
+ }

out:
return victim;
--
2.6.4