Message ID | 20231113170157.280181-4-zi.yan@sent.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp1340600vqg; Mon, 13 Nov 2023 09:02:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IGkmEkrQWFeBy3U71aofWEvDn/qtbyUwX6ieytnD0Nubj8xODMnxs0ZbjbIQGukBijfY68E X-Received: by 2002:a05:6a00:1796:b0:6c4:dd5b:9747 with SMTP id s22-20020a056a00179600b006c4dd5b9747mr8846499pfg.17.1699894965902; Mon, 13 Nov 2023 09:02:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699894965; cv=none; d=google.com; s=arc-20160816; b=zsNZVmMM6fRpWxUZM/cQzAV7LTtHo/vHx5Ri356T0cHUbi/EgW8Cz0Ojj/2XijaYjF 1A5gEW7rW7ez0pc95fAuJ3QOEMow5CejkMxJeQd+GFKTG4SnMfM4egQaJPHkSPvQ3o99 oMh8oq64KvOjhnHu1aYE+YVeKBkFBFxib0akWHhV0JAKZZdUAW5LyDdsuXmjzAoCint4 fIPJzh65sE5i9C3lOsGvLH6jQyHHbw+O7z5ruzodrXFCxIwyzqGrvABZv5wrkynr5WUQ mLSg2H+mfa/3Ecjl4Xk88SJvLmJgXc10uU+eNA89bVlskeXgfeWhzRjpT78awDvZC42y 3Sgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version:reply-to :references:in-reply-to:message-id:date:subject:cc:to:from :feedback-id:dkim-signature:dkim-signature; bh=NjTQdoHSfkchZC9ErjtVbGgxIgagQAkQl6Bv0Pdns3o=; fh=vJ0CYzlC3FzFcxY+JvdHzizIe8XjzG5USPt1Sa6qsGI=; b=DLtveFjhAd59y2ShWT9gPQ9Qc28yWETikBVhJAIU0BE0eBTymfJ/NMhCAXvceYFHZG rCkVPT/fuekIHmSbw4GMkmdWxMjuh0yS8llAr41fXhkLv+mS7/DSuZrGoVsXtAXVe0sz CnVzj+NMYVWwShzqNV8JrxeaOBD0bW+HpNSSUMHj5C+HiuTrB3MfKmOkP8y+HhXVklb/ l+alJ1nQc91UKgLWKtiw/xa+glAcFD1FtPy/03nUhtPlU8kZb1xYAjx8zq6+8BgfBU4M 9+C5l4uOgI53m9bcndC78NFDcysMhN9L33PpG1FZP+xP8nRprYKNZYIGrf8VSWhIZzCW vlNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sent.com header.s=fm3 header.b=xsBipDat; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=fWrybCjv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sent.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id g12-20020a056a000b8c00b006c3463c7299si6187981pfj.197.2023.11.13.09.02.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Nov 2023 09:02:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@sent.com header.s=fm3 header.b=xsBipDat; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=fWrybCjv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sent.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id E0787802A725; Mon, 13 Nov 2023 09:02:36 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231611AbjKMRCb (ORCPT <rfc822;lhua1029@gmail.com> + 30 others); Mon, 13 Nov 2023 12:02:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230514AbjKMRC0 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 13 Nov 2023 12:02:26 -0500 Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8015FD72 for <linux-kernel@vger.kernel.org>; Mon, 13 Nov 2023 09:02:22 -0800 (PST) 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: <xms:nVZSZasMuxJd7pbK2RcAbtnPESEE9UvoUoYLzt9c1hJoTv6Hqb4-rA> <xme:nVZSZfcioEbeIQk5yMuiOf5UGVyaIO2_uZcoPSedeRKzk5oRs40NPCSnPPDgGi9Dh pV1eHzNJNEymMvkjQ> X-ME-Received: <xmr:nVZSZVwlrVZv9ogrFqp2eleXxZHUGR6RLQ5xcOnVIVJzf7B-aSU0_zq0V0wnunBhglf1m3brBjnlvG5slFVNx0TC6ilKLBdNxd2xHQ0UDClr4FbX4tEJEzdf> X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrudeftddgleefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhhrgggtgfesthekredtredtjeenucfhrhhomhepkghi ucgjrghnuceoiihirdihrghnsehsvghnthdrtghomheqnecuggftrfgrthhtvghrnhepje ekteekffelleekudfftdefvddtjeejuedtuedtteegjefgvedtfedujeekieevnecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepiihirdihrghnse hsvghnthdrtghomh X-ME-Proxy: <xmx:nVZSZVP8_PRLJYcdq-4IpD2eloYPw4YBEXz4PiBlbtuJMQ5mtkKtzw> <xmx:nVZSZa_FMW01gHgicBuwA6uNrrLYFPw_9osreaK2NFyGxVk1ZvW5QQ> <xmx:nVZSZdUBB7bPdxWnr4Yu1N97qn3Hkz5K3Y9clsvV5Vi0wJbxpTV_vA> <xmx:nVZSZd2tD3WN64Ry2nFpFUkb6KrNjy5oc1WZlUm2KlKujxjvAg0zYw> Feedback-ID: iccd040f4:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 13 Nov 2023 12:02:20 -0500 (EST) From: Zi Yan <zi.yan@sent.com> To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Zi Yan <ziy@nvidia.com>, "Huang, Ying" <ying.huang@intel.com>, Ryan Roberts <ryan.roberts@arm.com>, Andrew Morton <akpm@linux-foundation.org>, "Matthew Wilcox (Oracle)" <willy@infradead.org>, David Hildenbrand <david@redhat.com>, "Yin, Fengwei" <fengwei.yin@intel.com>, Yu Zhao <yuzhao@google.com>, Vlastimil Babka <vbabka@suse.cz>, "Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>, Johannes Weiner <hannes@cmpxchg.org>, Baolin Wang <baolin.wang@linux.alibaba.com>, Kemeng Shi <shikemeng@huaweicloud.com>, Mel Gorman <mgorman@techsingularity.net>, Rohan Puri <rohan.puri15@gmail.com>, Mcgrof Chamberlain <mcgrof@kernel.org>, Adam Manzanares <a.manzanares@samsung.com>, "Vishal Moola (Oracle)" <vishal.moola@gmail.com> 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 <ziy@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 13 Nov 2023 09:02:36 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782469063758005823 X-GMAIL-MSGID: 1782469063758005823 |
Series |
Enable >0 order folio memory compaction
|
|
Commit Message
Zi Yan
Nov. 13, 2023, 5:01 p.m. UTC
From: Zi Yan <ziy@nvidia.com> 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 <ziy@nvidia.com> --- mm/compaction.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-)
Comments
On 13/11/2023 17:01, Zi Yan wrote: > From: Zi Yan <ziy@nvidia.com> > > 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 <ziy@nvidia.com> > --- > 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; Perhaps just do: dst = (struct folio *)freepage; goto done; then move done: up a couple of statements below, so that post_alloc_hook() and prep_compound_page() are always done below in common path? Although perhaps the cast is frowned upon, you're already making the assumption that page and folio are interchangable the way you call list_first_entry(). > + } > + } > + 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); > }
On 22 Nov 2023, at 5:26, Ryan Roberts wrote: > On 13/11/2023 17:01, Zi Yan wrote: >> From: Zi Yan <ziy@nvidia.com> >> >> 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 <ziy@nvidia.com> >> --- >> 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; > > Perhaps just do: > > dst = (struct folio *)freepage; > goto done; > > then move done: up a couple of statements below, so that post_alloc_hook() and > prep_compound_page() are always done below in common path? Although perhaps the Sure. Thanks for the suggestion. > cast is frowned upon, you're already making the assumption that page and folio > are interchangable the way you call list_first_entry(). To save the _compound_head() in page_folio()? OK. > >> + } >> + } >> + 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); >> } -- Best Regards, Yan, Zi
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); }