From patchwork Mon Nov 13 17:01:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13454190 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 04F63C4167B for ; Mon, 13 Nov 2023 17:02:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 73C428D0001; Mon, 13 Nov 2023 12:02:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6B1498D0031; Mon, 13 Nov 2023 12:02:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 481528D0001; Mon, 13 Nov 2023 12:02:29 -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 28E748D002E for ; Mon, 13 Nov 2023 12:02:29 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 00552C0910 for ; Mon, 13 Nov 2023 17:02:28 +0000 (UTC) X-FDA: 81453549576.13.1249B94 Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) by imf24.hostedemail.com (Postfix) with ESMTP id B8A5C180064 for ; Mon, 13 Nov 2023 17:02:22 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=sent.com header.s=fm3 header.b=xsBipDat; dkim=pass header.d=messagingengine.com header.s=fm3 header.b=fWrybCjv; dmarc=pass (policy=none) header.from=sent.com; spf=pass (imf24.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=1699894942; 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=NjTQdoHSfkchZC9ErjtVbGgxIgagQAkQl6Bv0Pdns3o=; b=SP2N9Vyuh2Ybd9blXXuAdLPPvI0PB/yazzJCe5ZOUpy0ZpDyrYjic0NXxK8BcFs6oSI9ku zUXnk1b1PagEMaZiTcU0nGYFxEnc45WJYTWqaGB8uFOCeOlcVVquXV+aes6Fu1Iwa6tgsU 1w6oRLhc4BuVTUUHczbIJQi3KtZ85qo= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=sent.com header.s=fm3 header.b=xsBipDat; dkim=pass header.d=messagingengine.com header.s=fm3 header.b=fWrybCjv; dmarc=pass (policy=none) header.from=sent.com; spf=pass (imf24.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=1699894942; a=rsa-sha256; cv=none; b=asXOlmsxEg2R+rfPsABcEuXrUywWZhtpi3YxJSBL/XS9yV4bTPH5oOdrt+NV5Lo41IF5OK 7l3O2GAuZqYyBQ89bEKFOOzXjCBJ987duqbUmmq7vnfe55NAwQgD6msL5/7Okby9V+HELk /nuvn2TbVVLDlQ5QIE5s4ZDJ30PZtQo= Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id EC8375C01C0; Mon, 13 Nov 2023 12:02:21 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Mon, 13 Nov 2023 12:02:21 -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:sender:subject:subject:to:to; s= fm3; t=1699894941; x=1699981341; bh=NjTQdoHSfkchZC9ErjtVbGgxIgag QAkQl6Bv0Pdns3o=; b=xsBipDatk1P2U27rv1kUFkwMhX791z5A0ZKrm9KsdRqC gK6LlO03b005sR4uhJ4VXn3/9VPBjEHQAMKvUVOv7m97BXF8z5zMtwC3ek/ARRhF R6v4qyrbVM0PFppvmB6I0q3RMcI3XpCo9wukEu2BBKS5uK7l4ihGaoOTmEPr3uxr svRq7x+dKmgUJLdrqLGNvLQlhVBUWAmpTSNILEd4R2eguie/IUl5kxGip9n8nK7h VDYs+w5hlskJ1Vz1joC4tprZsQdQ0bJwEblbA1M8i/4tVtw7ss08GvSGirrCjwbX oUYKngh5vZP3UEq3PJZRcMkOejKm03tUkeGpA5Z10A== 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:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1699894941; x=1699981341; bh=NjTQdoHSfkchZC9ErjtVbGgxIgag QAkQl6Bv0Pdns3o=; b=fWrybCjv/T/lN8stCivDytBqdHgfEhrf4OaHsDT1O5FD 4WUOTiYtFuR1PHaSD6uYBAaSfGOmJtckDM4l3a8ngGYYKTuyQPHtPHNeRpctctNU CIoksa10PwZKw4Y18dINEDXQc9Iu1uku41mhRD8qc8lhyB0DdUgdt2lSwMBjQD59 lkTzkCpwoAx77imEhu1tP+vmNmSAgFEPIh9Dg/aX6csqf5wf9xlQc26XLh0oE+GA UPuz+ENFtAnSdnna61Lu8ieDd3c2x3Ta8aEC1kHhBgYlSkRzFq+7jM7fPjBwG8/y FBcBCLXq4rHtb6oOkAVDkQLkrNAXAbrkAc1Kpih2LQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrudeftddgleefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhhrgggtgfesthekredtredtjeenucfhrhhomhepkghi ucgjrghnuceoiihirdihrghnsehsvghnthdrtghomheqnecuggftrfgrthhtvghrnhepje ekteekffelleekudfftdefvddtjeejuedtuedtteegjefgvedtfedujeekieevnecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepiihirdihrghnse hsvghnthdrtghomh X-ME-Proxy: Feedback-ID: iccd040f4:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 13 Nov 2023 12:02:20 -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 v1 3/4] mm/compaction: optimize >0 order folio compaction with free page split. Date: Mon, 13 Nov 2023 12:01:56 -0500 Message-ID: <20231113170157.280181-4-zi.yan@sent.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231113170157.280181-1-zi.yan@sent.com> References: <20231113170157.280181-1-zi.yan@sent.com> Reply-To: Zi Yan MIME-Version: 1.0 X-Rspamd-Queue-Id: B8A5C180064 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: pbgiedwxj8cxx5eu96hjouak4uju3sxt X-HE-Tag: 1699894942-412613 X-HE-Meta: U2FsdGVkX1/qdsGWrrf8TsZnWOQ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dK8UwuecJHwvPNPN3hryJPQRxcjgTF52cMaXvBX7S5m2tC6Hu8f91R7PP+i//60/cwbw5dgotVkng2vMf0XOHdoTG+/fs4M+OZQcaQ1Y9HtLUxKxUh/6iaTT8W65OFkJSn44o1S5WHsdl4Pxp0EWX9Ln0/6qVhOVdGh20RQ08epACYXC6ArUrxbiinigrYuNEfwvhPKRkbdPY1bjAHaSgW4TALIhhYbaaWblWw1PjkeqlyzXo0eRXJ/col3P2h1aWioPrXTvlBej5+Lk25TEG9zHNlsJ0xv7Z9TYdIRBK3yFlqW+jGP783UdpvMyvmWyyzMcus43c8qU7eA5bI0ikD2zkcfLoYD1uNNxhJS3kuMsyXK19hMKEADu+u5Axc660JYPe5CwKqjQAaIuwUHsM7AE+5M7IY= 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. 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 | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/mm/compaction.c b/mm/compaction.c index ec6b5cc7e907..9c083e6b399a 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -1806,9 +1806,46 @@ 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 <= MAX_ORDER; 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); + } + post_alloc_hook(freepage, order, __GFP_MOVABLE); + if (order) + prep_compound_page(freepage, order); + dst = page_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; } @@ -1819,6 +1856,7 @@ static struct folio *compaction_alloc(struct folio *src, unsigned long data) post_alloc_hook(&dst->page, order, __GFP_MOVABLE); if (order) prep_compound_page(&dst->page, order); +done: cc->nr_freepages -= 1 << order; return page_rmappable_folio(&dst->page); }