From patchwork Mon Jan 9 15:16:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mel Gorman X-Patchwork-Id: 13093710 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05D56C5479D for ; Mon, 9 Jan 2023 15:17:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 84D0A8E000B; Mon, 9 Jan 2023 10:17:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7FC918E0001; Mon, 9 Jan 2023 10:17:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6EB938E000B; Mon, 9 Jan 2023 10:17:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 5FA8B8E0001 for ; Mon, 9 Jan 2023 10:17:18 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 44187AADCC for ; Mon, 9 Jan 2023 15:17:18 +0000 (UTC) X-FDA: 80335614156.26.A609C7E Received: from outbound-smtp47.blacknight.com (outbound-smtp47.blacknight.com [46.22.136.64]) by imf05.hostedemail.com (Postfix) with ESMTP id 8A6B5100011 for ; Mon, 9 Jan 2023 15:17:16 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf05.hostedemail.com: domain of mgorman@techsingularity.net designates 46.22.136.64 as permitted sender) smtp.mailfrom=mgorman@techsingularity.net ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1673277436; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yXUMy6cDPmif+grVxIc9oiJzcOxCxumptlQ5E1zTx7w=; b=4THHdiz1pIIgwQWgKsmOU0twKrB9WWKaq34xzcmAB2irllAiH0Z4VDEwb86eiJeSyCsw7O Ny+MCOeqaHo6DHyGhbtj2qmcLPl0FyY9XYId2xhihVApV1UjOQTUYgz0X7Tf7y+ht46DNO xI6fMs7H3SBeXF7C1qUCGvWo6jP2t5s= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf05.hostedemail.com: domain of mgorman@techsingularity.net designates 46.22.136.64 as permitted sender) smtp.mailfrom=mgorman@techsingularity.net ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1673277436; a=rsa-sha256; cv=none; b=5U3FTfz1sjORBSa9VmBVEF+spwqIYmTyi1nCDJe2nLGh1KrKH3jNkfLLdIb991WaYMPfcH gUUJpNIXUoABzFUfucAMzBn1ST8TWHf5e6wHaslVBTpCpeicict3Yw0juc22LdvzA9dO1A 5LzufVpY5iIXWPpheaGRLh1DiXjLccg= Received: from mail.blacknight.com (pemlinmail04.blacknight.ie [81.17.254.17]) by outbound-smtp47.blacknight.com (Postfix) with ESMTPS id 37100FA881 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 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 8A6B5100011 X-Stat-Signature: 65jqrfc5wa1k4xgt6ec8cwfhkit883tt X-Rspam-User: X-HE-Tag: 1673277436-495198 X-HE-Meta: U2FsdGVkX19PsmhxjL4BlU/oZX6E41MpeiLRPeyZPx8XHooM4kG6Q3wH2e4x0dy8GwnFnIRpZoYfcDhpQNJvq5B9Y5oOkH5tgygzFhhY4cKOr/Fn9K7OMbW54+hwNy7e1S3hB8RqjIb5MCS+gHXTcHZINjtc5Q10BuLdCVQiPDck4dcEJ2TUFPX/W4dRaKkafr2J6T4X8tUDOP+i30ntq7B6b7UOh5zZ3UzO/r3HbuvpqRqPnBSG5upNmo/8PSu2MChSmx4J7UC2hlgL+WdLb00sQkHoe3OZgaXcYdu+jYuCLgMXtQO+gUeE1AckHpEGAkQ+59wAt+my6B+IsZoMBQ9Kgd6tEG6/OpXlgVfry3nGLq6t/jtnG1upymNPUyQVQRNGL0BnZqg/zlsnLW+0GcjoA+v473k25QfoRJnOmGLy2V21B1ptho47PvIpudyFds1Qh1r97Wro2bD6uDKpzG2L6AI3mIxYjtJS1UAiTNHR9CIAUa4Aod+ZUs4b+ld9CPnjiVn7AOKw4mntXY15jXXXUu50SBvhqy0NVZ71lTxIXWBH7oqMajpcz6n33t2+Nwfa2Doi0S+aThZ0lHpYoQ9bhvJ8zSXExCxG53uS1nk6720PExvOS3/9MQVNPr1G+uApvRymcGTmUt4no33u6ylTWJJJoLhj8O9aAY9OmhDc66aikwQSmsj0Xz6U0cA1y/ujW2FmZfmT2Pc2ba0GQBw8FxLMmlSr5Zu3rBaigz/nYXnzU64xkSLhikPGDzOKmLiDLMDLgcPpC9GvQZcvgKbkgeRXOOT629Ksq4aiIRAiND5dr0itXgwwaNUbju5nmbNSm6Zn/fjda0dcsKGL7uKF6wsne6txPeyU4lkzwnHz1K4YJwMTimp0ktoNlj5lT/sihE+pbOD+6dJrjoChim0ncsgZN7xt0tOy5ssFD40mWN4FBv5duJWAcP7P/7BqVToXAAjAEYgpUDNclOQ AdS1oQ7D s5sKerglBgGbCThNJ0MC/IrFYwVhJVeTrgui69pc66YTCjG+gQ1hQdDWl004scVWO9x5N X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 Acked-by: Vlastimil Babka --- 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