From patchwork Wed Jan 5 17:51:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jann Horn X-Patchwork-Id: 12704566 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id EAAD9C433EF for ; Wed, 5 Jan 2022 17:52:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6654F6B0071; Wed, 5 Jan 2022 12:52:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 614766B0073; Wed, 5 Jan 2022 12:52:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4DB996B0074; Wed, 5 Jan 2022 12:52:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0041.hostedemail.com [216.40.44.41]) by kanga.kvack.org (Postfix) with ESMTP id 3936C6B0071 for ; Wed, 5 Jan 2022 12:52:16 -0500 (EST) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id EAC4086E98 for ; Wed, 5 Jan 2022 17:52:15 +0000 (UTC) X-FDA: 78996977430.03.70A2402 Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) by imf02.hostedemail.com (Postfix) with ESMTP id 5BEBB80016 for ; Wed, 5 Jan 2022 17:52:08 +0000 (UTC) Received: by mail-wr1-f54.google.com with SMTP id w20so75639414wra.9 for ; Wed, 05 Jan 2022 09:52:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=J5GT6AWgowXMeNIuQyJYxsilVHwUS2CUc3fcBKbiq5M=; b=Z4UaC+WcOqG1yJseMWSPH9mDiu4olkW2I0tHm5x4PXwZ413u/NenAQZ5o5LUlc0DTM V2DLOD0kwfnuPlFLo0gcu9GoQXmxww9za1w3i6X9D6XzrQQEGeskyjn2+R6aVc1DryqJ oYGII0Yt336SXJgYycaWvEN2WGURvyyl4wct8xyqE5aLu/jbE25zKgudmOqRJi4VV0gK kg6/61YfaywhiDs0nssIdhcVDzw7pXazrjTsnkqdj0dUU0YY2ac5jkrAgR2nKD1bbNWG 0L/K7KzXalozcC5o4pj924GYVepD5oEfTtlj/E3eet8NSjDEsHuNjDwMsSOYgVjHIa7y XpIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=J5GT6AWgowXMeNIuQyJYxsilVHwUS2CUc3fcBKbiq5M=; b=F2btc6Cak+vtLv1G0ABUxyUuIeVRi/RIRgpWcq4YgsWhmrkn7WhyB7NV4IjfjJr0E0 C42D0R+vYy4yx81T8BLJlg1c6LRflgn2X8DbKfj7ajO4xXgR+b2CMqGeRIS+rUsiHt6E 23fNCeu2LHBCgzx60cORd3oS+EnpOnJyktLuXvOGQGkC6ZYleStcZoYvVBcuB1uqNUnT Z5dKkY2zpwap6q8fekMjTVnMfrD6JG/r5MobZljPPeXGLbELGgYfFFihBO79bdoDrEcm PHey+c7OcZ73XfBIj9evaUeqbYTN1t4icimdt5Riq7UQnEo6fdzKH2A5ku8CR9xgALFp cjCg== X-Gm-Message-State: AOAM533aOfm9kIJY/lTXySAs02y4k6/k1oITNBWzuy7Mm5nGgBtoIJ2v OAeNBwTN5kGyUVgzZqr5HCc3lw== X-Google-Smtp-Source: ABdhPJxkDT3SlyZ2BvvPWw1OKwAZ5KiuQVU4U7TxsMzATu+Vxw+3+4t1wNjyxIq7/1Yldgo+a/ewtA== X-Received: by 2002:adf:ef01:: with SMTP id e1mr10927619wro.647.1641405133760; Wed, 05 Jan 2022 09:52:13 -0800 (PST) Received: from localhost ([2a02:168:96c5:1:55ed:514f:6ad7:5bcc]) by smtp.gmail.com with ESMTPSA id b1sm47085290wrd.92.2022.01.05.09.52.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jan 2022 09:52:13 -0800 (PST) From: Jann Horn To: Andrew Morton , linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, Martin Schwidefsky , Jann Horn Subject: [PATCH] mm, oom: OOM sysrq should always kill a process Date: Wed, 5 Jan 2022 18:51:15 +0100 Message-Id: <20220105175115.605074-1-jannh@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 5BEBB80016 X-Stat-Signature: gezjtyqqj3z1augbxudboq3efjj34z5y Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Z4UaC+Wc; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf02.hostedemail.com: domain of jannh@google.com designates 209.85.221.54 as permitted sender) smtp.mailfrom=jannh@google.com X-HE-Tag: 1641405128-571536 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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. Signed-off-by: Jann Horn Acked-by: Michal Hocko --- mm/oom_kill.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) base-commit: c9e6606c7fe92b50a02ce51dda82586ebdf99b48 diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 1ddabefcfb5a..dc645cbc6e0d 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -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; }