Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp97678rdb; Wed, 14 Feb 2024 14:04:49 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWF4pLhKpHQneCzk1EIuWhMwc7Yadfh9SSOYEEKp4ikZt9CFTlfjoafNzsrp1eHAJR/tTrR+GN7j0BMu998tspjTmg2PRfuJFYOiUsTqQ== X-Google-Smtp-Source: AGHT+IFAMk6KgpIK2mdmSqSIC1tbk0oF++/0hsUZU1WWXtOtz9MgRuJMgI9kdnYesF/EtK35Bpol X-Received: by 2002:a05:6402:69a:b0:560:1c4:cb31 with SMTP id f26-20020a056402069a00b0056001c4cb31mr3098321edy.17.1707948289596; Wed, 14 Feb 2024 14:04:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707948289; cv=pass; d=google.com; s=arc-20160816; b=uFBxpDtu/9xYCKa637vCWeBNRslAfbzCwCqAe3v+20V4N0EuNLQdXwK9Jn1uUMBpik RdR/fM3vZ2G/ML39e5OpOojGv968wRmVLU/+63XuoVXCHCRu+3fMJ7XZslB1AaA0cnUF LYQ9ytg+S3/oHNF0IMWeFa6xPWyStxzG9OG0dTF6fLF5HSYEh0XsGzc2T1oCYQ7GBbKX BURUKE2gFrYX5TW+4CCOqr9mZnHWjMsX6Q78db4hyrIvdkrQ3ygN5uQBm0DHYH5ysdGj WynYprZlLu4MfrPy35ok0VClDV70LGKliimR2+EXT6GSZjthjNNWTkErioaYWJs2GWzC xRmw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:reply-to:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:dkim-signature :dkim-signature; bh=iXB4hFIGUr+5qlTT7GwOhxHq+2xnf+LZ7P4ZJxJN83A=; fh=rFAT75LYUvZt3IlXvnlfQDwvPAjgaMFPvaOERh6OjB0=; b=Q380xD4feOwA0yJIYlLt2l9YIIdDE2J2yOPdr/qx8x5fWcJh9e/YdA218G4mWpfgxy fe1+NZCkyzQtfh8qw6/3RUB8pzBo5hl0h2zjDe6atD37Nf3L5Uybws5Aesq55+wtiw7d IxxbTtT0OdjWPA7SMnM7YY0L1LWrkSX9L/nqfA9MIzUQJxvehim0gmZT183cjyAuIIeC uNT4UCNUj6nZH5OFCT5FFA4WmeGSRI2i3gfHB3f1A3XQUy1pq5hnDaCyzosQr2AIBQwp zdqKFF/+2TPvn0+mZ5JBH3K6/WvNnVAPGa90dkJJ2O7VqfI8dC20dH4i98OMWh5kNCJA QIOg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sent.com header.s=fm3 header.b=Sd+c9faY; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=Xkqa1QfF; arc=pass (i=1 spf=pass spfdomain=sent.com dkim=pass dkdomain=sent.com dkim=pass dkdomain=messagingengine.com dmarc=pass fromdomain=sent.com); spf=pass (google.com: domain of linux-kernel+bounces-66021-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66021-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sent.com X-Forwarded-Encrypted: i=2; AJvYcCXR3cGFKlD/AG8NjPUaUXpcoDlM+Y4uEG1kTUiUazspDJmKxhfiyEBBAzImmQtUNN5a4s/zeWznnJcorH1cfPqhCQGurdU0I5uj199k3g== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id e26-20020a50a69a000000b005639620ab6dsi358562edc.350.2024.02.14.14.04.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 14:04:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-66021-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@sent.com header.s=fm3 header.b=Sd+c9faY; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=Xkqa1QfF; arc=pass (i=1 spf=pass spfdomain=sent.com dkim=pass dkdomain=sent.com dkim=pass dkdomain=messagingengine.com dmarc=pass fromdomain=sent.com); spf=pass (google.com: domain of linux-kernel+bounces-66021-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66021-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sent.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 31B611F26E3A for ; Wed, 14 Feb 2024 22:04:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2645F14199D; Wed, 14 Feb 2024 22:04:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sent.com header.i=@sent.com header.b="Sd+c9faY"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Xkqa1QfF" Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A81C713F01D for ; Wed, 14 Feb 2024 22:04:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=66.111.4.28 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707948279; cv=none; b=jnpjw7IaeDUMSpJM5aQIasKGkGFVJThG34YHCmx6YrexZAFTwdkQchmNgzw6Q6GNnw8Yk7h+qChB8qyCRM0OyaYpc79CWXRLdZDirXsXXBRabOy7AQGWflm5y7ho2HP+Cbvm0Q+OlFWV0EIbv+mOm/QIuQ0nkJJmE3FDQaIUc/Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707948279; c=relaxed/simple; bh=yUf65XhFg19drgHy7Tb4+9uoq0ZDXxUWdKwSfrAbetc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UChuQls1Qc/I8pRERC2m3KdwebiHjRLUe5Hiif1EIhCCb/GNPAo/gzYpZee7sDqlNKMEncex1jLCwhD918GAwk+VLyEHefdhu5CwCzgtNAriD3JorXzpf+Yd1coDmMKOCe5P9O6Xzu7zs9NIiLj8K/X0TcOTbLRjrZvd4BSF3yc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sent.com; spf=pass smtp.mailfrom=sent.com; dkim=pass (2048-bit key) header.d=sent.com header.i=@sent.com header.b=Sd+c9faY; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Xkqa1QfF; arc=none smtp.client-ip=66.111.4.28 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sent.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit 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 --- 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); -- 2.43.0