From patchwork Mon Feb 12 16:35:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13553621 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 50FB5C48297 for ; Mon, 12 Feb 2024 16:35:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 68F098D0003; Mon, 12 Feb 2024 11:35:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 642358D0001; Mon, 12 Feb 2024 11:35:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 252738D0003; Mon, 12 Feb 2024 11:35:20 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id EC6A08D0003 for ; Mon, 12 Feb 2024 11:35:19 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id B8858A0DB5 for ; Mon, 12 Feb 2024 16:35:19 +0000 (UTC) X-FDA: 81783701958.11.AD787C8 Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by imf06.hostedemail.com (Postfix) with ESMTP id 6DC87180008 for ; Mon, 12 Feb 2024 16:35:16 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=sent.com header.s=fm3 header.b=jtwatxbu; dkim=pass header.d=messagingengine.com header.s=fm3 header.b="afPdzl/w"; dmarc=pass (policy=none) header.from=sent.com; spf=pass (imf06.hostedemail.com: domain of zi.yan@sent.com designates 66.111.4.27 as permitted sender) smtp.mailfrom=zi.yan@sent.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707755716; h=from:from:sender:reply-to: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=olLqROIyqpY7Zf7udKwLJkzhBkxMJLzel8K572FqHrM=; b=YZ/+6/1SRCqYwo9PeLwI3Mu5aKZIyduQZ/ntJ84s513MJaDtKQEj/NGTEUviDpACckgGqs jEaFyoFHq8kCvZpNli8cz8LhRV9SbxLb7098vws6H3eoVmhKJA8rvfJ7cyvoZ0OyPbLQda HNfnVBapTEbC3pezbiBpeRotaX9cpMc= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=sent.com header.s=fm3 header.b=jtwatxbu; dkim=pass header.d=messagingengine.com header.s=fm3 header.b="afPdzl/w"; dmarc=pass (policy=none) header.from=sent.com; spf=pass (imf06.hostedemail.com: domain of zi.yan@sent.com designates 66.111.4.27 as permitted sender) smtp.mailfrom=zi.yan@sent.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707755716; a=rsa-sha256; cv=none; b=6GX4YOjusXyGVFVsnGPbMMm9yINlinDniOkvOrZW/0FnIYyMTwqtAFXixWWALASkOORhSY tUUBpesTKMYlfLqaZbkZpncZ1405uEdOSMPi00D+9+vbqsqVdtWU7Anhw/3Z2SEpj0FKJa vhZH04PR+s3tkifMe3ccSmeA9F6l1as= Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailout.nyi.internal (Postfix) with ESMTP id B4EA05C0045; Mon, 12 Feb 2024 11:35:15 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Mon, 12 Feb 2024 11:35:15 -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:subject:subject:to:to; s=fm3; t= 1707755715; x=1707842115; bh=olLqROIyqpY7Zf7udKwLJkzhBkxMJLzel8K 572FqHrM=; b=jtwatxbu2FB6nKWyP/fincfHoJzs3A/lOqghTUCfK8J2wIPfn+T S7tgChnPEhCuIkTn2XGVynpfbrJbYfBthSX3ykoAKK9oXEIo/prqFZGwwIhjWTlQ DNiAK3a0QGpNnqYGofiADYaL3e5cw+rodaym6RLoCPDr063CCHWZwZDr5H0fYNnD kusC71OYg4vy8Qrx1Se+t2B1iGG0flCQFRyIsYt09qIRN+QvCsociw3VhV56xRxg GCatDpdKRwRmBvL4po67ti8E7H2pNkbA8w5j0No/3nLzsDIrIPlxJw16dwwZ9b6u 7ayARCU+f14z6UEhgOqCrpd+9K11KKT3mog== 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:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1707755715; x=1707842115; bh=olLqROIyqpY7Zf7udKwLJkzhBkxMJLzel8K 572FqHrM=; b=afPdzl/wbipcN9f++f1MwyUl2kN36DxNta5xjrdSb8dXrEsRFAo xo7OsCUgZeEhSpFbdtqCThXFVasVrxVTPPTEx2p6O1aYzM/hMXiyN6491K7ZZCNi O/qQnBk4YAOq3mPhYbIxNHgdfDYpVbbW0P7zBkY7gG2wrZ/jqzq18M6zGSJ87ydy LyBeVGF4OgDRheJ0g/q9ctcTHU9XVehqXAAeHd7xiR6mYjGSfW89E5oJsqxIdtqH 6JD0gjjd0i1ONje2fLCfvuepRer/QnfmRNK2WzGLjKkQVckZFpU+t4Qw/G3FKwos 3m5emENiTgMzi8qVjue2V0gKwyyKdS30I2A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudefgdeklecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvfevufffkffojghfrhggtgfgsehtkeertdertdejnecuhfhrohhmpegkihcu jggrnhcuoeiiihdrhigrnhesshgvnhhtrdgtohhmqeenucggtffrrghtthgvrhhnpeejke etkeffleelkeduffdtfedvtdejjeeutdeutdetgeejgfevtdefudejkeeiveenucevlhhu shhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpeiiihdrhigrnhessh gvnhhtrdgtohhm X-ME-Proxy: Feedback-ID: iccd040f4:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 12 Feb 2024 11:35:14 -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 v4 1/3] mm/compaction: enable compacting >0 order folios. Date: Mon, 12 Feb 2024 11:35:08 -0500 Message-ID: <20240212163510.859822-2-zi.yan@sent.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212163510.859822-1-zi.yan@sent.com> References: <20240212163510.859822-1-zi.yan@sent.com> Reply-To: Zi Yan MIME-Version: 1.0 X-Rspamd-Queue-Id: 6DC87180008 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: u1k9pzhcmka3akormfbfa1kbtod4joz5 X-HE-Tag: 1707755716-606445 X-HE-Meta: U2FsdGVkX1+w0Fo7qwRCubvFje85XjGR8+bkHssnkwhvEzBdST1w6dS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3hgh0lU5OMgESiUDkqXgaXCYVjL59dkP1ky52qmPEA/NlYzQ/IsnammN55f8/QO3sPGaLEoknqOyST9iZFUiYmFz6dcwSAfKWuEJO6du5LS1hcRX9iGwderlaqoLm/HgE5PQm97C70FqmnWTVATN1REZpi3aBZdcqtquW7cliIPhghIPpczeLw7VcxMFi0rPdaSDXhLQjxxfqhHHfWkTpBkH5kHHNhV4jKFLxCK/RSThnLjHpMJiu7PshG8j4tAG+jK6sc9d2OrOmDvOnlNX7BFZmJyyaA1O5fCuGAFKiPLhCAJRrJGOay40OqATDyUrTfCaFQdnDH5Ud83YnqnoQT//DXAfmncpREAS9AcpzknpLD6MuucaAudEbCMCiFb/drlkEHnA/3Vm2ZUkBtseC10Im5EWGfYEeA9BzoqPtoHHXEP5ipx+f9kRHr+ILvryL/uEQD2yz9Fm1xHb0WwKmC6gJSWa+/ncVKQeM2OT8bLCXD7TNWVRvk3N9z6aW5ECuR254OBbFtX83VJ+RtCrmnznI5LZ9YjW0fYwq31cD8QwFvNizH062siIxR6Dbq0zbyk2Fg9ZuPQdCF9IW0olAtN9wTukbK6ilekhZ+aWZhEjL83hdPDMfi8OIrujGV3rs7ruVeBfNNoVu56PmGhDGUTVExnisoylCI1Vj+VGoPhqSziKDwqI4oDEsgI+krVvagNThrsvzlXqHZKmKEivmAvwa8nB+LrJm9U9lJbnfIzrLR2AcRVupmT0/sREdIfnOVBoueOOJ1VhLytwqBMeMDqTvHcjNbX6socMzoKDoRM7ybaqi7F1IQociZLCwNnB6cc6M/DJj4RaPqCIy6Ghm eZ0m8mTk YUiNrfYrbYDj4vTgCA4HD3b53dBkIdKx 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: From: Zi Yan migrate_pages() supports >0 order folio migration and during compaction, even if compaction_alloc() cannot provide >0 order free pages, migrate_pages() can split the source page and try to migrate the base pages from the split. It can be a baseline and start point for adding support for compacting >0 order folios. Signed-off-by: Zi Yan Suggested-by: Huang Ying Reviewed-by: Baolin Wang Tested-by: Baolin Wang Cc: Adam Manzanares Cc: David Hildenbrand Cc: Johannes Weiner Cc: Kemeng Shi Cc: Kirill A. Shutemov Cc: Luis Chamberlain Cc: Matthew Wilcox (Oracle) Cc: Mel Gorman Cc: Ryan Roberts Cc: Vishal Moola (Oracle) Cc: Vlastimil Babka Cc: Yin Fengwei Cc: Yu Zhao --- mm/compaction.c | 66 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 52 insertions(+), 14 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index cc801ce099b4..aa6aad805c4d 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -816,6 +816,21 @@ static bool too_many_isolated(struct compact_control *cc) return too_many; } +/* + * 1. if the page order is larger than or equal to target_order (i.e., + * cc->order and when it is not -1 for global compaction), skip it since + * target_order already indicates no free page with larger than target_order + * exists and later migrating it will most likely fail; + * + * 2. compacting > pageblock_order pages does not improve memory fragmentation, + * skip them; + */ +static bool skip_isolation_on_order(int order, int target_order) +{ + return (target_order != -1 && order >= target_order) || + order >= pageblock_order; +} + /** * isolate_migratepages_block() - isolate all migrate-able pages within * a single pageblock @@ -947,7 +962,22 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, valid_page = page; } - if (PageHuge(page) && cc->alloc_contig) { + if (PageHuge(page)) { + /* + * skip hugetlbfs if we are not compacting for pages + * bigger than its order. THPs and other compound pages + * are handled below. + */ + if (!cc->alloc_contig) { + const unsigned int order = compound_order(page); + + if (order <= MAX_PAGE_ORDER) { + low_pfn += (1UL << order) - 1; + nr_scanned += (1UL << order) - 1; + } + goto isolate_fail; + } + /* for alloc_contig case */ if (locked) { unlock_page_lruvec_irqrestore(locked, flags); locked = NULL; @@ -1008,21 +1038,24 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, } /* - * Regardless of being on LRU, compound pages such as THP and - * hugetlbfs are not to be compacted unless we are attempting - * an allocation much larger than the huge page size (eg CMA). - * We can potentially save a lot of iterations if we skip them - * at once. The check is racy, but we can consider only valid - * values and the only danger is skipping too much. + * Regardless of being on LRU, compound pages such as THP + * (hugetlbfs is handled above) are not to be compacted unless + * we are attempting an allocation larger than the compound + * page size. We can potentially save a lot of iterations if we + * skip them at once. The check is racy, but we can consider + * only valid values and the only danger is skipping too much. */ if (PageCompound(page) && !cc->alloc_contig) { const unsigned int order = compound_order(page); - if (likely(order <= MAX_PAGE_ORDER)) { - low_pfn += (1UL << order) - 1; - nr_scanned += (1UL << order) - 1; + /* Skip based on page order and compaction target order. */ + if (skip_isolation_on_order(order, cc->order)) { + if (order <= MAX_PAGE_ORDER) { + low_pfn += (1UL << order) - 1; + nr_scanned += (1UL << order) - 1; + } + goto isolate_fail; } - goto isolate_fail; } /* @@ -1165,10 +1198,11 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, } /* - * folio become large since the non-locked check, - * and it's on LRU. + * Check LRU folio order under the lock */ - if (unlikely(folio_test_large(folio) && !cc->alloc_contig)) { + if (unlikely(skip_isolation_on_order(folio_order(folio), + cc->order) && + !cc->alloc_contig)) { low_pfn += folio_nr_pages(folio) - 1; nr_scanned += folio_nr_pages(folio) - 1; folio_set_lru(folio); @@ -1788,6 +1822,10 @@ static struct folio *compaction_alloc(struct folio *src, unsigned long data) struct compact_control *cc = (struct compact_control *)data; struct folio *dst; + /* this makes migrate_pages() split the source page and retry */ + if (folio_test_large(src) > 0) + return NULL; + if (list_empty(&cc->freepages)) { isolate_freepages(cc);