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: 202249 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:c619:b0:108:e6aa:91d0 with SMTP id hn25csp652105dyb; Fri, 16 Feb 2024 09:06:31 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWfOVM9aKL46skoaLqFtf2NdDvSgv38+qa3ZXE/kwar1oVv48gx3QC0T2CMjEWZ2dKtzMg1y5NqCS9L2PaYK2S9MlusHg== X-Google-Smtp-Source: AGHT+IH1ESX+6Msdb1b++eCx5t2dJhVDWkPH+Yq21lrD17F7581bjqjD4F8VgvPcRZOqxtqqEt7Q X-Received: by 2002:a05:6870:c79a:b0:21a:4820:7fe2 with SMTP id dy26-20020a056870c79a00b0021a48207fe2mr4061226oab.35.1708103191560; Fri, 16 Feb 2024 09:06:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708103191; cv=pass; d=google.com; s=arc-20160816; b=jCVaQETpahzW2bthj+FG0gj7MnN/17rajgUKkxAjI0Kknl5rL7oDmXp8mTRM7SfooZ gQj/T09cWL57V7wu9dh8kDA/jtV/JaU582j/4jaykN83fjTCieksF/FTuZVLNTLURuh0 /8fVjU2dSDCqID+v7G/aRjl2vE++HBLy1C3KDdaZc84LI3Yfh8hYqDvcT4+z5IjaoTFX seCqkL1SytbsYPkZnwZprSG67RUiXLl4uZHDsbynZkk+8voln/ANhZd4Fqttv6pwoA3c wk6+vPnzXscXXMXTlfCybO7E0/gRdvRksPtoltb/1Mv8XIYeR9sP1eigR0vwyONQYhMt EHOg== 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=+doHrWMX2AVjOxCrYcWaACj3dxXZqOZangVROH6gYto=; fh=vJ0CYzlC3FzFcxY+JvdHzizIe8XjzG5USPt1Sa6qsGI=; b=UhA+0j+6xjmIyDArrlL+6wH0c786L+MUkK/jjEO2MEAcFUZIsb9mLla24Cr4dl4jdS oRwesF6MBk7C4l43evzHKgOkDl960EW/ajEMKeV3cllERB+T0xKnrWY4vNTwnV0fPVhU pd4/EWd8+SvAPPqJAlOWffUtqv05eAmSJjnsRof5wZOpxvFuxG5dQf6CTzup0ZTBmpBJ OiYF9ozxz0l2EZwdiohscyk9t2dlwUPel7IGQwPsnt0zNv+ywlPBGh2RV0O4CQN/MnW4 +Biq9PNoddq62QVKsxFb5YjJRoUsMWyN+8aarvakOp+bd1+Mrb65T1uDLx7oB0GnNjT0 3p3w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sent.com header.s=fm1 header.b=ko4K3rk2; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=qgfQCRP5; 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-69014-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69014-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 v7-20020a056102226700b0046ece3b15a3si77600vsd.112.2024.02.16.09.06.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 09:06:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69014-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=fm1 header.b=ko4K3rk2; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=qgfQCRP5; 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-69014-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69014-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 CC8B21C21296 for ; Fri, 16 Feb 2024 17:05:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 567931332B1; Fri, 16 Feb 2024 17:04:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sent.com header.i=@sent.com header.b="ko4K3rk2"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="qgfQCRP5" Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) (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 89D7C130E59 for ; Fri, 16 Feb 2024 17:04:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=66.111.4.25 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708103093; cv=none; b=l5k6Tb9Xi2KZyid4r/06rfLFTUQc4AIEAKrupxj7kHrSdZ6NAq6jxYMNEI3IZPeGnh4Po1PKEq9MVwzGFCzjYvNs98NOC+tDpvRsxj41URSWEBfNrzFRak3OQvrE61fcnL3axwvMijv366GGpiGwBaDVDGqSOh/+Oe7duPk2B7Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708103093; c=relaxed/simple; bh=pHij3X8JOVWOkfWCWqtjgbkOy9WQpzuTbSOzombxQTo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=u2fL4i8k4LWSqp++ijJnoSXFPZIPWGQzmUFkYDoSwkvj2gjFrreGla26lcNA/l5XEP8PBjPNko3FlSL2+sFIjPI4sgUIVf1v5Ow1TOA0d8lXY/eKsPdHF3U71cRC1s1LAmFgTbyYSiUDAc1VwkcQAZtM7WuZBh02IBPds+zhSn0= 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=ko4K3rk2; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=qgfQCRP5; arc=none smtp.client-ip=66.111.4.25 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 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 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: 1791076012154793171 X-GMAIL-MSGID: 1791076012154793171 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);