From patchwork Tue Feb 25 00:08:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Weiner X-Patchwork-Id: 13989138 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 D0F97C021A4 for ; Tue, 25 Feb 2025 00:10:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 62E0328000B; Mon, 24 Feb 2025 19:10:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5DE43280002; Mon, 24 Feb 2025 19:10:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 47F9E28000B; Mon, 24 Feb 2025 19:10:45 -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 257CC280002 for ; Mon, 24 Feb 2025 19:10:45 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id BCFAF1404DA for ; Tue, 25 Feb 2025 00:10:44 +0000 (UTC) X-FDA: 83156536008.17.DB87F28 Received: from mail-qv1-f51.google.com (mail-qv1-f51.google.com [209.85.219.51]) by imf21.hostedemail.com (Postfix) with ESMTP id D0A151C000A for ; Tue, 25 Feb 2025 00:10:42 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=Pvc83PRt; spf=pass (imf21.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.219.51 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1740442242; 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:dkim-signature; bh=2e25n5vpfxDFEGmdOG76BnXvJ2FJi0Uv+lwO0Tt+wqc=; b=qO3tXrWYQ80Zuo4eSTNZSvtqjZPHDOaFVLvuYvKex40kVT+4Z8eOhW8OCRWC31jRpHrALn Qx9MRO+4i6MtmAbdx3UXsi+YjRXk8d2jcFxNH3YhcFrolggGtOTAvbVbKKB9JyLDsL4IaT sW+ZNOy2K/8tdb5So8cCFz+HOWv0PRI= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=Pvc83PRt; spf=pass (imf21.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.219.51 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1740442242; a=rsa-sha256; cv=none; b=ua4eHP35klXx+cztXWJxUpgCmBqGh9tntN59hD+lmE7u6xBXmKIMW+s71SjQewNPFnyZoW l9ZmsvK/Ol8nKf1VCDXqSNl6DszHWpN3BzRog4jJ5ecUKW7uVjxlIKtKAg9DKIpHkotqDJ 6q9gV70hi7jG7+9lvS3l5v1mrcTWKvc= Received: by mail-qv1-f51.google.com with SMTP id 6a1803df08f44-6e660740061so45336806d6.3 for ; Mon, 24 Feb 2025 16:10:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20230601.gappssmtp.com; s=20230601; t=1740442242; x=1741047042; darn=kvack.org; 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=2e25n5vpfxDFEGmdOG76BnXvJ2FJi0Uv+lwO0Tt+wqc=; b=Pvc83PRtz28jFJ1hpkdsJ5HkL7wlJIh75FdwbtwkzkfhSHdU+eSnnHXlanAE3nmZyQ OOXR42EEl3lkb+4fO1dJYTgspwp8s2NrTlChAMkwQ8Orp/Ej0G1mUzLIIQknsTj4lDPZ LC3QEpzjjpOR/QQ8gwDRGKg4ExWz3sfkD9VIgJJ4z1gFrPQplA0811DS6P9fDTQ/VxhY eaYQRfk3TKgFEGi2oXbGSGTsP+ErBphgfn0p3hTfo6kxSg6K5e1DqI9gSTrVwPwgZG9G 14p9YKRolfnxkvPGO08mq/Nr0lwDAwWWcH9ARxm/rAa8tRT7u4It/TNAaTo0MCiXiZ7j Wi9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740442242; x=1741047042; 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=2e25n5vpfxDFEGmdOG76BnXvJ2FJi0Uv+lwO0Tt+wqc=; b=pabWMxxctZlO+wxCC5c6EIGNNlYKsgejqHUP2KWkGrOJJdW0f1zsFj6h7G1jt7nA1V KzZvBGVNbflS3IwPskPPAPt/NfhVp03qqsZoSMo/G1VRvjdAve89paQKf0sWEMZSJhBo NxMKd2mrY++SMM4nzUc15XUGR/nuzQbeZ4A5i3kiyvsrXxP2G96s+HNaKrLppHDKrdun Jrs7bG7+QgE/KhH8iXa5zBCUPoeHFuhvnJzS/XH9gPVVbQaG0TTLfyTpN6E45aBm7W8D Ih1sKNyghcICkaPRFyt5ik5IlWaHatjBN0t/OX8CgodFineyrfkyi9tDGEcY4o0os79L P5Lw== X-Forwarded-Encrypted: i=1; AJvYcCUeKv+FzdLyMEUwVXfiVopU9drc7WbVJCWqpAHcnprjwUdpnjiwxP8XhWcb6qNRlmbWzcvSFz7sbQ==@kvack.org X-Gm-Message-State: AOJu0YzkhBPV0XwOzREAICdVCuuIEZrcgTJmNaAD71ugCSPc03K8s3eW YLWvP39gsF+GotFDpodDVCdyyR9RaNlc1/8kkuWNYGNm0D6x+x+mbx6NPaxNYNs= X-Gm-Gg: ASbGncs0c0LFEZF1Fb/c3z3P+M8HC4DDfEcWebvtUhkwwyvwflbUZwD10cEA9Jr5cz7 90UmiKrD5lzYxz0qJ3HBq0avITtgml7YL87A/D7i9VrE+mh25cBWaeuCnbFD0o3esvgGuTVYrEb NPFy/aB+QzfcmBMBihaveF4y549WsNbh4srjKUqwAZGBiJNDeHh5Ta/dHT8/c9gmDq8Mwdv8zUN De7cg6dcEdQQ+4DYHIWt6d1JzHzb6twUHej4qmHrb3CJit8EoMGwL+wEft8Zy6nmgVE5OQQEHXi rrDrUT4Fqzlmz+PIArBAMY9u X-Google-Smtp-Source: AGHT+IGgkiR9iptSEyFu7U9mGo/QIIVICqxDDnkseqj6QpgDVUGUnhk9KHuZIRF7lIakpsCc0f0yiA== X-Received: by 2002:a05:6214:2463:b0:6e4:1e1d:10a7 with SMTP id 6a1803df08f44-6e6ae7c6211mr196896276d6.1.1740442241870; Mon, 24 Feb 2025 16:10:41 -0800 (PST) Received: from localhost ([2603:7000:c01:2716:da5e:d3ff:fee7:26e7]) by smtp.gmail.com with UTF8SMTPSA id 6a1803df08f44-6e87b0871e2sm3224846d6.27.2025.02.24.16.10.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Feb 2025 16:10:36 -0800 (PST) From: Johannes Weiner To: Andrew Morton Cc: Vlastimil Babka , Brendan Jackman , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] mm: page_alloc: group fallback functions together Date: Mon, 24 Feb 2025 19:08:26 -0500 Message-ID: <20250225001023.1494422-4-hannes@cmpxchg.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250225001023.1494422-1-hannes@cmpxchg.org> References: <20250225001023.1494422-1-hannes@cmpxchg.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: D0A151C000A X-Stat-Signature: 8zqzm5oshg13ifz71i9c8xgcabi7eo93 X-Rspamd-Server: rspam03 X-HE-Tag: 1740442242-994100 X-HE-Meta: U2FsdGVkX1+npY61faVzamNNtX9DHnDLumaYZJa3d4pNlacfEbQPW5lloK1C75f+InsRNZb1e+qpqwRn9fnF/k1y3/7eF+lxuaOTKeodbM5gol6Vlh3IyqdpSobZGdR2gNdSoxU69E0q4Wznn1/nTIdjh1ymajuo3HKofekKYxe3qTR7G9KBiSWf5LYsgyVNEXqQTBLqRvfIc9zjiM2aPv+NtNZ4sgqE7aUDSQUl9+cJ21B9yb355x+3A7SDREkEGeHhZ+GFRtGpy8ba/F4GgPrh6w4sD0lbhLQhEDdVyehHlBRAXawFhmY8eOqSQ2uPJVBjgnB4AjrNQ2PW7X6sIHjaUB+f0AuZUoEg05ilVOOnDU1uMQcJe/769sqwvxp59la8Ea4QKVL+gjBIZseQ2TxdXPAmmDkUaqf5PP8kg3guELWggkT0u4ATFpC2Njzaur19jO5K1kqtuKjHw2fm4Q1g+jhCVzhhT5/NMx6iVOHvnEgFrZVbP87WuU3eyka7mAw4MlG6yKoQDGS477RaH1LxcZMjIALar2flFpmzDUbhDipkP+0YXlYYol5+0X1+q7cr8bO9WXxfpPlIpBq86s956wzaTNG3Kisxo89Z/CCRKk8M5htY9KkH7Dl6HMRDz6LumniSW32gO7O5jsB2aADdgU0+UKv4m8RSsTinNPPiq+S1+mHZr5pgFa4pQ02uZOYztXTH4Q4zeyuFLTJJaT07IG+BCEzTFa3KF5eycR48rIIHabWuPsYP5ZkFkgPHdWNDACUynHyymdDBRoR6a9ClswCxyWUJLd/bFtd9qLPhmxCyrTFi48H6RZhOje12at3ilT3BPOx4AI6axPB7jtDuV3s0nfm6RZJTufUuImXXZhfF4jSrh2ljyS7iRG9Wa8L9GPsrUNmIpzmRRygW/BRJVGeIbRr6gFGVGEqJooobyYwDKrG7pNdXEik/FOjywACKYA08tNBMd8CRz6e IlPLwfz1 fHfonKO0uS80gNMYRR+7FPTq89U8r48Nhx3ftdEuh5AK2fk18KKX4ilKDnj/22PPAghieOQcj9Z8h55KenZjhgnCApqjRiEhmIAU29UvzdipMCFrnuwasdL2DTSgOqEi9yzEJqidqQYtEewnSWJ2KIpXDwE8aC9+Aiy1jsl436Q0ZLqxNNDATZBOGmsLZsHWwQ2nlDezV6fhcrJ0oM0wBE4fVWxhF+xsNJ3Uaaq6OKiBhnPCiCI3SzcQxmdAEVOlhTK6eI98/ojyR/CnfXQ4j1TLDeHxSWRQ1ZgwxxXFJklYrxeH/Q+GRiR9l//Xnd8dAdtiED8FkroPQVTNgrqIkePkSmLWCqZ43dCBUgPHliJoSmMPwW8+6eZroZJzexLZB5GepLMDaGtyu1oz7ur+1TkwSUXGPej/+T+UWw2d5iqmvL7BYisFVykml1xPDhF7DlYd6Nqknp7OMfvUH1fLyfKEh8H62UQPK5ETp/7MiOyMghCs= 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: List-Subscribe: List-Unsubscribe: The way the fallback rules are spread out makes them hard to follow. Move the functions next to each other at least. Signed-off-by: Johannes Weiner --- mm/page_alloc.c | 394 ++++++++++++++++++++++++------------------------ 1 file changed, 197 insertions(+), 197 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 53d315aa69c4..d02edb7d5e21 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1903,6 +1903,43 @@ static void change_pageblock_range(struct page *pageblock_page, } } +static inline bool boost_watermark(struct zone *zone) +{ + unsigned long max_boost; + + if (!watermark_boost_factor) + return false; + /* + * Don't bother in zones that are unlikely to produce results. + * On small machines, including kdump capture kernels running + * in a small area, boosting the watermark can cause an out of + * memory situation immediately. + */ + if ((pageblock_nr_pages * 4) > zone_managed_pages(zone)) + return false; + + max_boost = mult_frac(zone->_watermark[WMARK_HIGH], + watermark_boost_factor, 10000); + + /* + * high watermark may be uninitialised if fragmentation occurs + * very early in boot so do not boost. We do not fall + * through and boost by pageblock_nr_pages as failing + * allocations that early means that reclaim is not going + * to help and it may even be impossible to reclaim the + * boosted watermark resulting in a hang. + */ + if (!max_boost) + return false; + + max_boost = max(pageblock_nr_pages, max_boost); + + zone->watermark_boost = min(zone->watermark_boost + pageblock_nr_pages, + max_boost); + + return true; +} + /* * When we are falling back to another migratetype during allocation, try to * steal extra free pages from the same pageblocks to satisfy further @@ -1944,41 +1981,38 @@ static bool can_steal_fallback(unsigned int order, int start_mt) return false; } -static inline bool boost_watermark(struct zone *zone) +/* + * Check whether there is a suitable fallback freepage with requested order. + * If only_stealable is true, this function returns fallback_mt only if + * we can steal other freepages all together. This would help to reduce + * fragmentation due to mixed migratetype pages in one pageblock. + */ +int find_suitable_fallback(struct free_area *area, unsigned int order, + int migratetype, bool only_stealable, bool *can_steal) { - unsigned long max_boost; + int i; + int fallback_mt; - if (!watermark_boost_factor) - return false; - /* - * Don't bother in zones that are unlikely to produce results. - * On small machines, including kdump capture kernels running - * in a small area, boosting the watermark can cause an out of - * memory situation immediately. - */ - if ((pageblock_nr_pages * 4) > zone_managed_pages(zone)) - return false; + if (area->nr_free == 0) + return -1; - max_boost = mult_frac(zone->_watermark[WMARK_HIGH], - watermark_boost_factor, 10000); + *can_steal = false; + for (i = 0; i < MIGRATE_PCPTYPES - 1 ; i++) { + fallback_mt = fallbacks[migratetype][i]; + if (free_area_empty(area, fallback_mt)) + continue; - /* - * high watermark may be uninitialised if fragmentation occurs - * very early in boot so do not boost. We do not fall - * through and boost by pageblock_nr_pages as failing - * allocations that early means that reclaim is not going - * to help and it may even be impossible to reclaim the - * boosted watermark resulting in a hang. - */ - if (!max_boost) - return false; + if (can_steal_fallback(order, migratetype)) + *can_steal = true; - max_boost = max(pageblock_nr_pages, max_boost); + if (!only_stealable) + return fallback_mt; - zone->watermark_boost = min(zone->watermark_boost + pageblock_nr_pages, - max_boost); + if (*can_steal) + return fallback_mt; + } - return true; + return -1; } /* @@ -2054,175 +2088,6 @@ try_to_steal_block(struct zone *zone, struct page *page, return NULL; } -/* - * Check whether there is a suitable fallback freepage with requested order. - * If only_stealable is true, this function returns fallback_mt only if - * we can steal other freepages all together. This would help to reduce - * fragmentation due to mixed migratetype pages in one pageblock. - */ -int find_suitable_fallback(struct free_area *area, unsigned int order, - int migratetype, bool only_stealable, bool *can_steal) -{ - int i; - int fallback_mt; - - if (area->nr_free == 0) - return -1; - - *can_steal = false; - for (i = 0; i < MIGRATE_PCPTYPES - 1 ; i++) { - fallback_mt = fallbacks[migratetype][i]; - if (free_area_empty(area, fallback_mt)) - continue; - - if (can_steal_fallback(order, migratetype)) - *can_steal = true; - - if (!only_stealable) - return fallback_mt; - - if (*can_steal) - return fallback_mt; - } - - return -1; -} - -/* - * Reserve the pageblock(s) surrounding an allocation request for - * exclusive use of high-order atomic allocations if there are no - * empty page blocks that contain a page with a suitable order - */ -static void reserve_highatomic_pageblock(struct page *page, int order, - struct zone *zone) -{ - int mt; - unsigned long max_managed, flags; - - /* - * The number reserved as: minimum is 1 pageblock, maximum is - * roughly 1% of a zone. But if 1% of a zone falls below a - * pageblock size, then don't reserve any pageblocks. - * Check is race-prone but harmless. - */ - if ((zone_managed_pages(zone) / 100) < pageblock_nr_pages) - return; - max_managed = ALIGN((zone_managed_pages(zone) / 100), pageblock_nr_pages); - if (zone->nr_reserved_highatomic >= max_managed) - return; - - spin_lock_irqsave(&zone->lock, flags); - - /* Recheck the nr_reserved_highatomic limit under the lock */ - if (zone->nr_reserved_highatomic >= max_managed) - goto out_unlock; - - /* Yoink! */ - mt = get_pageblock_migratetype(page); - /* Only reserve normal pageblocks (i.e., they can merge with others) */ - if (!migratetype_is_mergeable(mt)) - goto out_unlock; - - if (order < pageblock_order) { - if (move_freepages_block(zone, page, mt, MIGRATE_HIGHATOMIC) == -1) - goto out_unlock; - zone->nr_reserved_highatomic += pageblock_nr_pages; - } else { - change_pageblock_range(page, order, MIGRATE_HIGHATOMIC); - zone->nr_reserved_highatomic += 1 << order; - } - -out_unlock: - spin_unlock_irqrestore(&zone->lock, flags); -} - -/* - * Used when an allocation is about to fail under memory pressure. This - * potentially hurts the reliability of high-order allocations when under - * intense memory pressure but failed atomic allocations should be easier - * to recover from than an OOM. - * - * If @force is true, try to unreserve pageblocks even though highatomic - * pageblock is exhausted. - */ -static bool unreserve_highatomic_pageblock(const struct alloc_context *ac, - bool force) -{ - struct zonelist *zonelist = ac->zonelist; - unsigned long flags; - struct zoneref *z; - struct zone *zone; - struct page *page; - int order; - int ret; - - for_each_zone_zonelist_nodemask(zone, z, zonelist, ac->highest_zoneidx, - ac->nodemask) { - /* - * Preserve at least one pageblock unless memory pressure - * is really high. - */ - if (!force && zone->nr_reserved_highatomic <= - pageblock_nr_pages) - continue; - - spin_lock_irqsave(&zone->lock, flags); - for (order = 0; order < NR_PAGE_ORDERS; order++) { - struct free_area *area = &(zone->free_area[order]); - unsigned long size; - - page = get_page_from_free_area(area, MIGRATE_HIGHATOMIC); - if (!page) - continue; - - /* - * It should never happen but changes to - * locking could inadvertently allow a per-cpu - * drain to add pages to MIGRATE_HIGHATOMIC - * while unreserving so be safe and watch for - * underflows. - */ - size = max(pageblock_nr_pages, 1UL << order); - size = min(size, zone->nr_reserved_highatomic); - zone->nr_reserved_highatomic -= size; - - /* - * Convert to ac->migratetype and avoid the normal - * pageblock stealing heuristics. Minimally, the caller - * is doing the work and needs the pages. More - * importantly, if the block was always converted to - * MIGRATE_UNMOVABLE or another type then the number - * of pageblocks that cannot be completely freed - * may increase. - */ - if (order < pageblock_order) - ret = move_freepages_block(zone, page, - MIGRATE_HIGHATOMIC, - ac->migratetype); - else { - move_to_free_list(page, zone, order, - MIGRATE_HIGHATOMIC, - ac->migratetype); - change_pageblock_range(page, order, - ac->migratetype); - ret = 1; - } - /* - * Reserving the block(s) already succeeded, - * so this should not fail on zone boundaries. - */ - WARN_ON_ONCE(ret == -1); - if (ret > 0) { - spin_unlock_irqrestore(&zone->lock, flags); - return ret; - } - } - spin_unlock_irqrestore(&zone->lock, flags); - } - - return false; -} - /* * Try finding a free buddy page on the fallback list. * @@ -3143,6 +3008,141 @@ struct page *rmqueue(struct zone *preferred_zone, return page; } +/* + * Reserve the pageblock(s) surrounding an allocation request for + * exclusive use of high-order atomic allocations if there are no + * empty page blocks that contain a page with a suitable order + */ +static void reserve_highatomic_pageblock(struct page *page, int order, + struct zone *zone) +{ + int mt; + unsigned long max_managed, flags; + + /* + * The number reserved as: minimum is 1 pageblock, maximum is + * roughly 1% of a zone. But if 1% of a zone falls below a + * pageblock size, then don't reserve any pageblocks. + * Check is race-prone but harmless. + */ + if ((zone_managed_pages(zone) / 100) < pageblock_nr_pages) + return; + max_managed = ALIGN((zone_managed_pages(zone) / 100), pageblock_nr_pages); + if (zone->nr_reserved_highatomic >= max_managed) + return; + + spin_lock_irqsave(&zone->lock, flags); + + /* Recheck the nr_reserved_highatomic limit under the lock */ + if (zone->nr_reserved_highatomic >= max_managed) + goto out_unlock; + + /* Yoink! */ + mt = get_pageblock_migratetype(page); + /* Only reserve normal pageblocks (i.e., they can merge with others) */ + if (!migratetype_is_mergeable(mt)) + goto out_unlock; + + if (order < pageblock_order) { + if (move_freepages_block(zone, page, mt, MIGRATE_HIGHATOMIC) == -1) + goto out_unlock; + zone->nr_reserved_highatomic += pageblock_nr_pages; + } else { + change_pageblock_range(page, order, MIGRATE_HIGHATOMIC); + zone->nr_reserved_highatomic += 1 << order; + } + +out_unlock: + spin_unlock_irqrestore(&zone->lock, flags); +} + +/* + * Used when an allocation is about to fail under memory pressure. This + * potentially hurts the reliability of high-order allocations when under + * intense memory pressure but failed atomic allocations should be easier + * to recover from than an OOM. + * + * If @force is true, try to unreserve pageblocks even though highatomic + * pageblock is exhausted. + */ +static bool unreserve_highatomic_pageblock(const struct alloc_context *ac, + bool force) +{ + struct zonelist *zonelist = ac->zonelist; + unsigned long flags; + struct zoneref *z; + struct zone *zone; + struct page *page; + int order; + int ret; + + for_each_zone_zonelist_nodemask(zone, z, zonelist, ac->highest_zoneidx, + ac->nodemask) { + /* + * Preserve at least one pageblock unless memory pressure + * is really high. + */ + if (!force && zone->nr_reserved_highatomic <= + pageblock_nr_pages) + continue; + + spin_lock_irqsave(&zone->lock, flags); + for (order = 0; order < NR_PAGE_ORDERS; order++) { + struct free_area *area = &(zone->free_area[order]); + unsigned long size; + + page = get_page_from_free_area(area, MIGRATE_HIGHATOMIC); + if (!page) + continue; + + /* + * It should never happen but changes to + * locking could inadvertently allow a per-cpu + * drain to add pages to MIGRATE_HIGHATOMIC + * while unreserving so be safe and watch for + * underflows. + */ + size = max(pageblock_nr_pages, 1UL << order); + size = min(size, zone->nr_reserved_highatomic); + zone->nr_reserved_highatomic -= size; + + /* + * Convert to ac->migratetype and avoid the normal + * pageblock stealing heuristics. Minimally, the caller + * is doing the work and needs the pages. More + * importantly, if the block was always converted to + * MIGRATE_UNMOVABLE or another type then the number + * of pageblocks that cannot be completely freed + * may increase. + */ + if (order < pageblock_order) + ret = move_freepages_block(zone, page, + MIGRATE_HIGHATOMIC, + ac->migratetype); + else { + move_to_free_list(page, zone, order, + MIGRATE_HIGHATOMIC, + ac->migratetype); + change_pageblock_range(page, order, + ac->migratetype); + ret = 1; + } + /* + * Reserving the block(s) already succeeded, + * so this should not fail on zone boundaries. + */ + WARN_ON_ONCE(ret == -1); + if (ret > 0) { + spin_unlock_irqrestore(&zone->lock, flags); + return ret; + } + } + spin_unlock_irqrestore(&zone->lock, flags); + } + + return false; +} + static inline long __zone_watermark_unusable_free(struct zone *z, unsigned int order, unsigned int alloc_flags) {