From: Chris Mason On a NUMA machine, a process can exhaust nodes that its own task mempolicy or cpuset. The mempolicy can kill unrelated tasks one after the other, and then panic, while that process is never selected. The OOM killer skips a task that oom_cpuset_eligible() rejects, on the assumption that killing it frees nothing on the nodes that ran out. But each of the two tests in that function can reject the process whose mm is filling those nodes: - In a mempolicy OOM, the function checks the mempolicy of the task. But the nodemask of the allocation can come from the mempolicy of a VMA, so a task with MPOL_BIND to other nodes can still fill the exhausted nodes. - In a cpuset OOM, the function compares the mems_allowed of the task with that of current. mems_allowed is per task, so a vfork() child can allocate in a different cpuset from its parent. oom_badness() skips the child because it is in vfork(). The parent shares the mm, but it is rejected because its cpuset has other nodes. Tasks with no mempolicy, or in the root cpuset, pass these tests and are killed instead. When none is left, out_of_memory() panics. The fix used here is to treat every process that shares the mm of current as eligible, since current is allocating on the exhausted nodes. Fixes: 6f48d0ebd907 ("oom: select task from tasklist for mempolicy ooms") Signed-off-by: Chris Mason Acked-by: Michal Hocko Signed-off-by: David Hildenbrand (Arm) --- mm/oom_kill.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 9de57a23893c..30c314069d5b 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -82,7 +82,8 @@ static inline bool is_memcg_oom(struct oom_control *oc) * * Task eligibility is determined by whether or not a candidate task, @tsk, * shares the same mempolicy nodes as current if it is bound by such a policy - * and whether or not it has the same set of allowed cpuset nodes. + * and whether or not it has the same set of allowed cpuset nodes. A process + * that shares the mm of current is always eligible. * * This function is assuming oom-killer context and 'current' has triggered * the oom-killer. @@ -90,11 +91,23 @@ static inline bool is_memcg_oom(struct oom_control *oc) static bool oom_cpuset_eligible(struct task_struct *start, struct oom_control *oc) { + struct mm_struct *mm = current->mm; struct task_struct *tsk; bool ret = false; const nodemask_t *mask = oc->nodemask; rcu_read_lock(); + /* + * current allocates on the nodes of this oom, so its mm may have memory + * there. The tests below can miss that: the nodemask can come from the + * mempolicy of a vma while that of the task binds it to other nodes, and + * a process that shares the mm can be in another cpuset. + */ + if (mm && process_shares_mm(start, mm)) { + ret = true; + goto unlock; + } + for_each_thread(start, tsk) { if (mask) { /* @@ -114,6 +127,7 @@ static bool oom_cpuset_eligible(struct task_struct *start, if (ret) break; } +unlock: rcu_read_unlock(); return ret; @@ -407,8 +421,8 @@ static int dump_task(struct task_struct *p, void *arg) * @oc: pointer to struct oom_control * * Dumps the current memory state of all eligible tasks. Tasks not in the same - * memcg, not in the same cpuset, or bound to a disjoint set of mempolicy nodes - * are not shown. + * memcg are not shown. Nor are tasks not in the same cpuset or bound to a + * disjoint set of mempolicy nodes, unless they share the mm of current. * State information includes task's pid, uid, tgid, vm size, rss, * pgtables_bytes, swapents, oom_score_adj value, and name. */ -- 2.56.1