From mboxrd@z Thu Jan 1 00:00:00 1970 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 82659C77B7D for ; Tue, 18 Apr 2023 19:13:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F2917280005; Tue, 18 Apr 2023 15:13:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EB1BF280001; Tue, 18 Apr 2023 15:13:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CE11F280005; Tue, 18 Apr 2023 15:13:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 9C31F280001 for ; Tue, 18 Apr 2023 15:13:38 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 6B0BC1202A3 for ; Tue, 18 Apr 2023 19:13:38 +0000 (UTC) X-FDA: 80695460916.12.7098199 Received: from mail-qv1-f53.google.com (mail-qv1-f53.google.com [209.85.219.53]) by imf09.hostedemail.com (Postfix) with ESMTP id A1A8B140017 for ; Tue, 18 Apr 2023 19:13:36 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=cmpxchg-org.20221208.gappssmtp.com header.s=20221208 header.b=fHLEDZEs; spf=pass (imf09.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.219.53 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1681845216; 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=l59ZyyVgyCUBMvUoPArfOg/Tu2nHrtxfgxoKhkDEsRQ=; b=zsCK8+tJTG7LExbEqIShJuy6/jN227W5z4+wDVR5kfcYkMqjNWIn2ir8UgQ0Qo/Bo+mkCX m9bRSYT08NRTbIcfGHTcEc6n5waZXLK4hY0muTT7USZnuCyCQyQsjDxf1t09gFIdqSh5qo 5Nvnqevw+LvekEHuE3NJuqfZVaSRyJY= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=cmpxchg-org.20221208.gappssmtp.com header.s=20221208 header.b=fHLEDZEs; spf=pass (imf09.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.219.53 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681845216; a=rsa-sha256; cv=none; b=hIuU7Qvd+HUPeLXRypZG19OQbP4uU7jKPxCb6zD31a8j4AKqG1H8hs+x+l5VJJkTITKnCP 5Y7ZOoAcJiYmq+3f1bn3OelmaFjm9TGZxMtR7jvjQS+mDoLG7B0c/iwRPWSB5DRxRFn/pm sZPYWu0XG/Y3PteIlUwan0Uafj9kFdA= Received: by mail-qv1-f53.google.com with SMTP id a15so7395531qvn.2 for ; Tue, 18 Apr 2023 12:13:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20221208.gappssmtp.com; s=20221208; t=1681845215; x=1684437215; 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=l59ZyyVgyCUBMvUoPArfOg/Tu2nHrtxfgxoKhkDEsRQ=; b=fHLEDZEsV9N0D0X0rv9luI4kf2Ny4hu81LBmLjiQQISEpJJ+RqngAVpAPnFoR0YJg5 +rnu1yHL/o1ivzsyaceccwRhzNhhqiyoYCKe93qsF3ayw2qwII6swNfekI6XGKLg0WKN ufiP8FtZHi0gw8HoJMh10Ahc4nfREGT88vUp2AeAYI8oivqhu8YfXmH0mXPBZwkUumtM cdyBUXt7wmT0HtYc+n8SW7cn8uD60GO8c+eVN2+jqkKgf8Z6KnRU8bZkIL2jEokwqAx5 sPCj0+lVYfaoZN3UpGcQ5ZNRelLySP7T0KS9IIKSrs2ehaDuMkRxPwMV16n9lIi+UQCl Tevw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681845215; x=1684437215; 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=l59ZyyVgyCUBMvUoPArfOg/Tu2nHrtxfgxoKhkDEsRQ=; b=CJTBJmp2yaGG6gy+kGLjdGGEjASoZ9GL3uXMqEKopsc1mIJ1acxVob+r5+mESe/5XS Fk6Qx7E6T6/tXik6mLUzOuSUlk2vFLNKkBPu+uqUSKIm7oT7iF1t2O1Net7DZDKXGjD9 MrbXaAhUG55YJjVAGhGj+808BgGHq+3B/Yu5ObE2zS3qihcxoBwdyAKF9Ssd/518Fbhd dljTYPu+AnFbwHHh7G1dh2UjQU+vl0W4WgohDfG/x6CZai/vMYMgIwcs5rJQiHQ1ZWkH 9GA7eTnBFb6JQ7im4CE8dLjZvWx24xXwea7nt0YRvG0EDxGQ3LhR3Z31AsMxB+hhuZnx uiWw== X-Gm-Message-State: AAQBX9fvIPD1A9XLYQIszxeeLdDJs8tXeQ82mM9BkMpZ8yd/L2GjkWld tFXKb+5+dvnNbnmSjt9+CL4NFPI01DoY35pnR+U= X-Google-Smtp-Source: AKy350Y+h1X4MZEW+S29kRDU7ycQ7OqCtKgHBzDa7byusJ+iYdu4NQRhrwkjbrpSqc3/yAnVuA2tCQ== X-Received: by 2002:a05:6214:1942:b0:5f1:6904:a2d6 with SMTP id q2-20020a056214194200b005f16904a2d6mr1035437qvk.51.1681845215347; Tue, 18 Apr 2023 12:13:35 -0700 (PDT) Received: from localhost ([2620:10d:c091:400::5:e646]) by smtp.gmail.com with ESMTPSA id k15-20020a05620a414f00b007463509f94asm4089576qko.55.2023.04.18.12.13.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Apr 2023 12:13:35 -0700 (PDT) From: Johannes Weiner To: linux-mm@kvack.org Cc: Kaiyang Zhao , Mel Gorman , Vlastimil Babka , David Rientjes , linux-kernel@vger.kernel.org, kernel-team@fb.com Subject: [RFC PATCH 14/26] mm: compaction: simplify should_compact_retry() Date: Tue, 18 Apr 2023 15:13:01 -0400 Message-Id: <20230418191313.268131-15-hannes@cmpxchg.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230418191313.268131-1-hannes@cmpxchg.org> References: <20230418191313.268131-1-hannes@cmpxchg.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: A1A8B140017 X-Rspam-User: X-Stat-Signature: jqnjkmb96yweeg7yka4tnofehgyk436s X-HE-Tag: 1681845216-796075 X-HE-Meta: U2FsdGVkX1+ZiyqQZchjglJhlw1xn1dM2tDZvh1ZNPzTrkr5+mBZ5/ulTlfmy9WF9KpD0D9sci+rHz+MEp0kCzra6IM8LeExFjX7yTrq8mVPVnSLy+B2G5fNOlihoE66HYni/Xgh7LOSe/4Dk23fZJ6B0tZf6D/d/MVCSnNRw2rmrUi/IPlKmn4YgpZHhn+DYTKG42wykAJ5qFgCqNHIlI/W9zkmcj3A/0qDBwAAG7BCa5SKW5rPdb35qtrc945kxolI/s/oJvc/IUc48g/RwIQj9R2jSsggjxqNfw2wuWKet5YZOdVFoWxCaRVn2WyhiPZjZpLF43jSZrCOSiHQmZUHv8YlHUlg85AhmLyImhhOffEV93/Ojp76yvKP5PIQQmnWgiyO+nHU/JbT6fdcbds5ckQw+x1kw12czjvEHWr5FmD7F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CMEg== 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 is really only three outcomes: progress, skipped, failed. Also, the retry counter only applies to loops that made progress, move it there. Signed-off-by: Johannes Weiner --- mm/page_alloc.c | 60 +++++++++++++++++-------------------------------- 1 file changed, 20 insertions(+), 40 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index c3b7dc479936..18fa2bbba44b 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -4608,7 +4608,6 @@ should_compact_retry(struct alloc_context *ac, int order, int alloc_flags, enum compact_priority *compact_priority, int *compaction_retries) { - int max_retries = MAX_COMPACT_RETRIES; int min_priority; bool ret = false; int retries = *compaction_retries; @@ -4621,19 +4620,27 @@ should_compact_retry(struct alloc_context *ac, int order, int alloc_flags, return false; /* - * Compaction managed to coalesce some page blocks, but the - * allocation failed presumably due to a race. Retry some. + * Compaction coalesced some page blocks, but the allocation + * failed, presumably due to a race. Retry a few times. */ - if (compact_result == COMPACT_SUCCESS) - (*compaction_retries)++; + if (compact_result == COMPACT_SUCCESS) { + int max_retries = MAX_COMPACT_RETRIES; - /* - * 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; + /* + * !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; + + ret = ++(*compaction_retries) <= MAX_COMPACT_RETRIES; + goto out; + } /* * Compaction was skipped due to a lack of free order-0 @@ -4645,35 +4652,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; -- 2.39.2