From nobody Tue Feb 10 04:23:16 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