From patchwork Mon Mar 15 16:58:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Tomlin X-Patchwork-Id: 12140169 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 76405C433DB for ; Mon, 15 Mar 2021 17:23:01 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D9E3C64E83 for ; Mon, 15 Mar 2021 17:23:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D9E3C64E83 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 533E66B0070; Mon, 15 Mar 2021 13:23:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 50B476B0071; Mon, 15 Mar 2021 13:23:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3AC276B0072; Mon, 15 Mar 2021 13:23:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0036.hostedemail.com [216.40.44.36]) by kanga.kvack.org (Postfix) with ESMTP id 1EF8C6B0070 for ; Mon, 15 Mar 2021 13:23:00 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id D27341E0B for ; Mon, 15 Mar 2021 17:22:59 +0000 (UTC) X-FDA: 77922778878.07.5F67E2C Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by imf05.hostedemail.com (Postfix) with ESMTP id C587AE11D1D9 for ; Mon, 15 Mar 2021 16:58:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615827522; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Q6aA+wae6vAkyvGM3B2yBBd2LbIPXzseOAaDvzuOi6I=; b=WBQVAP/CSfg4sMD4bF76DW1hCPZEC4L+uFCx5Y74ixaKg+cmfv/BoMcxCxQp6PrpLfP4mo Cxaq2LpIlRGOUy0RzoUytyQE89kPRGgSxOxLhhjZ5LuWzSxDLXr2uwdf7f3wubzwUkm/cx DZnT+NBVL5aaa93ioO5LtlYqQqpBhVA= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-412-5AkvYLh3POqQIePH9LqRcQ-1; Mon, 15 Mar 2021 12:58:40 -0400 X-MC-Unique: 5AkvYLh3POqQIePH9LqRcQ-1 Received: by mail-wr1-f71.google.com with SMTP id e29so15347200wra.12 for ; Mon, 15 Mar 2021 09:58:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Q6aA+wae6vAkyvGM3B2yBBd2LbIPXzseOAaDvzuOi6I=; b=i8iLmi0QeXyze3/uNMlDYwd4YBe0af2Y9rx14CppvgZgTAeViJbunXQISFzCEnBPnG VYUhiFQRslD9fcGzBkm4l7kanGN+IqM6lIF8NYirXhKUcKVH/swNQu1AdJP6QeCrLWgo 7kOA6KhjKZbDKJeqe3wo+iGfIoNofemvSzKbIIaA14XlG0/dzbVXET4OEoX2kws7pmzs mrsbNRNjOFQGrDMv7yMdyUhhDdiffqPl1XOkf6QUjt11cNSC9fwvoSbQtcIV2sToHn95 zfjmNl4Z9Y5H5y9LrW5dLHA1yRXiawBZ4AhWm2VVonciLFu9IeJfEEZXvIm5f3QO/qek wNRQ== X-Gm-Message-State: AOAM532DQF4inQpZRELyOSN6/KfvP5o7idkWKcADxGfh1uHA+V35ZSMM 5r3GkkjJCAHLSQJsnMTkDv7ReIPBkK100bc/UJp16jygucC4D+xIcwzFrYB97a/jujk7+sWddVn lo2ObL9DAVP0uZwBpIG5AXOMXlblPopcFTfavGPmvfkcip939LJVEykZxdegH X-Received: by 2002:adf:cd8c:: with SMTP id q12mr566294wrj.185.1615827519040; Mon, 15 Mar 2021 09:58:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxf8ZZkQAvzrafu/QCYVzh/aotrIe8BtfHIGGCSksBVGk9W497j1C6xZhgVqF3BvGiPeDV/+w== X-Received: by 2002:adf:cd8c:: with SMTP id q12mr566275wrj.185.1615827518814; Mon, 15 Mar 2021 09:58:38 -0700 (PDT) Received: from localhost (cpc111743-lutn13-2-0-cust979.9-3.cable.virginm.net. [82.17.115.212]) by smtp.gmail.com with ESMTPSA id n1sm555664wro.36.2021.03.15.09.58.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Mar 2021 09:58:38 -0700 (PDT) From: Aaron Tomlin To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm/page_alloc: try oom if reclaim is unable to make forward progress Date: Mon, 15 Mar 2021 16:58:37 +0000 Message-Id: <20210315165837.789593-1-atomlin@redhat.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=atomlin@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: C587AE11D1D9 X-Stat-Signature: sorjy158reafw4ehtd5fysyj8pqxhi6y Received-SPF: none (redhat.com>: No applicable sender policy available) receiver=imf05; identity=mailfrom; envelope-from=""; helo=us-smtp-delivery-124.mimecast.com; client-ip=63.128.21.124 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615827522-854397 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: In the situation where direct reclaim is required to make progress for compaction but no_progress_loops is already over the limit of MAX_RECLAIM_RETRIES consider invoking the oom killer. Signed-off-by: Aaron Tomlin Reported-by: kernel test robot Reported-by: kernel test robot Reported-by: kernel test robot --- mm/page_alloc.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 7a2c89b21115..8d748b1b8d1e 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -4181,6 +4181,16 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order, return NULL; } +static inline bool +should_try_oom(int no_progress_loops, + enum compact_result last_compact_result) +{ + if (no_progress_loops > MAX_RECLAIM_RETRIES && last_compact_result + == COMPACT_SKIPPED) + return true; + return false; +} + static inline bool should_compact_retry(struct alloc_context *ac, int order, int alloc_flags, enum compact_result compact_result, @@ -4547,10 +4557,11 @@ should_reclaim_retry(gfp_t gfp_mask, unsigned order, * Make sure we converge to OOM if we cannot make any progress * several times in the row. */ - if (*no_progress_loops > MAX_RECLAIM_RETRIES) { - /* Before OOM, exhaust highatomic_reserve */ - return unreserve_highatomic_pageblock(ac, true); - } + if (*no_progress_loops > MAX_RECLAIM_RETRIES) + result false; + /* Last chance before OOM, try draining highatomic_reserve once */ + else if (*no_progress_loops == MAX_RECLAIM_RETRIES) + return unreserve_highatomic_pageblock(ac, true) /* * Keep reclaiming pages while there is a chance this will lead @@ -4822,6 +4833,8 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, did_some_progress > 0, &no_progress_loops)) goto retry; + if (should_try_oom(no_progress_loops, compact_result)) + goto oom: /* * It doesn't make any sense to retry for the compaction if the order-0 * reclaim is not able to make any progress because the current @@ -4839,6 +4852,7 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, if (check_retry_cpuset(cpuset_mems_cookie, ac)) goto retry_cpuset; +oom: /* Reclaim has failed us, start killing things */ page = __alloc_pages_may_oom(gfp_mask, order, ac, &did_some_progress); if (page)