From patchwork Mon Nov 13 17:01:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 164572 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp1340676vqg; Mon, 13 Nov 2023 09:02:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IHgbsaIKeuvMnTxwT+ACghu8MVMqonxim48RSx7f0MgVUZ1qjOEU6qtsh79va90SrHGVVcl X-Received: by 2002:a17:902:b7c8:b0:1cc:6ab6:df26 with SMTP id v8-20020a170902b7c800b001cc6ab6df26mr121512plz.49.1699894970367; Mon, 13 Nov 2023 09:02:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699894970; cv=none; d=google.com; s=arc-20160816; b=KxNEesZMsFlc+nqqaw2kCbr7IvC65vhGzxclPTUXP373B65mlyTvclrXAUWo+ylesH K+h87kloOOtoc3x9UzroTo38inByCOHQUQZibNd3QM7c6tvAlRAA6minZItZGLx0vgxy 9q9maXmbJ07xomwOvoymZ/dutmAE9cgyuTvv75HcV/UVLkTofXEVU7g8o6fSyrlAHT96 iCxTFX4g+LMy5nnen5i5aEA9FdPl6uaGMdVUpakaAiGuTeBnhf4JZk5+gDV5X0P08bQ6 O4YcCCkbAQKAk3V4CQFlqNTOvuqT2PYIHEbmZ41Jk+FBx/y6swrEQuJjePQFSnqY7x+B ydZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version:reply-to :references:in-reply-to:message-id:date:subject:cc:to:from :feedback-id:dkim-signature:dkim-signature; bh=nzOUpjfyn/JJJn/Enob781hONORF3mJcpBIoO1y6HOc=; fh=vJ0CYzlC3FzFcxY+JvdHzizIe8XjzG5USPt1Sa6qsGI=; b=BewF40/8e8aOdaR4D6xeSw1tl5+StkSBZGmEhkedm84VxZxU75igr0Htncve9/27sv yOBGb7zG4G7b9L0khR6ZWfPDmtBVSNAFz93oQb9NsfzLNnl4H/RtUTFNKQ9GvPge8qRk dTsHi1tly0D/5POycB2R9VVmynYhtN+P8tDoQDHocgMmDv2+/cXMr8vDbiJi9tOtXL6r r89MLStOdjiTuIukwBtD0vDx4loduLvOnPMCNBRrej5p7mAcmysVqLOeXuM1st4NT/pP xY98VdSIfeyYXheeSfRjsXh/9218M1VOvvR6/8jG1wuQptu2tiwapor9vasv8NMgnPDt 2Bsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sent.com header.s=fm3 header.b=LLVv3ylo; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=BY18zVII; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sent.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id i1-20020a17090332c100b001ca8f6b3b8fsi6345177plr.266.2023.11.13.09.02.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Nov 2023 09:02:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@sent.com header.s=fm3 header.b=LLVv3ylo; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=BY18zVII; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sent.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id D4F50802A734; Mon, 13 Nov 2023 09:02:37 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231755AbjKMRCf (ORCPT + 30 others); Mon, 13 Nov 2023 12:02:35 -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 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 13 Nov 2023 09:02:37 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782469068341478326 X-GMAIL-MSGID: 1782469068341478326 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_list *freepages) } #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 = 0; order <= MAX_ORDER; order++) + init_page_list(&page_list[order]); + + list_for_each_entry_safe(folio, next, pages, lru) { + order = folio_order(folio); + + if (order > MAX_ORDER) + continue; + + list_move(&folio->lru, &page_list[order].pages); + page_list[order].nr_pages++; + } + + for (order = MAX_ORDER; order >= 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 capture_control *capc) pageblock_start_pfn(cc->migrate_pfn - 1)); } + sort_folios_by_order(&cc->migratepages); + err = migrate_pages(&cc->migratepages, compaction_alloc, compaction_free, (unsigned long)cc, cc->mode, MR_COMPACTION, &nr_succeeded);