From patchwork Tue Feb 25 00:08:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Weiner X-Patchwork-Id: 13989136 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 1B57BC021B8 for ; Tue, 25 Feb 2025 00:10:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A0060280007; Mon, 24 Feb 2025 19:10:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 961ED280002; Mon, 24 Feb 2025 19:10:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7B3EB280007; Mon, 24 Feb 2025 19:10:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 6107E280002 for ; Mon, 24 Feb 2025 19:10:36 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 26512B102A for ; Tue, 25 Feb 2025 00:10:36 +0000 (UTC) X-FDA: 83156535672.21.0E1FB79 Received: from mail-qt1-f177.google.com (mail-qt1-f177.google.com [209.85.160.177]) by imf12.hostedemail.com (Postfix) with ESMTP id 322454000B for ; Tue, 25 Feb 2025 00:10:34 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=ITM8eJrw; spf=pass (imf12.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.160.177 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=1740442234; 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=Jfbz8GKSHpu/xyC6cCph+07KnkaKzui+briDAaa0nnU=; b=ajDnfsw1Hyw+5/U7CIU8Q6DnQtZKAJoplOivdXIJz1lvUkg8WdRfcyL9XMSVGBKNlfMpeP a9O12+a7A8p4c0kh/TyDqDzyONb7NCmQhCoI/YPD4X/Q761WwM6MBh0d7Q7gVZSwMltHDE 3vMp8PtJaG+tv7mV6tLyQ9iFbTLbhNI= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=ITM8eJrw; spf=pass (imf12.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.160.177 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=1740442234; a=rsa-sha256; cv=none; b=35HMgZPMNHokvo5jGbEVfcKHHG7ANt7sskXoGKgN2HEKD/IQnTNvkfzhEgn3cZs9YHtWC2 CfiLMGstE4yu4vRzS5PZUvkshzohKrlV0sYR6qUl4trWqLIBDr0ZaFrEo+FJ0OD29U+hsJ FMyZcF+TP8ZRnaGQxI+oBU5C2gjA8zY= Received: by mail-qt1-f177.google.com with SMTP id d75a77b69052e-471f2e1bea9so48062941cf.2 for ; Mon, 24 Feb 2025 16:10:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20230601.gappssmtp.com; s=20230601; t=1740442233; x=1741047033; 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=Jfbz8GKSHpu/xyC6cCph+07KnkaKzui+briDAaa0nnU=; b=ITM8eJrwtbXb8ZuFfBiQF+9jD44liQf9mUgBvW/B3i3kY72OirW6GHDMJ/NSroaH7a q6gfXBc5mnD4T1+ArxTNrX4p/V1v2wS5NeCkt0sEoGNiditBy00GQGFlNMAri7Wq4+SQ usH7brIRy5lkSeB4Vu4N/DL05r9zIJwn/XWjdQx3PZiIhKwsjAWyRXgdI+20DJis6VBV GZNPp2yIKL6sGkCOxrdlD5Mm9JnmXN+LrSZMXm538Qo2IgveCFtJnmiy1cTFdytJSu+p MJYB9s5p79ZZ2avD+Siv/K/sSvcs/FwkCtojHAMpttXkXFm5di5P6pm3ZiYJDZFBqRVw pkoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740442233; x=1741047033; 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=Jfbz8GKSHpu/xyC6cCph+07KnkaKzui+briDAaa0nnU=; b=pDi3eow7ma/8yxFYeiSXt/dUkAXsH8WQKaAFsMXsKQRgoxlfblDtLFn+wu1/V3b4sH Yf7Fmmme3fnyjfgV4ABPkE4Bq3hhr2ZY8U4pgUQf5I3u0kTkjU1Ngv4v6rgjj9Ge9YNX UmnRxVdb2Z/ukso7uUzcI/vQ4eHdwTR3g/9kacSHnCOtbmWieh4WsIncOVhYPcibZfTF CpUG5G4XhFKyQl5V6XTozqOWokbjDyMFYlbK6z0sBwLoJalsYHbu1e2VEu7WVbLTw8JR zJo99r0uk3xETcv3ti6qb7Be/liUHFYDiYMpsaaCKASgNkKfkwXT2DqXlSRmn5WqGOQE 5f1Q== X-Forwarded-Encrypted: i=1; AJvYcCUtpdM68EKiTc8+n39BqvVIji5uQK+xF20PTTSyH1yoIRqTDNcs2Wont52wSTRlyIpbVIS5Qe0hOw==@kvack.org X-Gm-Message-State: AOJu0YzxjaKLa7mqASkdvhkyLRdJOXkdyJCxVCY6MvxeE+FKqyvV2Fbr r+AmjvR9+/doa3bdpx2bZu+7mO001eoIddXZjb20F3esYiVB6b0X1IM1qYFueaQ= X-Gm-Gg: ASbGncuXSPA0mzEebpvwJXLKgKwn7BRxkB8RkgeX4jfnsVz27+aTOapuW6I5dNuk3fc pDVW8NQ3AgSgK5+GE8PhEl+QZZy4uKOqUmHbDbqdgfRlunOqVj1n/lvWaQ/gLn4OOac3A8n8Oux E4Ux1s5Yk90UlGSbmV57UANVZ+ttWFEfBy1F9cSb8zwZoAHTdzBzZg1wG7V3hr1AUcZ86GTYI3a Z1QXugYZc6i8LQSWbdFWMEXm+SBnqvi2aFN3B7INe2GxwaR3ubQAY9sDoVWzmU62IUMZcb7UxBC Sc5BGG8ftuW8nYwqSL94Bx8i X-Google-Smtp-Source: AGHT+IGM3VVUjbDeCXvrKFFPK7jbq7t2UH3GiR9glB2p9o0jhpvV1lYU60G0oFU/Ke/PG5Pti/cUBg== X-Received: by 2002:a05:6214:1bcb:b0:6e6:5a8a:aba with SMTP id 6a1803df08f44-6e6ae829f34mr221625886d6.21.1740442232965; Mon, 24 Feb 2025 16:10:32 -0800 (PST) Received: from localhost ([2603:7000:c01:2716:da5e:d3ff:fee7:26e7]) by smtp.gmail.com with UTF8SMTPSA id 6a1803df08f44-6e87b1564easm3076106d6.72.2025.02.24.16.10.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Feb 2025 16:10:32 -0800 (PST) From: Johannes Weiner To: Andrew Morton Cc: Vlastimil Babka , Brendan Jackman , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] mm: page_alloc: don't steal single pages from biggest buddy Date: Mon, 24 Feb 2025 19:08:24 -0500 Message-ID: <20250225001023.1494422-2-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-Stat-Signature: 9ga9tx9jaeig45q73c7pg64uhhru1s8h X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 322454000B X-HE-Tag: 1740442234-456985 X-HE-Meta: U2FsdGVkX18yZGZIZ6P3UhKON4ICP4dD+uQYJnUIJZ0Sq9CueotK5MIg7OlKiy0v5GJZiV4Z+HHB83aG+ukf9blpmvvYBlD5h+HhYiy/CB6asuwaqhcmZQzXEzxo28rKr5QzZo4knADms44m+m1opar6S7MwNyeKeF4C/5s0VqJGTq07hUKCaAfLf/86mu6q7AqoDKMuwzIbEY/O8czMMwgs6YiRleDbD2tp8lvUzJo6bHEafW9108WPuxqQYrn3wa86ELaevG0Op0vJruREB9l4ziFGTuv/YUJ7T9sXJM4OsOCINA6zdhTENKlk1OX0pXaVm7dTTXvK6DynzWMloVCzk8S107tSHf+f7or7ILRN6HnjF5NPXGDU0cPIKcKwA+t1cdhafjpvblEYTdoGd4mGsIAhN9hZmLTtxvrJYuek7GNT0K/L1aZbWAbu+fmfSpD2kMbEAqyR32H/in/ynHKZdQ8vRmndcfUvvjZgsj3lXpsIrhpT0ol2gIIWLkrdVaUtbSlB4n4uoXW0R0sWYxjRfBFG1Ysi63lUcEqYwMVad7dv/wvR2HV6a21yUxKk+eOqfpGVCv/P0pcGcBYndWcdE+bNnYTO7NMFnwguXuTfow4hQFzLxONPm5uJEWD9MG3XzZmqn/v+/mTDGZjVD1zCKBWuCg/8FXHcwf0pSC8Tklbo0hecFUqnaTZ/Kf3VrGfFZWAiMQPu3bBpzYQQGNIbRkV4WFDffoa3X+txjaFeY+gcgPrhQjjwCAPiJxDOyxnU2q4M7ElbAPLDXdTDcV1czLsZEP85jiVfrd9vK3ldyhGJxcs996YRp4mytFJNtE4k3Q8qfujNBp44PUC1Qo1VDWtTQLsNP6y/PKS7Ch1QHlh8l9nmqvYatn2cpUwfZVXUNpniNcYNaMstgTZ5Au0x35TkfngDeQRllDsijz1CDs6HNlOCOBUKq8D69sRedak/mLMXc1eWHuVAG3V 2Mw9mvSn 7Av7P2MZqRoEF0ESRVMvYcY96ksToo02DKh+DwTF9jc7gXA1ViXhy0MlVLFOsM9QODUOxIJsD7oM54e0niQXh/z8TTeOnSnAy7i3otL+V/PTHB8owS7XwY+qKD8ldSLIUynhqsX2VTtjx9cOHHR8gb4IzPDROx/ivfhDbRXglRXQKprDLv+sa48kmcDcisHVRuVJMFhG/mDzR5yjI3v9zjo8YP8Fp9o6Ic4ekzhgFZhCAdpX/k1s1Zas2y3a0k6cofK6m+3XpIfPbJUsLb3WnpszctzN6tpIV1mZegUorZWCdzV0WsxKEQ/nvsxyh0XwjzmKC2B7Y3h9JfoLQ7UtEx3qiw6Z0/De8X7bx43ib/mJAcnjvII+YsNOxluLMdCbWeb9QNeKK0+bwppFqn/CTHLCK+nAoNvwxTwq7PSU1U9WSQ3r4zWjamaqdEzdUuH+QRPZ94aIlPR9JVGmiL74Powb5u0YYeU2y2V+Pw5YpqnmuP94= 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 fallback code searches for the biggest buddy first in an attempt to steal the whole block and encourage type grouping down the line. The approach used to be this: - Non-movable requests will split the largest buddy and steal the remainder. This splits up contiguity, but it allows subsequent requests of this type to fall back into adjacent space. - Movable requests go and look for the smallest buddy instead. The thinking is that movable requests can be compacted, so grouping is less important than retaining contiguity. c0cd6f557b90 ("mm: page_alloc: fix freelist movement during block conversion") enforces freelist type hygiene, which restricts stealing to either claiming the whole block or just taking the requested chunk; no additional pages or buddy remainders can be stolen any more. The patch mishandled when to switch to finding the smallest buddy in that new reality. As a result, it may steal the exact request size, but from the biggest buddy. This causes fracturing for no good reason. Fix this by committing to the new behavior: either steal the whole block, or fall back to the smallest buddy. Remove single-page stealing from steal_suitable_fallback(). Rename it to try_to_steal_block() to make the intentions clear. If this fails, always fall back to the smallest buddy. The following is from 4 runs of mmtest's thpchallenge. "Pollute" is single page fallback, "steal" is conversion of a partially used block. The numbers for free block conversions (omitted) are comparable. vanilla patched @pollute[unmovable from reclaimable]: 27 106 @pollute[unmovable from movable]: 82 46 @pollute[reclaimable from unmovable]: 256 83 @pollute[reclaimable from movable]: 46 8 @pollute[movable from unmovable]: 4841 868 @pollute[movable from reclaimable]: 5278 12568 @steal[unmovable from reclaimable]: 11 12 @steal[unmovable from movable]: 113 49 @steal[reclaimable from unmovable]: 19 34 @steal[reclaimable from movable]: 47 21 @steal[movable from unmovable]: 250 183 @steal[movable from reclaimable]: 81 93 The allocator appears to do a better job at keeping stealing and polluting to the first fallback preference. As a result, the numbers for "from movable" - the least preferred fallback option, and most detrimental to compactability - are down across the board. Fixes: c0cd6f557b90 ("mm: page_alloc: fix freelist movement during block conversion") Suggested-by: Vlastimil Babka Signed-off-by: Johannes Weiner --- mm/page_alloc.c | 80 +++++++++++++++++++++---------------------------- 1 file changed, 34 insertions(+), 46 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 16dfcf7ade74..9ea14ec52449 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1986,13 +1986,12 @@ static inline bool boost_watermark(struct zone *zone) * can claim the whole pageblock for the requested migratetype. If not, we check * the pageblock for constituent pages; if at least half of the pages are free * or compatible, we can still claim the whole block, so pages freed in the - * future will be put on the correct free list. Otherwise, we isolate exactly - * the order we need from the fallback block and leave its migratetype alone. + * future will be put on the correct free list. */ static struct page * -steal_suitable_fallback(struct zone *zone, struct page *page, - int current_order, int order, int start_type, - unsigned int alloc_flags, bool whole_block) +try_to_steal_block(struct zone *zone, struct page *page, + int current_order, int order, int start_type, + unsigned int alloc_flags) { int free_pages, movable_pages, alike_pages; unsigned long start_pfn; @@ -2005,7 +2004,7 @@ steal_suitable_fallback(struct zone *zone, struct page *page, * highatomic accounting. */ if (is_migrate_highatomic(block_type)) - goto single_page; + return NULL; /* Take ownership for orders >= pageblock_order */ if (current_order >= pageblock_order) { @@ -2026,14 +2025,10 @@ steal_suitable_fallback(struct zone *zone, struct page *page, if (boost_watermark(zone) && (alloc_flags & ALLOC_KSWAPD)) set_bit(ZONE_BOOSTED_WATERMARK, &zone->flags); - /* We are not allowed to try stealing from the whole block */ - if (!whole_block) - goto single_page; - /* moving whole block can fail due to zone boundary conditions */ if (!prep_move_freepages_block(zone, page, &start_pfn, &free_pages, &movable_pages)) - goto single_page; + return NULL; /* * Determine how many pages are compatible with our allocation. @@ -2066,9 +2061,7 @@ steal_suitable_fallback(struct zone *zone, struct page *page, return __rmqueue_smallest(zone, order, start_type); } -single_page: - page_del_and_expand(zone, page, order, current_order, block_type); - return page; + return NULL; } /* @@ -2250,14 +2243,19 @@ static bool unreserve_highatomic_pageblock(const struct alloc_context *ac, } /* - * Try finding a free buddy page on the fallback list and put it on the free - * list of requested migratetype, possibly along with other pages from the same - * block, depending on fragmentation avoidance heuristics. Returns true if - * fallback was found so that __rmqueue_smallest() can grab it. + * Try finding a free buddy page on the fallback list. + * + * This will attempt to steal a whole pageblock for the requested type + * to ensure grouping of such requests in the future. + * + * If a whole block cannot be stolen, regress to __rmqueue_smallest() + * logic to at least break up as little contiguity as possible. * * The use of signed ints for order and current_order is a deliberate * deviation from the rest of this file, to make the for loop * condition simpler. + * + * Return the stolen page, or NULL if none can be found. */ static __always_inline struct page * __rmqueue_fallback(struct zone *zone, int order, int start_migratetype, @@ -2291,45 +2289,35 @@ __rmqueue_fallback(struct zone *zone, int order, int start_migratetype, if (fallback_mt == -1) continue; - /* - * We cannot steal all free pages from the pageblock and the - * requested migratetype is movable. In that case it's better to - * steal and split the smallest available page instead of the - * largest available page, because even if the next movable - * allocation falls back into a different pageblock than this - * one, it won't cause permanent fragmentation. - */ - if (!can_steal && start_migratetype == MIGRATE_MOVABLE - && current_order > order) - goto find_smallest; + if (!can_steal) + break; - goto do_steal; + page = get_page_from_free_area(area, fallback_mt); + page = try_to_steal_block(zone, page, current_order, order, + start_migratetype, alloc_flags); + if (page) + goto got_one; } - return NULL; + if (alloc_flags & ALLOC_NOFRAGMENT) + return NULL; -find_smallest: + /* No luck stealing blocks. Find the smallest fallback page */ for (current_order = order; current_order < NR_PAGE_ORDERS; current_order++) { area = &(zone->free_area[current_order]); fallback_mt = find_suitable_fallback(area, current_order, start_migratetype, false, &can_steal); - if (fallback_mt != -1) - break; - } - - /* - * This should not happen - we already found a suitable fallback - * when looking for the largest page. - */ - VM_BUG_ON(current_order > MAX_PAGE_ORDER); + if (fallback_mt == -1) + continue; -do_steal: - page = get_page_from_free_area(area, fallback_mt); + page = get_page_from_free_area(area, fallback_mt); + page_del_and_expand(zone, page, order, current_order, fallback_mt); + goto got_one; + } - /* take off list, maybe claim block, expand remainder */ - page = steal_suitable_fallback(zone, page, current_order, order, - start_migratetype, alloc_flags, can_steal); + return NULL; +got_one: trace_mm_page_alloc_extfrag(page, order, current_order, start_migratetype, fallback_mt); From patchwork Tue Feb 25 00:08:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Weiner X-Patchwork-Id: 13989137 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 77B11C021A4 for ; Tue, 25 Feb 2025 00:10:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8A171280008; Mon, 24 Feb 2025 19:10:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8303D280002; Mon, 24 Feb 2025 19:10:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 655B4280008; Mon, 24 Feb 2025 19:10:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 44D59280002 for ; Mon, 24 Feb 2025 19:10:38 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id EC7D3160348 for ; Tue, 25 Feb 2025 00:10:37 +0000 (UTC) X-FDA: 83156535714.21.EC1ABC2 Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) by imf16.hostedemail.com (Postfix) with ESMTP id 0C0BB180002 for ; Tue, 25 Feb 2025 00:10:35 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=I5Jxnxy3; spf=pass (imf16.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.222.181 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=1740442236; 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=m4nVpOQMfdjSDVLItpR5dEn5Uy7LgPPGmplcVb1mIdw=; b=7GMVvPWI65u8/HizcYcPanyDKZ+zcY/YJ8B0eE16rBY66DwwFsjjnHJcb2LlJZxjyj7ue8 JQrcFSv19bYY1v6IXUOLVawIsDAGGuUWLre7Zob3ONXxkqyQCi9mTxi0jG/4TJFzdNccnI tQS6PhHXX1QesdJUOrNngqL1qA3PXmM= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=I5Jxnxy3; spf=pass (imf16.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.222.181 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=1740442236; a=rsa-sha256; cv=none; b=q9ernRsTpoJLKaazZK83JnB3P+X8M9vHW+sHb1RN1dFKiNYqjEfs1dc3nOKh+F2nExcY+L GxHx5KuzZCye5YNMPudTnzs7nqVSq9SuzVSHF8y7sJAM4yYEmbdc8ilRjCAxnhpBXoljar o08CtUHSDuG5pVsAzX/zHcPYGf3uZ8s= Received: by mail-qk1-f181.google.com with SMTP id af79cd13be357-7c0a5aa0f84so438015285a.1 for ; Mon, 24 Feb 2025 16:10:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20230601.gappssmtp.com; s=20230601; t=1740442235; x=1741047035; 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=m4nVpOQMfdjSDVLItpR5dEn5Uy7LgPPGmplcVb1mIdw=; b=I5Jxnxy3AHrKsE3fqH60O0xFpLUN4xPoPKICVk+o1em9TMov3WHQevI4cGk7v9VKU9 8QEUkoaILoz2+Cg2OdVGViTjoXkevf1iA4qWXnutwLfrvXaeIcB+Ml2nVpcd5CHjsk+a tYo8in9rnyxaO3mTlG7SJXJft50g8NvnrahuMtiORM45kWz34cJg44tCD6hl1evxlueQ yi3KQO/Pug6RYtB/v+j82sHTH0Wd4fG2uOFvKV4KHk/XWV57RHV1qnCjISWQ22lw9DDv FT+ODO2CT0aL2fu3pMaAA5ruv643a6P5tzQITMsAhrvBu8gxavHIwwROfyFJ7M851Q+a 2djw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740442235; x=1741047035; 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=m4nVpOQMfdjSDVLItpR5dEn5Uy7LgPPGmplcVb1mIdw=; b=Cmg5IFA1wlyFcfTVe3kbWufk4pzxtqyL1/NJTv800tuZBwqOia0+KcmU4GWmB0hZCd 6PYfLAWlGD70FGfC9k8RYjDftvzWKulxBzb04utLmBaxRslnG4O63eGvbB1mA72MdKYz g3gMNYaElej+Aq/rQrYA5cgG49McYFHti4tHdDNtUaFXEtJF2ZLPrhMmWrn42meutpEZ aQNHiQ10Fc2dtKaMsQiayw9k7FyP0OYAOtm49PmcfHFK2ykTbqed3ZR93C9GLlgxQcBH HNr14TP3BxNy0Ty7aqJ6zc8uElLOL01Kvm0f/GuXxc8e7SNNlgAR8BVcKurtnumE7kjH P1pA== X-Forwarded-Encrypted: i=1; AJvYcCXrmuI27Tnivjvzi57XD+VXpZoTNXVJfBc9p8PnqK7qsqAQSTJ7IsRe/Mxgcxk+RdJausrVLZ/iDQ==@kvack.org X-Gm-Message-State: AOJu0YxF2bdqDAe2+r29AHq+pV0RmScqYn15o//VaItJEwoRiw2iVxle THamPFtCbbEH0kZb+/z8v8dLgoN4YazzWWYimiNHjZlRv1QtuCJ44jMxubc0Q0M= X-Gm-Gg: ASbGncvJU6S3qqxqvCNnULuBXs2SCcFek77QpTbGh9qLB3Q4w3YFeanKP0EKhuTgJHG NA6AIb68PH7lwaEZ3urGPz8eQoYed80hniqmxykgQkLep8BeX8d8E+akCtjebucOOdDyeYtJFNz i4OWvU9Q8qvruMUsjNAYvYcIiahX0UkGRNW6jeQh0a7ET7lDtb/+EORBLPmhDhCOJLw1NU9Q+zE ASPj2333wmZOGPcwjpDMfvv2Z2cIW/gIXgASWONEsJi0zvrGFHw3b6oAEgbkBs5yZsAb3Z6fHFn y2qDRCp4pPWEHhPYULeu88Hu X-Google-Smtp-Source: AGHT+IGoJS6Omh/ikKjODCsa7sYHe0e2NcEJ5qqBqC2I0BPARGB9vb4PzMba6XBAw4fGsuwISK59Ag== X-Received: by 2002:a05:620a:4621:b0:7be:73f6:9e86 with SMTP id af79cd13be357-7c0c227c72dmr2463429485a.20.1740442235091; Mon, 24 Feb 2025 16:10:35 -0800 (PST) Received: from localhost ([2603:7000:c01:2716:da5e:d3ff:fee7:26e7]) by smtp.gmail.com with UTF8SMTPSA id 6a1803df08f44-6e87b06dd05sm3185086d6.8.2025.02.24.16.10.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Feb 2025 16:10:34 -0800 (PST) From: Johannes Weiner To: Andrew Morton Cc: Vlastimil Babka , Brendan Jackman , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] mm: page_alloc: remove remnants of unlocked migratetype updates Date: Mon, 24 Feb 2025 19:08:25 -0500 Message-ID: <20250225001023.1494422-3-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-Stat-Signature: r5aszfdubjguf4kfr35y46diuyphe8w3 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 0C0BB180002 X-HE-Tag: 1740442235-314924 X-HE-Meta: U2FsdGVkX19rEUaIa28/NpgYJVJkPVsrVBHf5+hEShCbXwuRgARwg42csqWI9korIa02p21BXNuO+QCsJYN4XB0VWY7hEc732rRYqcoOTTEOe6D+6WZTrk70r199baWt46N7W1PWznCEd4TbnCKTBnfsilX4Y/fYnL/MAPYcNi1l3WWRNHYLnnxNqmhjLpby38qfxhLUHbun+QqtXjmG2/2YNlhrLVXssVuTnPm9oL54kOU4+EaWRqrdACfy7Qqga9Oe1WoJV13747h8dwNhPI89aVzODxCbTX7LMCbCvHE7g07NO7yhEMUnxeBQNLdFP2LLYrBM1sYEBISoerCubsXsxmHF4LqJMRATJSWAMmq/8LN0wmqvB7UWSkKN2YXTX0W+PVN96rrdYcroBfDrkVgMJsBMf+i5uy9TYCtkqdcm5+scENxaJmvKJwGkUU/UC9jaHfW3tHg0bTCC8c/Bk4aIiMLV7JQwQEFj/itRQiS/7Tu0v+daCzwlsVucxqMBXWBZbK+3/x7FBRNbuJRLDuLGu27Au93w+KixU4i4yBpxk3gi6beT2uogVcezAJ4Q5Yj7xBb094l+fRFqjrmNbre31noy82oie6H/WSKEk//xNmGuB/L8uEY2fMiAAuzxecxK4HnrFe0YfjyzQ1teZE2q/TQ79SlXDQDlZfvZF36vmlv0/HLMZqx2xSWM/YeqJUse30is5N67Z+i2TIXkQj4cjKZZt6YruN6wVDh4T7ITlaYpUWVVtV9tzoTZxTi0fEr+LYL28GfmJlRXOpyPoPDQCqvGBTCGnwqp7ccyEgw+Br345tyiWj+iOjZj3zFyLqEVuQPwXCCR9Bnxfg0KriOzAiIVD6G3tcXUGtioG26lRDiEAzmOwkFFOriifD7Lpj6f6vGttVVZBbsbunAvKl4doEFYT7s7eG437vaVRQeQs63shgG91oOFlsGcTfBE1FCn1mg+VmoP20jG7iI /Gm0kM4S vbTZNY+uxCkEQK6Fxo9wudStHzmyGMen3AE/vYhrGXRLnX+jAgW8G+NHLnyhtvvZ5dq/l8hFvIaM7T32BJrg2h+Em5W1zCbUoFQUtJv/KIlNONnThXdS2PGk9/1J5zYdsXrQkiZ96eyZAE+D19eXxyAYP1bVh+cOrd85E2Xqj3UYMaqCcSRG0G5wJheSKIGWiBVMvD7uK6z3Op4080xPPRwq0B77HjAviCvGUvbdeJbDnO2Y6dTQ+Ts/4AoZh8ueHm+Ryb9WZY0nK8OH//QVCEJwM2b+gShnDrsNjnkOcxtBztAzAPgcYtX0SmnqR263P7147bwGWE6GY64VLdTN8nMfbdnXA/EM93PkS7k9QXCqdaJZ7+EpOnNsu0FtYf10EG5bkbwH4UNCQIpHk6IEDbgDjg1XcnuZ3Hnr2ieItGnaN6ljbNgKQWa7JxSyO+l5w0d20p2YCgGruH0qAhraSSeAtQ7EME+2qdScSKceLJAjGhso= 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 freelist hygiene patches made migratetype accesses fully protected under the zone->lock. Remove remnants of handling the race conditions that existed before from the MIGRATE_HIGHATOMIC code. Signed-off-by: Johannes Weiner --- mm/page_alloc.c | 50 ++++++++++++++++--------------------------------- 1 file changed, 16 insertions(+), 34 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 9ea14ec52449..53d315aa69c4 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1991,20 +1991,10 @@ static inline bool boost_watermark(struct zone *zone) static struct page * try_to_steal_block(struct zone *zone, struct page *page, int current_order, int order, int start_type, - unsigned int alloc_flags) + int block_type, unsigned int alloc_flags) { int free_pages, movable_pages, alike_pages; unsigned long start_pfn; - int block_type; - - block_type = get_pageblock_migratetype(page); - - /* - * This can happen due to races and we want to prevent broken - * highatomic accounting. - */ - if (is_migrate_highatomic(block_type)) - return NULL; /* Take ownership for orders >= pageblock_order */ if (current_order >= pageblock_order) { @@ -2179,33 +2169,22 @@ static bool unreserve_highatomic_pageblock(const struct alloc_context *ac, spin_lock_irqsave(&zone->lock, flags); for (order = 0; order < NR_PAGE_ORDERS; order++) { struct free_area *area = &(zone->free_area[order]); - int mt; + unsigned long size; page = get_page_from_free_area(area, MIGRATE_HIGHATOMIC); if (!page) continue; - mt = get_pageblock_migratetype(page); /* - * In page freeing path, migratetype change is racy so - * we can counter several free pages in a pageblock - * in this loop although we changed the pageblock type - * from highatomic to ac->migratetype. So we should - * adjust the count once. + * 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. */ - if (is_migrate_highatomic(mt)) { - unsigned long size; - /* - * 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; - } + 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 @@ -2217,10 +2196,12 @@ static bool unreserve_highatomic_pageblock(const struct alloc_context *ac, * may increase. */ if (order < pageblock_order) - ret = move_freepages_block(zone, page, mt, + ret = move_freepages_block(zone, page, + MIGRATE_HIGHATOMIC, ac->migratetype); else { - move_to_free_list(page, zone, order, mt, + move_to_free_list(page, zone, order, + MIGRATE_HIGHATOMIC, ac->migratetype); change_pageblock_range(page, order, ac->migratetype); @@ -2294,7 +2275,8 @@ __rmqueue_fallback(struct zone *zone, int order, int start_migratetype, page = get_page_from_free_area(area, fallback_mt); page = try_to_steal_block(zone, page, current_order, order, - start_migratetype, alloc_flags); + start_migratetype, fallback_mt, + alloc_flags); if (page) goto got_one; } 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) {