From patchwork Wed Feb 14 22:04:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13557107 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 BA94CC48BEB for ; Wed, 14 Feb 2024 22:04:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CE8CC8D0014; Wed, 14 Feb 2024 17:04:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C73278D0001; Wed, 14 Feb 2024 17:04:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B60728D0014; Wed, 14 Feb 2024 17:04:39 -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 AA2C38D0001 for ; Wed, 14 Feb 2024 17:04:39 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 6966E40EE4 for ; Wed, 14 Feb 2024 22:04:39 +0000 (UTC) X-FDA: 81791789478.05.BE7A28B Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) by imf21.hostedemail.com (Postfix) with ESMTP id 2E1831C001C for ; Wed, 14 Feb 2024 22:04:36 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=sent.com header.s=fm3 header.b=Sd+c9faY; dkim=pass header.d=messagingengine.com header.s=fm3 header.b=Xkqa1QfF; spf=pass (imf21.hostedemail.com: domain of zi.yan@sent.com designates 66.111.4.28 as permitted sender) smtp.mailfrom=zi.yan@sent.com; dmarc=pass (policy=none) header.from=sent.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707948277; 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=iXB4hFIGUr+5qlTT7GwOhxHq+2xnf+LZ7P4ZJxJN83A=; b=7JJxIkxhV6Ztr+Mdhzx70dGAdjg6qPwbXJMmNPcOY71x89jQblLtk6+aGo9n6o4lFRxr2T sTr2N6SoxPqqpO7QhI7UwjB4ZhiAmzfDZZzEFItiAd0yDsTj8D3KZzC1hP7S/ZaAzXF9AE J51oGqWtP5md86sbwFxBkPrJLlcRQBg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707948277; a=rsa-sha256; cv=none; b=rG+ZGf9IaJRFHZXuqMPlR3Z7/tTklZUJcHHuYRVzq5OXSWrPiAkhoBaiShV4pXKkTK3Kdn BRw19yFy7lZSalkfHPTAlmODAyAQ9emaHDb1YQIxBDVNyVikrYwKpUP9Xd2hufivB6YHsi N2mb8AdOInM3k4B47i+nTBSYhg0o7G4= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=sent.com header.s=fm3 header.b=Sd+c9faY; dkim=pass header.d=messagingengine.com header.s=fm3 header.b=Xkqa1QfF; spf=pass (imf21.hostedemail.com: domain of zi.yan@sent.com designates 66.111.4.28 as permitted sender) smtp.mailfrom=zi.yan@sent.com; dmarc=pass (policy=none) header.from=sent.com Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 6DB7C5C0085; Wed, 14 Feb 2024 17:04:36 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Wed, 14 Feb 2024 17:04:36 -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= 1707948276; x=1708034676; bh=iXB4hFIGUr+5qlTT7GwOhxHq+2xnf+LZ7P4 ZJxJN83A=; b=Sd+c9faYu7Kd229fSoKw0355HFCsVOXAmbPELIaKX/YxD+WxFDY vcGu+NgtgbpHDMFUrsbUSZUxVxKA8uI0/9CNsL0iziGpjnnv2gxQ7DXjjQN4ya4V 34KuyW0R91ZbLMbqMXQ0scp6jhEGZoha+V5eJkqGcjWOHmEXB3qtrgPl5Sb6BKzn Oqif52IBUC9w/4mZxLPB512uluRfD95IFp4J/Db8JJKKSEHbzuf8Jbo60T1kW2T9 TuQXp+qtRaWVixfnb1fRQYifBirC8HUdBkOF7NLqhN+2Nb/mY3ha6ovbk1oFJlSL GdOObLz0w9rXa3thQec+12QdRyBIAheVe2A== 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= 1707948276; x=1708034676; bh=iXB4hFIGUr+5qlTT7GwOhxHq+2xnf+LZ7P4 ZJxJN83A=; b=Xkqa1QfFUJAP2Oc2PqL9OOQdKTWF4TU8hECtytbueECS/aK02jW xQVPmuwXdxW4dQ8F5llHdSDxXHuTXjeG/UTWq0BOX66FyAc/DDPmuox7konafdnm 7U4YRpsJCBHKz567H7o514UxXn7E8ZCQtEx8p/QdWRnGK8zf5BLrU9zw4HLL+dkF qMuqV/fEm+gii2q0jN+utvOcl7cfBx83lwg99A6Ss7O8GO2Qy1PSozvGolw7Z5+n viw2oV8U/nMSuKkCHI7kYTiRpPKKaVURc819sW3+gb/kSIQAQonRnamZgUWpE6TY Ql7EgqEWwIvn9kDvQLB/jmeZz7a1BaiFgDg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudejgdduheejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhhrgggtgfesthekredtredtjeenucfhrhhomhepkghi ucgjrghnuceoiihirdihrghnsehsvghnthdrtghomheqnecuggftrfgrthhtvghrnhepje ekteekffelleekudfftdefvddtjeejuedtuedtteegjefgvedtfedujeekieevnecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepiihirdihrghnse hsvghnthdrtghomh X-ME-Proxy: Feedback-ID: iccd040f4:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 14 Feb 2024 17:04:35 -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 v5 1/3] mm/compaction: enable compacting >0 order folios. Date: Wed, 14 Feb 2024 17:04:18 -0500 Message-ID: <20240214220420.1229173-2-zi.yan@sent.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240214220420.1229173-1-zi.yan@sent.com> References: <20240214220420.1229173-1-zi.yan@sent.com> Reply-To: Zi Yan MIME-Version: 1.0 X-Rspamd-Queue-Id: 2E1831C001C X-Rspam-User: X-Stat-Signature: xtbt788foi4iw7s6fk5nxzikc64eicyk X-Rspamd-Server: rspam03 X-HE-Tag: 1707948276-683264 X-HE-Meta: U2FsdGVkX1+DChFs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C6C8ocs6oyk5oLtIWJsIAntK9yjZ6ytI+5VJZkfGAK1pcvwChAgOLc3JoTHW86qciZBj/OBFO87r7t6OY9GBMegQdltdlYIEJ7z7NgFhL2fZXsV1UGc9hfeJlgXH+mCH6YqZQOaONywLfu3M5iPQRiZVGwq1A2CPOdmHst7IMzt9M1mZfLcVLRm043Ak84BMebTW5c/3y/KKzPKLju2AOdQWb1Ili219UT+Bg4i+LKiD9okpVhVQvELdGWDS/M9ptWgbtfr6Jwvwf2pPuFY625C8wbQv0lL99Oni0BQacybPwHYPdD6ZC7glrFUmIpB8GbHQTwmvfImcPywk/tDDHIkuMSTECoxP1zI+zqnBt3ozQTF6jzBStLUBkPFusFw9dNdX8kLzVyBkeZkdqYHs4mjSA2TcEEn7ywMWmQPBIAasaSFsPJIj057AcVsF5DTIEAeb2RAzbnLwOkonJBLOJCXUSPHybvwiUCT7vSK8/5TmahrKYB11OR0wfC8DkQYm9a+kbvkKCrheKrB1GlDBGF8gMs000GverMAFq6UR8Lc9k8OCrNc0ktDgjQzjQAOz9LfEL4Bz3Yk7/8gJFezn23fiyHWnMLeVSWVnD2aUPzPBzVybNY926zYMA0JBvRSG8tYJun2tncJDgSrclTm7sRKIwV3KyfKRZpe+/lGEuUbUE659w7q09xKL/fN/sRH7R8xEEdxsroT2CljwzXAez5i/SCNO6umJtTnp64aMjPIYGN3U2X08wsVgGF+oQlRlukUjcbFHmUX2T4fIRVCXAvo19DodTsPISPTorxVW2QR0o23p7mpTbGnvVY/JNxvqmV1VLiMj7NTb1NGpQibBFuZAtOA4VwZVl9kpq73lpf4EOxbU+yTO9mqmWP7zGG0/a +ZnLROHF Eoi8tw0HIwWT3uHYKrR2HckT7PkhEwDLNDfeHIYHOac= 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 Tested-by: Yu Zhao 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 Reviewed-by: Vlastimil Babka --- 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);