From patchwork Wed Feb 14 22:04:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13557109 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 12ACEC48BEB for ; Wed, 14 Feb 2024 22:04:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 129C38D0019; Wed, 14 Feb 2024 17:04:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0DCBC8D0001; Wed, 14 Feb 2024 17:04:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E94E28D0019; Wed, 14 Feb 2024 17:04:41 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id DB1428D0001 for ; Wed, 14 Feb 2024 17:04:41 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 827651A05D4 for ; Wed, 14 Feb 2024 22:04:41 +0000 (UTC) X-FDA: 81791789562.07.DA97078 Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) by imf12.hostedemail.com (Postfix) with ESMTP id 5B8BA4001B for ; Wed, 14 Feb 2024 22:04:39 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=sent.com header.s=fm3 header.b=TYVPJiuB; dkim=pass header.d=messagingengine.com header.s=fm3 header.b=HqHud2bg; dmarc=pass (policy=none) header.from=sent.com; spf=pass (imf12.hostedemail.com: domain of zi.yan@sent.com designates 66.111.4.28 as permitted sender) smtp.mailfrom=zi.yan@sent.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707948279; a=rsa-sha256; cv=none; b=edcThI2P/QxyshD2OMg5X4xFanHdWlqkju6uQkfpGy6xvZ0vXDPQ2hRpeBl3p0G1B8wEmA Dya3h7muPcztbGi0RtxMUsX1IlZCvWkrmTgIJkzvlTSP8Hzip+swPBtFI71wUEpuDWbQ6p /imO2xtNzwL424lmOZ/RPnSzAHhfKdM= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=sent.com header.s=fm3 header.b=TYVPJiuB; dkim=pass header.d=messagingengine.com header.s=fm3 header.b=HqHud2bg; dmarc=pass (policy=none) header.from=sent.com; spf=pass (imf12.hostedemail.com: domain of zi.yan@sent.com designates 66.111.4.28 as permitted sender) smtp.mailfrom=zi.yan@sent.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707948279; 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=wQXk9BjzfNbSk+TtQUdIPTBzuKrc4Uz9jkx3jsjH0ns=; b=3EKsFKjcgwW8yxrtN5RbMr+52Xk9gXfKOh7YEJhKocwIoCHzJOzZvrVX6vrA+N+C8vu3zr 6Oml4MlBtXJzClIl9p6VaRtbHbpEOEb3A1Zb9pffxcl8n0XHhd6YCWx/aI03xuap0Rxk4C JL1g7Iji9Xj88oywgqBXtdFIKM/UZ/c= Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id A39FC5C0086; Wed, 14 Feb 2024 17:04:38 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Wed, 14 Feb 2024 17:04:38 -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= 1707948278; x=1708034678; bh=wQXk9BjzfNbSk+TtQUdIPTBzuKrc4Uz9jkx 3jsjH0ns=; b=TYVPJiuB1JXeQIw8A86L+E6UEI1u4J6XAa1bTxbdRDxlLKK6T9f 1SKgzazMOLcJAFUvzSSe18CwB8JAk2lGIinVMXUswOyaPYyU9MKcZ/0gUG64DlE+ iotkdloZi8W6SU2CDx3DdY7EyzM4xvyJVxZZXLb5ff1heJw+9iG2AHeNEz3Vm3lj KYJcFrSuBUbv53jyQs8E7fCmqs9LxBVjqDdldFm5CkZF1muz32jl8CoUn1UbTF70 Hpfr5MD9QtU/YpuKYeeNKkTfxw9sVc1pVyr+UFOYioNEyEBUrSfbC7kgo2FHy2eA O++9ITQ1VvlZC0PuQw3c7pKO3pQV4eCgbeg== 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= 1707948278; x=1708034678; bh=wQXk9BjzfNbSk+TtQUdIPTBzuKrc4Uz9jkx 3jsjH0ns=; b=HqHud2bgtxbuleg7JIQcX/6DijCsT84RWDVT6WNJueqIH8OoZz5 QHc0wZ5e0+c0P8e1gDZj/PLns77lLJU3OurXalw7lsCU4Ozff3kzIBlFICbROKz5 Wr63YF3Tp0rb5FvwOHBYA3QDMQpVhypJkSEx/uO5DTSDYRpsgdmNIP3pslQiQaDX R7ja2MceSRwLgMR0gMRqB/E973AYvLWD9U7gB4OECl3nI5kGjlQtFHMREofZCpAt fMzWhn4bnRDdT0k6lOwItkdiP264YIQXALVJgNDiwRHlAiyu1Ka+tknWutKzxjcG aEzhxaMbrq/v1MZr5B2/dFn5qCJbKuW35jg== 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:37 -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 3/3] mm/compaction: optimize >0 order folio compaction with free page split. Date: Wed, 14 Feb 2024 17:04:20 -0500 Message-ID: <20240214220420.1229173-4-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 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 5B8BA4001B X-Stat-Signature: 4owi37f3oyu1jgk4wwkwmwxg66rgxx7q X-HE-Tag: 1707948279-304595 X-HE-Meta: U2FsdG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dxrG0b60p8HATmOXvJ/Cx9Aag9txPKCtF3mkySLheMJtdKGdZ3oRRxWcdmUQmHt4BD3nqbMkYhHwh3oSt8JJKj/o4jhdGwWeYDQ8cvZxdZlvQ5DdxkktjO0Aeu/Tr7CWef9k7G9Hu/Ac7DQTPKG8ucuV3O4FOVuJcsIC5dUFJxaArcigDyu4n1sGlr7SHAxGRTqtHdMSaoOL9/i8QJ8aRzHxl2GqKV3K6jeM3Izxi2Ji56QLpeDXoL5iEo0T96gUEi8Snqzry7bMU64g+PceVpeiOMj5jplfEMN8x0MJo08ckDcIagnD7mEP0GpIlH/y9sSc2N+VTyPkXd157Y1KqkK9z41BdrmLDYxAd5JaFRuT8RRuW+G+ZVA5buoJBmCR8/N1+lc0hG25J+Y4e4jDOPL1vQNG7l596y+Kmi9ldoNaFA7xGqAdbBwpGc2+nwdlsrBRFZQVZEZgm4h0CD4YujwcFqSeJ7e3gGBCe3dOS0JBcmkhI47vnTNxMwPhhWQ9Q3zpvFti0d/Ok+wyGRlFHqAwEMStIAsdmm/IclmksxKPi9M63SMK4GtUPQqO6XiGhc5C7kXROauznKWUD9hKW+uxTzDp2ffO2AxgzIaETPu2yw42QDFmO+665OsGIp34LWRV0hdPu8RdkK8KQebLU/THZVTWGsjTjlHU6sNShsk/NkadmtyA1k5YBD670tUHEzwQYkEIpNX9Ma5sQfXKgPgzdM9i9IjkBONJ5d2b5mso0uTISpefrQmCnn/TaO15ZjvSdP9QLlM32HBdfn3NW65jtErP918NVZT1O5nRdt6z0/5IfFOSjuVI9MAcoKQJT6N+Z3IMEeqgFavl7QJVIAwb4/MsZokNjTYVrl+nYt1SD 4cStNqwu 8LlY2NyoLGAtSCimsVLTS5hBt8rPHb1D 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 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 Reviewed-by: Vlastimil Babka --- mm/compaction.c | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index d0a05a621b67..b261c5f13bef 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);