From nobody Sun Feb 8 10:03:10 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6F67C77B7A for ; Fri, 19 May 2023 12:40:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229525AbjESMkV (ORCPT ); Fri, 19 May 2023 08:40:21 -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-Google-Smtp-Source: ACHHUZ7oj3yMtwF1chSvwKUqZhCd0vlmhEuYEkCw7mv9MYs7nSCkZ05x4A7DYg+PKersqbn5+LRfWg== 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 zo= ne *zone, int order, extern void compaction_defer_reset(struct zone *zone, int order, bool alloc_success); =20 -/* 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 =3D=3D 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 =3D=3D 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 =3D=3D 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 st= ill - * 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 =3D=3D 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 =3D=3D 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 =3D=3D COMPACT_PARTIAL_SKIPPED) - return true; - - return false; -} - - bool compaction_zonelist_suitable(struct alloc_context *ac, int order, int alloc_flags); =20 @@ -185,26 +113,6 @@ static inline enum compact_result compaction_suitable(= struct zone *zone, int ord return COMPACT_SKIPPED; } =20 -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 =3D result; \ - (compaction_failed(__result)) ? COMPACTION_FAILED : \ - (compaction_withdrawn(__result)) ? COMPACTION_WITHDRAWN : COMPACTION_PRO= GRESS; \ + (__result =3D=3D COMPACT_COMPLETE) ? COMPACTION_FAILED : \ + (__result =3D=3D COMPACT_SUCCESS) ? COMPACTION_PROGRESS : COMPACTION_WIT= HDRAWN; \ }) =20 #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; =20 - 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 =3D=3D COMPACT_SUCCESS) (*compaction_retries)++; =20 /* - * 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 =3D=3D COMPACT_COMPLETE) goto check_priority; =20 /* - * 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 =3D=3D COMPACT_SKIPPED) { ret =3D compaction_zonelist_suitable(ac, order, alloc_flags); goto out; } =20 /* - * 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 =3D=3D COMPACT_DEFERRED || + compact_result =3D=3D COMPACT_CONTENDED || + compact_result =3D=3D COMPACT_PARTIAL_SKIPPED) goto check_priority; - } =20 /* * !costly requests are much more important than __GFP_RETRY_MAYFAIL --=20 2.40.0 From nobody Sun Feb 8 10:03:10 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1213CC77B7A for ; Fri, 19 May 2023 12:40:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231347AbjESMkY (ORCPT ); Fri, 19 May 2023 08:40:24 -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-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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 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 =3D=3D COMPACT_SUCCESS) - (*compaction_retries)++; + if (compact_result =3D=3D 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 /=3D 4; =20 - /* - * 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 =3D=3D COMPACT_COMPLETE) - goto check_priority; + ret =3D ++(*compaction_retries) <=3D max_retries; + goto out; + } =20 /* * Compaction was skipped due to a lack of free order-0 @@ -3793,35 +3799,8 @@ should_compact_retry(struct alloc_context *ac, int o= rder, int alloc_flags, } =20 /* - * 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 =3D=3D COMPACT_DEFERRED || - compact_result =3D=3D COMPACT_CONTENDED || - compact_result =3D=3D 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 /=3D 4; - if (*compaction_retries <=3D max_retries) { - ret =3D 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 =3D (order > PAGE_ALLOC_COSTLY_ORDER) ? MIN_COMPACT_COSTLY_PRIORITY : MIN_COMPACT_PRIORITY; =20 --=20 2.40.0 From nobody Sun Feb 8 10:03:10 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A8020C77B7F for ; Fri, 19 May 2023 12:40:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231536AbjESMk0 (ORCPT ); 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-Google-Smtp-Source: ACHHUZ5OI99u6ZjRHk2L81FZPXX2dcOxJ0p3S0XoqUDF0BmNWfVXDxnHp4ONjafiSuyLZ1d4i1Us2w== 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" __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 --- 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 orde= r, - unsigned int alloc_flags, int highest_zoneidx); + int highest_zoneidx); =20 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) } =20 static inline enum compact_result compaction_suitable(struct zone *zone, i= nt 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) } =20 static enum compact_result __compaction_suitable(struct zone *zone, int or= der, - unsigned int alloc_flags, int highest_zoneidx, unsigned long wmark_target) { unsigned long watermark; - - if (is_via_compact_memory(order)) - return COMPACT_CONTINUE; - - watermark =3D 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(st= ruct 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; =20 - ret =3D __compaction_suitable(zone, order, alloc_flags, highest_zoneidx, + ret =3D __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_conte= xt *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 =3D wmark_pages(zone, alloc_flags & ALLOC_WMARK_MASK); + if (zone_watermark_ok(zone, order, watermark, + ac->highest_zoneidx, alloc_flags)) + continue; =20 /* * Do not consider all the reclaimable memory because we do not @@ -2316,9 +2310,8 @@ bool compaction_zonelist_suitable(struct alloc_contex= t *ac, int order, */ available =3D zone_reclaimable_pages(zone) / order; available +=3D zone_page_state_snapshot(zone, NR_FREE_PAGES); - compact_result =3D __compaction_suitable(zone, order, alloc_flags, - ac->highest_zoneidx, available); - if (compact_result =3D=3D COMPACT_CONTINUE) + if (__compaction_suitable(zone, order, ac->highest_zoneidx, + available) =3D=3D COMPACT_CONTINUE) return true; } =20 @@ -2348,11 +2341,23 @@ compact_zone(struct compact_control *cc, struct cap= ture_control *capc) INIT_LIST_HEAD(&cc->migratepages); =20 cc->migratetype =3D gfp_migratetype(cc->gfp_mask); - ret =3D compaction_suitable(cc->zone, cc->order, cc->alloc_flags, - cc->highest_zoneidx); - /* Compaction is likely to fail */ - if (ret =3D=3D COMPACT_SUCCESS || ret =3D=3D COMPACT_SKIPPED) - return ret; + + if (!is_via_compact_memory(cc->order)) { + unsigned long watermark; + + /* Allocation can already succeed, nothing to do */ + watermark =3D 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 =3D compaction_suitable(cc->zone, cc->order, + cc->highest_zoneidx); + /* Compaction is likely to fail */ + if (ret =3D=3D COMPACT_SKIPPED) + return ret; + } =20 /* * 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; =20 - 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) =3D=3D COMPACT_CONTINUE) return true; } @@ -2883,10 +2897,18 @@ static void kcompactd_do_work(pg_data_t *pgdat) if (compaction_deferred(zone, cc.order)) continue; =20 - if (compaction_suitable(zone, cc.order, 0, zoneid) !=3D - 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; =20 + if (compaction_suitable(zone, cc.order, + zoneid) !=3D COMPACT_CONTINUE) + continue; +compact: if (kthread_should_stop()) return; =20 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 p= glist_data *pgdat, if (!managed_zone(zone)) continue; =20 - switch (compaction_suitable(zone, sc->order, 0, sc->reclaim_idx)) { - case COMPACT_SUCCESS: - case COMPACT_CONTINUE: + if (sc->order =3D=3D -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) =3D=3D COMPACT_CONTINUE) return false; - default: - /* check next zone */ - ; - } } =20 /* @@ -6592,16 +6595,20 @@ static void shrink_node(pg_data_t *pgdat, struct sc= an_control *sc) static inline bool compaction_ready(struct zone *zone, struct scan_control= *sc) { unsigned long watermark; - enum compact_result suitable; =20 - suitable =3D compaction_suitable(zone, sc->order, 0, sc->reclaim_idx); - if (suitable =3D=3D COMPACT_SUCCESS) - /* Allocation should succeed already. Don't reclaim. */ + if (sc->order =3D=3D -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 =3D=3D COMPACT_SKIPPED) - /* Compaction cannot yet proceed. Do reclaim. */ - return false; =20 + /* Compaction cannot yet proceed. Do reclaim. */ + if (compaction_suitable(zone, sc->order, + sc->reclaim_idx) =3D=3D 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 --=20 2.40.0 From nobody Sun Feb 8 10:03:10 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B2D2DC77B7F for ; Fri, 19 May 2023 12:40:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231567AbjESMka (ORCPT ); Fri, 19 May 2023 08:40:30 -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-Google-Smtp-Source: ACHHUZ4u90+qy6wcMhun2oAgrbOIc2XjLRHqEiy1bSQkvwbZrSERksL8jCVIYbiTqqILkLPHJwuusA== 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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_contex= t *ac, int order, unsigned long available; unsigned long watermark; =20 - if (is_via_compact_memory(order)) - return true; - /* Allocation can already succeed, nothing to do */ watermark =3D 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; =20 - 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; =20 - 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) !=3D COMPACT_CONTINUE) continue; -compact: + if (kthread_should_stop()) return; =20 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 pgl= ist_data *pgdat, if (!managed_zone(zone)) continue; =20 - if (sc->order =3D=3D -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; =20 - if (sc->order =3D=3D -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) =3D=3D 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 --=20 2.40.0 From nobody Sun Feb 8 10:03:10 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ECEA5C77B7F for ; Fri, 19 May 2023 12:40:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231583AbjESMkd (ORCPT ); Fri, 19 May 2023 08:40:33 -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-Google-Smtp-Source: ACHHUZ5HyrBz4voNu4RQsLSn8EHNU2geTDUc+VN5aCe45DZsHq2yRGRL9hB9xWE6eywvCBf1dsLcEQ== 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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_conte= xt *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 =3D wmark_pages(zone, alloc_flags & ALLOC_WMARK_MASK); - if (zone_watermark_ok(zone, order, watermark, - ac->highest_zoneidx, alloc_flags)) - continue; =20 /* * Do not consider all the reclaimable memory because we do not --=20 2.40.0 From nobody Sun Feb 8 10:03:10 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8CD3FC77B7A for ; Fri, 2 Jun 2023 15:12:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236236AbjFBPMo (ORCPT ); Fri, 2 Jun 2023 11:12:44 -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-Google-Smtp-Source: ACHHUZ5wAOrk5rjCrY0Dlm7rbBBgwnU5R/Uyki7/cLYa2PdV1jZwGY75NujMF8tPmrf9pYd5FOk6eQ== 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> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 orde= r, +extern bool compaction_suitable(struct zone *zone, int order, int highest_zoneidx); =20 extern void compaction_defer_reset(struct zone *zone, int order, @@ -107,10 +107,10 @@ static inline void reset_isolation_suitable(pg_data_t= *pgdat) { } =20 -static inline enum compact_result compaction_suitable(struct zone *zone, i= nt order, +static inline bool compaction_suitable(struct zone *zone, int order, int highest_zoneidx) { - return COMPACT_SKIPPED; + return false; } =20 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 co= mpact_control *cc) return ret; } =20 -static enum compact_result __compaction_suitable(struct zone *zone, int or= der, - 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(st= ruct zone *zone, int order, watermark =3D (order > PAGE_ALLOC_COSTLY_ORDER) ? low_wmark_pages(zone) : min_wmark_pages(zone); watermark +=3D 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); } =20 /* * compaction_suitable: Is this suitable to run compaction on this zone no= w? - * 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; =20 - ret =3D __compaction_suitable(zone, order, highest_zoneidx, - zone_page_state(zone, NR_FREE_PAGES)); + suitable =3D __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 =3D=3D COMPACT_CONTINUE && (order > PAGE_ALLOC_COSTLY_ORDER)) { - fragindex =3D fragmentation_index(zone, order); - if (fragindex >=3D 0 && fragindex <=3D sysctl_extfrag_threshold) - ret =3D COMPACT_NOT_SUITABLE_ZONE; + if (suitable) { + compact_result =3D COMPACT_CONTINUE; + if (order > PAGE_ALLOC_COSTLY_ORDER) { + int fragindex =3D fragmentation_index(zone, order); + + if (fragindex >=3D 0 && + fragindex <=3D sysctl_extfrag_threshold) { + suitable =3D false; + compact_result =3D COMPACT_NOT_SUITABLE_ZONE; + } + } + } else { + compact_result =3D COMPACT_SKIPPED; } =20 - trace_mm_compaction_suitable(zone, order, ret); - if (ret =3D=3D COMPACT_NOT_SUITABLE_ZONE) - ret =3D COMPACT_SKIPPED; + trace_mm_compaction_suitable(zone, order, compact_result); =20 - return ret; + return suitable; } =20 bool compaction_zonelist_suitable(struct alloc_context *ac, int order, @@ -2300,7 +2300,7 @@ bool compaction_zonelist_suitable(struct alloc_contex= t *ac, int order, available =3D zone_reclaimable_pages(zone) / order; available +=3D zone_page_state_snapshot(zone, NR_FREE_PAGES); if (__compaction_suitable(zone, order, ac->highest_zoneidx, - available) =3D=3D COMPACT_CONTINUE) + available)) return true; } =20 @@ -2341,11 +2341,10 @@ compact_zone(struct compact_control *cc, struct cap= ture_control *capc) cc->highest_zoneidx, cc->alloc_flags)) return COMPACT_SUCCESS; =20 - ret =3D compaction_suitable(cc->zone, cc->order, - cc->highest_zoneidx); /* Compaction is likely to fail */ - if (ret =3D=3D COMPACT_SKIPPED) - return ret; + if (!compaction_suitable(cc->zone, cc->order, + cc->highest_zoneidx)) + return COMPACT_SKIPPED; } =20 /* @@ -2846,7 +2845,7 @@ static bool kcompactd_node_suitable(pg_data_t *pgdat) continue; =20 if (compaction_suitable(zone, pgdat->kcompactd_max_order, - highest_zoneidx) =3D=3D COMPACT_CONTINUE) + highest_zoneidx)) return true; } =20 @@ -2888,8 +2887,7 @@ static void kcompactd_do_work(pg_data_t *pgdat) min_wmark_pages(zone), zoneid, 0)) continue; =20 - if (compaction_suitable(zone, cc.order, - zoneid) !=3D COMPACT_CONTINUE) + if (!compaction_suitable(zone, cc.order, zoneid)) continue; =20 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 pgl= ist_data *pgdat, sc->reclaim_idx, 0)) return false; =20 - if (compaction_suitable(zone, sc->order, - sc->reclaim_idx) =3D=3D COMPACT_CONTINUE) + if (compaction_suitable(zone, sc->order, sc->reclaim_idx)) return false; } =20 @@ -6599,8 +6598,7 @@ static inline bool compaction_ready(struct zone *zone= , struct scan_control *sc) return true; =20 /* Compaction cannot yet proceed. Do reclaim. */ - if (compaction_suitable(zone, sc->order, - sc->reclaim_idx) =3D=3D COMPACT_SKIPPED) + if (!compaction_suitable(zone, sc->order, sc->reclaim_idx)) return false; =20 /* --=20 2.40.1