From patchwork Fri Feb 2 16:15:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13543131 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 B5C05C4828F for ; Fri, 2 Feb 2024 16:16:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0C9A36B0074; Fri, 2 Feb 2024 11:16:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0ACCF6B0078; Fri, 2 Feb 2024 11:16:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E836D6B0075; Fri, 2 Feb 2024 11:16:19 -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 DA65E6B0072 for ; Fri, 2 Feb 2024 11:16:19 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 83080A162C for ; Fri, 2 Feb 2024 16:16:19 +0000 (UTC) X-FDA: 81747366078.22.DA63429 Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) by imf22.hostedemail.com (Postfix) with ESMTP id 68EBFC0029 for ; Fri, 2 Feb 2024 16:16:17 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=sent.com header.s=fm3 header.b=w9AwuLYZ; dkim=pass header.d=messagingengine.com header.s=fm3 header.b=jITQjR9f; spf=pass (imf22.hostedemail.com: domain of zi.yan@sent.com designates 66.111.4.26 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=1706890577; 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=b0LGZXB2atC7cRDxeVKB29tfMJXHfhbupvuqzgL5H0w=; b=3o1r0H7HNihR/53eeFvXrNdaAGQ/fS6JwfxrJxK2z3eGaPKx72KyB0swuVuYWIgQHium+X HU6qeC1SuzNQYRGA8I2EbEjLz+OQSzNPoIXDZmT2Jz1yjRT/+4WVDcijGUI8WAZVG4y4aX +itcrxJwtnpuuQ/rUL+tmX8P4eerD/c= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706890577; a=rsa-sha256; cv=none; b=Efd8BrGTeOIG4dQfIJ6p/9H5kQ2QS/LkeVEdwzPxhrbe1EoWduT8r2UzKgosdUR5QbHiS9 6WXsdUvGiQxFdXo7qgp84WDawuXF5dLyjYRkkQz8bFKg68toE0XgVyixv1dKGZJoVLd/R7 kx0exLZm6RC78ErA8VbzCVXRqbfyI7U= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=sent.com header.s=fm3 header.b=w9AwuLYZ; dkim=pass header.d=messagingengine.com header.s=fm3 header.b=jITQjR9f; spf=pass (imf22.hostedemail.com: domain of zi.yan@sent.com designates 66.111.4.26 as permitted sender) smtp.mailfrom=zi.yan@sent.com; dmarc=pass (policy=none) header.from=sent.com Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id BE2FD5C0080; Fri, 2 Feb 2024 11:16:16 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Fri, 02 Feb 2024 11:16:16 -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= 1706890576; x=1706976976; bh=b0LGZXB2atC7cRDxeVKB29tfMJXHfhbupvu qzgL5H0w=; b=w9AwuLYZjR/BP+cqnv3LMOCFQHBsCSwi895LQemcBc+Vo5ZToOt HCHtnMIu+rwnyKxCfClEPDT0/5F+CkwVbcGInCTjWeCWmRjStV7xls7XKOArtfsI w5V3vmmkw+KiHx2VdkyMZ0QacA6O+hqiEA/i4E9XOJ9z+Q/x3xQMDQ8arvA/lk0g BqHpu1wNeN9kn2L6C96cJ1thlhPyVv97m93rRRo8gewh7pXpNJHfVbnhc94d+/OT 8eny1dAyhp8oVMCHXdhdF/yxvyNKMP/6aOC8MZKzfU4jhN/6nuOWJw7hUSqswAT0 if8thmyelZ6EE/eBsHrgVEmiLME2G476qSA== 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= 1706890576; x=1706976976; bh=b0LGZXB2atC7cRDxeVKB29tfMJXHfhbupvu qzgL5H0w=; b=jITQjR9fZ4vUH7jpIKUSGUf69CmGaNlTyKWC7zCok4dJZu5NM+M tfqbsksM2p0nTWynjXbTfU3uIPh+tzf0SEH3sdEbK6yLqYCUcsSri81slnPWg0Vl +tv7SmGQ6GXwLg/uEogMGAdWcRQ2uUpLFNRY5TeNJYaKuyqHrI9LDFZyoAHDTJrv laJlFvAREQb49Osr7ozT8+HHU7Do0nEFj3n2Ks80KnGAxDm5blkXMdpNaQpb5tkl znMVFC71CcxwrGQpSwLwE8Et4YppV1zGIp7VMnNW8+rHy1e+kLti4NGDKwzC/JLD oTrbPSupWq5z6Db9SfEWk+3EevvpLfpHAYw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrfedugedgkeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhhrgggtgfesthekredtredtjeenucfhrhhomhepkghi ucgjrghnuceoiihirdihrghnsehsvghnthdrtghomheqnecuggftrfgrthhtvghrnhepje ekteekffelleekudfftdefvddtjeejuedtuedtteegjefgvedtfedujeekieevnecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepiihirdihrghnse hsvghnthdrtghomh X-ME-Proxy: Feedback-ID: iccd040f4:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 2 Feb 2024 11:16:15 -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 v3 1/3] mm/compaction: enable compacting >0 order folios. Date: Fri, 2 Feb 2024 11:15:52 -0500 Message-ID: <20240202161554.565023-2-zi.yan@sent.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240202161554.565023-1-zi.yan@sent.com> References: <20240202161554.565023-1-zi.yan@sent.com> Reply-To: Zi Yan MIME-Version: 1.0 X-Rspamd-Queue-Id: 68EBFC0029 X-Rspam-User: X-Stat-Signature: 67u18149jnghen93ddg1u8x5anqawt3b X-Rspamd-Server: rspam03 X-HE-Tag: 1706890577-231540 X-HE-Meta: U2FsdGVkX1/pi/ZZcPHMp7troicR2TTPf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TYoj/VHj8tlp6WAByLCX5kcFqWelAEEKIEQN3scMMKKRXiW8LxmdDPm8HFP1D/OSo4xV2Ba3KQjm58WTq23EFYcFHz/4aksBeSNkoqqQAftorL7MaWf8BARiSLJ7CMrIx5o79Msblu/02/aETs8hDyqbjYUvEaoXorDkgKDxLuttdfxV/lPNUHy8tqYc4jMllOd3CIKb4CE2P36EiX53+37FjO3Izbu8ErsF5MCX21IsvBqfBWnBr1wRhe/0l8/HjaXtRJHNx1mYjU9TtJjYNIUqK35WC+qTAw4A3aOfypIQtd1VLyN8wtcGZzqG+WyMp12lsU6WGtsGeQgd1DiyUfA64JKNjoIPtbQK32N9L+dbvR9TSAnRg/SYjQNJJj6DzOJGq2zmNsy8R2JXjKLhi7CWYanBunOROPsaT0FCZxSLg1//efe451HDc= 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. Suggested-by: Huang Ying Signed-off-by: Zi Yan --- mm/compaction.c | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index 4add68d40e8d..e43e898d2c77 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 @@ -1010,7 +1025,7 @@ 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). + * 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. @@ -1018,11 +1033,18 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, 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 + * and skip hugetlbfs pages. + */ + if (skip_isolation_on_order(order, cc->order) || + PageHuge(page)) { + if (order <= MAX_PAGE_ORDER) { + low_pfn += (1UL << order) - 1; + nr_scanned += (1UL << order) - 1; + } + goto isolate_fail; } - goto isolate_fail; } /* @@ -1165,10 +1187,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); @@ -1786,6 +1809,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);