From patchwork Tue Jan 23 03:46:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 190700 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2553:b0:103:945f:af90 with SMTP id p19csp104341dyi; Mon, 22 Jan 2024 19:47:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IGf6nmFMUMjU2uaIM8fLMgjMLZ/GQqhff5xFDCEHr8JCkMo/OZAblBlu1MUuOcY9PQUDgj+ X-Received: by 2002:a05:620a:6219:b0:783:2c2e:3c7f with SMTP id ou25-20020a05620a621900b007832c2e3c7fmr5853675qkn.140.1705981675934; Mon, 22 Jan 2024 19:47:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705981675; cv=pass; d=google.com; s=arc-20160816; b=rp+/xXEaWovP4DTfUePPKTdZfl00xFc0c3r6S0lLbhiBzICsRUyoaZgbxX6rxN83Xx SAAN0vg2SxIbsqZ9LHvUPJqpsFu9e7bfPEDaJPxkN+4SbTiVks8N9gttSLJkSMF5F380 f6dDLwfy8GBqFFjkhnjvVbc0EMdbzRoCeXtThorC8topvDRNK7z/bYdsM2EihF4WA95e PX6eO9Hk+IH6040+hpq0drRPgxzqq108SHiJliMGNbndVbEghXVOsMrnF/6/83rQwEio mEsQkCFMY/3/Qn23mU9Rm7JcydKPrJXBz4fdC1D0BwMDu8AyJJoWuWSqrNVHYAlH6U4e 950g== 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=mC6ae0v7zXTnCM6lhVafmauC3M7j0hzzYKYZ+UScLOA=; fh=vJ0CYzlC3FzFcxY+JvdHzizIe8XjzG5USPt1Sa6qsGI=; b=sSsP55/BBiSpygV8JP46ouVI75qOFBgweKBwr2Vk6x60kZOuUpeOCkfHh2cQ57jTGM Sa8eS6yalAre/qpwuD7fqGtT6oE+pVmxtP55dGVmU1WKmcb+BYND7PmmOvKGlvnpvwmG 6CeT8OYNCVMQ2AuPgCRbdGNS+9newDFcWY72ve5NX3bpUPaEIvwhpk1mSh/VJkMdDCbg ejJDm7LHScXoIYEE7TY/YlWlMsFIunkn9JisvQekeiFid7zIuyLe1aIUuFvztx5IfkqZ MZTFUGuAzr3NvT91g8sAjGlhe2VI3aGbffmZAKIpw/WdB9vtjTsxgfdkvwJnz1s6UhRs SOaA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sent.com header.s=fm3 header.b=R8JVod3l; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=IBydtwlk; 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-34688-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34688-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sent.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id a20-20020a05620a125400b0078344669c37si7006622qkl.61.2024.01.22.19.47.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 19:47:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-34688-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@sent.com header.s=fm3 header.b=R8JVod3l; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=IBydtwlk; 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-34688-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34688-ouuuleilei=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id A788D1C26549 for ; Tue, 23 Jan 2024 03:47:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C9238469F; Tue, 23 Jan 2024 03:47:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sent.com header.i=@sent.com header.b="R8JVod3l"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="IBydtwlk" Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) (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 E317315C6 for ; Tue, 23 Jan 2024 03:47:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=66.111.4.26 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705981631; cv=none; b=Kbgshmf1TGeKdjgAwb3EzB5vJ8TYBPnzRcEhko1yd7cuHyQF3SnKC1B+vBrIXcTu9+7dyk5KlQezCI6J2fC6FxF8H3rUl3gfVK+nXwuEzjiI72AHLysNNqnVw5UFL300u3bLNreb9L782ij7yRK91XJhkazgOLiX3VEoCjPLwrE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705981631; c=relaxed/simple; bh=oh4apvSWdmMkF18+DQ+QPTbHpZZBWwkxm6XwqLBEwxY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QQCqCb5iGsHodmNFUZzQINCDok6SMR4MYWJfq/KhxjZzBY0JDMDBEGtiWb4OIeGo2ODgHowx7H4s0SkNvjvQ9fWqkyXvYJg6MsvT2t6FaQNLt7VKSqRROB+WMZuw86b13f/RDSMIFfMQV1gVZreIbbubeBG+kG9wXsvSntMzQjE= 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=R8JVod3l; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=IBydtwlk; arc=none smtp.client-ip=66.111.4.26 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 compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 39D365C0051; Mon, 22 Jan 2024 22:47:08 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Mon, 22 Jan 2024 22:47:08 -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= 1705981628; x=1706068028; bh=mC6ae0v7zXTnCM6lhVafmauC3M7j0hzzYKY Z+UScLOA=; b=R8JVod3laPmb7g1HLtsYlFfqWul2+VE2dg3TQlgwT3R5cPWzbis EcZkF+hmp86rGEd6ibctWpwxhzerM8OsVEvs8/Yr7HA2RWvxe5b/xrq9zwUNS1v0 M+3wVSTD3eNLrED3w2G/ZM11O/jyeLhf4wpxkT2sj/0sAvg6aV5v/xfC9d/a/GIb ZhvssWRXPSwph6Pa+atCSApUSwUwXuDD3A3AHJoU47PAenkdkURR0GUOL3lP1ESt KiaVNtVpqEn6hTgDmbV5hR4iRI+EK0UblW3Wmha4wPSd2tFEoITwM1H/4dSAzz03 zrv6xTwoQ5uE1MVN4SEtipS+r/RHpdCMb+w== 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= 1705981628; x=1706068028; bh=mC6ae0v7zXTnCM6lhVafmauC3M7j0hzzYKY Z+UScLOA=; b=IBydtwlk9+lvDYtAAJ8KD4EgF1URCX6jmKxJV6kJUZZylFudmUa t1e68onsyFym0E8LQt6q7fsJmxputLlJh3XVYp+jur7Rgu5X9nJ1Aah2n11OySOn sTM/yRuXWY8cxihEUQ/3YKiKxkPIQW34g0OPQfdl5WANkeINHBkhstCX3BhkVqiP QadejVULEhjzkZefAcGBCUkuXc7eR3JG1RPFORj3VMvhseq0fKGrlnRh2KbpH5EG 513h2uRqcBY6KSIuB3oT5mlYXULKr0YMFmL1HLV4St0SVYsPnbkQsJ+vVGEziMlu LXUi1kNb69FU+PBU8baYumXkx+AaZd1gq/Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrvdekjedgieduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhhrgggtgfesthekredtredtjeenucfhrhhomhepkghi ucgjrghnuceoiihirdihrghnsehsvghnthdrtghomheqnecuggftrfgrthhtvghrnhepje ekteekffelleekudfftdefvddtjeejuedtuedtteegjefgvedtfedujeekieevnecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepiihirdihrghnse hsvghnthdrtghomh X-ME-Proxy: Feedback-ID: iccd040f4:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 22 Jan 2024 22:47:07 -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 v2 1/3] mm/compaction: enable compacting >0 order folios. Date: Mon, 22 Jan 2024 22:46:33 -0500 Message-ID: <20240123034636.1095672-2-zi.yan@sent.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240123034636.1095672-1-zi.yan@sent.com> References: <20240123034636.1095672-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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788851441678627291 X-GMAIL-MSGID: 1788851441678627291 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 Reviewed-by: Baolin Wang --- mm/compaction.c | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index 27ada42924d5..61389540e1f1 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 @@ -1009,7 +1024,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. @@ -1017,11 +1032,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; } /* @@ -1146,10 +1168,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); @@ -1767,6 +1790,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);