From patchwork Tue Jan 23 03:46:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13526810 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 6A549C47258 for ; Tue, 23 Jan 2024 03:47:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EABAC6B008A; Mon, 22 Jan 2024 22:47:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E5AF76B0095; Mon, 22 Jan 2024 22:47:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A3D876B008A; Mon, 22 Jan 2024 22:47:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 84D056B008A for ; Mon, 22 Jan 2024 22:47:13 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 35765A1986 for ; Tue, 23 Jan 2024 03:47:13 +0000 (UTC) X-FDA: 81709190346.24.1240FEE Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) by imf23.hostedemail.com (Postfix) with ESMTP id 333B014000B for ; Tue, 23 Jan 2024 03:47:11 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=sent.com header.s=fm3 header.b=Qb1tyZd8; dkim=pass header.d=messagingengine.com header.s=fm3 header.b=y6CtXNfh; spf=pass (imf23.hostedemail.com: domain of zi.yan@sent.com designates 66.111.4.26 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=1705981631; 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=nFXKGo9rKF119RBUFLJm4CCIEN+EywVvwTP6Mlui2MY=; b=YzWtSxM2ITmeJmbFpsPzrJyMECDta8HleCBhO05OBxRqwlLnIAIrqxJzvHN0GQ0D9Cim3a VZvnEw4zEJhniGgMTTRNiasEiu5jljjAHysSrp11ktKQpACa8RqQrJAzv90vxeBxNUywWF IT1kaZfh3osi8uUX8s6zcuJOCFwybGI= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=sent.com header.s=fm3 header.b=Qb1tyZd8; dkim=pass header.d=messagingengine.com header.s=fm3 header.b=y6CtXNfh; spf=pass (imf23.hostedemail.com: domain of zi.yan@sent.com designates 66.111.4.26 as permitted sender) smtp.mailfrom=zi.yan@sent.com; dmarc=pass (policy=none) header.from=sent.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1705981631; a=rsa-sha256; cv=none; b=HC1gwkFI0Nvsg/BSUAolLTJoHb4Q+rlQk6aylhSCnJw9cltIBPA4hzmVkxulmpgDqY03Sp p4OVM8Y3LGiGvXK1XiDPEL3M37sUPvC4Vhc/ngYScN/6oQLhH3BQYRzz+NCPKej+uJrZ6z UzS/RyK8StXvsH0rWzfEjleGYNQQXcg= Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 6F0165C0335; Mon, 22 Jan 2024 22:47:10 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Mon, 22 Jan 2024 22:47:10 -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= 1705981630; x=1706068030; bh=nFXKGo9rKF119RBUFLJm4CCIEN+EywVvwTP 6Mlui2MY=; b=Qb1tyZd8hBxmQdzvOqm/NUrXgHvdk6O59nKJ/UAjsWmR+NJt8o0 sQMQ3BHdYvYBMUEaTgEVGQ1Yg0p04a5toQcQHryZNBnFE/N5HHcXAjP1RpfJGbBg zPxkJCCea7vc0sx3iBeqQy2Kxpj5MYwfVZHYJh8Yqrw/4c2PUnINhNsXKCl+3Wwn Z78At21kPb3Rb1YBAt0Fjjn0QCaYhlfnl/tbX02RhfSUi3eBNufKh+/pEgpOOvE7 DQW1765+/v+nbu7Tf8agm8NoaVUoa4ohTLXtbJk7cY2KtIYz35JKRDhqDy5SnuqG 5/D/WpH1IkLPUgbJm1HcW4IcFI0J+VhgOxQ== 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= 1705981630; x=1706068030; bh=nFXKGo9rKF119RBUFLJm4CCIEN+EywVvwTP 6Mlui2MY=; b=y6CtXNfhQE6UEMdpchPy2BMY5+J1ZsljEUixwVzuhCDkmIckFIu MXK96g2nWTilV5FRWN9CrDxiyGd9DbYosxAXS9pSZYbZqN17/nULWf+mylk3uEm8 CCC6nENgxubwk4/OmfXmDfGlB2tHQI5SQV8A4vVyHUsqRKvAvRr6s03hxvmCeViT jJerNmHRpIN0E0Fo0RChyTjp5BNs4uZjvZk4SnQFETm0b+iJL0bK5GBtbM5PFhzq z574F6aBUj9JBJjAZdDvWvX+Jpk47SjgmRkm6lTvWSFKzUeYVen1otfGPdf9/UGI k75oGdJXDYQGfdq8CvnGI/Tp74NEEKpvGWw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrvdekjedgieduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhhrgggtgfesthekredtredtjeenucfhrhhomhepkghi ucgjrghnuceoiihirdihrghnsehsvghnthdrtghomheqnecuggftrfgrthhtvghrnhepje ekteekffelleekudfftdefvddtjeejuedtuedtteegjefgvedtfedujeekieevnecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepiihirdihrghnse hsvghnthdrtghomh X-ME-Proxy: Feedback-ID: iccd040f4:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 22 Jan 2024 22:47:09 -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 v2 3/3] mm/compaction: optimize >0 order folio compaction with free page split. Date: Mon, 22 Jan 2024 22:46:35 -0500 Message-ID: <20240123034636.1095672-4-zi.yan@sent.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240123034636.1095672-1-zi.yan@sent.com> References: <20240123034636.1095672-1-zi.yan@sent.com> Reply-To: Zi Yan MIME-Version: 1.0 X-Rspamd-Queue-Id: 333B014000B X-Rspam-User: X-Stat-Signature: yb4ygwcbn3up9af7c57tr6747s4n98om X-Rspamd-Server: rspam01 X-HE-Tag: 1705981631-716099 X-HE-Meta: U2FsdGVkX19sJ/L1gVsOWY/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5ItBCMQj6obxI/51upZm1k+zcv2V/kZ42iHIaDlc/rkO5nI1aDvR2F+FN/618sbZKR+rYOk8oYbb0I4E0iBWZC/2Iq6JaUaup5YkZ0RVgPAPYlTtPHceTuiSNRFi4UoadbroDFlih8GxccYVn8xbj/d01ZfkKQJuKyXEivKQ9H9ja5LJPrRdJwAmoRtiGw2i8ZkHvyxI759R3q2ea7hSy1lcQOs/vSDJGkNlLmDMY0yHtCwTEali3OFc7g/oSpUr7lAEBZHJyufr3F3iE8HPmiS+0CArYFQsPCBr02PbbT5Tr0QpW8tKo0gaD7+LVwhCsvH5kemJCf4ItZj/wSzFwfgBWo8hN874EMbsZCP11U/+ctGCv8BuggnMUx7b13YclyZld/LR9ZIcJLTy19UQywtnlhWzDfCoW9troMHUByo3TBxM= 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 --- mm/compaction.c | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/mm/compaction.c b/mm/compaction.c index 11f9898e39da..052c82481d64 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -1812,9 +1812,43 @@ 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; +again: if (!cc->freepages[order].nr_pages) { - isolate_freepages(cc); + int i; + + for (i = order + 1; i < NR_PAGE_ORDERS; i++) { + if (cc->freepages[i].nr_pages) { + struct page *freepage = + list_first_entry(&cc->freepages[i].pages, + struct page, lru); + + int start_order = i; + unsigned long size = 1 << start_order; + + list_del(&freepage->lru); + cc->freepages[i].nr_pages--; + + while (start_order > order) { + start_order--; + size >>= 1; + + list_add(&freepage[size].lru, + &cc->freepages[start_order].pages); + cc->freepages[start_order].nr_pages++; + set_page_private(&freepage[size], start_order); + } + dst = (struct folio *)freepage; + goto done; + } + } + if (!has_isolated_pages) { + isolate_freepages(cc); + has_isolated_pages = true; + goto again; + } + if (!cc->freepages[order].nr_pages) return NULL; } @@ -1822,6 +1856,7 @@ static struct folio *compaction_alloc(struct folio *src, unsigned long data) dst = list_first_entry(&cc->freepages[order].pages, struct folio, lru); cc->freepages[order].nr_pages--; list_del(&dst->lru); +done: post_alloc_hook(&dst->page, order, __GFP_MOVABLE); if (order) prep_compound_page(&dst->page, order);