From patchwork Fri Feb 2 16:15:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13543134 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 F28ACC4828F for ; Fri, 2 Feb 2024 16:16:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8E2DC6B007B; Fri, 2 Feb 2024 11:16:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 890C06B007D; Fri, 2 Feb 2024 11:16:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 695666B007E; Fri, 2 Feb 2024 11:16:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 54FC46B007B for ; Fri, 2 Feb 2024 11:16:22 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 21367160F8A for ; Fri, 2 Feb 2024 16:16:22 +0000 (UTC) X-FDA: 81747366204.27.D851BBC Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) by imf09.hostedemail.com (Postfix) with ESMTP id EC1F614002C for ; Fri, 2 Feb 2024 16:16:19 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=sent.com header.s=fm3 header.b=Q6BNiPci; dkim=pass header.d=messagingengine.com header.s=fm3 header.b=w3EzSPMY; dmarc=pass (policy=none) header.from=sent.com; spf=pass (imf09.hostedemail.com: domain of zi.yan@sent.com designates 66.111.4.26 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=1706890580; 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=Srz2TBF5bSmmDzT+fRItHrkdBt/FNKVEiEoyh1M6V+0=; b=hkY1IeX+MKjjx3ryRSrm2+RjWeqf7K7rCDFJ45zUT4j6mW8bhApTzLK6LMscZsODbpiegt 2nXMSl6D13s2Ptst565rYn90escamo6coVtmAp0SOpCQ6ied+WH5QykYxd/8Jp3PA7OLww HcwQON0gXieHCh0UtDWVwAXrjybIz6A= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=sent.com header.s=fm3 header.b=Q6BNiPci; dkim=pass header.d=messagingengine.com header.s=fm3 header.b=w3EzSPMY; dmarc=pass (policy=none) header.from=sent.com; spf=pass (imf09.hostedemail.com: domain of zi.yan@sent.com designates 66.111.4.26 as permitted sender) smtp.mailfrom=zi.yan@sent.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706890580; a=rsa-sha256; cv=none; b=RpsFYr2EP75SuIeLozCIKhz+MF/q0T2Q2hwVi8QX74yjzZfaemCGlqmCg3RgjyleKKYSzK ut/wTEXXthzRJZJZyoEeiBB+iAHvleNymZrrNnAd8vN0C0T61x3LZ7XvXmxknD3ZIV2cYS T0rtGCdWKNkgeRTavCng01O4OBTqmJc= Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 450FD5C0108; Fri, 2 Feb 2024 11:16:19 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Fri, 02 Feb 2024 11:16:19 -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= 1706890579; x=1706976979; bh=Srz2TBF5bSmmDzT+fRItHrkdBt/FNKVEiEo yh1M6V+0=; b=Q6BNiPcizadAd+EZgLpzobSWkpvEDzg+ntUAZW2HFba3/Lbpme2 O8sD/KsTLcClEooEDS+rgni1VKTOJVvjKG2BECTjNiNda9PMom5VpxTwxk+kmX9g 5SJAxrVHTNtZxoS5jAUi56r/D8XWcS0OJh2+HEwhuwHmt1t9F6ixsOpYuh0Z62lf jsolvlGzfHgQFVTRoeCZd2VaMnTaM1ocYqJaIOR1z9/NUXsfDnUeuUp37YoN3RGo h9R7gudHRW7KTw4tSyeCZ1fkU5pRSQ2k5vAl5Zfe3Gl+tFLgCwcmgP1//oQ2W0+0 ZAsBefLjP95IPfEJx9zsNtGrcaHxRnXII7w== 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= 1706890579; x=1706976979; bh=Srz2TBF5bSmmDzT+fRItHrkdBt/FNKVEiEo yh1M6V+0=; b=w3EzSPMYiSxw7VrU6CcZVS7tnyWg0o5f4EO+FRuCOUgJup6WH3A gUN6QtlNYcx+Xn13uj0UTgRkf7/WGHrUMYbh0SZWawyQ1VsQMjqfWMGZIYZFIdqB TgfodME8fk/7pVIskKCsZPmLBTaZTRcAhff4gV09XWLcq2pcbc6xc//W7iVxO8y1 k6Mv24maaJmmjZhsBbAUxbjFqyQp+8mkxO3FQkx6tvJUlZgqg+MLuMvmItlouDmy QqdBcxCFwfun+0ZBRcIHVEJ2iA/lBy8U/xlgdDOcFYEGbzGP8Vtg7NECbWUCEn7U NABFdFaLw/It9y8LVlvkv8GiKqoNy+b8vYQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrfedugedgkeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhhrgggtgfesthekredtredtjeenucfhrhhomhepkghi ucgjrghnuceoiihirdihrghnsehsvghnthdrtghomheqnecuggftrfgrthhtvghrnhepje ekteekffelleekudfftdefvddtjeejuedtuedtteegjefgvedtfedujeekieevnecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepiihirdihrghnse hsvghnthdrtghomh X-ME-Proxy: Feedback-ID: iccd040f4:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 2 Feb 2024 11:16:17 -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 v3 3/3] mm/compaction: optimize >0 order folio compaction with free page split. Date: Fri, 2 Feb 2024 11:15:54 -0500 Message-ID: <20240202161554.565023-4-zi.yan@sent.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240202161554.565023-1-zi.yan@sent.com> References: <20240202161554.565023-1-zi.yan@sent.com> Reply-To: Zi Yan MIME-Version: 1.0 X-Rspamd-Queue-Id: EC1F614002C X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: ygwem5whu8n9scgp9aq3mutasdd5ho9p X-HE-Tag: 1706890579-988553 X-HE-Meta: U2FsdGVkX18F7G+fUlIqRXVk98+o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Ph3tR0tPTwAFg4r2Jhj6LwaWcoVDlyRAccShoW00rygUNXesK3NTNPA+VY6umLnHzuJQPoXAds8elPyU4dT+Ggh3Z2Xlvyk6ii1JxRse6uNgnbGpyFIRJ7neKB8Bbb40YMgsRj5Xu7qqFulavdyZLY4K+l2eawcJrkLI/dUfxFmVMPZr9S/zW41dua8ge8GxsatjELCENY+o/8di6apNw7vEu4/waYn+NCBjG1o1Nd4nTR1FKfv/GWfZcFkdr1ZQfYzSK5TAbB8k83nNAZHvg+xL9NNvRbnHwDjgkzDwsU2JMb3a/UYpOzal1bfHWuE+Kwfg8rrfYxWAF9vpU9ztakfTqo+aJRwP1N9aNA8MtOvSpvPQ9T8Kk0rErt1uJvUxFPRX9g5+6kJrFz4= 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 58a4e3fb72ec..fa9993c8a389 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -1832,9 +1832,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; } @@ -1842,6 +1876,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);