From nobody Tue Dec 30 18:48:57 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A7ADC4167B for ; Mon, 13 Nov 2023 17:02:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231781AbjKMRCh (ORCPT ); Mon, 13 Nov 2023 12:02:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231564AbjKMRC1 (ORCPT ); Mon, 13 Nov 2023 12:02:27 -0500 Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A1A818D for ; Mon, 13 Nov 2023 09:02:25 -0800 (PST) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 829795C0099; Mon, 13 Nov 2023 12:02:24 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Mon, 13 Nov 2023 12:02:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sent.com; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:reply-to:sender:subject:subject:to:to; s= fm3; t=1699894944; x=1699981344; bh=nzOUpjfyn/JJJn/Enob781hONORF 3mJcpBIoO1y6HOc=; b=LLVv3yloNFUmMZ6xGakYy4VMI5jabZP1oX9qTx7H16gO 1CZG/Vu4y682pbGiU601G2tvZkKoGS/cQelvSjNl8IyVRCvBxY6ZDp/I8Z0El/7X 9ZfcY15EYusoFRVwvMbdZP6TQvbCHhLECsmgGAFbJf9HFgYb01aD31ORb3xofy3Y 7MIOzM0o59YHJxOvwcxZHA0/sbuL5Je60bq6A/+EhOnwDSY4kDNInc0UL2GwUU2y KoMrFOjoHe/NngSo17AreCt7IaANttkYOr1/Q8o2fk4fb2YI47vmTdRL2ARxdrcs 37aplOkVJOt1jGNxORVOB3T9vRyR7rMhKXKxozk+5g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1699894944; x=1699981344; bh=nzOUpjfyn/JJJn/Enob781hONORF 3mJcpBIoO1y6HOc=; b=BY18zVIIhn/w0FEXwxzpd9RefEDeDi6eMLhNRbpMZAVb 9dGnvGsCq+Z6W22Gby2w0+eOoExdovlBnvJ84qpX5Plpj10dvXTreo4EGwYu7EXN C0G1KpE+tNFcW/GqNrybEqajzff+3jNMkIQdJaYehnaeJl2Dwkc2E0poBSk45Qbk nCPaOWGnMh/SBtyKU3va+yhTH7DvRNKe9NfqaeaXfGUbEQDjCaGg6XRfUbGaQ1YU 3hnkKo6HsZhFLBGIbuxZHZCximCfxM2GOv+SU6jOJyn/jEb74S9EN0ECVc+h43Bf xVLHDT/QAI2Qqt1sAZQ5wYKxhrWruO0RmuXr7juCMQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrudeftddgleefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhhrgggtgfesthekredtredtjeenucfhrhhomhepkghi ucgjrghnuceoiihirdihrghnsehsvghnthdrtghomheqnecuggftrfgrthhtvghrnhepje ekteekffelleekudfftdefvddtjeejuedtuedtteegjefgvedtfedujeekieevnecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepiihirdihrghnse hsvghnthdrtghomh X-ME-Proxy: Feedback-ID: iccd040f4:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 13 Nov 2023 12:02:22 -0500 (EST) From: Zi Yan To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Zi Yan , "Huang, Ying" , Ryan Roberts , Andrew Morton , "Matthew Wilcox (Oracle)" , David Hildenbrand , "Yin, Fengwei" , Yu Zhao , Vlastimil Babka , "Kirill A . Shutemov" , Johannes Weiner , Baolin Wang , Kemeng Shi , Mel Gorman , Rohan Puri , Mcgrof Chamberlain , Adam Manzanares , "Vishal Moola (Oracle)" Subject: [PATCH v1 4/4] mm/compaction: optimize >0 order folio compaction by sorting source pages. Date: Mon, 13 Nov 2023 12:01:57 -0500 Message-ID: <20231113170157.280181-5-zi.yan@sent.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231113170157.280181-1-zi.yan@sent.com> References: <20231113170157.280181-1-zi.yan@sent.com> Reply-To: Zi Yan MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zi Yan It should maximize high order free page use and minimize free page splits. It might be useful before free page merging is implemented. Signed-off-by: Zi Yan --- mm/compaction.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/mm/compaction.c b/mm/compaction.c index 9c083e6b399a..91809bee5422 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -127,6 +127,37 @@ static unsigned long release_free_list(struct page_lis= t *freepages) } =20 #ifdef CONFIG_COMPACTION + +static void sort_folios_by_order(struct list_head *pages) +{ + struct page_list page_list[MAX_ORDER + 1]; + int order; + struct folio *folio, *next; + + for (order =3D 0; order <=3D MAX_ORDER; order++) + init_page_list(&page_list[order]); + + list_for_each_entry_safe(folio, next, pages, lru) { + order =3D folio_order(folio); + + if (order > MAX_ORDER) + continue; + + list_move(&folio->lru, &page_list[order].pages); + page_list[order].nr_pages++; + } + + for (order =3D MAX_ORDER; order >=3D 0; order--) { + if (page_list[order].nr_pages) { + + list_for_each_entry_safe(folio, next, + &page_list[order].pages, lru) { + list_move_tail(&folio->lru, pages); + } + } + } +} + bool PageMovable(struct page *page) { const struct movable_operations *mops; @@ -2639,6 +2670,8 @@ compact_zone(struct compact_control *cc, struct captu= re_control *capc) pageblock_start_pfn(cc->migrate_pfn - 1)); } =20 + sort_folios_by_order(&cc->migratepages); + err =3D migrate_pages(&cc->migratepages, compaction_alloc, compaction_free, (unsigned long)cc, cc->mode, MR_COMPACTION, &nr_succeeded); --=20 2.42.0