From patchwork Tue Sep 12 16:28:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 138430 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp671341vqx; Tue, 12 Sep 2023 13:47:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IErAswxuaxpeFbs6yNjTKATq8n0OWsTVVjuYiEPfJalImxG+RyFW+JQvnU69Hd+lrEl8QgU X-Received: by 2002:a05:6a20:9148:b0:154:e887:f581 with SMTP id x8-20020a056a20914800b00154e887f581mr504278pzc.58.1694551640333; Tue, 12 Sep 2023 13:47:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694551640; cv=none; d=google.com; s=arc-20160816; b=k8hCIkMADm5u2nE9ml3ZlXguf8Ednfl4VUhKvGtrESmGsY7w6vKUzCREZcqKaKQ136 ADUf/K8fOy0ecTRfXcjXnqgCaB/hTu9VuKAUKGpqWxOgiCFWfiuUtyjTTF8eLgs/j3xV b8l1TcFK0DW1MExBDnb1TfsUohA9QF7Nc260odv3Ar9e4lD1f/8DXgMqXWnvrY3oe937 1BjHdB5JAok/5AAzNdZXMhpXeer7r+PxEp+Km9vpFI3PW5bCHIyobD5BZ3xRE0YTLuZI irSZy2MbpJ4Zpiifav05JVsvLqJx9m3B4GOQAF+K5BuGDLetIHJsRIhGNVFPY7h4SBtU fdDQ== 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=9vQ7qsdQ+RP7SfzfLEPFzsLiQiKEomD6WH+2Rhu3mcA=; fh=bUDnJOBC0/apF/24NaPi+H6rvMB40CebS5Pe6QbQjAo=; b=GHWlNNq/+SzYJMLqTUDfUY6HIq99ZVniWPYwI9xAk0ljqhrPDMrUKYE7cBc1qx43N4 89Kq3Q68KVj819nztN3QKRPmI0VGrrM+FZc6KdjHZG4EVcz3Il4PtWXEF9sp+fKdVU/H 5VtVFdXktDO/YcdsuIbiin554D5QlXN3w/R1opOOu/geR7/SPZ/qpcV/gDt8Kre8fMpe onPOqSXPo/jpMQBCZ6T0elD4PW9K445D67nOcN+VZvt31QLKEO1cSeYxl8Wz4d7QNouz TiJ9OMjKaU7KpJVzKhVPk7MvFWsqZmbGM9gPrr8JkWNleyAEQdA2ohB4ed2Uffa6qpsw DQ6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sent.com header.s=fm1 header.b=ZpTUQyvb; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=OcdsQuOP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id j9-20020a635509000000b005740286f2a8si8346739pgb.286.2023.09.12.13.47.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 13:47:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@sent.com header.s=fm1 header.b=ZpTUQyvb; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=OcdsQuOP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (Postfix) with ESMTP id 30855829D26C; Tue, 12 Sep 2023 09:29:03 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236769AbjILQ2l (ORCPT + 37 others); Tue, 12 Sep 2023 12:28:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236704AbjILQ2i (ORCPT ); Tue, 12 Sep 2023 12:28:38 -0400 Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5407E1703 for ; Tue, 12 Sep 2023 09:28:34 -0700 (PDT) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id BEFC75C0208; Tue, 12 Sep 2023 12:28:33 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Tue, 12 Sep 2023 12:28:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sent.com; h=cc :cc:content-transfer-encoding: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=fm1; t= 1694536113; x=1694622513; bh=9vQ7qsdQ+RP7SfzfLEPFzsLiQiKEomD6WH+ 2Rhu3mcA=; b=ZpTUQyvbyV86YCj8+3kbPP+syFXBrGgx3+Nr/1LDYo3RlD0TEfe z+DgnttaQrSQLsdQ4bk6O9orX5XPfxFqTZ5TIm91hxMMdPnE3IsZTfH4DHuh3zDq E3O3SG4nLzshPZr/boNkN5n4z6/qYeUaFnu5FNV0M24VVvKIYs4CtQSlclzSnY0d AIifFKGP9lCkVhsJm8c2RS8kedtIot0h00/dra5EBUjL+ShKp0CTPWrL6B0k87JY bzIxO3VlxRN522MYC0/aMnxR74xaE4HTxQsiTrqv/Xw2Ov/p5QcdW7qdyEeCipCm KHJihqMxfqb/dNjpf/IEbzw0MQGzNwpGJcA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :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=fm1; t= 1694536113; x=1694622513; bh=9vQ7qsdQ+RP7SfzfLEPFzsLiQiKEomD6WH+ 2Rhu3mcA=; b=OcdsQuOPW/n5J3Tv/jrZYHO7ACqUAqPO7cbR7NEnnUDNby5cBmt JIGBbEHQLathe3cIGoaYPVMirFM/uLUyoUq+o43WBp+VoyJSBlSxaEDX7wFgUwjU 7PKImSoNiYSUVemuQHP05u0C2kiuWUOukrIZyNnPcw4lXe+oKXQssqXns0Yvqcht jaY9VPsQozSigm0SAXnGBNoHYUmzfyky8yFUf5BSER69qJHhxTyg730gi5yIRr1c x02bDfPEObCnoFRelAypAvUUOJ3LyXZmVRgFSNleq6x1Con7O286zDl7qMZHw3Nw 81eOQDT9HRCb3DXw602USF4Ju5VtkNZvj6Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrudeiiedguddtudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhvfevufffkffojghfrhgggfestdhqredtredttdenucfhrhhomhepkghi ucgjrghnuceoiihirdihrghnsehsvghnthdrtghomheqnecuggftrfgrthhtvghrnhepge eghedugfduuddvleehheetgeeltdetieevuefhffevkefhveeufeeiieejgedvnecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepiihirdihrghnse hsvghnthdrtghomh X-ME-Proxy: Feedback-ID: iccd040f4:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 12 Sep 2023 12:28:32 -0400 (EDT) From: Zi Yan To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Zi Yan , Ryan Roberts , Andrew Morton , "Matthew Wilcox (Oracle)" , David Hildenbrand , "Yin, Fengwei" , Yu Zhao , Vlastimil Babka , Johannes Weiner , Baolin Wang , Kemeng Shi , Mel Gorman , Rohan Puri , Mcgrof Chamberlain , Adam Manzanares , John Hubbard Subject: [RFC PATCH 1/4] mm/compaction: add support for >0 order folio memory compaction. Date: Tue, 12 Sep 2023 12:28:12 -0400 Message-Id: <20230912162815.440749-2-zi.yan@sent.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230912162815.440749-1-zi.yan@sent.com> References: <20230912162815.440749-1-zi.yan@sent.com> Reply-To: Zi Yan MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Tue, 12 Sep 2023 09:29:03 -0700 (PDT) X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776858260906963871 X-GMAIL-MSGID: 1776866180851476156 From: Zi Yan Before, memory compaction only migrates order-0 folios and skips >0 order folios. This commit adds support for >0 order folio compaction by keeping isolated free pages at their original size without splitting them into order-0 pages and using them directly during migration process. What is different from the prior implementation: 1. All isolated free pages are kept in a MAX_ORDER+1 array of page lists, where each page list stores free pages in the same order. 2. All free pages are not post_alloc_hook() processed nor buddy pages, although their orders are stored in first page's private like buddy pages. 3. During migration, in new page allocation time (i.e., in compaction_alloc()), free pages are then processed by post_alloc_hook(). When migration fails and a new page is returned (i.e., in compaction_free()), free pages are restored by reversing the post_alloc_hook() operations. Step 3 is done for a latter optimization that splitting and/or merging free pages during compaction becomes easier. Signed-off-by: Zi Yan --- mm/compaction.c | 108 +++++++++++++++++++++++++++++++++++++++--------- mm/internal.h | 7 +++- 2 files changed, 94 insertions(+), 21 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index 01ba298739dd..868e92e55d27 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -107,6 +107,44 @@ static void split_map_pages(struct list_head *list) list_splice(&tmp_list, list); } +static unsigned long release_free_list(struct free_list *freepages) +{ + int order; + unsigned long high_pfn = 0; + + for (order = 0; order <= MAX_ORDER; order++) { + struct page *page, *next; + + list_for_each_entry_safe(page, next, &freepages[order].pages, lru) { + unsigned long pfn = page_to_pfn(page); + + list_del(&page->lru); + /* + * Convert free pages into post allocation pages, so + * that we can free them via __free_page. + */ + post_alloc_hook(page, order, __GFP_MOVABLE); + __free_pages(page, order); + if (pfn > high_pfn) + high_pfn = pfn; + } + } + return high_pfn; +} + +static void sort_free_pages(struct list_head *src, struct free_list *dst) +{ + unsigned int order; + struct page *page, *next; + + list_for_each_entry_safe(page, next, src, lru) { + order = buddy_order(page); + + list_move(&page->lru, &dst[order].pages); + dst[order].nr_free++; + } +} + #ifdef CONFIG_COMPACTION bool PageMovable(struct page *page) { @@ -1422,6 +1460,7 @@ fast_isolate_around(struct compact_control *cc, unsigned long pfn) { unsigned long start_pfn, end_pfn; struct page *page; + LIST_HEAD(freelist); /* Do not search around if there are enough pages already */ if (cc->nr_freepages >= cc->nr_migratepages) @@ -1439,7 +1478,8 @@ fast_isolate_around(struct compact_control *cc, unsigned long pfn) if (!page) return; - isolate_freepages_block(cc, &start_pfn, end_pfn, &cc->freepages, 1, false); + isolate_freepages_block(cc, &start_pfn, end_pfn, &freelist, 1, false); + sort_free_pages(&freelist, cc->freepages); /* Skip this pageblock in the future as it's full or nearly full */ if (start_pfn == end_pfn && !cc->no_set_skip_hint) @@ -1568,7 +1608,7 @@ static void fast_isolate_freepages(struct compact_control *cc) nr_scanned += nr_isolated - 1; total_isolated += nr_isolated; cc->nr_freepages += nr_isolated; - list_add_tail(&page->lru, &cc->freepages); + list_add_tail(&page->lru, &cc->freepages[order].pages); count_compact_events(COMPACTISOLATED, nr_isolated); } else { /* If isolation fails, abort the search */ @@ -1642,13 +1682,13 @@ static void isolate_freepages(struct compact_control *cc) unsigned long isolate_start_pfn; /* exact pfn we start at */ unsigned long block_end_pfn; /* end of current pageblock */ unsigned long low_pfn; /* lowest pfn scanner is able to scan */ - struct list_head *freelist = &cc->freepages; unsigned int stride; + LIST_HEAD(freelist); /* Try a small search of the free lists for a candidate */ fast_isolate_freepages(cc); if (cc->nr_freepages) - goto splitmap; + return; /* * Initialise the free scanner. The starting point is where we last @@ -1708,7 +1748,8 @@ static void isolate_freepages(struct compact_control *cc) /* Found a block suitable for isolating free pages from. */ nr_isolated = isolate_freepages_block(cc, &isolate_start_pfn, - block_end_pfn, freelist, stride, false); + block_end_pfn, &freelist, stride, false); + sort_free_pages(&freelist, cc->freepages); /* Update the skip hint if the full pageblock was scanned */ if (isolate_start_pfn == block_end_pfn) @@ -1749,10 +1790,6 @@ static void isolate_freepages(struct compact_control *cc) * and the loop terminated due to isolate_start_pfn < low_pfn */ cc->free_pfn = isolate_start_pfn; - -splitmap: - /* __isolate_free_page() does not map the pages */ - split_map_pages(freelist); } /* @@ -1763,18 +1800,21 @@ 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); - if (list_empty(&cc->freepages)) { + if (!cc->freepages[order].nr_free) { isolate_freepages(cc); - - if (list_empty(&cc->freepages)) + if (!cc->freepages[order].nr_free) return NULL; } - dst = list_entry(cc->freepages.next, struct folio, lru); + dst = list_first_entry(&cc->freepages[order].pages, struct folio, lru); + cc->freepages[order].nr_free--; list_del(&dst->lru); - cc->nr_freepages--; - + post_alloc_hook(&dst->page, order, __GFP_MOVABLE); + if (order) + prep_compound_page(&dst->page, order); + cc->nr_freepages -= 1 << order; return dst; } @@ -1786,9 +1826,34 @@ static struct folio *compaction_alloc(struct folio *src, unsigned long data) static void compaction_free(struct folio *dst, unsigned long data) { struct compact_control *cc = (struct compact_control *)data; + int order = folio_order(dst); + struct page *page = &dst->page; - list_add(&dst->lru, &cc->freepages); - cc->nr_freepages++; + if (order) { + int i; + + page[1].flags &= ~PAGE_FLAGS_SECOND; + for (i = 1; i < (1 << order); i++) { + page[i].mapping = NULL; + clear_compound_head(&page[i]); + page[i].flags &= ~PAGE_FLAGS_CHECK_AT_PREP; + } + + } + /* revert post_alloc_hook() operations */ + page->mapping = NULL; + page->flags &= ~PAGE_FLAGS_CHECK_AT_PREP; + set_page_count(page, 0); + page_mapcount_reset(page); + reset_page_owner(page, order); + page_table_check_free(page, order); + arch_free_page(page, order); + set_page_private(page, order); + INIT_LIST_HEAD(&dst->lru); + + list_add(&dst->lru, &cc->freepages[order].pages); + cc->freepages[order].nr_free++; + cc->nr_freepages += 1 << order; } /* possible outcome of isolate_migratepages */ @@ -2412,6 +2477,7 @@ compact_zone(struct compact_control *cc, struct capture_control *capc) const bool sync = cc->mode != MIGRATE_ASYNC; bool update_cached; unsigned int nr_succeeded = 0; + int order; /* * These counters track activities during zone compaction. Initialize @@ -2421,7 +2487,10 @@ compact_zone(struct compact_control *cc, struct capture_control *capc) cc->total_free_scanned = 0; cc->nr_migratepages = 0; cc->nr_freepages = 0; - INIT_LIST_HEAD(&cc->freepages); + for (order = 0; order <= MAX_ORDER; order++) { + INIT_LIST_HEAD(&cc->freepages[order].pages); + cc->freepages[order].nr_free = 0; + } INIT_LIST_HEAD(&cc->migratepages); cc->migratetype = gfp_migratetype(cc->gfp_mask); @@ -2607,7 +2676,7 @@ compact_zone(struct compact_control *cc, struct capture_control *capc) * so we don't leave any returned pages behind in the next attempt. */ if (cc->nr_freepages > 0) { - unsigned long free_pfn = release_freepages(&cc->freepages); + unsigned long free_pfn = release_free_list(cc->freepages); cc->nr_freepages = 0; VM_BUG_ON(free_pfn == 0); @@ -2626,7 +2695,6 @@ compact_zone(struct compact_control *cc, struct capture_control *capc) trace_mm_compaction_end(cc, start_pfn, end_pfn, sync, ret); - VM_BUG_ON(!list_empty(&cc->freepages)); VM_BUG_ON(!list_empty(&cc->migratepages)); return ret; diff --git a/mm/internal.h b/mm/internal.h index 8c90e966e9f8..f5c691bb5c1c 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -465,6 +465,11 @@ int split_free_page(struct page *free_page, /* * in mm/compaction.c */ + +struct free_list { + struct list_head pages; + unsigned long nr_free; +}; /* * compact_control is used to track pages being migrated and the free pages * they are being migrated to during memory compaction. The free_pfn starts @@ -473,7 +478,7 @@ int split_free_page(struct page *free_page, * completes when free_pfn <= migrate_pfn */ struct compact_control { - struct list_head freepages; /* List of free pages to migrate to */ + struct free_list freepages[MAX_ORDER + 1]; /* List of free pages to migrate to */ struct list_head migratepages; /* List of pages being migrated */ unsigned int nr_freepages; /* Number of isolated free pages */ unsigned int nr_migratepages; /* Number of pages to migrate */ From patchwork Tue Sep 12 16:28:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 138469 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp719119vqx; Tue, 12 Sep 2023 15:34:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF8DL0zcRA/hqtkq9uY8YBR+PvHE2m5ZNduUJA+uOltqg80oI9t9yAht5odeg5lCZWv780B X-Received: by 2002:a05:6a20:978a:b0:137:fa5:8519 with SMTP id hx10-20020a056a20978a00b001370fa58519mr659043pzc.31.1694558079059; Tue, 12 Sep 2023 15:34:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694558079; cv=none; d=google.com; s=arc-20160816; b=Gil9stAuz9LxKs/4ZeIb+08b8V8kLQoMjOMKdQ8QIxm7EvFCAAJCmv6BjeBzGwYaJz srrwJTnlWqvbcNjGfW/A8BUzSJxsKKsCAY6gXyBx6IBE0XyekEWCy6Ue1B5RAhzsGNlc uRK9xCB72qH2gUwoLjDiSeer4Lq7ortFsoxlDdqyx6MDCmT/Ri+ivAwVrxGlPQjqDjFp AE4SStUqZ8Wrx2V/NnJneT+oNnYng9CL7vuYLRYNBCjmkB7ErYfMvO45QJ978bkuZUyf MilHcsFff30DGPpdly8gn7I1Ew0T2XWNFFAnmQwEtyXCzJJFcqjUxic2swhi30EkhpT7 dU1Q== 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=l1QmaKsAs0paNUi+ts0YZyUc8/34+jxr73p6s3d8XgM=; fh=bUDnJOBC0/apF/24NaPi+H6rvMB40CebS5Pe6QbQjAo=; b=ep/MNKPThGO7ZYPgoKaqAgwvaGyxpGdYrEjYgWcPTub1T0U1mn+Omjvo8JgZcHahfD jkY/fSzNxM0Oq3fQMVi89g/9vZXZTQuB3F9OA21hWf09Af28TG510OE/LrK4Qgz5KAOs /LktV/mJSmm+xzz3pVzOedqTcz39yc3kom7BsQxosRU3HtYt7UWHpLUP8g2nCSW0+Jg4 G+fTO037axaK2U+8D6ZBrJOR17P64ZMMmrqrNIMTyR4Dp8CLP7zLNEU9DPNEUmbtMKnm CivZ1kIzbwqXoEytWxKc/vNjeMagEgpD9WPGZ25hsr8GGRKpXBDmlyKGGWaQPqk2MeJE ni3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sent.com header.s=fm1 header.b="CGv0U/fN"; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=Vo2kSa9N; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id p1-20020a17090a868100b0026b54eb88d4si208291pjn.126.2023.09.12.15.34.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 15:34:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@sent.com header.s=fm1 header.b="CGv0U/fN"; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=Vo2kSa9N; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id 5D16F8024DF4; Tue, 12 Sep 2023 09:28:55 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236729AbjILQ2o (ORCPT + 37 others); Tue, 12 Sep 2023 12:28:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236773AbjILQ2i (ORCPT ); Tue, 12 Sep 2023 12:28:38 -0400 Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D43210E5 for ; Tue, 12 Sep 2023 09:28:35 -0700 (PDT) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 895995C022E; Tue, 12 Sep 2023 12:28:34 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Tue, 12 Sep 2023 12:28:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sent.com; h=cc :cc:content-transfer-encoding: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=fm1; t= 1694536114; x=1694622514; bh=l1QmaKsAs0paNUi+ts0YZyUc8/34+jxr73p 6s3d8XgM=; b=CGv0U/fN66Lrt9dDPPSCbQa5AY52dtGJOyDZ0tS7J1mGwebKfps NhByliGCEQkj6G9iRYleWIxPKatnk3rJ+a3YHxdHMGGVH37D5ZtF7No7vvUokyK9 m6rYYOfIbeW5T5WzXU1YQSQh/ujkDjAp/GS6wb3VFCgQtB3NsRu7HsCzxiO6Tay8 h//tS5qjIls/sjbucjzlUWQVvi/pHFFOKF+KaCd1kZ8XHVTxaT1oZ34RcKwXkOIP x7TR4ziqR4Q4enld9IeNFdHldT655BJNYA6nqAxlGEyVFDRzybk+DDVlSOlXPWS3 KDrLFpYI4P1+1qsZwB1jmNLdY9FPBG7A4Rw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :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=fm1; t= 1694536114; x=1694622514; bh=l1QmaKsAs0paNUi+ts0YZyUc8/34+jxr73p 6s3d8XgM=; b=Vo2kSa9Nzs4JRJzpGNI+smMKi1kWj7MvyRZkuvWyDbwklDKbNhR VtKNQ5K4LAtVehWPTp3K0wnH3Z7lwEM2QbBQ0lmVuTrZ5eJ/iF9xFeCDE3GBLowJ dswvJsUbW3/QBcQjmazYMI/Db03ANvlW6HavV4F6KDvvaDu7IUCgtWTqpqoOn2hj f5x6uu8UTIuEgfADSSmO37zlt8Gk4Jwii64Y4doC0dCIJ07ZtWm0Sw1J9A0ZdAi3 9awfWb0w/+pt1bzsGqK8LIC+Qz5nXcei30LmyucoiQS5yL4irtCavl0HrIoVZTR+ supWj9q8RT+NIUfYfm4Uwl/Wuw1hB81+R6g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrudeiiedguddtudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhvfevufffkffojghfrhgggfestdhqredtredttdenucfhrhhomhepkghi ucgjrghnuceoiihirdihrghnsehsvghnthdrtghomheqnecuggftrfgrthhtvghrnhepge eghedugfduuddvleehheetgeeltdetieevuefhffevkefhveeufeeiieejgedvnecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepiihirdihrghnse hsvghnthdrtghomh X-ME-Proxy: Feedback-ID: iccd040f4:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 12 Sep 2023 12:28:33 -0400 (EDT) From: Zi Yan To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Zi Yan , Ryan Roberts , Andrew Morton , "Matthew Wilcox (Oracle)" , David Hildenbrand , "Yin, Fengwei" , Yu Zhao , Vlastimil Babka , Johannes Weiner , Baolin Wang , Kemeng Shi , Mel Gorman , Rohan Puri , Mcgrof Chamberlain , Adam Manzanares , John Hubbard Subject: [RFC PATCH 2/4] mm/compaction: optimize >0 order folio compaction with free page split. Date: Tue, 12 Sep 2023 12:28:13 -0400 Message-Id: <20230912162815.440749-3-zi.yan@sent.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230912162815.440749-1-zi.yan@sent.com> References: <20230912162815.440749-1-zi.yan@sent.com> Reply-To: Zi Yan MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Tue, 12 Sep 2023 09:28:55 -0700 (PDT) X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776872932546630290 X-GMAIL-MSGID: 1776872932546630290 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 868e92e55d27..45747ab5f380 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -1801,9 +1801,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_free) { - isolate_freepages(cc); + int i; + + for (i = order + 1; i <= MAX_ORDER; i++) { + if (cc->freepages[i].nr_free) { + 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_free--; + + while (start_order > order) { + start_order--; + size >>= 1; + + list_add(&freepage[size].lru, + &cc->freepages[start_order].pages); + cc->freepages[start_order].nr_free++; + 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_free) return NULL; } @@ -1814,6 +1851,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 dst; } From patchwork Tue Sep 12 16:28:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 138512 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp777774vqx; Tue, 12 Sep 2023 18:02:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEi/UDYhgAY5bLP1E0NG4o5BQl4BXdfnxq4GsUgMw0j/ubLuhlHXbwbuaMq5lbAqMoud3QJ X-Received: by 2002:a05:620a:2f4:b0:76f:1850:b554 with SMTP id a20-20020a05620a02f400b0076f1850b554mr955169qko.72.1694566952098; Tue, 12 Sep 2023 18:02:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694566952; cv=none; d=google.com; s=arc-20160816; b=oxwFCH9j/pHNKi5FlhM7n9DVXAGs+rgrb6NEADV1jUGp0cg1i80y3Wk5q6hA1+k97t zWuYjLpcTQ4cT8M7LPdIiOLyd54xbuJI4GIGjuWdefDCacpGF/SSF+f0Jzi2gBGSeb92 HvFfzRF7LbTinzuuWyEVkcS//PLKc5zSwrWeC8tiTz2xY2+kmya+WAIwT03Sey8tLuCA LCGYt2aLvv9JMUg7mVL5ohBSljBXMMDPMv8nbeJrK0Pupjl74R2lEak4EL98ANVHg+T5 N2uTPjKZ7oqz3NyMzno00s7K9msIRxxkmbJDf1UHgiGfjzWG1jLGzzbg6SUA0txONaDS 9aZg== 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=byTyyd05JmDbEdKIibYodeYHRw97CddSTrRNeSPfl1g=; fh=bUDnJOBC0/apF/24NaPi+H6rvMB40CebS5Pe6QbQjAo=; b=QaaQ6rAIlrpKfPxU46xM3TX8r1KVskFBvmHBr6BlCwNsHuKGV8m8NjWmQ+2LYfuhum ziWxAzmPvDcwU/XKDo4uH8P0vG1IlzP1x0O3O24bomaw8Z07gL1jlIWTw59BRayyIzW2 qf/ZABgt5JOGI83sy8ufGfNLN63uiTY6uurEzlBFLoS/ZsCOxB5Qu2JrEsT3O6GoenEQ fWhnOw/mi1hXr0PO7Gu7SDU4P4lKtCrvpK6XXADvYIpwzEKDaSjJgOA20JYXUNea9/mZ nCrrDBTC9g0gv70RDcWcIfj9sN0/v3y/V4xM7tPKxOxKqpKWI0YCGDMP218eCKcYadgm Nutw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sent.com header.s=fm1 header.b=QqdKC9Fa; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=AN0P2K2R; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id cd11-20020a056a00420b00b0068e4704fd5bsi8843834pfb.346.2023.09.12.18.02.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 18:02:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@sent.com header.s=fm1 header.b=QqdKC9Fa; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=AN0P2K2R; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id 1002B8024DEE; Tue, 12 Sep 2023 09:29:17 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236697AbjILQ2s (ORCPT + 37 others); Tue, 12 Sep 2023 12:28:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236783AbjILQ2j (ORCPT ); Tue, 12 Sep 2023 12:28:39 -0400 Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 101931704 for ; Tue, 12 Sep 2023 09:28:36 -0700 (PDT) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 7034B5C023E; Tue, 12 Sep 2023 12:28:35 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Tue, 12 Sep 2023 12:28:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sent.com; h=cc :cc:content-transfer-encoding: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=fm1; t= 1694536115; x=1694622515; bh=byTyyd05JmDbEdKIibYodeYHRw97CddSTrR NeSPfl1g=; b=QqdKC9Fa63nIIylhuX3PCGQuwV9dmtWfR/mazLyGKQ2+4OZ9meo 6u0MbfmLELVh08tPW3VpY7eE0jUGpD0f0hBCcPsYbrayTPcKt/3g1vA79iRGirU0 0DDb98OuKZ+PT4Apw5Utx1zuXFyQY16Z0/Xa27jNbU38TSEDSAa5eVX1SRabMaK3 rU5n6S7L6TLL+OXTLhBTgYibdxYKKNvNlyE2JwryH+czxTQVES2TV7N744KECOgg Q99ZR3+1ToHDH6Px8nmnpvYBezdgguG/oJPurUO7UvHR36q6uUvVvj2jSaeqOSNh M2o69Dm4EJYBpPihti1BcLJfCecaK0eNMHg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :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=fm1; t= 1694536115; x=1694622515; bh=byTyyd05JmDbEdKIibYodeYHRw97CddSTrR NeSPfl1g=; b=AN0P2K2RSLzgy6uNFWDc4/uLPjZXoOm9SaCVkKxTpK1h/+O5YvW RH69TUb9/Pk7kdQYyfQeDpfaqTKnldImPdLpBLg9I0r1pC5C9YOe/zFQRLyjcjLE 6CLXwwzTneyVPkCjv0P3DNAcfh/58tJXgnOFP80Yru1KuPKDPNQdE3qR4Uvj3JqR UVuLKi632KaIKJwUpl2haQIKZ6+sIBk9SHD1GUADGTtx8GlNig7dqgijjl9pMXs0 U0yMjxL/RaikpR8MC+LgeXuFHTAAgRRMhoivHoE4sfhDdPGdIZu8QjRvxXE8Lg5X 2B1jHKabqKGec0yBj+SglEIA9NrhPDanLKA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrudeiiedguddtudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhvfevufffkffojghfrhgggfestdhqredtredttdenucfhrhhomhepkghi ucgjrghnuceoiihirdihrghnsehsvghnthdrtghomheqnecuggftrfgrthhtvghrnhepge eghedugfduuddvleehheetgeeltdetieevuefhffevkefhveeufeeiieejgedvnecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepiihirdihrghnse hsvghnthdrtghomh X-ME-Proxy: Feedback-ID: iccd040f4:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 12 Sep 2023 12:28:34 -0400 (EDT) From: Zi Yan To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Zi Yan , Ryan Roberts , Andrew Morton , "Matthew Wilcox (Oracle)" , David Hildenbrand , "Yin, Fengwei" , Yu Zhao , Vlastimil Babka , Johannes Weiner , Baolin Wang , Kemeng Shi , Mel Gorman , Rohan Puri , Mcgrof Chamberlain , Adam Manzanares , John Hubbard Subject: [RFC PATCH 3/4] mm/compaction: optimize >0 order folio compaction by sorting source pages. Date: Tue, 12 Sep 2023 12:28:14 -0400 Message-Id: <20230912162815.440749-4-zi.yan@sent.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230912162815.440749-1-zi.yan@sent.com> References: <20230912162815.440749-1-zi.yan@sent.com> Reply-To: Zi Yan MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Tue, 12 Sep 2023 09:29:17 -0700 (PDT) X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776855697309131512 X-GMAIL-MSGID: 1776882236553179477 From: Zi Yan It should maximize high order free page use and minimize free page splits. It might be useful before free page merging is implemented. Signed-off-by: Zi Yan --- mm/compaction.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/mm/compaction.c b/mm/compaction.c index 45747ab5f380..4300d877b824 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -145,6 +145,38 @@ static void sort_free_pages(struct list_head *src, struct free_list *dst) } } +static void sort_folios_by_order(struct list_head *pages) +{ + struct free_list page_list[MAX_ORDER + 1]; + int order; + struct folio *folio, *next; + + for (order = 0; order <= MAX_ORDER; order++) { + INIT_LIST_HEAD(&page_list[order].pages); + page_list[order].nr_free = 0; + } + + list_for_each_entry_safe(folio, next, pages, lru) { + order = folio_order(folio); + + if (order > MAX_ORDER) + continue; + + list_move(&folio->lru, &page_list[order].pages); + page_list[order].nr_free++; + } + + for (order = MAX_ORDER; order >= 0; order--) { + if (page_list[order].nr_free) { + + list_for_each_entry_safe(folio, next, + &page_list[order].pages, lru) { + list_move_tail(&folio->lru, pages); + } + } + } +} + #ifdef CONFIG_COMPACTION bool PageMovable(struct page *page) { @@ -2636,6 +2668,8 @@ compact_zone(struct compact_control *cc, struct capture_control *capc) pageblock_start_pfn(cc->migrate_pfn - 1)); } + sort_folios_by_order(&cc->migratepages); + err = migrate_pages(&cc->migratepages, compaction_alloc, compaction_free, (unsigned long)cc, cc->mode, MR_COMPACTION, &nr_succeeded); From patchwork Tue Sep 12 16:28:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 138515 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp779007vqx; Tue, 12 Sep 2023 18:04:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH0FlHfrZ57S9RhgUB/P/REuRwe9cZcyb7BkdEYMzu+6MMax2JUqSDZ5eOtAy+SqrqerZbz X-Received: by 2002:a05:6e02:1ba1:b0:34c:cbd4:114b with SMTP id n1-20020a056e021ba100b0034ccbd4114bmr1362034ili.7.1694567098285; Tue, 12 Sep 2023 18:04:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694567098; cv=none; d=google.com; s=arc-20160816; b=Ha9c2D1H7f2aT/XiQ1VVL+HsRIfGzOepC7VuQ6FZQXbzRDO6QMa8w1Xl5vrZ6SJqko yvrRdaqR1quojE03+DstskaSLOpggW1NKtOL8JgEx4sOgNZV4JQocAgtOn8IAVZUu99s DYeW6+TiDCjILMSuZvo1FxLRKC5cFDeHiiCakHyE+wmLPYR8pNddr7KzutdYaG+qp0dy JThLY0PjiCwsHKhoVi3y02lkzVI1KwKmco6wNgsoJ1YkvBOqNxi2w+Ow96vFhHpKgFy5 7U9zOVYvTsnFQ6gyQZ45LKImQSeAYA1Zp1z/mAgZiEN/TlMZzh2kAdkFz3cNXV4sn2bq tn5w== 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=TwEWLaTSuiPfXSyZQQREOyn/d6B8hR8gYLYTWMqOU5E=; fh=bUDnJOBC0/apF/24NaPi+H6rvMB40CebS5Pe6QbQjAo=; b=YWfiXjtzWaZsrcK0ELerPLipAN/XBYycS/ai+En/tLTuTToSMISJmJHUSBS7yLCnTD LY9F3p1KZ3x3TCKIR+CyNF4VdCrjjEZcFA6BPstIMh6umDiFiPnF1CiOGoxwKgiLUbVQ 0BlWpgTthwr1m2JNcaMvTpDKyOFrW8H3djkFqBjDSd1d5aMM9cZ/Z+sz3eBtymGxIEHT aSpYk4s+T1sNnJXFEV7ex+qCZaY68quyC3rVoEbpS1xP+BdnYnifhHRDxLpe4YvpEtiO IpiDp/RLxlY1eboKGDNVlj/PjiM2J+EghFfT+MQFt1ajSNeRa3k1L9XKgruKl7zN1mmJ F9IA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sent.com header.s=fm1 header.b=u5uNvQki; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b="VvFvl65/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id v71-20020a63894a000000b0057754fff97fsi6074351pgd.492.2023.09.12.18.04.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 18:04:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@sent.com header.s=fm1 header.b=u5uNvQki; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b="VvFvl65/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id 3503E85C4D47; Tue, 12 Sep 2023 09:28:56 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236847AbjILQ2v (ORCPT + 37 others); Tue, 12 Sep 2023 12:28:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233213AbjILQ2k (ORCPT ); Tue, 12 Sep 2023 12:28:40 -0400 Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0165910F2 for ; Tue, 12 Sep 2023 09:28:37 -0700 (PDT) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 5FFBE5C0209; Tue, 12 Sep 2023 12:28:36 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Tue, 12 Sep 2023 12:28:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sent.com; h=cc :cc:content-transfer-encoding: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=fm1; t= 1694536116; x=1694622516; bh=TwEWLaTSuiPfXSyZQQREOyn/d6B8hR8gYLY TWMqOU5E=; b=u5uNvQki5IChwpw7dqOdoH2RgOW6FYZOpuvWCwUsE8BibTdAFyC L8upBPyueKVuNqlWXYbuyapJfDQO20M5AqGh1+0aVvuzhlNl1Krtf7epALgCiqVT LtrFxAwSrToe6Er0K0x1TQOGJUoauWNEH1H9r5iPq0AQSuELfsQjRG9AbfXrPLfz M6xMX2l1mAwZ9/iAbsgg/soIaEIHaX3K9ZC3DzbgNUM+4GsJ94yzCA90KcELtR75 KHS06immhfhB8LT+Ir2TYfZg1Ha9S0LWb4+HYB3Mv0LDhdbH1t91QBfV+b73TkEX H47LcrEu6//1SXi+ITP1Xw21mEu44uXADXg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :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=fm1; t= 1694536116; x=1694622516; bh=TwEWLaTSuiPfXSyZQQREOyn/d6B8hR8gYLY TWMqOU5E=; b=VvFvl65/6cb6f0859IZG6gNDxwnMA826lLsINlmO37UMNzdvAeV KvEUnoG/gbp7oYZQ73UiJJiXyyO3TpEqnLU+6Cj6YZlgDhnG825QlYnTlw4bLhp8 JVzF3PzjA0HovacaUJerZ9qdg24e6KF4dV/PPPOGyaRmAekJv4SkXA1xOQtOe6Hu 2PxnMutqZ0KnjG0/dlscS3wTI67voGp/+tzIf453kIeWIUhQ+Z7OdrY75DMFLz9A zKTXBtzoxlfLqjVkSgz+FubWk32IaGcd5KJfDorOCzW3CrckRl9J49UllAbMkild lq6+F8xObqmsMXpZTojwhRCOit/zuGfhW+g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrudeiiedguddtudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhvfevufffkffojghfrhgggfestdhqredtredttdenucfhrhhomhepkghi ucgjrghnuceoiihirdihrghnsehsvghnthdrtghomheqnecuggftrfgrthhtvghrnhepge eghedugfduuddvleehheetgeeltdetieevuefhffevkefhveeufeeiieejgedvnecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepiihirdihrghnse hsvghnthdrtghomh X-ME-Proxy: Feedback-ID: iccd040f4:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 12 Sep 2023 12:28:35 -0400 (EDT) From: Zi Yan To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Zi Yan , Ryan Roberts , Andrew Morton , "Matthew Wilcox (Oracle)" , David Hildenbrand , "Yin, Fengwei" , Yu Zhao , Vlastimil Babka , Johannes Weiner , Baolin Wang , Kemeng Shi , Mel Gorman , Rohan Puri , Mcgrof Chamberlain , Adam Manzanares , John Hubbard Subject: [RFC PATCH 4/4] mm/compaction: enable compacting >0 order folios. Date: Tue, 12 Sep 2023 12:28:15 -0400 Message-Id: <20230912162815.440749-5-zi.yan@sent.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230912162815.440749-1-zi.yan@sent.com> References: <20230912162815.440749-1-zi.yan@sent.com> Reply-To: Zi Yan MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 12 Sep 2023 09:28:56 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776882389724026298 X-GMAIL-MSGID: 1776882389724026298 From: Zi Yan Since compaction code can compact >0 order folios, enable it during the process. Signed-off-by: Zi Yan --- mm/compaction.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index 4300d877b824..f72af74094de 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -1087,11 +1087,17 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, if (PageCompound(page) && !cc->alloc_contig) { const unsigned int order = compound_order(page); - if (likely(order <= MAX_ORDER)) { - low_pfn += (1UL << order) - 1; - nr_scanned += (1UL << order) - 1; + /* + * Compacting > pageblock_order pages does not improve + * memory fragmentation. Also skip hugetlbfs pages. + */ + if (likely(order >= pageblock_order) || PageHuge(page)) { + if (order <= MAX_ORDER) { + low_pfn += (1UL << order) - 1; + nr_scanned += (1UL << order) - 1; + } + goto isolate_fail; } - goto isolate_fail; } /* @@ -1214,17 +1220,6 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, goto isolate_abort; } } - - /* - * folio become large since the non-locked check, - * and it's on LRU. - */ - if (unlikely(folio_test_large(folio) && !cc->alloc_contig)) { - low_pfn += folio_nr_pages(folio) - 1; - nr_scanned += folio_nr_pages(folio) - 1; - folio_set_lru(folio); - goto isolate_fail_put; - } } /* The folio is taken off the LRU */