From patchwork Fri May 19 12:39:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Weiner X-Patchwork-Id: 96406 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1207494vqo; Fri, 19 May 2023 05:49:42 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7h1B27yXWY5nL1sw8wvEtJUOm/MVlKbRk6Sk8lI+asGFkyOxAgdYaOXLNrWMXi7gCpwBEW X-Received: by 2002:a05:6a00:1812:b0:63b:8dcc:84de with SMTP id y18-20020a056a00181200b0063b8dcc84demr2908551pfa.4.1684500582202; Fri, 19 May 2023 05:49:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684500582; cv=none; d=google.com; s=arc-20160816; b=Qj8HDitonLMUD06lzJqbppXm12ECY7UQsIc4i9i2P61vYaiuF9RjlEKD04MJW/X52Y 2Z1Cgw6ZMqRAaoephp1kiNNuRrASAFv5f00oWQLvHhulsSbXDs75yp69eyfyjkk+aSz6 bxsUCREpStlKEg0tfI0ccF0glhsQYdYXh7Pl5jisu9BB21HdIk/toHyXiX+c3Z5Zs/Wa VKBrxHM1K4hMiAT99bDT6qneboCJW8pvP+MokiRuQ/jovvHnSMbUiL7NRODfzEWD4GbD 2eaawv4wpdZIWWZCkG9kCf/SngRiAm2ZJEfXCP9DimAMKJW9GZjUHx44oWTmdIJX24YH DMkw== 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=eLUm7WZINfPJ8EnyZppR+QB8ZeshYnpRD1lp9jOg8YM=; b=j1ysJOxtKB8iYgAvGvS+FuB4RY4CVecKn2fnpUuRwNlRehYz2ur1PHEWfBe8uXRBzb 2GeDbpcPRuTZtxvjK+/P7tRGuSgtIlwyqa7IKNj7ytsTeOywJ5fHPLaiQ2DKvfJeIXKN UgT9syjrJe1NgGpW9Digi2AAywTMyq1TP8+OyWbqR1ew8XoLd7tEsbJFo7hYgGPsX8Y7 IGS/WVAEfEDWNO3TBD2tq/VzZzsMs+cyjEPWNX8wOUjFPgm3amBgP8HkGx/lnDP4nH/r QEh6dyQDpsXJNtmCLzyiACQyffaEZswE/gJfsWCRPFJ+YkGH75STRKTl72JaiNbTmtTJ UPNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20221208.gappssmtp.com header.s=20221208 header.b=UqY0Q1Qn; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t3-20020a625f03000000b0062dbc05a323si3834192pfb.298.2023.05.19.05.49.26; Fri, 19 May 2023 05:49:42 -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=UqY0Q1Qn; 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 S231342AbjESMkU (ORCPT + 99 others); Fri, 19 May 2023 08:40:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231156AbjESMkL (ORCPT ); Fri, 19 May 2023 08:40:11 -0400 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB54A109 for ; Fri, 19 May 2023 05:40:09 -0700 (PDT) Received: by mail-ed1-x52f.google.com with SMTP id 4fb4d7f45d1cf-510eb3dbaaeso2962884a12.1 for ; Fri, 19 May 2023 05:40:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20221208.gappssmtp.com; s=20221208; t=1684500008; x=1687092008; 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=eLUm7WZINfPJ8EnyZppR+QB8ZeshYnpRD1lp9jOg8YM=; b=UqY0Q1QneRWgaChbAJgyXkbGCj5MIeuFO1Mmxqo9b0QVAxAtyzG0jFAVliXTITC41q oC79XjrJW9vlGUQVQJWPUcF9FCRAbWfWtVRthlUqELkW1+wmsNFisu0FKzt8Vuy7O/0r gyMNuX0yd/37Jh6HhJKs7jW2i8YAXmc5zUZTmN3Rlmuo6uaaRSkBGojlNeDxEigi5TXY wkeYQj8gFL6V8RbvUzItTEhn0gtfrZrDjFrQqIDzdEz+gAAc8yjZKn2/LyNCcfsdWYPq V/bJWcjzyGeL1UMuy0CC5C2DgDrohlE58IRXywwbSfuUET9z+ZmQWIUXgcTO6ixIOW9N daFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684500008; x=1687092008; 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=eLUm7WZINfPJ8EnyZppR+QB8ZeshYnpRD1lp9jOg8YM=; b=aV8D8/saKMmT1OrsMwOfkn1N9VPBCxPpvi14KVb6RcZM0yHZk2w8u/SyNejZA16tUH 0cMqPph9kl7nVPO61/xNLAnB5SJDcFjikU/HGAoukuA1BKglSMxXMm/GtzOgG7c41fWr ORlmG0UDjfMT5BmlH1brNo2SkGmzob2xidoh4pKcp98iHP7Eike6X+irutdFbrEMaZ/d iFV1CI8hNFIFjvtes0H7L4G+W5CSWDzZbb2WAA19emSzmY3rSyJ9Znn4wUTYHIGDGB+2 tcHdC5YT0aIXFcWOX4A6Q9IZyoQB0XUkZU1HHho5VdUgax6Z84j6PYV5SQ62cRtLc7i1 0gGg== X-Gm-Message-State: AC+VfDx9LQkfvOmtvjhcISNBLzAOJAkeTShj9mtmfTLsMI/H2+qx5qrV ReWDewAyf2sWCSHR3uWd1kfdVA== X-Received: by 2002:a17:907:2cc7:b0:965:fb87:4215 with SMTP id hg7-20020a1709072cc700b00965fb874215mr1552073ejc.15.1684500008176; Fri, 19 May 2023 05:40:08 -0700 (PDT) Received: from localhost ([2a02:8070:6389:7d40:e266:3092:9afb:a7b1]) by smtp.gmail.com with ESMTPSA id m23-20020a1709061ed700b0095337c5da35sm2295229ejj.15.2023.05.19.05.40.07 (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 1/5] mm: compaction: remove compaction result helpers Date: Fri, 19 May 2023 14:39:55 +0200 Message-Id: <20230519123959.77335-2-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-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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766326882423661174?= X-GMAIL-MSGID: =?utf-8?q?1766326882423661174?= The compaction result helpers encode quirks that are specific to the allocator's retry logic. E.g. COMPACT_SUCCESS and COMPACT_COMPLETE actually represent failures that should be retried upon, and so on. I frequently found myself pulling up the helper implementation in order to understand and work on the retry logic. They're not quite clean abstractions; rather they split the retry logic into two locations. Remove the helpers and inline the checks. Then comment on the result interpretations directly where the decision making happens. Signed-off-by: Johannes Weiner Acked-by: Vlastimil Babka --- include/linux/compaction.h | 92 ---------------------------------- include/trace/events/mmflags.h | 4 +- mm/page_alloc.c | 30 ++++++----- 3 files changed, 19 insertions(+), 107 deletions(-) diff --git a/include/linux/compaction.h b/include/linux/compaction.h index a6e512cfb670..1f0328a2ba48 100644 --- a/include/linux/compaction.h +++ b/include/linux/compaction.h @@ -95,78 +95,6 @@ extern enum compact_result compaction_suitable(struct zone *zone, int order, extern void compaction_defer_reset(struct zone *zone, int order, bool alloc_success); -/* Compaction has made some progress and retrying makes sense */ -static inline bool compaction_made_progress(enum compact_result result) -{ - /* - * Even though this might sound confusing this in fact tells us - * that the compaction successfully isolated and migrated some - * pageblocks. - */ - if (result == COMPACT_SUCCESS) - return true; - - return false; -} - -/* Compaction has failed and it doesn't make much sense to keep retrying. */ -static inline bool compaction_failed(enum compact_result result) -{ - /* All zones were scanned completely and still not result. */ - if (result == COMPACT_COMPLETE) - return true; - - return false; -} - -/* Compaction needs reclaim to be performed first, so it can continue. */ -static inline bool compaction_needs_reclaim(enum compact_result result) -{ - /* - * Compaction backed off due to watermark checks for order-0 - * so the regular reclaim has to try harder and reclaim something. - */ - if (result == COMPACT_SKIPPED) - return true; - - return false; -} - -/* - * Compaction has backed off for some reason after doing some work or none - * at all. It might be throttling or lock contention. Retrying might be still - * worthwhile, but with a higher priority if allowed. - */ -static inline bool compaction_withdrawn(enum compact_result result) -{ - /* - * If compaction is deferred for high-order allocations, it is - * because sync compaction recently failed. If this is the case - * and the caller requested a THP allocation, we do not want - * to heavily disrupt the system, so we fail the allocation - * instead of entering direct reclaim. - */ - if (result == COMPACT_DEFERRED) - return true; - - /* - * If compaction in async mode encounters contention or blocks higher - * priority task we back off early rather than cause stalls. - */ - if (result == COMPACT_CONTENDED) - return true; - - /* - * Page scanners have met but we haven't scanned full zones so this - * is a back off in fact. - */ - if (result == COMPACT_PARTIAL_SKIPPED) - return true; - - return false; -} - - bool compaction_zonelist_suitable(struct alloc_context *ac, int order, int alloc_flags); @@ -185,26 +113,6 @@ static inline enum compact_result compaction_suitable(struct zone *zone, int ord return COMPACT_SKIPPED; } -static inline bool compaction_made_progress(enum compact_result result) -{ - return false; -} - -static inline bool compaction_failed(enum compact_result result) -{ - return false; -} - -static inline bool compaction_needs_reclaim(enum compact_result result) -{ - return false; -} - -static inline bool compaction_withdrawn(enum compact_result result) -{ - return true; -} - static inline void kcompactd_run(int nid) { } diff --git a/include/trace/events/mmflags.h b/include/trace/events/mmflags.h index b63e7c0fbbe5..1478b9dd05fa 100644 --- a/include/trace/events/mmflags.h +++ b/include/trace/events/mmflags.h @@ -223,8 +223,8 @@ IF_HAVE_VM_SOFTDIRTY(VM_SOFTDIRTY, "softdirty" ) \ #define compact_result_to_feedback(result) \ ({ \ enum compact_result __result = result; \ - (compaction_failed(__result)) ? COMPACTION_FAILED : \ - (compaction_withdrawn(__result)) ? COMPACTION_WITHDRAWN : COMPACTION_PROGRESS; \ + (__result == COMPACT_COMPLETE) ? COMPACTION_FAILED : \ + (__result == COMPACT_SUCCESS) ? COMPACTION_PROGRESS : COMPACTION_WITHDRAWN; \ }) #define COMPACTION_FEEDBACK \ diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 47421bedc12b..5a84a0bebc37 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -3768,35 +3768,39 @@ should_compact_retry(struct alloc_context *ac, int order, int alloc_flags, if (fatal_signal_pending(current)) return false; - if (compaction_made_progress(compact_result)) + /* + * 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)++; /* - * compaction considers all the zone as desperately out of memory - * so it doesn't really make much sense to retry except when the + * 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 (compaction_failed(compact_result)) + if (compact_result == COMPACT_COMPLETE) goto check_priority; /* - * compaction was skipped because there are not enough order-0 pages - * to work with, so we retry only if it looks like reclaim can help. + * Compaction was skipped due to a lack of free order-0 + * migration targets. Continue if reclaim can help. */ - if (compaction_needs_reclaim(compact_result)) { + if (compact_result == COMPACT_SKIPPED) { ret = compaction_zonelist_suitable(ac, order, alloc_flags); goto out; } /* - * make sure the compaction wasn't deferred or didn't bail out early - * due to locks contention before we declare that we should give up. - * But the next retry should use a higher priority if allowed, so - * we don't just keep bailing out endlessly. + * 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 (compaction_withdrawn(compact_result)) { + 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 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: 96402 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1204652vqo; Fri, 19 May 2023 05:44:40 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4pZ6BRWWNR6ZV5WThipKHYur1iIybhuHwxbraigG68elF9vslgFlG81FPWQk/TNyhv/ZS9 X-Received: by 2002:a05:6a20:7f86:b0:103:b436:aef7 with SMTP id d6-20020a056a207f8600b00103b436aef7mr3301898pzj.16.1684500280552; Fri, 19 May 2023 05:44:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684500280; cv=none; d=google.com; s=arc-20160816; b=omwMwHWuqgZ8ZbXjBYp4mrFnhlm15yE2kw5sytLBzAaBM4fxqi1JoA14+aLpYzB70J sJdy2iQV0cyShMP0M0VeZnSC8v2/kIjvgAICtEeyxaD+m5FD73r48uT7OMMvXj/pGCrZ 8W3H7fuhhiebXE5+cerEaBvTNPost+xJi9CMEkJHj58EAwNPrHmNVIT2mJmnheeXso7W 3ExZySsMedbtrqPtCXyAKf9C6tOvxI8xhrWLdF7WHRXXze0KFew2N69L1CQP5r2D2thh 48itZud0+6fDY5UfBMf+MWfLhXkgpAHNKTd2mfhEUHrE/8vdTz4xaDsxZtpYTCw+gvmm j8bw== 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=KcIbsIikfDMuopSmhbHndV34wIxjpvvu7t5RPKLo+Ds=; b=Gg5dCd7aO7T+VV+imNhDroCXt+GfZ7UDJUuzNNdYi9vsIT/TMNgD9/wC5HF/lOax6c 2RQIhhYU9cjqL9qf9sXWceCEdfb58cdmYBuBRfFAp2dnR3mQcx+Cu/WJxd7S34hgHVS0 VM34/gFnpn7baJ8luu4MYAAKiE8gqZQaMPTeIgWSZnOD88Y3jWDz0grTRX/xS3iJg9ub mYdV3zjyGIoDstf80ZhUTcFVLm5R5rAjvwXzbqyA7+BqOJZH0vP4Z/yyCxb5DV2tmwjE PB8oCJjwnteGITM8w1Dd3wDw8JO9njLgfIxk7m5IuEZkUAbtHC+26m0G71G0gWOO7nfL Qm2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20221208.gappssmtp.com header.s=20221208 header.b=sb6jjHiP; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t29-20020a63955d000000b005346bc0f749si2752270pgn.236.2023.05.19.05.44.24; Fri, 19 May 2023 05:44:40 -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=sb6jjHiP; 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 S231400AbjESMkX (ORCPT + 99 others); Fri, 19 May 2023 08:40:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229586AbjESMkM (ORCPT ); Fri, 19 May 2023 08:40:12 -0400 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0A94102 for ; Fri, 19 May 2023 05:40:10 -0700 (PDT) Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-96aadfb19d7so609384466b.2 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=Rvup7eSVESUeeeXTPL/mbT3ijKTm66o04ititcczos2YrhCLJec+DGA0nIEHKbmrIR Vr6Nt4uduNU0UmRbrAQgTEXx+YQheHacOtCOFcd/tuDMxpViotICTAw7/pTV4wxYmfYb Wro96y21MfR1+f0xScDBermbSBWpquc/4Pgoy++YM4+xzRvg+8HsU6GAuE28huqJv1sD Dt6KEV518TMTbCzChG/cQCwYPmpQN0TTH6aFP/wb/rs7btHynab+doVLjcdSX3bw39aj UjU2p35Dj5CBkiX1PcMPIO6htt/mYk6cZ6/XREaqYGk5zv9rfEW4p90hiKp6Y75pDwOf c83w== X-Gm-Message-State: AC+VfDzWO0/TlGc11WuMBBkUZX4J3PT1q9ocNMP6+2uDIqiULbKgZvv5 5G/3Wgl191X3+rOjrAnRlzml8g== 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-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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766326566058997171?= X-GMAIL-MSGID: =?utf-8?q?1766326566058997171?= 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 Signed-off-by: Johannes Weiner Acked-by: Vlastimil Babka --- 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; From patchwork Fri May 19 12:39:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Weiner X-Patchwork-Id: 96403 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1205116vqo; Fri, 19 May 2023 05:45:32 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7w+zKj5/+iNGu9nVssEVbh7rUm/TpR4lmSCguBwajOxXlnuZmZ8igPrt8ItwEGUhJpXtan X-Received: by 2002:a17:902:c20c:b0:1a8:626:6d9d with SMTP id 12-20020a170902c20c00b001a806266d9dmr2485416pll.62.1684500332453; Fri, 19 May 2023 05:45:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684500332; cv=none; d=google.com; s=arc-20160816; b=BgFQY9/faO6vB06M2bjHuFVUr9YNdDJ0tadXGLIdXFIOPRMWk/1dLukVE7DGU++LdA uvNnJ/Xr7UP4wR8oQuKfS+XcYyRfMeA6+yEOfHOHB06yiBGHAOO/tJKShgRzXAq6tYb7 /vAtkZLJOeelhyrcwXNywyQqJsSpBBTsI8VEXUq4NyCcIqathSsU9lBtjqehd8UU+3+5 NB7qhZ1RpMVZSeD4vRXaZasat18NxYEBynGPZh/mHD9PNg1pKsDcCAeC/Kw8Kmu+vaM3 JDPbK6F6WK7rwXPgXuHFWEJEyWnqAG+4itUnM6Aj7qkZiD1VV6Y2cmheTywFbixV0tTa fyUw== 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=vXkGmoOKMV9wp5TM6FJc6/QwLR/CY7AZ1q5R5QORiXk=; b=oRLZjmsEmhWUaYGsMeZ9cHaJClTSqZFKsdp+WkkzeKoa92SuonXv52iYiiY5AbURJU w5l/Ps4lR6faf+r/X4tAxjwNJIU+I3b0yo0Wda3VgMkAtTIEk5fc4vdGTXUuwp+2glCk HhGatTAKAZZuGMTomEZ48VBEPWJ75Bd3cFTiCn34Lp5PMZcVYpyPrELCTGCjJAtP9MNn qpKlPggGTs6fAxeUXHKV6Jj2KPhTtCdzcRxA4QxeovvY6QDVLAzhWeL/lJy/+RCNTFNm qeRhE3siPLFKFSPd7s8pLNeM0peBnk2M6knk34Ekkb9psir1zXDtaIJE8/dyd0tcDTdX MlrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20221208.gappssmtp.com header.s=20221208 header.b=j8nprdhT; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h10-20020a170902f54a00b001aaccc51d45si3782994plf.398.2023.05.19.05.45.15; Fri, 19 May 2023 05:45:32 -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=j8nprdhT; 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 S231513AbjESMk0 (ORCPT + 99 others); Fri, 19 May 2023 08:40:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231337AbjESMkU (ORCPT ); Fri, 19 May 2023 08:40:20 -0400 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BE9210B for ; Fri, 19 May 2023 05:40:11 -0700 (PDT) Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-96aadfb19d7so609388666b.2 for ; Fri, 19 May 2023 05:40:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20221208.gappssmtp.com; s=20221208; t=1684500010; x=1687092010; 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=vXkGmoOKMV9wp5TM6FJc6/QwLR/CY7AZ1q5R5QORiXk=; b=j8nprdhTRVRZX+b+MiJ39vvsPB8y0GGrbPhI6lsexF0dvkO4amR6WItiuegG9BfiRU MN8A49KVx8o86hTYpRXpcGjnSKD25lzyyj/NH4c3kzpIu8FH29Fwu9YXWODBkI/cR2tZ tOWDqP3eVUjsGYrXv9d6xlJKrPpVGZlF4AoFmjHQ8nIIaKIWelJHj4SHtHzvkTfTetw7 uwZhgOO/hTAb8A1ZkSqmIj2ZGQM1X+5/b7c6kdyR6bMbj9hfiKlwreo9cF2y7+qx1WJD 81n9YGKCYvomlnft2jGfo59NweehDvgmGgPIPXd9/QQdknjD+xJPIaq182eUfreAbQ8C sHmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684500010; x=1687092010; 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=vXkGmoOKMV9wp5TM6FJc6/QwLR/CY7AZ1q5R5QORiXk=; b=In2WT3SDP5czJ79X2HZ9erqWzWO0Rgzt/elfAUd3Xw46z4k4wd84Mejk943Jz9vvlN Ys7J19xRlgq12XM4PaVwADkmWJ1yv6pGbjvLH7uQpbf8YYNoViraImzRC8L8odawNGGL gP5G7C8clYd3OI5kE+/gHX7BOhtJSgtH+8s9XeAI4NWhZXesBpumWkhxyZ63rtjApiea oX2yxGMMFdLolKkwIYAhsSO7proa6xJ5rInyX7buphCLHOwJdFKUsXr5q2iVLsvIIvQ+ OMA2wcPOiRz9xqXERyKFTjs4JEhTKg1FYOC7p4Z6rCWkLYcMt0joXffhPS2cNBmZl+d0 7hpQ== X-Gm-Message-State: AC+VfDyU805csIlv7V2mk40ubc/ORD92XuALkqOiDzoy/ILTAMXA4+Kf OrkplGy6dDZN5RR7a9GDCNpTLw== X-Received: by 2002:a17:906:ee88:b0:94a:5819:5a2b with SMTP id wt8-20020a170906ee8800b0094a58195a2bmr1567192ejb.33.1684500010022; Fri, 19 May 2023 05:40:10 -0700 (PDT) Received: from localhost ([2a02:8070:6389:7d40:e266:3092:9afb:a7b1]) by smtp.gmail.com with ESMTPSA id u20-20020a170906125400b009571293d6acsm2236343eja.59.2023.05.19.05.40.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 May 2023 05:40:09 -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 3/5] mm: compaction: refactor __compaction_suitable() Date: Fri, 19 May 2023 14:39:57 +0200 Message-Id: <20230519123959.77335-4-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-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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766326620370187223?= X-GMAIL-MSGID: =?utf-8?q?1766326620370187223?= __compaction_suitable() is supposed to check for available migration targets. However, it also checks whether the operation was requested via /proc/sys/vm/compact_memory, and whether the original allocation request can already succeed. These don't apply to all callsites. Move the checks out to the callers, so that later patches can deal with them one by one. No functional change intended. Signed-off-by: Johannes Weiner Acked-by: Vlastimil Babka Signed-off-by: Johannes Weiner --- include/linux/compaction.h | 4 +- mm/compaction.c | 78 ++++++++++++++++++++++++-------------- mm/vmscan.c | 35 ++++++++++------- 3 files changed, 73 insertions(+), 44 deletions(-) diff --git a/include/linux/compaction.h b/include/linux/compaction.h index 1f0328a2ba48..9f7cf3e1bf89 100644 --- a/include/linux/compaction.h +++ b/include/linux/compaction.h @@ -90,7 +90,7 @@ extern enum compact_result try_to_compact_pages(gfp_t gfp_mask, struct page **page); extern void reset_isolation_suitable(pg_data_t *pgdat); extern enum compact_result compaction_suitable(struct zone *zone, int order, - unsigned int alloc_flags, int highest_zoneidx); + int highest_zoneidx); extern void compaction_defer_reset(struct zone *zone, int order, bool alloc_success); @@ -108,7 +108,7 @@ static inline void reset_isolation_suitable(pg_data_t *pgdat) } static inline enum compact_result compaction_suitable(struct zone *zone, int order, - int alloc_flags, int highest_zoneidx) + int highest_zoneidx) { return COMPACT_SKIPPED; } diff --git a/mm/compaction.c b/mm/compaction.c index c9a4b6dffcf2..8f61cfa87c49 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -2206,24 +2206,10 @@ static enum compact_result compact_finished(struct compact_control *cc) } static enum compact_result __compaction_suitable(struct zone *zone, int order, - unsigned int alloc_flags, int highest_zoneidx, unsigned long wmark_target) { unsigned long watermark; - - if (is_via_compact_memory(order)) - return COMPACT_CONTINUE; - - watermark = wmark_pages(zone, alloc_flags & ALLOC_WMARK_MASK); - /* - * If watermarks for high-order allocation are already met, there - * should be no need for compaction at all. - */ - if (zone_watermark_ok(zone, order, watermark, highest_zoneidx, - alloc_flags)) - return COMPACT_SUCCESS; - /* * Watermarks for order-0 must be met for compaction to be able to * isolate free pages for migration targets. This means that the @@ -2256,13 +2242,12 @@ static enum compact_result __compaction_suitable(struct zone *zone, int order, * COMPACT_CONTINUE - If compaction should run now */ enum compact_result compaction_suitable(struct zone *zone, int order, - unsigned int alloc_flags, int highest_zoneidx) { enum compact_result ret; int fragindex; - ret = __compaction_suitable(zone, order, alloc_flags, highest_zoneidx, + ret = __compaction_suitable(zone, order, highest_zoneidx, zone_page_state(zone, NR_FREE_PAGES)); /* * fragmentation index determines if allocation failures are due to @@ -2306,7 +2291,16 @@ bool compaction_zonelist_suitable(struct alloc_context *ac, int order, for_each_zone_zonelist_nodemask(zone, z, ac->zonelist, ac->highest_zoneidx, ac->nodemask) { unsigned long available; - enum compact_result compact_result; + unsigned long watermark; + + if (is_via_compact_memory(order)) + return true; + + /* Allocation can already succeed, nothing to do */ + watermark = wmark_pages(zone, alloc_flags & ALLOC_WMARK_MASK); + if (zone_watermark_ok(zone, order, watermark, + ac->highest_zoneidx, alloc_flags)) + continue; /* * Do not consider all the reclaimable memory because we do not @@ -2316,9 +2310,8 @@ bool compaction_zonelist_suitable(struct alloc_context *ac, int order, */ available = zone_reclaimable_pages(zone) / order; available += zone_page_state_snapshot(zone, NR_FREE_PAGES); - compact_result = __compaction_suitable(zone, order, alloc_flags, - ac->highest_zoneidx, available); - if (compact_result == COMPACT_CONTINUE) + if (__compaction_suitable(zone, order, ac->highest_zoneidx, + available) == COMPACT_CONTINUE) return true; } @@ -2348,11 +2341,23 @@ compact_zone(struct compact_control *cc, struct capture_control *capc) INIT_LIST_HEAD(&cc->migratepages); cc->migratetype = gfp_migratetype(cc->gfp_mask); - ret = compaction_suitable(cc->zone, cc->order, cc->alloc_flags, - cc->highest_zoneidx); - /* Compaction is likely to fail */ - if (ret == COMPACT_SUCCESS || ret == COMPACT_SKIPPED) - return ret; + + if (!is_via_compact_memory(cc->order)) { + unsigned long watermark; + + /* Allocation can already succeed, nothing to do */ + watermark = wmark_pages(cc->zone, + cc->alloc_flags & ALLOC_WMARK_MASK); + if (zone_watermark_ok(cc->zone, cc->order, watermark, + cc->highest_zoneidx, cc->alloc_flags)) + return COMPACT_SUCCESS; + + ret = compaction_suitable(cc->zone, cc->order, + cc->highest_zoneidx); + /* Compaction is likely to fail */ + if (ret == COMPACT_SKIPPED) + return ret; + } /* * Clear pageblock skip if there were failures recently and compaction @@ -2845,7 +2850,16 @@ static bool kcompactd_node_suitable(pg_data_t *pgdat) if (!populated_zone(zone)) continue; - if (compaction_suitable(zone, pgdat->kcompactd_max_order, 0, + if (is_via_compact_memory(pgdat->kcompactd_max_order)) + return true; + + /* Allocation can already succeed, check other zones */ + if (zone_watermark_ok(zone, pgdat->kcompactd_max_order, + min_wmark_pages(zone), + highest_zoneidx, 0)) + continue; + + if (compaction_suitable(zone, pgdat->kcompactd_max_order, highest_zoneidx) == COMPACT_CONTINUE) return true; } @@ -2883,10 +2897,18 @@ static void kcompactd_do_work(pg_data_t *pgdat) if (compaction_deferred(zone, cc.order)) continue; - if (compaction_suitable(zone, cc.order, 0, zoneid) != - COMPACT_CONTINUE) + if (is_via_compact_memory(cc.order)) + goto compact; + + /* Allocation can already succeed, nothing to do */ + if (zone_watermark_ok(zone, cc.order, + min_wmark_pages(zone), zoneid, 0)) continue; + if (compaction_suitable(zone, cc.order, + zoneid) != COMPACT_CONTINUE) + continue; +compact: if (kthread_should_stop()) return; diff --git a/mm/vmscan.c b/mm/vmscan.c index d257916f39e5..c9c0f3e081f5 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -6397,14 +6397,17 @@ static inline bool should_continue_reclaim(struct pglist_data *pgdat, if (!managed_zone(zone)) continue; - switch (compaction_suitable(zone, sc->order, 0, sc->reclaim_idx)) { - case COMPACT_SUCCESS: - case COMPACT_CONTINUE: + if (sc->order == -1) /* is_via_compact_memory() */ + return false; + + /* Allocation can already succeed, nothing to do */ + if (zone_watermark_ok(zone, sc->order, min_wmark_pages(zone), + sc->reclaim_idx, 0)) + return false; + + if (compaction_suitable(zone, sc->order, + sc->reclaim_idx) == COMPACT_CONTINUE) return false; - default: - /* check next zone */ - ; - } } /* @@ -6592,16 +6595,20 @@ static void shrink_node(pg_data_t *pgdat, struct scan_control *sc) static inline bool compaction_ready(struct zone *zone, struct scan_control *sc) { unsigned long watermark; - enum compact_result suitable; - suitable = compaction_suitable(zone, sc->order, 0, sc->reclaim_idx); - if (suitable == COMPACT_SUCCESS) - /* Allocation should succeed already. Don't reclaim. */ + if (sc->order == -1) /* is_via_compact_memory() */ + goto suitable; + + /* Allocation can already succeed, nothing to do */ + if (zone_watermark_ok(zone, sc->order, min_wmark_pages(zone), + sc->reclaim_idx, 0)) return true; - if (suitable == COMPACT_SKIPPED) - /* Compaction cannot yet proceed. Do reclaim. */ - return false; + /* Compaction cannot yet proceed. Do reclaim. */ + if (compaction_suitable(zone, sc->order, + sc->reclaim_idx) == COMPACT_SKIPPED) + return false; +suitable: /* * Compaction is already possible, but it takes time to run and there * are potentially other callers using the pages just freed. So proceed From patchwork Fri May 19 12:39:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Weiner X-Patchwork-Id: 96405 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1206501vqo; Fri, 19 May 2023 05:47:55 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ718Dx/dhjb+0q4efS4RBarKNG7eHvTjuu4RIAlC3L2BfwWoNJy/k0/DfoVkjMFijrY0V8M X-Received: by 2002:a17:903:1245:b0:1aa:f6e9:4cb3 with SMTP id u5-20020a170903124500b001aaf6e94cb3mr2926807plh.52.1684500475364; Fri, 19 May 2023 05:47:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684500475; cv=none; d=google.com; s=arc-20160816; b=titszU22BPLP500xQUs7H5NvtbNRItJEPQQdG4MSxYqPm3TB7F5aGPjCwmpyVBeYRb zPH5QMoSvgusOsKIHydUtrtk9wVF8oc4MyXxpZRpLDslrUI2ogIP6ObJTT9A8ppN//ww eNJWb6zMA3da4B9ajxorCwjNYVkWXA9gRaigUmktQo51W2icrr/wTkC7SX/QgPL3p8s3 9iiI6AzC362oO/86nOagOifi3mnCTsexjnZiTvGQN+GwNrX6KSjWN5XS95suKLwzSdRW EfwAblUJ00oYcYyfphkqd4Zxd+kkn2Tu+ZUy4xBBqDxHEWq+7rfYRY5G/82sdR0MKC4H FxjQ== 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=I12hzcEozsRt6JPAOpJEFjq1ISq2RgZIT2QaHAH/cww=; b=SXhsviJh9hzhxCiDKPq02K6u8Q6AfHTv1XvcUaJUeyRnRjlNqg1LTKGMgyoix8byJu dkm/HG7sbfjC7S4uThTZvnsZyW5LtOy+BFJ9FBssQpOC9QrgKr9FQZyt30bjlQwhCT2Q 5rTQNjxX65iZXaHX4f5hrZUvZ5c0IWp3YGgFUDbqrbdT8RNd23+vseY+yXBYiobkllcL EQNNd6unv1eUoM5j2YqxzpfQ0azAtXW/+mGrpzSWK5pHAbO9+JlChIt2qVanD/ef30SE gIok2xT2shrVHefdJ3YM6CtkGxRrh12U2i4t6fR1/uJpYbF3++Yd5ezVZPlGFOUmGC6X udog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20221208.gappssmtp.com header.s=20221208 header.b=GT59zzmh; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h10-20020a170902f54a00b001aaccc51d45si3790720plf.398.2023.05.19.05.47.39; Fri, 19 May 2023 05:47:55 -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=GT59zzmh; 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 S231559AbjESMk3 (ORCPT + 99 others); Fri, 19 May 2023 08:40:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231372AbjESMkV (ORCPT ); Fri, 19 May 2023 08:40:21 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7091D10D for ; Fri, 19 May 2023 05:40:12 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-96f0678de80so584063166b.3 for ; Fri, 19 May 2023 05:40:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20221208.gappssmtp.com; s=20221208; t=1684500011; x=1687092011; 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=I12hzcEozsRt6JPAOpJEFjq1ISq2RgZIT2QaHAH/cww=; b=GT59zzmhCzWRze5Mlw1ALcSFM9y1f9VU/vsZANEVBYHqrlCkXWWh82A+SSfKkAhcf4 3tQ4UFzmxgxZ15dHaxAEnORekxc5TClUeKGWjmM3kIdHBVyDw4ORdXKtk4UyFNmyLKsx bPrrt63f3L9CI/VluEvxZgTjbObARXFRQrS6O0wUVIlJvsvAh4EhyRGdH/5mzFfSMvAU Ma2idKjNNvoYRHFytUI0nQaXf6rj3SDgQr9NpgZmmj7Yk6zkusJ3ACinYJ0FWUKgb/PF jUETXeREzOwQbPb+s4QGvIlHS2Hg954aU5qGVb5Th2SArEQNshM7l3a3RdF3R0fs+NVo k1Ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684500011; x=1687092011; 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=I12hzcEozsRt6JPAOpJEFjq1ISq2RgZIT2QaHAH/cww=; b=S0E8WVigr6I4kZgbh5Q5UKSNyRk/yRSF2DvrSgmOUOJg0NbMUJDt70G+kcomsVCB4V ew3uK1AjBYgsIyYu/MH+Ru+pfFlr6vevuyci/e5VkcaIOmDwSA6qHOkxGo/GJxCuvu0z C+NmZ9oBlbTBA6wjd9lJfv6eqn0OD/MxLU8rcVJIxKF/ndJkcUZRLrm1v9Uj4uga2q0r ol12c058vVCS+B3qVT7QIWrdOs3dUCeb5Hu5ccYRla3B3GnJaOtszGP53QKzCMj8qjkq n7ybNTYSxHQ0h8m7U93aEEbtJ83ufXk1yDpGlKUQjGlxHGr4Mi03fsXWMLu1nsWusmbN k7xQ== X-Gm-Message-State: AC+VfDz5S7WbBZh3rv8vnZwgUf7SLQ8UrshsXCQGocnZpWKpVzChR+WV LGdbfK8ZbTc23RGpYHlWR7yscw== X-Received: by 2002:a17:907:5c7:b0:96a:ed6e:7d58 with SMTP id wg7-20020a17090705c700b0096aed6e7d58mr1561004ejb.7.1684500010821; Fri, 19 May 2023 05:40:10 -0700 (PDT) Received: from localhost ([2a02:8070:6389:7d40:e266:3092:9afb:a7b1]) by smtp.gmail.com with ESMTPSA id q26-20020a170906145a00b00966069b78absm2236221ejc.192.2023.05.19.05.40.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 May 2023 05:40:10 -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 4/5] mm: compaction: remove unnecessary is_via_compact_memory() checks Date: Fri, 19 May 2023 14:39:58 +0200 Message-Id: <20230519123959.77335-5-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-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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766326770330812003?= X-GMAIL-MSGID: =?utf-8?q?1766326770330812003?= Remove from all paths not reachable via /proc/sys/vm/compact_memory. Signed-off-by: Johannes Weiner Acked-by: Vlastimil Babka --- mm/compaction.c | 11 +---------- mm/vmscan.c | 8 +------- 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index 8f61cfa87c49..83ecbc829c62 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -2293,9 +2293,6 @@ bool compaction_zonelist_suitable(struct alloc_context *ac, int order, unsigned long available; unsigned long watermark; - if (is_via_compact_memory(order)) - return true; - /* Allocation can already succeed, nothing to do */ watermark = wmark_pages(zone, alloc_flags & ALLOC_WMARK_MASK); if (zone_watermark_ok(zone, order, watermark, @@ -2850,9 +2847,6 @@ static bool kcompactd_node_suitable(pg_data_t *pgdat) if (!populated_zone(zone)) continue; - if (is_via_compact_memory(pgdat->kcompactd_max_order)) - return true; - /* Allocation can already succeed, check other zones */ if (zone_watermark_ok(zone, pgdat->kcompactd_max_order, min_wmark_pages(zone), @@ -2897,9 +2891,6 @@ static void kcompactd_do_work(pg_data_t *pgdat) if (compaction_deferred(zone, cc.order)) continue; - if (is_via_compact_memory(cc.order)) - goto compact; - /* Allocation can already succeed, nothing to do */ if (zone_watermark_ok(zone, cc.order, min_wmark_pages(zone), zoneid, 0)) @@ -2908,7 +2899,7 @@ static void kcompactd_do_work(pg_data_t *pgdat) if (compaction_suitable(zone, cc.order, zoneid) != COMPACT_CONTINUE) continue; -compact: + if (kthread_should_stop()) return; diff --git a/mm/vmscan.c b/mm/vmscan.c index c9c0f3e081f5..c0cfa9b86b48 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -6397,9 +6397,6 @@ static inline bool should_continue_reclaim(struct pglist_data *pgdat, if (!managed_zone(zone)) continue; - if (sc->order == -1) /* is_via_compact_memory() */ - return false; - /* Allocation can already succeed, nothing to do */ if (zone_watermark_ok(zone, sc->order, min_wmark_pages(zone), sc->reclaim_idx, 0)) @@ -6596,9 +6593,6 @@ static inline bool compaction_ready(struct zone *zone, struct scan_control *sc) { unsigned long watermark; - if (sc->order == -1) /* is_via_compact_memory() */ - goto suitable; - /* Allocation can already succeed, nothing to do */ if (zone_watermark_ok(zone, sc->order, min_wmark_pages(zone), sc->reclaim_idx, 0)) @@ -6608,7 +6602,7 @@ static inline bool compaction_ready(struct zone *zone, struct scan_control *sc) if (compaction_suitable(zone, sc->order, sc->reclaim_idx) == COMPACT_SKIPPED) return false; -suitable: + /* * Compaction is already possible, but it takes time to run and there * are potentially other callers using the pages just freed. So proceed From patchwork Fri May 19 12:39:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Weiner X-Patchwork-Id: 96404 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1206343vqo; Fri, 19 May 2023 05:47:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5dHZdq+t/Wsa1uPLJM/V3HjeTYDE9QzOpwShNFdMrM3i3JtKI+M5kLm6ICnBkHOx5wzmLH X-Received: by 2002:a17:902:ef94:b0:1ab:1241:f671 with SMTP id iz20-20020a170902ef9400b001ab1241f671mr2490039plb.29.1684500459516; Fri, 19 May 2023 05:47:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684500459; cv=none; d=google.com; s=arc-20160816; b=Ai0/sSqP1KPzUHnxzvEnolu87aHsH+zuZP8Owkee+odvy+WVZIagDZo9ZlCS0ZFGIL D5yFyw4jV/r5PfMm+Pyhmni/SiUvSuxsHkJ6XkTHNeImZr2oDocIwLuM2NHAfVhc9Wbp DwMWhSy61y82Mocwvr51cmvlUwzcL+nmnOAj8SHdfJmhTvv4jhZsap8irslxk/x0J1v7 ZaBDiCm6kAhFtc254i9jKD7VXja/XL5PziPI0ErtwqkQjZrKjCnDdBRcMHSyhySvDN8Y jDG+8ubN0EUQkMDpLiDjGFKqhQlzJeYvnhKTzBPzgeSnAHGY8HWTYvhoVLVPMD+TDgo/ U0Yw== 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=Z4v+oqRzENdCCjglWNqDJ+55Ca3cK8hCc7vsdYbZrmE=; b=aTiL+ry1TTFTy2TIteMHLzwdgcN58GkNlWofrqrK30VKZrXVIHllOX1TJ0OVlqW7H9 8SoGqpJBw5qd4m/M1vQObzwVRFIwp8NdNTGZoxkCe/UX8KULM1rD5ToFo9C1AtnlEGV3 CW+lDW/toO3xLVluXbVJXkbdFi5wa54odpYCRry87Lob4Ea/ED+ERvukskCaKsvtJtAe LBr86UKtL1/iWeLoyqZx2Eaa32jNOymvOzOzoESN2iZYpB6tdGoKW1TF2SsuSit5jkR6 LfyWjAq4Ji9/SJ3mcXU0hqk2FECz1lMbmSyMDZLiAr3Cn9MmaP05ecHv2OkeKhFvdkYS w5cQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20221208.gappssmtp.com header.s=20221208 header.b=20CNqbvJ; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x11-20020a170902ec8b00b001a9b9c32ab7si3781039plg.624.2023.05.19.05.47.24; Fri, 19 May 2023 05:47:39 -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=20CNqbvJ; 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 S231575AbjESMkc (ORCPT + 99 others); Fri, 19 May 2023 08:40:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231410AbjESMkV (ORCPT ); Fri, 19 May 2023 08:40:21 -0400 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F04B12B for ; Fri, 19 May 2023 05:40:13 -0700 (PDT) Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-965ab8ed1fcso588459366b.2 for ; Fri, 19 May 2023 05:40:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20221208.gappssmtp.com; s=20221208; t=1684500011; x=1687092011; 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=Z4v+oqRzENdCCjglWNqDJ+55Ca3cK8hCc7vsdYbZrmE=; b=20CNqbvJsj1aXxY3uCUm45tf9ezX9S2bW71I97+RgtCqHWhejBmT7D8t6SgGPjZ4D0 78NGrpoPPgmK0cvKKi0ScZpI0FqlVDon7QXVVExvNnUuac/erh7fmnnN3w4DhzvLGwft WCQyIYWLBRXqrhGVyJEHXh8X9AnxXKhTN9drGkBpCz7ERqa241WhCyvJ98dXO21xlppI Sen2Lkn8tmpr3cNnF999AOPTRPS/iKGGc5L/ADLTcg86p/eC2uxUGukPE+/gtpo5wxcu PtBvaa/bveFRu5G2nltWcfYX1Yo0Ff93a5HBQCDMqcQ4Ts5TTOtSy8ylgH/sNIc0mkNn i6Pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684500011; x=1687092011; 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=Z4v+oqRzENdCCjglWNqDJ+55Ca3cK8hCc7vsdYbZrmE=; b=V0SntLQils5e2GWyjbGDLagdwtatrF+dcwCQCzygzr/emQ+GfKePttPj8r6RiZG3wW I0/6fCMR/kQ/flDFi/eH/4ddi9BWZu61Mig5tvoWRDy5xS6PKWpDmx8o5FTer+PfI3NH d6k2egyQK1cOevN58USPnUy1MdCwwhXGQ+mB5Pyr9oiPyR14uj4W1UrlZEB4DlUsCgOi 8IuGMqjHFULhv9mJ21hnDDe0lnW2HiMgGqnmYAX5bJ8GzZoYahNmxTx7bqff3DeT9Ced 2HBHKPq87RF11lPWFeo/FdBfMHOttdk59Ls5pMJP+EEMn6V04VHCx16jLVqojh50wrzn tveA== X-Gm-Message-State: AC+VfDyK+GbAXq/Y/c5+Ht251ylqKy0ElCrTiC5yvwyChOKZgIf6A+Ag JvQYMHvge7XlkUZf6FWzY2Cqkw== X-Received: by 2002:a17:907:26ca:b0:962:582d:89bf with SMTP id bp10-20020a17090726ca00b00962582d89bfmr1351778ejc.55.1684500011653; Fri, 19 May 2023 05:40:11 -0700 (PDT) Received: from localhost ([2a02:8070:6389:7d40:e266:3092:9afb:a7b1]) by smtp.gmail.com with ESMTPSA id a21-20020a170906191500b0096f7ae359a5sm318552eje.30.2023.05.19.05.40.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 May 2023 05:40:11 -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 5/5] mm: compaction: drop redundant watermark check in compaction_zonelist_suitable() Date: Fri, 19 May 2023 14:39:59 +0200 Message-Id: <20230519123959.77335-6-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-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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766326753443088287?= X-GMAIL-MSGID: =?utf-8?q?1766326753443088287?= The watermark check in compaction_zonelist_suitable(), called from should_compact_retry(), is sandwiched between two watermark checks already: before, there are freelist attempts as part of direct reclaim and direct compaction; after, there is a last-minute freelist attempt in __alloc_pages_may_oom(). The check in compaction_zonelist_suitable() isn't necessary. Kill it. Signed-off-by: Johannes Weiner Acked-by: Vlastimil Babka --- mm/compaction.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index 83ecbc829c62..40ce4e6dd17e 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -2291,13 +2291,6 @@ bool compaction_zonelist_suitable(struct alloc_context *ac, int order, for_each_zone_zonelist_nodemask(zone, z, ac->zonelist, ac->highest_zoneidx, ac->nodemask) { unsigned long available; - unsigned long watermark; - - /* Allocation can already succeed, nothing to do */ - watermark = wmark_pages(zone, alloc_flags & ALLOC_WMARK_MASK); - if (zone_watermark_ok(zone, order, watermark, - ac->highest_zoneidx, alloc_flags)) - continue; /* * Do not consider all the reclaimable memory because we do not From patchwork Fri Jun 2 15:12:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Weiner X-Patchwork-Id: 102597 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1106845vqr; Fri, 2 Jun 2023 08:22:41 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7nEGyF/SQlmTcuE8ESY3vw+cYoxPDKrFpIQr2SjXGldMUoBUYaQqFQ31eVwhkwNTQ76Bc2 X-Received: by 2002:a05:6a20:4322:b0:10b:bf2d:71bb with SMTP id h34-20020a056a20432200b0010bbf2d71bbmr5963509pzk.27.1685719360791; Fri, 02 Jun 2023 08:22:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685719360; cv=none; d=google.com; s=arc-20160816; b=yee1U7NRjrLOvhEn9EGzUX6LFEtSKqb7mAb3e8++SwsRMRV+oJV9WMBf66dW3pbK/I ChNXM9bXOMazuhvtxX21Z2ASzkxOOOMSWc/FDeIZ7+PsqAdhO+jSbqpMFa4YivLYeSe8 XusO3pNAESnSidTqqnofGNiNDDgviW/HaFs7P2sY3ZzGzvYEFKYF+zgntVPL/qW8jgFJ FtHqrHcaNRwDsfeaiAdK3TQApKEmLs5pJIvIZo6qV1nXBxWCU5EW0Hz7C9nHG+4NY9S8 EyZ28fM+J+r5gGaw2QNQaWQ+cwUO9tyyrP5TitLWImMhiuScKudZp22crh7cWWV6S7c0 mj3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=UJ/sY4fCIhElXrp/OIrwXZV72hsbkETwrAjou/86ODY=; b=iRi+dW/TXOf+jUnrJnXHOgDsexSpBImc8XWSDiTcGP7Wh1vHmc02IjgTuLE6Qm1mbz 7LI+lhPw2fU3tXu0vL+eznJ7qAFsVQuyKgFznEzMHd2Oq90BfA3TpjY77UtJpS+KeSIw 8WBTQ3CIwwH0yfAgTctv5KiJMtb9uSVPUZlmc/cC5Vy6rbFACbLbTHuCiPoRmLq9nK5I KfoLO4ikCsE6YvXHvf9h1VFG+G1XgqE1mJKeJAlgUEMcrvuBFBI6PbFZoLhwZlBluKe0 nmMxPYvCgXDnf7PtrwKG7F02Zkquq0avzegi5QokvZTeRvGddJ6CsIZ+YXhVw7PkctG9 rpYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20221208.gappssmtp.com header.s=20221208 header.b=AdJoDQlF; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bm18-20020a656e92000000b0052c575f1d8dsi1157099pgb.260.2023.06.02.08.22.25; Fri, 02 Jun 2023 08:22:40 -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=AdJoDQlF; 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 S236538AbjFBPMn (ORCPT + 99 others); Fri, 2 Jun 2023 11:12:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236541AbjFBPMh (ORCPT ); Fri, 2 Jun 2023 11:12:37 -0400 Received: from mail-qt1-x833.google.com (mail-qt1-x833.google.com [IPv6:2607:f8b0:4864:20::833]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7074C1BB for ; Fri, 2 Jun 2023 08:12:14 -0700 (PDT) Received: by mail-qt1-x833.google.com with SMTP id d75a77b69052e-3f85598697dso9035011cf.1 for ; Fri, 02 Jun 2023 08:12:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20221208.gappssmtp.com; s=20221208; t=1685718726; x=1688310726; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=UJ/sY4fCIhElXrp/OIrwXZV72hsbkETwrAjou/86ODY=; b=AdJoDQlF5Iksk/PUOHjnHUEqDumTdxB+6H38sFxxCD/sPBo4WfvnCg6gWAI+JJLDLu 8Fzc8Dh2W8S1TGk+hV7yqccfJMZKBbjjWIYTYOBnRMDUsMeEEAq7RjKzgVOTEs5Fl67j rO6k/p8QT9i6kOTeOyQpmx+qMyHHBdTssdLxPChlLvoS7APEdtBBtbDvG88mI79jpO+9 djVwPH5Vk/r95ZpZH1dKr4XaqD/Zh2teuk4Ul5DpAzfxmvc3AIOzhlUBu0zg2OL6MXtW XagS16TXQj9YuVR5C+yJw8avrbFffRVSV1dg0YL5vgGeoft8hi2UHkRoVpWMtxWEb2OE tHSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685718726; x=1688310726; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=UJ/sY4fCIhElXrp/OIrwXZV72hsbkETwrAjou/86ODY=; b=i/+jpOcY4zPy3Tn+8VVrRoSgb64RUvrbJFehtH/JC3MjBg+GKAgS78bG7NvC+HxRBp cPo5WdbZYqASNLsO/Y35S0hKcQsIodWh01YdZVe4XcrxrfvbQPoyE8nbDqkb7MrMV37n 87J9T37dUhsIAWGOgFEOh1bICGJG8JFz4KPBa21+EVeH70NzbJxwFNIdACPiOuAONJ1T nkQAuf9oDc6CbtLm288e6vAvarxfF3zbNqeILikIwVcolF7sp2kkwrAYWoEN1UzXUI9Z 9aOmvhE6SYnHHmILngqmkkcV1CXRrcfeo8tsLtpwFmPbhHCKzhxQHXWe/H3xzJk7a/BU ylwA== X-Gm-Message-State: AC+VfDzMBhZnGHK/XNGHHGrA7CfdbiPW0nLl8QRU9O6IFrMnvKVj7QMj AI8Ice4BPZVzL0xb6gttzUuJsQ== X-Received: by 2002:a05:622a:1a23:b0:3f8:494c:556e with SMTP id f35-20020a05622a1a2300b003f8494c556emr6082704qtb.29.1685718726024; Fri, 02 Jun 2023 08:12:06 -0700 (PDT) Received: from localhost ([2620:10d:c091:400::5:ec58]) by smtp.gmail.com with ESMTPSA id h22-20020ac846d6000000b003ef2db16e72sm849414qto.94.2023.06.02.08.12.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jun 2023 08:12:05 -0700 (PDT) Date: Fri, 2 Jun 2023 11:12:04 -0400 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 6/5] mm: compaction: have compaction_suitable() return bool Message-ID: <20230602151204.GD161817@cmpxchg.org> References: <20230519123959.77335-1-hannes@cmpxchg.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20230519123959.77335-1-hannes@cmpxchg.org> 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767604864347385727?= X-GMAIL-MSGID: =?utf-8?q?1767604864347385727?= Since it only returns COMPACT_CONTINUE or COMPACT_SKIPPED now, a bool return value simplifies the callsites. Suggested-by: Vlastimil Babka Signed-off-by: Johannes Weiner Acked-by: Vlastimil Babka --- include/linux/compaction.h | 6 ++-- mm/compaction.c | 64 ++++++++++++++++++-------------------- mm/vmscan.c | 6 ++-- 3 files changed, 36 insertions(+), 40 deletions(-) diff --git a/include/linux/compaction.h b/include/linux/compaction.h index 9f7cf3e1bf89..57b16e69c19a 100644 --- a/include/linux/compaction.h +++ b/include/linux/compaction.h @@ -89,7 +89,7 @@ extern enum compact_result try_to_compact_pages(gfp_t gfp_mask, const struct alloc_context *ac, enum compact_priority prio, struct page **page); extern void reset_isolation_suitable(pg_data_t *pgdat); -extern enum compact_result compaction_suitable(struct zone *zone, int order, +extern bool compaction_suitable(struct zone *zone, int order, int highest_zoneidx); extern void compaction_defer_reset(struct zone *zone, int order, @@ -107,10 +107,10 @@ static inline void reset_isolation_suitable(pg_data_t *pgdat) { } -static inline enum compact_result compaction_suitable(struct zone *zone, int order, +static inline bool compaction_suitable(struct zone *zone, int order, int highest_zoneidx) { - return COMPACT_SKIPPED; + return false; } static inline void kcompactd_run(int nid) diff --git a/mm/compaction.c b/mm/compaction.c index fdee5f1ac5a1..d354d8af157c 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -2205,9 +2205,9 @@ static enum compact_result compact_finished(struct compact_control *cc) return ret; } -static enum compact_result __compaction_suitable(struct zone *zone, int order, - int highest_zoneidx, - unsigned long wmark_target) +static bool __compaction_suitable(struct zone *zone, int order, + int highest_zoneidx, + unsigned long wmark_target) { unsigned long watermark; /* @@ -2227,27 +2227,20 @@ static enum compact_result __compaction_suitable(struct zone *zone, int order, watermark = (order > PAGE_ALLOC_COSTLY_ORDER) ? low_wmark_pages(zone) : min_wmark_pages(zone); watermark += compact_gap(order); - if (!__zone_watermark_ok(zone, 0, watermark, highest_zoneidx, - ALLOC_CMA, wmark_target)) - return COMPACT_SKIPPED; - - return COMPACT_CONTINUE; + return __zone_watermark_ok(zone, 0, watermark, highest_zoneidx, + ALLOC_CMA, wmark_target); } /* * compaction_suitable: Is this suitable to run compaction on this zone now? - * Returns - * COMPACT_SKIPPED - If there are too few free pages for compaction - * COMPACT_CONTINUE - If compaction should run now */ -enum compact_result compaction_suitable(struct zone *zone, int order, - int highest_zoneidx) +bool compaction_suitable(struct zone *zone, int order, int highest_zoneidx) { - enum compact_result ret; - int fragindex; + enum compact_result compact_result; + bool suitable; - ret = __compaction_suitable(zone, order, highest_zoneidx, - zone_page_state(zone, NR_FREE_PAGES)); + suitable = __compaction_suitable(zone, order, highest_zoneidx, + zone_page_state(zone, NR_FREE_PAGES)); /* * fragmentation index determines if allocation failures are due to * low memory or external fragmentation @@ -2264,17 +2257,24 @@ enum compact_result compaction_suitable(struct zone *zone, int order, * excessive compaction for costly orders, but it should not be at the * expense of system stability. */ - if (ret == COMPACT_CONTINUE && (order > PAGE_ALLOC_COSTLY_ORDER)) { - fragindex = fragmentation_index(zone, order); - if (fragindex >= 0 && fragindex <= sysctl_extfrag_threshold) - ret = COMPACT_NOT_SUITABLE_ZONE; + if (suitable) { + compact_result = COMPACT_CONTINUE; + if (order > PAGE_ALLOC_COSTLY_ORDER) { + int fragindex = fragmentation_index(zone, order); + + if (fragindex >= 0 && + fragindex <= sysctl_extfrag_threshold) { + suitable = false; + compact_result = COMPACT_NOT_SUITABLE_ZONE; + } + } + } else { + compact_result = COMPACT_SKIPPED; } - trace_mm_compaction_suitable(zone, order, ret); - if (ret == COMPACT_NOT_SUITABLE_ZONE) - ret = COMPACT_SKIPPED; + trace_mm_compaction_suitable(zone, order, compact_result); - return ret; + return suitable; } bool compaction_zonelist_suitable(struct alloc_context *ac, int order, @@ -2300,7 +2300,7 @@ bool compaction_zonelist_suitable(struct alloc_context *ac, int order, available = zone_reclaimable_pages(zone) / order; available += zone_page_state_snapshot(zone, NR_FREE_PAGES); if (__compaction_suitable(zone, order, ac->highest_zoneidx, - available) == COMPACT_CONTINUE) + available)) return true; } @@ -2341,11 +2341,10 @@ compact_zone(struct compact_control *cc, struct capture_control *capc) cc->highest_zoneidx, cc->alloc_flags)) return COMPACT_SUCCESS; - ret = compaction_suitable(cc->zone, cc->order, - cc->highest_zoneidx); /* Compaction is likely to fail */ - if (ret == COMPACT_SKIPPED) - return ret; + if (!compaction_suitable(cc->zone, cc->order, + cc->highest_zoneidx)) + return COMPACT_SKIPPED; } /* @@ -2846,7 +2845,7 @@ static bool kcompactd_node_suitable(pg_data_t *pgdat) continue; if (compaction_suitable(zone, pgdat->kcompactd_max_order, - highest_zoneidx) == COMPACT_CONTINUE) + highest_zoneidx)) return true; } @@ -2888,8 +2887,7 @@ static void kcompactd_do_work(pg_data_t *pgdat) min_wmark_pages(zone), zoneid, 0)) continue; - if (compaction_suitable(zone, cc.order, - zoneid) != COMPACT_CONTINUE) + if (!compaction_suitable(zone, cc.order, zoneid)) continue; if (kthread_should_stop()) diff --git a/mm/vmscan.c b/mm/vmscan.c index c0cfa9b86b48..e9a8ca124982 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -6402,8 +6402,7 @@ static inline bool should_continue_reclaim(struct pglist_data *pgdat, sc->reclaim_idx, 0)) return false; - if (compaction_suitable(zone, sc->order, - sc->reclaim_idx) == COMPACT_CONTINUE) + if (compaction_suitable(zone, sc->order, sc->reclaim_idx)) return false; } @@ -6599,8 +6598,7 @@ static inline bool compaction_ready(struct zone *zone, struct scan_control *sc) return true; /* Compaction cannot yet proceed. Do reclaim. */ - if (compaction_suitable(zone, sc->order, - sc->reclaim_idx) == COMPACT_SKIPPED) + if (!compaction_suitable(zone, sc->order, sc->reclaim_idx)) return false; /*