Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp6357142rwl; Mon, 9 Jan 2023 07:24:56 -0800 (PST) X-Google-Smtp-Source: AMrXdXuevHel1/0TE6cPPQXI//xPDcZqZnWummEAuzenvfYtTvCQKlFoHpFkc5XnS+pWeWItTory X-Received: by 2002:a17:903:24b:b0:187:282d:6990 with SMTP id j11-20020a170903024b00b00187282d6990mr53731637plh.28.1673277896097; Mon, 09 Jan 2023 07:24:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673277896; cv=none; d=google.com; s=arc-20160816; b=0XOYhJcqpGlb2Bpj/pTXQCs/dKyK81yLon5gXww3d8iLDrlh+TaUkkKUS3yjwtwY2Y 54f+u2etmM6KBkb8zVl/wJWWtJ5D3RCPnsyqa8PruO5+XIRgNjB5RfAKZWzEcNTQAGB9 YNJA/Hd5q106Ixked6LRbis3nTjyhHKHf3eKLdNUDNcKPGdpg8Ll2SjEGULMWdrhpq/S kVmUzjI5UVXAWNEY7GEzkQ2tKcAosvDVUQipmZYyVNQ1sKHCXB109bwIqeKQ7hL3pxpS C7tI2oVqQ1fTZH2zV29qpb1aK8E6iHSd3U6sHD1Y0yHYTFgzVqt1sH/8BSbICoCbYHjO ENOg== 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; bh=yXUMy6cDPmif+grVxIc9oiJzcOxCxumptlQ5E1zTx7w=; b=qOus+6G1wRxLFsLUmq7Hue8RndE3Xla8AfLvsvZRMwaVy8WsVwvO2GjAgseeFwEMOs yjhTJwyQCTkqD5ZcufrndH8CaUnJuWvQs/mXSLMw9IRs250+rGa23Kseal2xRVLulCLg z4vc7FACIVwcumQVV/HzoMIKPH2FXpNY+ws94LHsxTKSX2mUX7UBhUusMYt3tzNjhr7Q O7XbAIw8+JV051AvE0ns5kk9UhjghHM+M9LUY6Qc3GXg6LAgFveJx1m0674c4Ot2Foe7 WFmJgY6BLDDp30UzoY0DFEPUqlczsUizs9xfbOxTC5/fp3IZ9Q5ogcyZlJnpShsJu82I QvJA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n6-20020a634d46000000b004a32a462c19si9446425pgl.843.2023.01.09.07.24.49; Mon, 09 Jan 2023 07:24:56 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237138AbjAIPSZ (ORCPT + 53 others); Mon, 9 Jan 2023 10:18:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237180AbjAIPRz (ORCPT ); Mon, 9 Jan 2023 10:17:55 -0500 Received: from outbound-smtp17.blacknight.com (outbound-smtp17.blacknight.com [46.22.139.234]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA63E1A1 for ; Mon, 9 Jan 2023 07:17:16 -0800 (PST) Received: from mail.blacknight.com (pemlinmail04.blacknight.ie [81.17.254.17]) by outbound-smtp17.blacknight.com (Postfix) with ESMTPS id 37BFB1C40FC for ; Mon, 9 Jan 2023 15:17:15 +0000 (GMT) Received: (qmail 17642 invoked from network); 9 Jan 2023 15:17:15 -0000 Received: from unknown (HELO morpheus.112glenside.lan) (mgorman@techsingularity.net@[84.203.198.246]) by 81.17.254.9 with ESMTPA; 9 Jan 2023 15:17:15 -0000 From: Mel Gorman To: Linux-MM Cc: Andrew Morton , Michal Hocko , NeilBrown , Thierry Reding , Matthew Wilcox , Vlastimil Babka , LKML , Mel Gorman Subject: [PATCH 3/7] mm/page_alloc: Explicitly record high-order atomic allocations in alloc_flags Date: Mon, 9 Jan 2023 15:16:27 +0000 Message-Id: <20230109151631.24923-4-mgorman@techsingularity.net> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230109151631.24923-1-mgorman@techsingularity.net> References: <20230109151631.24923-1-mgorman@techsingularity.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_PASS 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 A high-order ALLOC_HARDER allocation is assumed to be atomic. While that is accurate, it changes later in the series. In preparation, explicitly record high-order atomic allocations in gfp_to_alloc_flags(). There is a slight functional change in that OOM handling avoids using high-order reserve until it has to. Signed-off-by: Mel Gorman --- mm/internal.h | 1 + mm/page_alloc.c | 29 +++++++++++++++++++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/mm/internal.h b/mm/internal.h index 403e4386626d..178484d9fd94 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -746,6 +746,7 @@ unsigned int reclaim_clean_pages_from_list(struct zone *zone, #else #define ALLOC_NOFRAGMENT 0x0 #endif +#define ALLOC_HIGHATOMIC 0x200 /* Allows access to MIGRATE_HIGHATOMIC */ #define ALLOC_KSWAPD 0x800 /* allow waking of kswapd, __GFP_KSWAPD_RECLAIM set */ enum ttu_flags; diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 0040b4e00913..0ef4f3236a5a 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -3706,10 +3706,20 @@ struct page *rmqueue_buddy(struct zone *preferred_zone, struct zone *zone, * reserved for high-order atomic allocation, so order-0 * request should skip it. */ - if (order > 0 && alloc_flags & ALLOC_HARDER) + if (alloc_flags & ALLOC_HIGHATOMIC) page = __rmqueue_smallest(zone, order, MIGRATE_HIGHATOMIC); if (!page) { page = __rmqueue(zone, order, migratetype, alloc_flags); + + /* + * If the allocation fails, allow OOM handling access + * to HIGHATOMIC reserves as failing now is worse than + * failing a high-order atomic allocation in the + * future. + */ + if (!page && (alloc_flags & ALLOC_OOM)) + page = __rmqueue_smallest(zone, order, MIGRATE_HIGHATOMIC); + if (!page) { spin_unlock_irqrestore(&zone->lock, flags); return NULL; @@ -4023,8 +4033,10 @@ bool __zone_watermark_ok(struct zone *z, unsigned int order, unsigned long mark, return true; } #endif - if (alloc_harder && !free_area_empty(area, MIGRATE_HIGHATOMIC)) + if ((alloc_flags & (ALLOC_HIGHATOMIC|ALLOC_OOM)) && + !free_area_empty(area, MIGRATE_HIGHATOMIC)) { return true; + } } return false; } @@ -4286,7 +4298,7 @@ get_page_from_freelist(gfp_t gfp_mask, unsigned int order, int alloc_flags, * If this is a high-order atomic allocation then check * if the pageblock should be reserved for the future */ - if (unlikely(order && (alloc_flags & ALLOC_HARDER))) + if (unlikely(alloc_flags & ALLOC_HIGHATOMIC)) reserve_highatomic_pageblock(page, zone, order); return page; @@ -4813,7 +4825,7 @@ static void wake_all_kswapds(unsigned int order, gfp_t gfp_mask, } static inline unsigned int -gfp_to_alloc_flags(gfp_t gfp_mask) +gfp_to_alloc_flags(gfp_t gfp_mask, unsigned int order) { unsigned int alloc_flags = ALLOC_WMARK_MIN | ALLOC_CPUSET; @@ -4839,8 +4851,13 @@ gfp_to_alloc_flags(gfp_t gfp_mask) * Not worth trying to allocate harder for __GFP_NOMEMALLOC even * if it can't schedule. */ - if (!(gfp_mask & __GFP_NOMEMALLOC)) + if (!(gfp_mask & __GFP_NOMEMALLOC)) { alloc_flags |= ALLOC_HARDER; + + if (order > 0) + alloc_flags |= ALLOC_HIGHATOMIC; + } + /* * Ignore cpuset mems for GFP_ATOMIC rather than fail, see the * comment for __cpuset_node_allowed(). @@ -5048,7 +5065,7 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, * kswapd needs to be woken up, and to avoid the cost of setting up * alloc_flags precisely. So we do that now. */ - alloc_flags = gfp_to_alloc_flags(gfp_mask); + alloc_flags = gfp_to_alloc_flags(gfp_mask, order); /* * We need to recalculate the starting point for the zonelist iterator -- 2.35.3