Skip to contentSkip to conversation

mm, oom: OOM sysrq should always kill a process

PATCH Superseded Jann Horn 2 participants 2 messages Jan 5, 2022 – Jan 6, 2022

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Jann Horn

author
#0 lore raw

PATCH 1/1 mm, oom: OOM sysrq should always kill a process

The OOM kill sysrq (alt+sysrq+F) should allow the user to kill the process with the highest OOM badness with a single execution.

However, at the moment, the OOM kill can bail out if an OOM notifier (e.g. the i915 one) says that it reclaimed a tiny amount of memory from somewhere. That's probably not what the user wants.

As documented in struct oom_control, order == -1 means the oom kill is required by sysrq. So check for that, and if it's true, don't bail out no matter what the OOM notifiers say.

---
 mm/oom_kill.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
mm/oom_kill.c +2 -1
index 1ddabefcfb5a..dc645cbc6e0d 100644
@@ -1051,13 +1051,14 @@ EXPORT_SYMBOL_GPL(unregister_oom_notifier);
 bool out_of_memory(struct oom_control *oc)
 {
 	unsigned long freed = 0;
+	bool sysrq_forced = oc->order == -1;
 
 	if (oom_killer_disabled)
 		return false;
 
 	if (!is_memcg_oom(oc)) {
 		blocking_notifier_call_chain(&oom_notify_list, 0, &freed);
-		if (freed > 0)
+		if (freed > 0 && !sysrq_forced)
 			/* Got some memory back in the last second. */
 			return true;
 	}

base-commit: c9e6606c7fe92b50a02ce51dda82586ebdf99b48

Signature · 1 line
2.34.1.448.ga2b2bfdf31-goog
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · Jann Horn

The OOM kill sysrq (alt+sysrq+F) should allow the user to kill the process with the highest OOM badness with a single execution.

However, at the moment, the OOM kill can bail out if an OOM notifier (e.g. the i915 one) says that it reclaimed a tiny amount of memory from somewhere. That's probably not what the user wants.

As documented in struct oom_control, order == -1 means the oom kill is required by sysrq. So check for that, and if it's true, don't bail out no matter what the OOM notifiers say.

I agree that it is suboptimal to disable sysrq+f because of notfiers because the OOM invocation is not a direct result of the OOM situation but rather an admin will. We already kill a new task even if an oom victim is still pending.

Quoted 1 line

with a minor update as below

Quoted 14 lines
---
 mm/oom_kill.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
mm/oom_kill.c +1 -0
index 1ddabefcfb5a..dc645cbc6e0d 100644
@@ -1051,13 +1051,14 @@ EXPORT_SYMBOL_GPL(unregister_oom_notifier);
 bool out_of_memory(struct oom_control *oc)
 {
 	unsigned long freed = 0;
+	bool sysrq_forced = oc->order == -1;
 

mm/oom_kill.c EXPORT_SYMBOL_GPL(unregister_oom_notifier); · line 1064

Quoted 10 lines
mm/oom_kill.c +1 -1
 	if (oom_killer_disabled)
 		return false;
 
 	if (!is_memcg_oom(oc)) {
 		blocking_notifier_call_chain(&oom_notify_list, 0, &freed);
-		if (freed > 0)
+		if (freed > 0 && !sysrq_forced)
 			/* Got some memory back in the last second. */
 			return true;
 	}

is_sysrq_oom(oc) is a more appropriate way to check this.

Quoted 4 lines

base-commit: c9e6606c7fe92b50a02ce51dda82586ebdf99b48

Signature · 1 line
2.34.1.448.ga2b2bfdf31-goog
Signature · 2 lines
Michal Hocko
SUSE Labs