From patchwork Fri Feb 16 17:04:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13560350 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 A52B7C48260 for ; Fri, 16 Feb 2024 17:05:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BCB358D001A; Fri, 16 Feb 2024 12:04:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B79888D0002; Fri, 16 Feb 2024 12:04:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9CC568D001A; Fri, 16 Feb 2024 12:04:57 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 88D7D8D0002 for ; Fri, 16 Feb 2024 12:04:57 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 5668D80118 for ; Fri, 16 Feb 2024 17:04:57 +0000 (UTC) X-FDA: 81798291834.26.5BE91FC Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by imf15.hostedemail.com (Postfix) with ESMTP id 0BE61A0029 for ; Fri, 16 Feb 2024 17:04:54 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=sent.com header.s=fm1 header.b=Qh+SFOC2; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=hrjQmkGw; spf=pass (imf15.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=1708103095; 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=bTCMfMRgj0TAxiQeyNSNVpFoxlWh0Oj72NH6xXdaFx0=; b=4cZVKefAaKZRqefgDTTCsyMPMMkSs67WwFL7VdfqddZSW3X93lIyMTIox2ilXPNxeqh2Sc 4NS/aLgnW2shFGetVZb6d9G/c8aRX3n0WR/cU8auv7zzy+BaGS9PyCnDnctDrUIHfo3tfA y7bHrhbkgYScerIlN5WZ2kwwfP7YqIo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708103095; a=rsa-sha256; cv=none; b=F90NiuwKb4ogo9+Rnp54gsft7VEp5HaqVI4g29hH0JQQg+mJAaiVOqNWz8RB9JHR6Kn5sF lJvF4W2M0B3AvjhNcecbSGOD6Gt0ZdGHHhInUWH+DZFWtACZL5ROGOCTLLW2n7J3RVt9Dd VMP8zVT5pvfOddAljGUe1WnqWPx6pH0= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=sent.com header.s=fm1 header.b=Qh+SFOC2; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=hrjQmkGw; spf=pass (imf15.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 compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 4C4285C00A3; Fri, 16 Feb 2024 12:04:54 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Fri, 16 Feb 2024 12:04:54 -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= 1708103094; x=1708189494; bh=bTCMfMRgj0TAxiQeyNSNVpFoxlWh0Oj72NH 6xXdaFx0=; b=Qh+SFOC2uzfXFBf2MQSyLCdE/iSEti9OEl50htzixNEhyH3p6uD ttorsdTatpDLJct9xYK/4M3p/v7LE26pEawkhX7e/2gw/IgIzs+ZnS0OlP6lk+GM ky8YC+gWiiRpMIiUyVUI440RtoKFFQL6F3XF/7jnQTCtljg5jUe8YyQDVCwSs2X0 EiaOz0v44hVK/fl2b4G4CGshkV4t5MDCSjUGswZ2+MZXyZCka1nlMw/+KtnzqqMb bRnU1jjZCdIibwvZ3ewjRHaciWMNXBOY5T5oWefeQM53QEmyjbNvjT09kiFL+KHE MK3s+71oUT9iXOSHIQqrV9Pigpngwe7lufQ== 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= 1708103094; x=1708189494; bh=bTCMfMRgj0TAxiQeyNSNVpFoxlWh0Oj72NH 6xXdaFx0=; b=hrjQmkGwrw/QsZ5Oscv5eFQex/wKIva4wZWzZZTaY8WxwPrCbpL /ZEs1k6WWt/DCUHTPsxn+xV/sxbFuyc/GeRxj0F+KqJKqsHAdfouZeJPYmbY3Llc qFDPmgp0dlEjvCp0JEAVVMc7CTuB4tudRrtgDKZQNbEDGajyQl7TZbpmBYzOK2AN +R8PjACg5jv+jcaXiSiRoegIQsH6NxUP8XFWTtzFS6HWHrSqvz589A1OuKpQ5i50 n3BqTWs+bOWlfzAO30MSVhbfDDlzGhM5UXXuob7GZAgXH9cPTf8pucGiIF2vUIRf sMR7aFPAF37x1XJ6C+uErmm2LAwmQQ172bg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddvgdelhecutefuodetggdotefrodftvf 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:52 -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 4/4] mm/compaction: optimize >0 order folio compaction with free page split. Date: Fri, 16 Feb 2024 12:04:32 -0500 Message-ID: <20240216170432.1268753-5-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-Stat-Signature: i1ro5i9fxkqxeubpb1jfop81pp1hnk1f X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 0BE61A0029 X-Rspam-User: X-HE-Tag: 1708103094-806610 X-HE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EoN1hU1nCmIsOnk4BHm5sxbSydoqD0q+mP7sL0N6DGfrqtaRyhtwAOvYwkWM/bpvoZvBEb82JJDPuvQtA6yr2XHn3u5N6J1gsfd4Ww9vV+uW3vuHDUQUXCwRYsCQNUciHpccJefhVExNV8QBiU/g2JpjVUsT6vjQNVT5hdz7eW6Wr3ISiImA/L9Xu3sCvX6L9FHIzpbbohytT/+5X2kgbWBm/pOTNunaiRYTA5ECR3uQlNO3a7m/trCCkSgw914XN7c2iI54CzDjKtV78WNFfDq671DgdYYsyR2yvMrdo78hZFW0uBgPXtnLTG4aL4BjjO05rnOMRgFAlZmG+Y7As9iDrrrx9+dISpyuDZ55xkKobZmZHxUXY93ud0WGEDitr+Gmzn7gDA37zowEZ6AFXjXxZ/zD78rjO7Hz8BU+FiyfHtQj68uH5hSQB5Gt25Wv071Y2gMhxVXJAai/aTlbmxv4WVUWxBGS7JChzyWQt3AxVMz0anawvXPe+MtVW6ZEgc4Wl/KU10A0IkE1k1e/tHCDvDh3O4DvQVbi/s0MUA/t1EbANulDyEHVUlM/dr8OzFe5T+IhAaztOBhMh3RV1484ux2Mdwrdd3vkm234Dyq1pvAobD+T1JLAqFzrURX2uCMRSAjq5Lj4Gi1dGiZg1DueZNedg0qXwz+sWlKZKImWIaFAVXy89RzNExXTRIuqEhRgThtuspN9yKazTELKWT90PJ7jp9sRG1wvLyzHkywfylYv4kNNHGygH2RdtKLojftvkLLAqsEHa4At5UVvqSUJVG5OSlnkeCHxqy711UYaPBfwCExqgdwyKseln1Kp+NVR8P8kr7LGt4kBNtIchkQBDx0oRy33GeTma2SjXZ6/rcP6+AMB8sv+mhmVXpy7HMTvV25b YVdsDmLx DzE2xGln2667+S8UjOpcd76pReDGkJa5 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 During migration in a memory compaction, free pages are placed in an array of page lists based on their order. But the desired free page order (i.e., the order of a source page) might not be always present, thus leading to migration failures and premature compaction termination. Split a high order free pages when source migration page has a lower order to increase migration successful rate. Note: merging free pages when a migration fails and a lower order free page is returned via compaction_free() is possible, but there is too much work. Since the free pages are not buddy pages, it is hard to identify these free pages using existing PFN-based page merging algorithm. Signed-off-by: Zi Yan Reviewed-by: Baolin Wang Reviewed-by: Vlastimil Babka Tested-by: Baolin Wang Tested-by: Yu Zhao Cc: Adam Manzanares Cc: David Hildenbrand Cc: Huang Ying 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 | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index f21836ca243a..b2a570e00a8e 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -1832,15 +1832,40 @@ static struct folio *compaction_alloc(struct folio *src, unsigned long data) struct compact_control *cc = (struct compact_control *)data; struct folio *dst; int order = folio_order(src); + bool has_isolated_pages = false; + int start_order; + struct page *freepage; + unsigned long size; + +again: + for (start_order = order; start_order < NR_PAGE_ORDERS; start_order++) + if (!list_empty(&cc->freepages[start_order])) + break; - if (list_empty(&cc->freepages[order])) { - isolate_freepages(cc); - if (list_empty(&cc->freepages[order])) + /* no free pages in the list */ + if (start_order == NR_PAGE_ORDERS) { + if (has_isolated_pages) return NULL; + isolate_freepages(cc); + has_isolated_pages = true; + goto again; + } + + freepage = list_first_entry(&cc->freepages[start_order], struct page, + lru); + size = 1 << start_order; + + list_del(&freepage->lru); + + while (start_order > order) { + start_order--; + size >>= 1; + + list_add(&freepage[size].lru, &cc->freepages[start_order]); + set_page_private(&freepage[size], start_order); } + dst = (struct folio *)freepage; - dst = list_first_entry(&cc->freepages[order], struct folio, lru); - list_del(&dst->lru); post_alloc_hook(&dst->page, order, __GFP_MOVABLE); if (order) prep_compound_page(&dst->page, order);