From patchwork Tue Nov 29 15:16:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mel Gorman X-Patchwork-Id: 13058711 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 29F63C4167B for ; Tue, 29 Nov 2022 15:17:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BF3466B0078; Tue, 29 Nov 2022 10:17:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B55316B007B; Tue, 29 Nov 2022 10:17:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A44096B007D; Tue, 29 Nov 2022 10:17:57 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 94E5E6B0078 for ; Tue, 29 Nov 2022 10:17:57 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 31E421A0BFA for ; Tue, 29 Nov 2022 15:17:57 +0000 (UTC) X-FDA: 80186834994.20.6E4D2D5 Received: from outbound-smtp59.blacknight.com (outbound-smtp59.blacknight.com [46.22.136.243]) by imf26.hostedemail.com (Postfix) with ESMTP id 914B714000F for ; Tue, 29 Nov 2022 15:17:56 +0000 (UTC) Received: from mail.blacknight.com (pemlinmail02.blacknight.ie [81.17.254.11]) by outbound-smtp59.blacknight.com (Postfix) with ESMTPS id 47FEDFA9B4 for ; Tue, 29 Nov 2022 15:17:55 +0000 (GMT) Received: (qmail 5288 invoked from network); 29 Nov 2022 15:17:55 -0000 Received: from unknown (HELO morpheus.112glenside.lan) (mgorman@techsingularity.net@[84.203.198.246]) by 81.17.254.9 with ESMTPA; 29 Nov 2022 15:17:55 -0000 From: Mel Gorman To: Linux-MM Cc: Andrew Morton , Michal Hocko , NeilBrown , Thierry Reding , Matthew Wilcox , Vlastimil Babka , LKML , Mel Gorman Subject: [PATCH 4/6] mm/page_alloc: Explicitly define what alloc flags deplete min reserves Date: Tue, 29 Nov 2022 15:16:59 +0000 Message-Id: <20221129151701.23261-5-mgorman@techsingularity.net> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221129151701.23261-1-mgorman@techsingularity.net> References: <20221129151701.23261-1-mgorman@techsingularity.net> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669735076; a=rsa-sha256; cv=none; b=fHoCkkfrba9xvjDi+JFR+GzrW225A8IRGqmQ8H2eyVk+Oc/Jir8XcAK64mO8QXY/KKB5gk yCMSBGELFYdcfZf5HoqxqAwc9NUHkeU/3rchGiJM/8f3wuCJ17J5mV42OrXa/XUtA8sHyB NG+RiE8GLfDKjDxraAEQX4xvFOhCuug= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf26.hostedemail.com: domain of mgorman@techsingularity.net designates 46.22.136.243 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=1669735076; 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=6aG26MM7VZbzZxAxq6nZIKz4NQXQI+yGR47DbM3N59I=; b=UUqYmXLgKAlzcr5meY01QrbE7CFGXwyCwkWevdyLKyeIWjsj5zuSzabN5zNrGI1tvvM4Me RtNeIdNMceQEZqC9bDMUVOfJhST/FdkII5P0mAm1RLWDvGLjidTurTtmFWiWHCiV7H/yuh iKuDAEzJiAMsM3ilmT0X/jMA8EqdQ/M= X-Stat-Signature: k54i6bqri8a3ag9yuweazy59tqw7zift Authentication-Results: imf26.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf26.hostedemail.com: domain of mgorman@techsingularity.net designates 46.22.136.243 as permitted sender) smtp.mailfrom=mgorman@techsingularity.net X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 914B714000F X-Rspam-User: X-HE-Tag: 1669735076-691934 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: As there are more ALLOC_ flags that affect reserves, define what flags affect reserves and clarify the effect of each flag. Signed-off-by: Mel Gorman Signed-off-by: Mel Gorman --- mm/internal.h | 3 +++ mm/page_alloc.c | 36 +++++++++++++++++++++++------------- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/mm/internal.h b/mm/internal.h index 9a9d9b5ee87f..370500718732 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -757,6 +757,9 @@ unsigned int reclaim_clean_pages_from_list(struct zone *zone, #define ALLOC_HIGHATOMIC 0x200 /* Allows access to MIGRATE_HIGHATOMIC */ #define ALLOC_KSWAPD 0x800 /* allow waking of kswapd, __GFP_KSWAPD_RECLAIM set */ +/* Flags that allow allocations below the min watermark. */ +#define ALLOC_RESERVES (ALLOC_HARDER|ALLOC_MIN_RESERVE|ALLOC_HIGHATOMIC|ALLOC_OOM) + enum ttu_flags; struct tlbflush_unmap_batch; diff --git a/mm/page_alloc.c b/mm/page_alloc.c index e2b65767dda0..85a87d0ac57a 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -3944,15 +3944,14 @@ ALLOW_ERROR_INJECTION(should_fail_alloc_page, TRUE); static inline long __zone_watermark_unusable_free(struct zone *z, unsigned int order, unsigned int alloc_flags) { - const bool alloc_harder = (alloc_flags & (ALLOC_HARDER|ALLOC_OOM)); long unusable_free = (1 << order) - 1; /* - * If the caller does not have rights to ALLOC_HARDER then subtract - * the high-atomic reserves. This will over-estimate the size of the - * atomic reserve but it avoids a search. + * If the caller does not have rights to reserves below the min + * watermark then subtract the high-atomic reserves. This will + * over-estimate the size of the atomic reserve but it avoids a search. */ - if (likely(!alloc_harder)) + if (likely(!(alloc_flags & ALLOC_RESERVES))) unusable_free += z->nr_reserved_highatomic; #ifdef CONFIG_CMA @@ -3976,25 +3975,36 @@ bool __zone_watermark_ok(struct zone *z, unsigned int order, unsigned long mark, { long min = mark; int o; - const bool alloc_harder = (alloc_flags & (ALLOC_HARDER|ALLOC_OOM)); /* free_pages may go negative - that's OK */ free_pages -= __zone_watermark_unusable_free(z, order, alloc_flags); - if (alloc_flags & ALLOC_MIN_RESERVE) - min -= min / 2; + if (alloc_flags & ALLOC_RESERVES) { + /* + * __GFP_HIGH allows access to 50% of the min reserve as well + * as OOM. + */ + if (alloc_flags & ALLOC_MIN_RESERVE) + min -= min / 2; - if (unlikely(alloc_harder)) { /* - * OOM victims can try even harder than normal ALLOC_HARDER + * Non-blocking allocations can access some of the reserve + * with more access if also __GFP_HIGH. The reasoning is that + * a non-blocking caller may incur a more severe penalty + * if it cannot get memory quickly, particularly if it's + * also __GFP_HIGH. + */ + if (alloc_flags & (ALLOC_HARDER|ALLOC_HIGHATOMIC)) + min -= min / 4; + + /* + * OOM victims can try even harder than the normal reserve * users on the grounds that it's definitely going to be in * the exit path shortly and free memory. Any allocation it * makes during the free path will be small and short-lived. */ if (alloc_flags & ALLOC_OOM) min -= min / 2; - else - min -= min / 4; } /* @@ -5293,7 +5303,7 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, * could deplete whole memory reserves which would just make * the situation worse */ - page = __alloc_pages_cpuset_fallback(gfp_mask, order, ALLOC_HARDER, ac); + page = __alloc_pages_cpuset_fallback(gfp_mask, order, ALLOC_MIN_RESERVE|ALLOC_HARDER, ac); if (page) goto got_pg;