From patchwork Fri Feb 16 17:04:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13560348 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 5F7E9C48260 for ; Fri, 16 Feb 2024 17:04:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 539C58D0017; Fri, 16 Feb 2024 12:04:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4EA738D0002; Fri, 16 Feb 2024 12:04:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 33CAD8D0017; Fri, 16 Feb 2024 12:04:54 -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 19D378D0002 for ; Fri, 16 Feb 2024 12:04:54 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id A6289402EE for ; Fri, 16 Feb 2024 17:04:53 +0000 (UTC) X-FDA: 81798291666.15.EE0B402 Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by imf03.hostedemail.com (Postfix) with ESMTP id 727AF2002E for ; Fri, 16 Feb 2024 17:04:51 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=sent.com header.s=fm1 header.b=ko4K3rk2; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=qgfQCRP5; spf=pass (imf03.hostedemail.com: domain of zi.yan@sent.com designates 66.111.4.25 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=1708103091; 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=+doHrWMX2AVjOxCrYcWaACj3dxXZqOZangVROH6gYto=; b=IvFn8F2bZFdLVO1BZHsRbGZKkdrvq52j+so6iynliGa2U6gS8b0m2Q+pg4weBx956CcbAb rCuJodDmibSFtgRn58/GJR5F6qcoVFDQ9KNCPy8GcjQBASGH7h/ei1hd0FVU/kTE3brq5n IGqdaURzpBr9ZtWt6fjUX71TBmhXwNU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708103091; a=rsa-sha256; cv=none; b=XX3YlHQVAJbdQS1J54ryJ01DY1/N8U5FZIlxi8Sj8pGqIxvlqk0k2ynoSAwfdmb8LokvMV wrcXnJfP1nWEg/0KUbSoaKrKgTpGgakK7AWaT7FzuErj7GQKX5lAc/yJjM6ig2Dm4tIZy1 gUXDpLMpMEKFAAcN3B1IuTuDv5tjYVA= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=sent.com header.s=fm1 header.b=ko4K3rk2; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=qgfQCRP5; spf=pass (imf03.hostedemail.com: domain of zi.yan@sent.com designates 66.111.4.25 as permitted sender) smtp.mailfrom=zi.yan@sent.com; dmarc=pass (policy=none) header.from=sent.com Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id A355E5C009C; Fri, 16 Feb 2024 12:04:50 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Fri, 16 Feb 2024 12:04:50 -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=fm1; t= 1708103090; x=1708189490; bh=+doHrWMX2AVjOxCrYcWaACj3dxXZqOZangV ROH6gYto=; b=ko4K3rk2g+mrEQbTGfvy/IoeGbtndA10HCmGrX6ZBtcKPPtBtmT 9LaRVxlDcb81bTq/B6JKEfTj0gCUyY/09qsnrLNmSWu0fJfzBKl+r+N7hGehbV2D 7joQdvSWDxEWjTYywpwgts3JDLO1Bnxgs4q7zjVkES4oSRsGHAO0evn2ipnoUiWT CTwaQqhvmPadH8fnZ5lZNN+TTjPTka0U7WHOirLr97H9oJHc74BbEb8hFUT1i/S1 gNau3uupUOetpVvyVlkyGiGoQC5dCqDAnfQMdDvkpl7LjzKLvqHyVKdnUvJhOTwI LJ/ofpw/r5sFrWKmzvfDXYaZMDGoqyJUFmg== 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=fm1; t= 1708103090; x=1708189490; bh=+doHrWMX2AVjOxCrYcWaACj3dxXZqOZangV ROH6gYto=; b=qgfQCRP5yc+VoPEksHSAB8Efae6JHt8FyDzmpfmb6aE6OVR6fsu o58jzMAEDbkzYZWozsaSClSp7LCI2wa0UkI/tXVALveXxZMu7PlLvcMoD3ZFAuhI x+tK9PYeHp0r6IZJ9kOf6w85wl/wUXQqSCy24i4jrrEiyFQWhKT9w+ZXeOr9J7wa HobdQOTKH6m77luNHiVbfb11c7ETZCjpMV48bpe5gxJAD794fI4itPyVDw6/FnOj 0jYPhx++z0pZe5cvQFcxm2ZVhKJm99zbJHuQxIz7MdYqVzPe3TZ2Fr6CW1zM7kqf Kl7OHb4N/oW3SF9IzhZ0BWfYSwN7Qrge5Ew== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddvgdeliecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvfevufffkffojghfrhggtgfgsehtkeertdertdejnecuhfhrohhmpegkihcu jggrnhcuoeiiihdrhigrnhesshgvnhhtrdgtohhmqeenucggtffrrghtthgvrhhnpeejke etkeffleelkeduffdtfedvtdejjeeutdeutdetgeejgfevtdefudejkeeiveenucevlhhu shhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpeiiihdrhigrnhessh gvnhhtrdgtohhm X-ME-Proxy: Feedback-ID: iccd040f4:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 16 Feb 2024 12:04:47 -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 v6 2/4] mm/compaction: enable compacting >0 order folios. Date: Fri, 16 Feb 2024 12:04:30 -0500 Message-ID: <20240216170432.1268753-3-zi.yan@sent.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240216170432.1268753-1-zi.yan@sent.com> References: <20240216170432.1268753-1-zi.yan@sent.com> Reply-To: Zi Yan MIME-Version: 1.0 X-Rspamd-Queue-Id: 727AF2002E X-Rspam-User: X-Stat-Signature: rh771hrgipikc3p64t9ka3uyt6aixd6n X-Rspamd-Server: rspam03 X-HE-Tag: 1708103091-4460 X-HE-Meta: U2FsdGVkX18splZvmQfo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xpxNSXP0D664Z33jHVq04iIjt/bLMCwDL1uUZq7uQJP8bV+HHOeMpiYZ6SrDo+M/a1XAe8ke/3A9BIVQQ== 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 Reviewed-by: Vlastimil Babka 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);