From patchwork Tue Feb 20 18:32: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: 13564336 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 1F810C54764 for ; Tue, 20 Feb 2024 18:32:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 981826B008A; Tue, 20 Feb 2024 13:32:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 908A56B008C; Tue, 20 Feb 2024 13:32:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 70E496B0092; Tue, 20 Feb 2024 13:32:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 544EF6B008A for ; Tue, 20 Feb 2024 13:32:54 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 342F84078A for ; Tue, 20 Feb 2024 18:32:54 +0000 (UTC) X-FDA: 81813028668.05.87DBDA0 Received: from wout3-smtp.messagingengine.com (wout3-smtp.messagingengine.com [64.147.123.19]) by imf11.hostedemail.com (Postfix) with ESMTP id 13DE14001C for ; Tue, 20 Feb 2024 18:32:51 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=sent.com header.s=fm1 header.b="C/BfFgk3"; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=Udaf3BFo; dmarc=pass (policy=none) header.from=sent.com; spf=pass (imf11.hostedemail.com: domain of zi.yan@sent.com designates 64.147.123.19 as permitted sender) smtp.mailfrom=zi.yan@sent.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708453972; a=rsa-sha256; cv=none; b=0WsxrJxKQ0eFqNodOFuR6MrUGP5jiffqm1NtN7Zar1AJ+gxSuWQnDQZ2xoqtK5jkVhSYgi rP6h2l5aZyGlwb2WE1XkwaQsPP944yeUTzasPXUWHpW5KB1MnKKctGkgz5kWTfRAWW+8oV JUUvwj1hZOie4/Ax24zfzKTQ1bH2nyg= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=sent.com header.s=fm1 header.b="C/BfFgk3"; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=Udaf3BFo; dmarc=pass (policy=none) header.from=sent.com; spf=pass (imf11.hostedemail.com: domain of zi.yan@sent.com designates 64.147.123.19 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=1708453972; 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=2I9yVROKB+W15mI+UpYHE5WhFE4737+G/6r8N16qHZk=; b=pQmC1sm+RnZ0XakiYJufyH6+Ip/w5D/mpPMdgzHelVb3+pHY84EeLZBE8u0A0xx6LVP5Z7 9KyCU1+rR/lfYzZvqZ1NEsHUp31mLJBotNUm26b9Ot0ZON1NNL6+4ckC+mMwjL+l9I1ecG PCM6u8yVrT6s3/uoTQFwqgy/W4SlDcs= Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 1454C3200A54; Tue, 20 Feb 2024 13:32:48 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Tue, 20 Feb 2024 13:32: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= 1708453968; x=1708540368; bh=2I9yVROKB+W15mI+UpYHE5WhFE4737+G/6r 8N16qHZk=; b=C/BfFgk39mofWJiQq1RU1DWERdAHjGqZ9CYe67lUaTnv4DkXexC JUgAvnAb0Geveu0vCR8Yc9SLyPMqyN/tNho4hPNJx4U/8p4TzIyaIc5OktmhEKCr br24aOTURhAPSOHXhberlecYH0+s+agkxnTKkHWM7EBjj9LkiJlmyvYIg9lYsb39 k1MC00poth8h21dF4zg8DknBjbZouWKEK9G0gXzDmEqPy/WYgcb5cbhSnBK3PxEU ezq4uAP4EnS/t7OdwAvx1gFmLzKX6+0I4E9AaHC+dQFzsxKKnCmseSrNxt7+pneX K8rOQO1BMHCdml1nFSal2TuN6nsalawNrtQ== 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= 1708453968; x=1708540368; bh=2I9yVROKB+W15mI+UpYHE5WhFE4737+G/6r 8N16qHZk=; b=Udaf3BFoiTXOq1ww31/D3N6rdbCeObxT1gXG2hXa5NBnQUEJ+p1 FrTz7sVN7TfskcfLfC8lvIg7uWLwAM4gKoGLGq5PDq1H3TzHRCOWn5eABFHaUPWP hRcLPmnjhUdWr7YgxaQgBvgIUqBEFq8sUmNuaeI6CvWUaUlfr3eaIw45CIHpesDM Na1wRUkDZmVVdMvqma3brYOhrSvHyQgVMba8K8fiGYgkM1qfP2v3zaZpIaOApfNj XL6QJvDFvWitaPcbo8lJ/oJtMrlxWiFEHifseopH2PWBynBXM9l0160t+59lzuIK WRXy6u9dxKaJeE4fNamBvXRDfWPNYrzk+uA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrfedtgdduudehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhhrgggtgfesthekredtredtjeenucfhrhhomhepkghi ucgjrghnuceoiihirdihrghnsehsvghnthdrtghomheqnecuggftrfgrthhtvghrnhepje ekteekffelleekudfftdefvddtjeejuedtuedtteegjefgvedtfedujeekieevnecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepiihirdihrghnse hsvghnthdrtghomh X-ME-Proxy: Feedback-ID: iccd040f4:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 20 Feb 2024 13:32: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 v7 4/4] mm/compaction: optimize >0 order folio compaction with free page split. Date: Tue, 20 Feb 2024 13:32:20 -0500 Message-ID: <20240220183220.1451315-5-zi.yan@sent.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240220183220.1451315-1-zi.yan@sent.com> References: <20240220183220.1451315-1-zi.yan@sent.com> Reply-To: Zi Yan MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 13DE14001C X-Stat-Signature: uicjyc8w6jcstto1ssim8ofnb3mnqos9 X-HE-Tag: 1708453971-558100 X-HE-Meta: U2FsdGVkX1/KDa2yWqr/+Q7j6fBRxpNkRd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4/qfoTufD08NKgUf3YG67eUnQIGElvZVo08D2mBOwrrw0vz8LQLHU+MQ1PB5Ls7j3YdpDQ== 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 112711752321..e70309674262 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -1856,15 +1856,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);