Skip to content

Commit bbbe480

Browse files
shakeelbtorvalds
authored andcommitted
mm, oom: remove 'prefer children over parent' heuristic
Since the start of the git history of Linux, the kernel after selecting the worst process to be oom-killed, prefer to kill its child (if the child does not share mm with the parent). Later it was changed to prefer to kill a child who is worst. If the parent is still the worst then the parent will be killed. This heuristic assumes that the children did less work than their parent and by killing one of them, the work lost will be less. However this is very workload dependent. If there is a workload which can benefit from this heuristic, can use oom_score_adj to prefer children to be killed before the parent. The select_bad_process() has already selected the worst process in the system/memcg. There is no need to recheck the badness of its children and hoping to find a worse candidate. That's a lot of unneeded racy work. Also the heuristic is dangerous because it make fork bomb like workloads to recover much later because we constantly pick and kill processes which are not memory hogs. So, let's remove this whole heuristic. [akpm@linux-foundation.org: coding-style fixes] Link: http://lkml.kernel.org/r/20190121215850.221745-2-shakeelb@google.com Signed-off-by: Shakeel Butt <shakeelb@google.com> Acked-by: Michal Hocko <mhocko@suse.com> Acked-by: Roman Gushchin <guro@fb.com> Acked-by: Johannes Weiner <hannes@cmpxchg.org> Cc: David Rientjes <rientjes@google.com> Cc: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent d9f7979 commit bbbe480

1 file changed

Lines changed: 18 additions & 60 deletions

File tree

‎mm/oom_kill.c‎

Lines changed: 18 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ static bool task_will_free_mem(struct task_struct *task)
843843
return ret;
844844
}
845845

846-
static void __oom_kill_process(struct task_struct *victim)
846+
static void __oom_kill_process(struct task_struct *victim, const char *message)
847847
{
848848
struct task_struct *p;
849849
struct mm_struct *mm;
@@ -874,8 +874,9 @@ static void __oom_kill_process(struct task_struct *victim)
874874
*/
875875
do_send_sig_info(SIGKILL, SEND_SIG_PRIV, victim, PIDTYPE_TGID);
876876
mark_oom_victim(victim);
877-
pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB, shmem-rss:%lukB\n",
878-
task_pid_nr(victim), victim->comm, K(victim->mm->total_vm),
877+
pr_err("%s: Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB, shmem-rss:%lukB\n",
878+
message, task_pid_nr(victim), victim->comm,
879+
K(victim->mm->total_vm),
879880
K(get_mm_counter(victim->mm, MM_ANONPAGES)),
880881
K(get_mm_counter(victim->mm, MM_FILEPAGES)),
881882
K(get_mm_counter(victim->mm, MM_SHMEMPAGES)));
@@ -926,24 +927,19 @@ static void __oom_kill_process(struct task_struct *victim)
926927
* Kill provided task unless it's secured by setting
927928
* oom_score_adj to OOM_SCORE_ADJ_MIN.
928929
*/
929-
static int oom_kill_memcg_member(struct task_struct *task, void *unused)
930+
static int oom_kill_memcg_member(struct task_struct *task, void *message)
930931
{
931932
if (task->signal->oom_score_adj != OOM_SCORE_ADJ_MIN) {
932933
get_task_struct(task);
933-
__oom_kill_process(task);
934+
__oom_kill_process(task, message);
934935
}
935936
return 0;
936937
}
937938

938939
static void oom_kill_process(struct oom_control *oc, const char *message)
939940
{
940-
struct task_struct *p = oc->chosen;
941-
unsigned int points = oc->chosen_points;
942-
struct task_struct *victim = p;
943-
struct task_struct *child;
944-
struct task_struct *t;
941+
struct task_struct *victim = oc->chosen;
945942
struct mem_cgroup *oom_group;
946-
unsigned int victim_points = 0;
947943
static DEFINE_RATELIMIT_STATE(oom_rs, DEFAULT_RATELIMIT_INTERVAL,
948944
DEFAULT_RATELIMIT_BURST);
949945

@@ -952,57 +948,18 @@ static void oom_kill_process(struct oom_control *oc, const char *message)
952948
* its children or threads, just give it access to memory reserves
953949
* so it can die quickly
954950
*/
955-
task_lock(p);
956-
if (task_will_free_mem(p)) {
957-
mark_oom_victim(p);
958-
wake_oom_reaper(p);
959-
task_unlock(p);
960-
put_task_struct(p);
951+
task_lock(victim);
952+
if (task_will_free_mem(victim)) {
953+
mark_oom_victim(victim);
954+
wake_oom_reaper(victim);
955+
task_unlock(victim);
956+
put_task_struct(victim);
961957
return;
962958
}
963-
task_unlock(p);
959+
task_unlock(victim);
964960

965961
if (__ratelimit(&oom_rs))
966-
dump_header(oc, p);
967-
968-
pr_err("%s: Kill process %d (%s) score %u or sacrifice child\n",
969-
message, task_pid_nr(p), p->comm, points);
970-
971-
/*
972-
* If any of p's children has a different mm and is eligible for kill,
973-
* the one with the highest oom_badness() score is sacrificed for its
974-
* parent. This attempts to lose the minimal amount of work done while
975-
* still freeing memory.
976-
*/
977-
read_lock(&tasklist_lock);
978-
979-
/*
980-
* The task 'p' might have already exited before reaching here. The
981-
* put_task_struct() will free task_struct 'p' while the loop still try
982-
* to access the field of 'p', so, get an extra reference.
983-
*/
984-
get_task_struct(p);
985-
for_each_thread(p, t) {
986-
list_for_each_entry(child, &t->children, sibling) {
987-
unsigned int child_points;
988-
989-
if (process_shares_mm(child, p->mm))
990-
continue;
991-
/*
992-
* oom_badness() returns 0 if the thread is unkillable
993-
*/
994-
child_points = oom_badness(child,
995-
oc->memcg, oc->nodemask, oc->totalpages);
996-
if (child_points > victim_points) {
997-
put_task_struct(victim);
998-
victim = child;
999-
victim_points = child_points;
1000-
get_task_struct(victim);
1001-
}
1002-
}
1003-
}
1004-
put_task_struct(p);
1005-
read_unlock(&tasklist_lock);
962+
dump_header(oc, victim);
1006963

1007964
/*
1008965
* Do we need to kill the entire memory cgroup?
@@ -1011,14 +968,15 @@ static void oom_kill_process(struct oom_control *oc, const char *message)
1011968
*/
1012969
oom_group = mem_cgroup_get_oom_group(victim, oc->memcg);
1013970

1014-
__oom_kill_process(victim);
971+
__oom_kill_process(victim, message);
1015972

1016973
/*
1017974
* If necessary, kill all tasks in the selected memory cgroup.
1018975
*/
1019976
if (oom_group) {
1020977
mem_cgroup_print_oom_group(oom_group);
1021-
mem_cgroup_scan_tasks(oom_group, oom_kill_memcg_member, NULL);
978+
mem_cgroup_scan_tasks(oom_group, oom_kill_memcg_member,
979+
(void*)message);
1022980
mem_cgroup_put(oom_group);
1023981
}
1024982
}

0 commit comments

Comments
 (0)