From patchwork Mon Feb 12 16:35:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13553622 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 0F70EC4829C for ; Mon, 12 Feb 2024 16:35:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 139CD8D0006; Mon, 12 Feb 2024 11:35:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0E9368D0001; Mon, 12 Feb 2024 11:35:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E7F578D0006; Mon, 12 Feb 2024 11:35:20 -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 D8BF38D0001 for ; Mon, 12 Feb 2024 11:35:20 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id A84C7A137A for ; Mon, 12 Feb 2024 16:35:20 +0000 (UTC) X-FDA: 81783702000.23.506A4FE Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by imf11.hostedemail.com (Postfix) with ESMTP id 52ECC40014 for ; Mon, 12 Feb 2024 16:35:18 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=sent.com header.s=fm3 header.b=HlmOQr9q; dkim=pass header.d=messagingengine.com header.s=fm3 header.b=J2YOywBV; dmarc=pass (policy=none) header.from=sent.com; spf=pass (imf11.hostedemail.com: domain of zi.yan@sent.com designates 66.111.4.27 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=1707755718; 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=/EqPdua3wUu7egs9hj3joQyCeB5KILvG5+17pYfAKJw=; b=ao+4JGgWSx9UmfbheG+EHDEpG3z18GFCJV/NSFtn8JqJHwTLQoIsoqw1DibkZOwhsv1fz5 bw2SfqYjRjV1iRBaHjyY33VQ7c2jHCL0oTWzlW5vmNZW9z4WQvmiLMMGyNtB9fivaxOWpz Oj6Q5SoIDZj9nmDjq0AXOY1DawR5iFY= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=sent.com header.s=fm3 header.b=HlmOQr9q; dkim=pass header.d=messagingengine.com header.s=fm3 header.b=J2YOywBV; dmarc=pass (policy=none) header.from=sent.com; spf=pass (imf11.hostedemail.com: domain of zi.yan@sent.com designates 66.111.4.27 as permitted sender) smtp.mailfrom=zi.yan@sent.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707755718; a=rsa-sha256; cv=none; b=4CmhGgGcW/5xS2i2BDnxNLXhZ8BGUJ815YWJg246nXD2SwqTrT3RUz8Ywr1plj5Qjf+/jX qwkos5y9+oDhoNn7KgpQva2fXXXeAeE00wiDiEeSE5IMbUvZ68N5zF93NxLdUQlwqKMBK5 zZ4xtKv+davhT9UesvwAC4DibnXWxgw= Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 8F20A5C00CA; Mon, 12 Feb 2024 11:35:17 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Mon, 12 Feb 2024 11:35:17 -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= 1707755717; x=1707842117; bh=/EqPdua3wUu7egs9hj3joQyCeB5KILvG5+1 7pYfAKJw=; b=HlmOQr9qvHE0N6b7r3vJLZNcb3UVrG8RUx4z6QwPWhLBya5sAT9 V/S8Zqpwle9MkAqKRpupK3V2y9nYsva6hSKmft+SWN0zTIoSACDHPIyodradZMjy g+GChb5rZTZ44gfLzd7CUhTC0ssGdm7FJ4mYXHBBtjFA0hDoYMWCuOFobhFSSMaK my8JWVzC16TrYyZO0HNWwVqcee9zpknq/X4JA2fQlF2BU5e2k/PCfbhgTnkzNt2i 2hZBq9/vVwdpRqc9Jw3Ba02aMdxcuP6xjPriauzPyPw+VO5OH8Q9t/KqKNte/okX gxJiwWJoFaUX3BdyN2TVc42jIOZnVCM3oNg== 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= 1707755717; x=1707842117; bh=/EqPdua3wUu7egs9hj3joQyCeB5KILvG5+1 7pYfAKJw=; b=J2YOywBVYcHvZh7SL9Ztx6GaM3mrxWauzT0f5e3Y4/dspDxc67z 0VnElepBVZ/VU9ofd0CW9IdSk+E7tGKMbk72o8MDHt4nIP/V3BV1+7XRh8zkGLZi Qwjkb6t/nNlSuJseIqlikcvWUbzFbWnXQJ+MheLqK7u1DlXuf28jrhHStz07sqFi 0GW/1LGHaNq5478fa5nBMOQpSzr6nmCKNpj7n/tRqAbB07H0Iwze+SKx5tyt2Blm H0L4gRsQaUbjFFUNrwbG1TrzHq5cqxNGBkLFKaCIgBOOftaOWtNkzNsfxoiCkguE JICNz/Blga59c1UaxavgBIMUYrtQMc6AtlA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudefgdekkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvfevufffkffojghfrhggtgfgsehtkeertdertdejnecuhfhrohhmpegkihcu jggrnhcuoeiiihdrhigrnhesshgvnhhtrdgtohhmqeenucggtffrrghtthgvrhhnpeejke etkeffleelkeduffdtfedvtdejjeeutdeutdetgeejgfevtdefudejkeeiveenucevlhhu shhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpeiiihdrhigrnhessh gvnhhtrdgtohhm X-ME-Proxy: Feedback-ID: iccd040f4:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 12 Feb 2024 11:35:16 -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 v4 3/3] mm/compaction: optimize >0 order folio compaction with free page split. Date: Mon, 12 Feb 2024 11:35:10 -0500 Message-ID: <20240212163510.859822-4-zi.yan@sent.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212163510.859822-1-zi.yan@sent.com> References: <20240212163510.859822-1-zi.yan@sent.com> Reply-To: Zi Yan MIME-Version: 1.0 X-Rspamd-Queue-Id: 52ECC40014 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: agniahda34ze11whitgxsiy6sryarw3q X-HE-Tag: 1707755718-303908 X-HE-Meta: U2FsdGVkX1/9L5+ebMP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KMCXs1r2CSHXZWHdXnEyg7y/jiNOKNO0GnhLjS7WU6VMED2Rai6V+Gb0ZkMuoonoJLyfeIYIkY2QyYxekCDAe6JFnJEqYnIxME9Vz9PMmwXyiKxZWaKXwgnR/0UgOUP0UQVEVPFiN2k7LVLx1uxcxgGE1fJYfK1zNg5x6Rlx2FXGLxy7C2tUF3N8V6JAnwJiIqYUEayLPkgKSwFjST5M5h9OpYuT96Xxw9McqcHuaX67etU5swZve78AexhLBq11h9XsTFe6/GCYlJO35NWmRonIQ3i5jIAa+18NJRyDw9DWaGLdpFtsGmBDkmFeDsQJUkikhyma8D4jfqstNaKhKGYyIy3raps1XHddv713yLDDoq6VjvdfP8dECR0ianiBj8vcE0F1xHjp6X7EKcnHd2lbUzeuL6bYl3+KV1ysWQDJ8kz9Jp4yM28qVMYjyF2Lb24mnnwrNIZ1wc5BAv/7nsqGy/geqYpT1kx0qyS50iID7UgWxcHl8k62EbCovvekm+jQn7i1kWuvf35ntzBd3Dv66ID6R/d/ewM5PgJu3fLUlOcOK5rX65u/AnMv2rIovzZE0q7KovooMxPaphqQQOwNo4ASQ0LBS0WHF8LQktm0tpgJx6WTH602a7qcvTJWSUma0Q7wdPb+C+PR9Rf+y3/130ZXhO+t+ZX+k6I+QGapu5c75fxU+34SC6kz7OFwzxwkacgqo9JY07EHrP9wAgFFeQ7jexrTxtJKnVqYfySVLmZn3xY1iOV+vfcUgvBPBfy6OOPIEGZhV2jcb5WnrUAFk2WRIzj27cAoTIIhK3I0jJH7Htosaupdkbq4UY0xkU6RpSSqxJhs+FeecoZLZ7NCuHzj9pjtTlqLFDEW9fdR1 XWDnkGH9 ZfNyGWDh+EF2KOX7cQ58ONKmAuDiT6Xz 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 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 Cc: Yu Zhao --- mm/compaction.c | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index d0a05a621b67..25908e36b97c 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -1832,15 +1832,41 @@ 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) { + isolate_freepages(cc); + has_isolated_pages = true; + goto again; + } else return NULL; } - dst = list_first_entry(&cc->freepages[order], struct folio, lru); - list_del(&dst->lru); + 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; + post_alloc_hook(&dst->page, order, __GFP_MOVABLE); if (order) prep_compound_page(&dst->page, order);