From mboxrd@z Thu Jan 1 00:00:00 1970 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 AA13EC021BB for ; Tue, 25 Feb 2025 14:35:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F25CC6B0082; Tue, 25 Feb 2025 09:35:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id ED53E6B0085; Tue, 25 Feb 2025 09:35:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D4E6B6B0088; Tue, 25 Feb 2025 09:35:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id BA0326B0082 for ; Tue, 25 Feb 2025 09:35:30 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 6E51112154F for ; Tue, 25 Feb 2025 14:35:30 +0000 (UTC) X-FDA: 83158715220.20.8616565 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf19.hostedemail.com (Postfix) with ESMTP id BD0C31A001C for ; Tue, 25 Feb 2025 14:35:27 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=tc+0kEdC; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=E64UIUET; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=tc+0kEdC; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=E64UIUET; spf=pass (imf19.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1740494128; a=rsa-sha256; cv=none; b=MNZelsLanL4csagbRkYDS2hfEE7A9utMMO9f0nzvzKVqjcCGJ5wkravgYTAsF0FiEh9PbB tnlZ99sMeunwjAY5U7bWwxX6uhYBNyD4ntGQ/1SM3rGtt9cIoAqnPve2NHGsla1sVL9uPR 5B0zLZ+J/nRRvJH4Gx+PVYT4AXv1Zh0= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=tc+0kEdC; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=E64UIUET; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=tc+0kEdC; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=E64UIUET; spf=pass (imf19.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1740494128; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=g948sWdBhGFc6lvbZcYWo/e847khBaVEBSceIS7zpcQ=; b=p8K+7W/gN5j70zv0/6Iw2n4hn/buHdBqdoon/7DZgoe1n8rGwR81yuBPmk12AEkgpX9lja fLVkdtBRehAKmwemh7BSWWo4HGoecrI8BkWQbwaSAOUzNwfYUUAy+yVEHpAyPw1jHEICNw YbCotTvcq2iSAGJg2LLm6i9odAZUols= Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 2928F21170; Tue, 25 Feb 2025 14:35:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1740494126; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=g948sWdBhGFc6lvbZcYWo/e847khBaVEBSceIS7zpcQ=; b=tc+0kEdCVtJyqPi2vjzQS4r94khL14ziHyHDLwf/lXvu9/1xSQyHmIhUJT1MbRBlqIqBDf ntkr3jOuJR6jGed9g9J38MOBfIE3aMGFEYoSLE83SSBeOMUMqMgKZAB3QP/FdYS1O2x/XD Hc47hi3O8rTk80GlyGa1IBpQ+VJGWEI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1740494126; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=g948sWdBhGFc6lvbZcYWo/e847khBaVEBSceIS7zpcQ=; b=E64UIUETgpZ5QMJkD5gnn29EwRrcoJiRyQGnvWGHM+AQZcr2H9DHTlXOhR4BjpnFBTttGB AJ/0aM+OpEte9SBA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1740494126; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=g948sWdBhGFc6lvbZcYWo/e847khBaVEBSceIS7zpcQ=; b=tc+0kEdCVtJyqPi2vjzQS4r94khL14ziHyHDLwf/lXvu9/1xSQyHmIhUJT1MbRBlqIqBDf ntkr3jOuJR6jGed9g9J38MOBfIE3aMGFEYoSLE83SSBeOMUMqMgKZAB3QP/FdYS1O2x/XD Hc47hi3O8rTk80GlyGa1IBpQ+VJGWEI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1740494126; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=g948sWdBhGFc6lvbZcYWo/e847khBaVEBSceIS7zpcQ=; b=E64UIUETgpZ5QMJkD5gnn29EwRrcoJiRyQGnvWGHM+AQZcr2H9DHTlXOhR4BjpnFBTttGB AJ/0aM+OpEte9SBA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 1A50213888; Tue, 25 Feb 2025 14:35:26 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id WSb7BS7VvWdTFgAAD6G6ig (envelope-from ); Tue, 25 Feb 2025 14:35:26 +0000 Message-ID: Date: Tue, 25 Feb 2025 15:35:25 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/3] mm: page_alloc: don't steal single pages from biggest buddy Content-Language: en-US To: Brendan Jackman , Johannes Weiner Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20250225001023.1494422-1-hannes@cmpxchg.org> <20250225001023.1494422-2-hannes@cmpxchg.org> From: Vlastimil Babka Autocrypt: addr=vbabka@suse.cz; keydata= xsFNBFZdmxYBEADsw/SiUSjB0dM+vSh95UkgcHjzEVBlby/Fg+g42O7LAEkCYXi/vvq31JTB KxRWDHX0R2tgpFDXHnzZcQywawu8eSq0LxzxFNYMvtB7sV1pxYwej2qx9B75qW2plBs+7+YB 87tMFA+u+L4Z5xAzIimfLD5EKC56kJ1Cs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p/pSel0jnvBX8L2cmniYnmI883NhtGZsEWj++wyKiS4NranDFlA HdDM3b4lUth1pTtABKQ1YuTvehj7EfoWD3bv9kuGZGPrAeFNiHPdOT7DaXKeHpW9homgtBxj 8aX/UkSvEGJKUEbFL9cVa5tzyialGkSiZJNkWgeHe+jEcfRT6pJZOJidSCdzvJpbdJmm+eED w9XOLH1IIWh7RURU7G1iOfEfmImFeC3cbbS73LQEFGe1urxvIH5K/7vX+FkNcr9ujwWuPE9b 1C2o4i/yZPLXIVy387EjA6GZMqvQUFuSTs/GeBcv0NjIQi8867H3uLjz+mQy63fAitsDwLmR EP+ylKVEKb0Q2A== In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: BD0C31A001C X-Stat-Signature: gzwtu7d4zmpjdieaspz11i6f9gsocthd X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1740494127-461741 X-HE-Meta: U2FsdGVkX19NZvV82kNk5Ek6LOO1CN1P14IzneXExE4Y3Wq/Z7gDlfy8a3qCNZDGBO7JJPQPE8MYMdqJw866dUNT/fzVQ430M2bGHXwPZX0M5spXTueMQX5JqrNjv1VJ+6zV1aabE6fGPfhg9ZUWi9Y09d5Asr2qs7Z+EvzHjjuIFLgEiGiWN5ewaCFlf04e8hiVsnRngCjvOSWAHcYb7R0He3Ju1iYVv6J0wVSY4he19kzAfA+aATYiHDH65xoNF3CQfebdoD64RKiBXNK6fZJ9xN6QsjonyvzpGOIVORZChrkwg9nsuKB7gTXlFRbYNcfO9SaMBCGnXeYFoJ4rvfPjTlxs69v9VVK4ZOWTht9kumnCvF4Z6TEnBAyX2aEK/9QNBsdKpBxZH3D3hUMcPUQ6SwqxbVgXg82emeZC9muHdEdstcSExunNxRv4KXiY70TCA5JlpsQRmc7PvQgukbxC2GWMZE6Vfsfbt1E2o1JlZ/8ja4PRPtDaNUBrZB7cKNbPWD/q1Po1pu1/EgSwYcXECfl2ZoiLTvWE989I+7OVQkIn9HTXi4+LiQqgYRPuHH7y3D6cZRTlureLBOXlDQC9NHv/pQNO63zKxd+OUnFYzkxmtywbw1JmP/jgGKpxjMALanTsLG7xsvvonCotF5VlJ3Kh+qu5t4ikd+UX/9Af/UGgdKBS0OPt9E1sxir+fKTxfyNLAHIuI5gGHR5nZsGhqL3tLwIPBPBcmDpjSH5jCG1Y0WNDczZMpPanH2xIzkIpLZ6YZZOohBS+A10p9virQWd5YtWlEwSIz7thsphmDEXrbPbAWyICuErNy4NORfNMa/ze1RixFilN0OUFyisRdgHyQYbbgHU8i6I8qDYLQyBqA12h2vO69b85MEOntqcxuLMhuMscHFA4p/c9ZF9UTPoaRYlQmpN7XKn146sU7OJSry8gRkH+L742rB45nwoAJjHNwh87nCrKjEh 2yesop71 unFab/tTLISFtlyMHqVTLLiKcWCEbAp9n+Jv9PkT99cBSPMpYiLHIphom0Zce/BwdetERjUrPJJY7zh9EIdmZSuFUSN+3oNJQtQSILAzFI7zZIs92asSEaVXFNuvAd4o5K4GI58SONO7IUDeVRFz+kBv3pN4QSbLXXDpCZoqNNPJAaJ9rjtseJss84nPh32Usqxzfni/gayT4LzOdVjmziI7r+xh9If2KsAXwamsA4PGop5UP4p0x5H6aTTJw//2IfKoJsj5w/b4O8EkPCxOwdIU0Mr4OOBXceiUcbUjU6PAPri1cF5xPyoLQi0XKI1aI2N4j0hsJCtq2060= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000047, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On 2/25/25 14:34, Brendan Jackman wrote: > On Mon, Feb 23, 2025 at 07:08:24PM -0500, Johannes Weiner wrote: >> 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. > > Nit - I think the try_to_steal_block() changes could be a separate > patch, the history might be easier to understand if it went: > > [1/N] mm: page_alloc: don't steal single pages from biggest buddy > [2/N] mm: page_alloc: drop unused logic in steal_suitable_fallback() > > (But not a big deal, it's not that hard to follow as-is). > >> 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; > > Is this a separate change? Is it a bug that we currently allow > stealing a from a fallback type when ALLOC_NOFRAGMENT? (I wonder if > the second loop was supposed to start from min_order). It's subtle but not a new condition. Previously ALLOC_NOFRAGMENT would result in not taking the "goto find_smallest" path because it means searching >=pageblock_order only and that would always be can_steal == true if it found a fallback. And failure to find fallback would reach an unconditional return NULL here. Now we fall through the search below (instead of the goto), but ALLOC_NOFRAGMENT must not do it so it's now explicit here. >> >> -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);