Skip to contentSkip to conversation

mm, oom: fix oom_unkillable_task for memcg OOMs

PATCH In review Shakeel Butt 2 participants 3 messages Jun 17, 2019

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

PATCH 1/1 mm, oom: fix oom_unkillable_task for memcg OOMs

Currently oom_unkillable_task() checks mems_allowed even for memcg OOMs which does not make sense as memcg OOMs can not be triggered due to numa constraints. Fixing that.

Also if memcg is given, oom_unkillable_task() will check the task's memcg membership as well to detect oom killability. However all the memcg related code paths leading to oom_unkillable_task(), other than dump_tasks(), come through mem_cgroup_scan_tasks() which traverses tasks through memcgs. Once dump_tasks() is converted to use mem_cgroup_scan_tasks(), there is no need to do memcg membership check in oom_unkillable_task().

---
 fs/proc/base.c      |   3 +-
 include/linux/oom.h |   3 +-
 mm/oom_kill.c       | 100 +++++++++++++++++++++++++-------------------
 3 files changed, 60 insertions(+), 46 deletions(-)
fs/proc/base.c +1 -2
index b8d5d100ed4a..69b0d1b6583d 100644
@@ -532,8 +532,7 @@ static int proc_oom_score(struct seq_file *m, struct pid_namespace *ns,
 	unsigned long totalpages = totalram_pages() + total_swap_pages;
 	unsigned long points = 0;
 
-	points = oom_badness(task, NULL, NULL, totalpages) *
-					1000 / totalpages;
+	points = oom_badness(task, NULL, totalpages) * 1000 / totalpages;
 	seq_printf(m, "%lu\n", points);
 
 	return 0;
include/linux/oom.h +1 -2
index d07992009265..39c42caa3231 100644
@@ -108,8 +108,7 @@ static inline vm_fault_t check_stable_address_space(struct mm_struct *mm)
 bool __oom_reap_task_mm(struct mm_struct *mm);
 
 extern unsigned long oom_badness(struct task_struct *p,
-		struct mem_cgroup *memcg, const nodemask_t *nodemask,
-		unsigned long totalpages);
+		struct oom_control *oc, unsigned long totalpages);
 
 extern bool out_of_memory(struct oom_control *oc);
 
mm/oom_kill.c +58 -42

174 lines not on this page · raw message

Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
#1 lore raw
Quoted 11 lines · Shakeel Butt

Currently oom_unkillable_task() checks mems_allowed even for memcg OOMs which does not make sense as memcg OOMs can not be triggered due to numa constraints. Fixing that.

Also if memcg is given, oom_unkillable_task() will check the task's memcg membership as well to detect oom killability. However all the memcg related code paths leading to oom_unkillable_task(), other than dump_tasks(), come through mem_cgroup_scan_tasks() which traverses tasks through memcgs. Once dump_tasks() is converted to use mem_cgroup_scan_tasks(), there is no need to do memcg membership check in oom_unkillable_task().

I think this patch just does too much in one go. Could you split out the dump_tasks part and the oom_unkillable_task parts into two patches please? It should be slightly easier to review.

[...]

mm/oom_kill.c static inline bool is_memcg_oom(struct oom_control *oc) · line 162

Quoted 8 lines
mm/oom_kill.c +3 -0
+static bool oom_unkillable_task(struct task_struct *p, struct oom_control *oc)
 {
 	if (is_global_init(p))
 		return true;
 	if (p->flags & PF_KTHREAD)
 		return true;
+	if (!oc)
+		return false;

Bah, this is just too ugly. AFAICS this is only because oom_score still uses oom_unkillable_task which is kinda dubious, no? While you are touching this code, can we remove this part as well? I would be really surprised if any code really depends on ineligible tasks reporting 0 oom_score.

Other than that it looks reasonable to me from a quick glance but I have to look more carefuly.

Signature · 2 lines
Michal Hocko
SUSE Labs
#2 lore raw
Quoted 14 lines · Michal Hocko
Quoted 11 lines · Shakeel Butt

Currently oom_unkillable_task() checks mems_allowed even for memcg OOMs which does not make sense as memcg OOMs can not be triggered due to numa constraints. Fixing that.

Also if memcg is given, oom_unkillable_task() will check the task's memcg membership as well to detect oom killability. However all the memcg related code paths leading to oom_unkillable_task(), other than dump_tasks(), come through mem_cgroup_scan_tasks() which traverses tasks through memcgs. Once dump_tasks() is converted to use mem_cgroup_scan_tasks(), there is no need to do memcg membership check in oom_unkillable_task().

Quoted 4 lines

I think this patch just does too much in one go. Could you split out the dump_tasks part and the oom_unkillable_task parts into two patches please? It should be slightly easier to review.

Yes, will do in v2.

Quoted 10 lines

[...]

mm/oom_kill.c static inline bool is_memcg_oom(struct oom_control *oc) · line 162

Quoted 8 lines
mm/oom_kill.c +3 -0
+static bool oom_unkillable_task(struct task_struct *p, struct oom_control *oc)
 {
      if (is_global_init(p))
              return true;
      if (p->flags & PF_KTHREAD)
              return true;
+     if (!oc)
+             return false;
Quoted 5 lines

Bah, this is just too ugly. AFAICS this is only because oom_score still uses oom_unkillable_task which is kinda dubious, no? While you are touching this code, can we remove this part as well? I would be really surprised if any code really depends on ineligible tasks reporting 0 oom_score.

I think it is safer to just localize the is_global_init() and PF_KTHREAD checks in oom_badness() instead of invoking oom_unkillable_task(). Also I think cpuset_mems_allowed_intersects() check from /proc/[pid]/oom_score is unintentional.

Shakeel