From patchwork Fri May 19 12:39:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Weiner X-Patchwork-Id: 13248284 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 0BC9BC77B7F for ; Fri, 19 May 2023 12:40:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 081A3900007; Fri, 19 May 2023 08:40:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EBD97900003; Fri, 19 May 2023 08:40:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D6592900008; Fri, 19 May 2023 08:40:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id C2C21900003 for ; Fri, 19 May 2023 08:40:12 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 7E77A120A64 for ; Fri, 19 May 2023 12:40:12 +0000 (UTC) X-FDA: 80806962264.23.1E2D5EE Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) by imf21.hostedemail.com (Postfix) with ESMTP id 976551C0007 for ; Fri, 19 May 2023 12:40:10 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=cmpxchg-org.20221208.gappssmtp.com header.s=20221208 header.b=sb6jjHiP; dmarc=pass (policy=none) header.from=cmpxchg.org; spf=pass (imf21.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.218.45 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684500010; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=KcIbsIikfDMuopSmhbHndV34wIxjpvvu7t5RPKLo+Ds=; b=sxjjNkVjfsH2AuFcJP9lHHHOm+iKx4hPduUkYCUwMaYB4TBtWlu0xPsvJRemjnO5gr1aeL XNMM48OEDrnokoTN2oDU2XCrvMPJt5jJ4UcPkcMTppwvn2flwU2LYJ6dETkrMenQgPlw2B 2H8XK5xggiAT4RyR/9AyoXnabFWB0Y8= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=cmpxchg-org.20221208.gappssmtp.com header.s=20221208 header.b=sb6jjHiP; dmarc=pass (policy=none) header.from=cmpxchg.org; spf=pass (imf21.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.218.45 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684500010; a=rsa-sha256; cv=none; b=FEMjKzHp/uPzJx4LzIvfSthBL+r9x/4iBgzEQEvXFMdlx/qNqb/CXc2Nppc70K235BFVil eB6D0GgkE010fagQQuexwtHY4zn25gXqqjhstPiz35ki0oz6U8tCzR1ReV5gCQVNpmXqGX hBzAa5b+uVFUfG8mznPCU/emCd41828= Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-96f7377c86aso77298066b.1 for ; Fri, 19 May 2023 05:40:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20221208.gappssmtp.com; s=20221208; t=1684500009; x=1687092009; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KcIbsIikfDMuopSmhbHndV34wIxjpvvu7t5RPKLo+Ds=; b=sb6jjHiPTREDcXdqa2JjB543aE4BffIZF/xpQ81XMOPbM5HDi7RIw/E2nSt+nx319g gPJgXd5jWMC7y6+vkLqrHE+0zbFS3gbHUeppbPpBCiBAohfGYKUfPFayPpzAob9UXhxE QEegswrzo+Jdcji9zBexb7zusPe6L0fKPR2rbjXa/EhMVS7NUITvoive3AA6Xwbeno+A CwED3HrTiR3swlcHMBb0od8FoLayohcwFMLmKVO2c2Y2qhgfs87pyMfAMwlsVGKgzU0o AYN8sqSYl+atdFoHRcFi2lu+/nsFdkF/r6TrTSzeUZT2EACdDjtMk4pC+XdWoe8U+5xo fkVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684500009; x=1687092009; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KcIbsIikfDMuopSmhbHndV34wIxjpvvu7t5RPKLo+Ds=; b=GgY8urojqJo3wk4YMp/Z4RR3HVZNfQwL1BKIjsfgoND61UcpczRtH/KL7fpnaS0R5z W92t+bZ3kJ29x5OAgnvB6GNDk9Zyc/d+EAKICOdLk8/FwWcmd05BxkWt8oMZUsmPejpb 4BhE61/tC4T7+fPy0Vf9uwyTVhYU6D3DoXbpwUxj9PFp/6nHLAUsogY0JLAa9IIf9naV 1IurwBm9zBfxwPFwM3S8qPLQXGjJ5Fi2YDgiTSccvf5bLdJjWu8yw8hqQL54/Eq0HNUY dGtbkm8bx7P0Wo+rVki6457Lz10ZI5Y09LhuO6bsb3TCsZFCKwdThZQ4rbC5AMBVqGPR U1vw== X-Gm-Message-State: AC+VfDxdc3Nxnto2kCHyjosUEmwMp56eQzKCa6a4ILAMsfxOZwI67lpH i31Nwx2cUSPfZ/ahFxEMRqaD3Q== X-Google-Smtp-Source: ACHHUZ42BThcRQN7iBlCrc1jrTpTmxdOBr2VDl2uvIRk1Qsm8fZ7lS6NcIBzfFWtNzJJ8hIX2xrwWg== X-Received: by 2002:a17:907:1c0e:b0:969:dda1:3896 with SMTP id nc14-20020a1709071c0e00b00969dda13896mr2224646ejc.0.1684500009025; Fri, 19 May 2023 05:40:09 -0700 (PDT) Received: from localhost ([2a02:8070:6389:7d40:e266:3092:9afb:a7b1]) by smtp.gmail.com with ESMTPSA id l18-20020a170906a41200b00965a52d2bf6sm2253368ejz.88.2023.05.19.05.40.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 May 2023 05:40:08 -0700 (PDT) From: Johannes Weiner To: Andrew Morton Cc: Mel Gorman , Vlastimil Babka , Michal Hocko , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 2/5] mm: compaction: simplify should_compact_retry() Date: Fri, 19 May 2023 14:39:56 +0200 Message-Id: <20230519123959.77335-3-hannes@cmpxchg.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230519123959.77335-1-hannes@cmpxchg.org> References: <20230519123959.77335-1-hannes@cmpxchg.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 976551C0007 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: fs9yq8k95ghhkzeft5aoo8dbuugbw6dn X-HE-Tag: 1684500010-572992 X-HE-Meta: U2FsdGVkX18Yq/5iM3nMSTirEVDOiV5pxwCUBXwArlf9YdIMTcKwMZnG+51jjbmpX8QbV9gWXZm+ERxTo1joEcYedKTUXEtKXqmlnHq3sOKePjPAj2KSNZpWMXmvrdtmzgpVukJv+XZQtroiRHgyIQ9AUNfFNJwj9CwRhrmLOuRVeheRCTTgAy2LAV5lVu02hCNmMtBOJCad2Rk50y+JY0uAVHQf7KVZSTrSHlKfqzOEL1jR60QwMxPGR6RcKHP8g9O4+N83quDGfkKKbi3uR7DztW28EGDLKbWYzHPU/iHHt/4h2eCKm9GFptySRmgnDJotCiVZQEIuplnBMrP8qescO4VXfBbWIjyKN7IHn2vDhOOpZ1p5z/FbbSvnzxneJn+qhuRNRX/pA7vpWFo2QKEirPxugC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Tq5gMrG4+GiR0McQIU= 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 different branches for retry are unnecessarily complicated. There are really only three outcomes: progress (retry n times), skipped (retry if reclaim can help), failed (retry with higher priority). Rearrange the branches and the retry counter to make it simpler. v2: - fix trace point build (Mel) - fix max_retries logic for costly allocs (Huang) Signed-off-by: Johannes Weiner --- mm/page_alloc.c | 53 +++++++++++++++---------------------------------- 1 file changed, 16 insertions(+), 37 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 5a84a0bebc37..72660e924b95 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -3772,16 +3772,22 @@ should_compact_retry(struct alloc_context *ac, int order, int alloc_flags, * Compaction managed to coalesce some page blocks, but the * allocation failed presumably due to a race. Retry some. */ - if (compact_result == COMPACT_SUCCESS) - (*compaction_retries)++; + if (compact_result == COMPACT_SUCCESS) { + /* + * !costly requests are much more important than + * __GFP_RETRY_MAYFAIL costly ones because they are de + * facto nofail and invoke OOM killer to move on while + * costly can fail and users are ready to cope with + * that. 1/4 retries is rather arbitrary but we would + * need much more detailed feedback from compaction to + * make a better decision. + */ + if (order > PAGE_ALLOC_COSTLY_ORDER) + max_retries /= 4; - /* - * All zones were scanned completely and still no result. It - * doesn't really make much sense to retry except when the - * failure could be caused by insufficient priority - */ - if (compact_result == COMPACT_COMPLETE) - goto check_priority; + ret = ++(*compaction_retries) <= max_retries; + goto out; + } /* * Compaction was skipped due to a lack of free order-0 @@ -3793,35 +3799,8 @@ should_compact_retry(struct alloc_context *ac, int order, int alloc_flags, } /* - * If compaction backed due to being deferred, due to - * contended locks in async mode, or due to scanners meeting - * after a partial scan, retry with increased priority. - */ - if (compact_result == COMPACT_DEFERRED || - compact_result == COMPACT_CONTENDED || - compact_result == COMPACT_PARTIAL_SKIPPED) - goto check_priority; - - /* - * !costly requests are much more important than __GFP_RETRY_MAYFAIL - * costly ones because they are de facto nofail and invoke OOM - * killer to move on while costly can fail and users are ready - * to cope with that. 1/4 retries is rather arbitrary but we - * would need much more detailed feedback from compaction to - * make a better decision. - */ - if (order > PAGE_ALLOC_COSTLY_ORDER) - max_retries /= 4; - if (*compaction_retries <= max_retries) { - ret = true; - goto out; - } - - /* - * Make sure there are attempts at the highest priority if we exhausted - * all retries or failed at the lower priorities. + * Compaction failed. Retry with increasing priority. */ -check_priority: min_priority = (order > PAGE_ALLOC_COSTLY_ORDER) ? MIN_COMPACT_COSTLY_PRIORITY : MIN_COMPACT_PRIORITY;