Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp5836916rwe; Tue, 18 Apr 2023 12:17:10 -0700 (PDT) X-Google-Smtp-Source: AKy350ZpSvjcY3qhaln50nzX7R+Ti1105ncYMGi6szNN17c/me1QkHyJt0dU9dYZn/n4yM1ysPw9 X-Received: by 2002:a17:903:32d2:b0:1a6:bbf4:ed79 with SMTP id i18-20020a17090332d200b001a6bbf4ed79mr3671009plr.20.1681845429885; Tue, 18 Apr 2023 12:17:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681845429; cv=none; d=google.com; s=arc-20160816; b=kvqmauwUO1E4117gCzVObLkpBXVhFpnDj9gSYulxNzKnGa51FhRNNR/Rb/3xMtJINs Ey4eEHK+0yXXB8AJXtnV23qHzs02ZIdELyomotBkeQaH11EuJ0HNWuvElfV+54K8HXLe P8Q7eQSkXNgSHn4KUagKN+5zDMQSnv900rHs4gmXPALoNp6niPEmJqaCnQJsEv/Aj4UY rPYq0tXWTURAoilxIC6oQVAB28kPtWVuoSDqUWzD8dWt7t7jk6tvaaVPO5gWn064tXpj VWCjczwGAbjNf6/Uyf2QY2S73Woda6tABvtqG8H4IZhzfIW28gn8unP5cOuVs9ma5PjI kYUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=l59ZyyVgyCUBMvUoPArfOg/Tu2nHrtxfgxoKhkDEsRQ=; b=L2abd55pgVShxoWikydhtnxeRDDxw0vH0Lkba/ahhkCYJQzSVivrHj7ic0i4fi7dGY ijXZvIqbzqD4CAtaBjlbocSO4SaitIV+uo4nERDU1srHYRWCBW/RubqHLJm17Hn0cB73 e12wKbf4Ck6tbxWSkMMJ/jElN55DfSbmGGLd/J46gZiEs+0jL93nTr1ksEsvnaBk8Xrh oKnMC9H3TH8nIfQ0hDTUTqfthre5RE2JnHT6+J+0RMQul74cH9APWlYrmHn3iR/G+YND 4xUrcYorsygjyd5Vlqt/AO9lzU5A5i/kQOoX5wP18+6LykQoJwY0gxHpuSFmQa+2Q+Nm Xz2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20221208.gappssmtp.com header.s=20221208 header.b=fHLEDZEs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nv10-20020a17090b1b4a00b0024742007433si12726454pjb.19.2023.04.18.12.16.57; Tue, 18 Apr 2023 12:17:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@cmpxchg-org.20221208.gappssmtp.com header.s=20221208 header.b=fHLEDZEs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233072AbjDRTPB (ORCPT + 99 others); Tue, 18 Apr 2023 15:15:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232868AbjDRTOE (ORCPT ); Tue, 18 Apr 2023 15:14:04 -0400 Received: from mail-qv1-xf36.google.com (mail-qv1-xf36.google.com [IPv6:2607:f8b0:4864:20::f36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68CF68A60 for ; Tue, 18 Apr 2023 12:13:36 -0700 (PDT) Received: by mail-qv1-xf36.google.com with SMTP id op30so18259176qvb.3 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=beB6hRg24HWRMEAEKTQX7OIcUtV69Q05qNXP9B3mcC13LHk0eV/03q6bwYW7FXPmhz 4c2UL3ZNJpP3Anbx8YR8mXgizetgeSO+C52W77ouSb+hF7puug7CMrjVLGbfKussik1d XFFlVnj6sJ1PIn3H0pRaTKFenWpR6JQ+3iOIm2DAcBvVp9HphfEMH2vx/uDDhIwVjVAN J/mBr8Uuab8x+XRsFgmqVzKHVF4+QLRz7w6j0OnhclweSG49i7gpUJhRiORCLhwZAthB UVVP+NU7EkadOBPZaObOe4Dm7fUcWsytkXWDg+QfiRNqrTNymaI4v03EAAQAXTNLx+WE N/Mw== X-Gm-Message-State: AAQBX9dobuq8Y90mFHFi/M7Gyd/1AeXxSkegUql3/JCme/bWD6avVCd0 obWJgZi3Ihyyc9waigKxdPg8tw== 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-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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