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: 13381933 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 9BE7FCA0EF1 for ; Tue, 12 Sep 2023 16:28:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DFE546B012C; Tue, 12 Sep 2023 12:28:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D86F56B012D; Tue, 12 Sep 2023 12:28:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C27626B012E; Tue, 12 Sep 2023 12:28:36 -0400 (EDT) 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 B62D46B012C for ; Tue, 12 Sep 2023 12:28:36 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 8AB48C02F9 for ; Tue, 12 Sep 2023 16:28:36 +0000 (UTC) X-FDA: 81228478632.26.5057287 Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) by imf22.hostedemail.com (Postfix) with ESMTP id 6E4C4C0019 for ; Tue, 12 Sep 2023 16:28:34 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=sent.com header.s=fm1 header.b=ZpTUQyvb; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=OcdsQuOP; dmarc=pass (policy=none) header.from=sent.com; spf=pass (imf22.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=1694536114; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=9vQ7qsdQ+RP7SfzfLEPFzsLiQiKEomD6WH+2Rhu3mcA=; b=CGsOVDAo1XhyEa4URd1MmFRD93IVOgs/aXuz+b9UaiyLNc0nF3XIt9tN4py6lt9zfUbNXA 9/7mhidi/HyO5m6mei5HmIVS8ZludfQucoKhYO/sF2E6BH85HU7xOpd/41sAw9TztXt4/C VJbwLqc0nfm2MrJ41GBA3embavdtpeE= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=sent.com header.s=fm1 header.b=ZpTUQyvb; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=OcdsQuOP; dmarc=pass (policy=none) header.from=sent.com; spf=pass (imf22.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=1694536114; a=rsa-sha256; cv=none; b=uru8waVV0dXyhU2pNtrNZWtX0joyAzbebuQ3sXBmMU/9N+8L4iCjmem2EXkuxHqLYibfEN dpfxjk34cEO/Dm4VqjtXHTr/byhMfJa4L9A/uy6J5RDr/bboiizMG4QFnFQkaFFNouHQg5 R92/UCHUZj7aRqMURTi4eZy9RIPaC/s= 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 X-Rspam-User: X-Stat-Signature: h7g73zdq89wcg7bpd9xc7hzj3c4u3ctf X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 6E4C4C0019 X-HE-Tag: 1694536114-784188 X-HE-Meta: U2FsdGVkX19tX5KHQEpQHSNeyTr5qHHiPg4w4EshVniOwCSAtMHcr2JxP5ls49KDZAE1Pxr3DbiWcuzhNgZingvWsBjOf1WJ35n7jaoHq5/7xjUkawQ++PcKRnLNfHT2GZ0AqPe1G1sjYpdDJEmU+AyB9KtntSzhWF1fqedCW+sL+9BnyyX2GWImlc5YbIEvdjRgrbVW58Myig3gfz8vOBO46OCNEvZXfqQvvnqKMeiq17Ggg8HMkQYnl4Nl+hrmpkdMeeuujQw/SgJ2RYkQk7IYFnzIelhBzsAzwMJRNjlpSfuiJxrWrAbYVUKbKwTydZHbPvOI6fSphwtt5HNaVnYLf49q3IchWrNzrmtx9IyL7cCpUClEgRWfQdVGk37Aj1aoC46BK9XmS+3XbiZKpv+bhUQoLt+E+9S9uMGtO/TJxXi7m3vt4TARZwNDgpqx3VReWhAWhNGHzv4itKu1w8kJ7f4OTAaGKuZJysa1hAD+6VQQ8Qv6eF9z2ItPFMq5gwWI8gNDdcMCV/AvVRYIrSxdIbktV1bj/jdhU5BwIR7KaPlFE4fMvKlXiIgZV5blTqLZ3PTGQQULzuIHhzZ9mqwGjM/9D0JLsYYEZODqzP9NbG4KEbctniYeqCeuriKeKbV3D5+yqI/jScxi87+g7mVJqA5BeVJG+ImfUAUKb3WLIRWVlXDGzpUwqM7v9GA6IkZ2GZnmFJi06+tGDzxcrJxbc637JiK1sJXWM+uzHT7e1yFBaB/pR5tVZkJs4Fy54IME7ELUm6q+LYX5szcKMF/ye6c8GNAwb6QNhdmqb4F4Rauf1Gte/8uHS3F0sT7O+uhzX2REkqjrmAdm/A498yot6h8mWcM65vnbZ8PJBor/xB8s5dKrPnfrB9PI7yuMkV2B19hC3QK0FI+HabA7W2vzwIu8kk8Qi1+Mxx9rHfSF0tHv2OsesA/Q/CjcAdWVtpBxyX8sMW4yTrLY0AD 5lPd8bh+ F7ttf9Ve8E2M7ymlIxZPh+yu1t82XASbYDysgNo9pSK7ps5mnz4BwLXXGjnEa4rOEb84UX5a96XhLe6nh1ok/VjKcJRtzLBwa/u+f40AiWGNpb1V68OC34scLDhEHqJ3YiYjVFtX5LiWBd1Az50laMKc3AarkRuFitdlDNWM7S0UgWx7oaLSZmmV+21ornoN2eygULC07qN+B1tp++DV7iPalvu/Jj06/KdPZcTjwU3MBNcYt1tsbg61hc3WCscaj+R0vDNN8ZSAtx0eanWSRsFTltWoIp5OWxGCQSqMcnE8r+k9qF3dacq5XlIiIFgvOvLgqTHiVkmo63YabLkMbnOxlsxIDy+QSUDXPiN0CnsQfkRAMb2VrqLIf0fO02iNJf2BlK7PjpNZFRmYbr7JwwAKku1XFGzlNKPeKdxvgQrVN3xusXp+oYSaFe47Bpc4hmz4dFLJ/Z3+590ySQzpfihlvSdbEAv1tXkC4LIOa7hJFgwnelHJ1QRlXo6UuZ2uJoEAk 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: 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: 13381932 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 CF45DCA0EF5 for ; Tue, 12 Sep 2023 16:28:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 350256B012D; Tue, 12 Sep 2023 12:28:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2D91E6B012E; Tue, 12 Sep 2023 12:28:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 12C4C6B012F; Tue, 12 Sep 2023 12:28:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id EF3B86B012D for ; Tue, 12 Sep 2023 12:28:37 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id C46621A0C5D for ; Tue, 12 Sep 2023 16:28:37 +0000 (UTC) X-FDA: 81228478674.11.1D69547 Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) by imf25.hostedemail.com (Postfix) with ESMTP id 45487A0027 for ; Tue, 12 Sep 2023 16:28:35 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=sent.com header.s=fm1 header.b="CGv0U/fN"; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=Vo2kSa9N; spf=pass (imf25.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=1694536115; a=rsa-sha256; cv=none; b=WndHT3cSEwnoUt6yad0JNA0MfsQguzOIBYyRcefz2IKDfQhH+ZJH6ti0lhJAiDUHxpeaoX b4XNkK22KsKoHt96sOzL7X3vL5DOwEmIsBnVEtGA/CRGhoQVuek5hX+rZLJrrwaeiPpGcv msdBheAfGnh+k6rLJMGo20iiZ8e09Eo= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=sent.com header.s=fm1 header.b="CGv0U/fN"; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=Vo2kSa9N; spf=pass (imf25.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=1694536115; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=l1QmaKsAs0paNUi+ts0YZyUc8/34+jxr73p6s3d8XgM=; b=ji5B5Z+LgHnh8dag0w7UeUGjpLERvuL1hyZ7FvEgpB7pPTmWS38e2rtkX4HVOsK+3vycnU w82AsIAeIRjoxCdM6oRq2m/AmNNavssEoC4nHqIoSEDdDCwBjXMnW2bfjRsygGyWvRpbBW 1OjGUNxR3iKQ1WLuWRKgFTMDvQCCGgU= 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 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 45487A0027 X-Stat-Signature: 3p3kwigsnywf1z4ukn5swsxrh6rr7ub8 X-Rspam-User: X-HE-Tag: 1694536115-1038 X-HE-Meta: U2FsdGVkX1+5CKOG13gAOfXAPJGoRGo5DyxSZdAM+RywxkrhfTRxaHfGgFM4IRjsvkWk3l3KtAjAo6MOTgjYM5fjVP77OSlibmSsTdekYU2inRswfjfY+RV7WO9eXebYuiqNv+BsHhqJx1agrXOIkYToWybW9wCMQGmT+I00X0LODZNlj/KAU85M1Iv66LLvDury/bDc6MZaFX48MHUsuw0jKVnjwYYNhyQ2tHzMD01byPtqKjwGhmD07feOAWsM5NHrnCrKM3e6oGpSlQfk4FWkriFXw7WkAAmPjWaVmUTtyepor5r248qs+LrrItonyFivVc3u5GQpDKxxfD5SVyVKkm2gRBcQkYSBKtA3fgzYMWDsjk/JS9iOItayVIt8jmbO/+/W2unwi4bjM3ApvL9//XSziopmAukM3LV3ZbNor/pZJ9+TG01yaHQNI4Pm9zUQpYwAxa7HhWEpsCqSK5BaQDRBDh2aHIyOKZCu5Zza8VeB98X9Oe12csH3qrXQbfsKck7PmnsN9JQ6m4db6EWugNEGOFzSiDhk94SLVIlrZ8G1cmaDn/fWSGLFfxD35m4Jh46lAig+Xioy6lHTb9IPH9dYEF0FRnx6/C2wL7ToJa28uSkjsn5rpFco+ANmsZ/aOrcDr0ahhSxZc/idEaBS0jJfvkVfvqEDGIKIs6fIIQsGyctDfHUkQmX55o6IO46nkTbNSL4VCFIcDICpBQxTerIox+TCh+yXesSHxrfxacCEwk6e+G+UEiy+TBWnEh5IPxYwfyPT89uqn0+qj2lo/2rdf15VCJ2M8mS05PXnPq+2q3q944tHQTB6k0Y/PAsybsWb8a5vNqrwYshiTFaNzOkgC0b83TMsHs79JdDsT1AoUei5jfM1hgQk+UkKDIsywNvyiYLzt2yVBXmiMQSTrJOmZu+KKWXdt7pnq/O9kA7E3GGNQplPzOe6saYteWk6l+oQiNBRR5Cz+en gLpY9Ywm Bnsg+ATLE/cUZko6jw5WSl1R9FVuG2LezTSnh5ud5Vw0bpG7pXFuFrwaH/gtVuZJVYiX1Z5Ko2px7hM2J9RMV0Gxir10BtPHj9F9b/zkPLpiOXit33XDvTZtRIoR68DyfzAVwLtir2CE/2K3Ikjbl5Bq93Cwuk+bKQ97FH0Jf+5tYM9bZPrIu+dTbUR0KIrF2qzu5WFZwruG/UUC4Wb6rfarHvL4fxyYLmlvITrb0lHUjYJCUw50IE8f6NWF08PedAKV/M15+P6wPcgdT4/5bTK4bQfpLoUcy8TlmOOgk71Lr3/8I2qFXY9sPxKvM4yIt7LaL3x/eOcMX0PcroAM+K2wvedSp+tBl0NdEtcJ1MZU+PnTq5xl5FRKMtnDvZniPH5EWqKspzv+lJB+VkcNtcKkNYkHctR1vI/9j8swEZf8GSBZI1aT2UZ1cegVQSXzcLTvteHRArST0RnTX5pNJwcqDng== 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: 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: 13381934 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 E7900CA0EEB for ; Tue, 12 Sep 2023 16:28:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9928C6B012E; Tue, 12 Sep 2023 12:28:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8F2E36B012F; Tue, 12 Sep 2023 12:28:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 745406B0130; Tue, 12 Sep 2023 12:28:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 624AB6B012E for ; Tue, 12 Sep 2023 12:28:38 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 3B87AC02F9 for ; Tue, 12 Sep 2023 16:28:38 +0000 (UTC) X-FDA: 81228478716.09.86D8B69 Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) by imf16.hostedemail.com (Postfix) with ESMTP id 1B52B180031 for ; Tue, 12 Sep 2023 16:28:35 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=sent.com header.s=fm1 header.b=QqdKC9Fa; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=AN0P2K2R; dmarc=pass (policy=none) header.from=sent.com; spf=pass (imf16.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=1694536116; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=byTyyd05JmDbEdKIibYodeYHRw97CddSTrRNeSPfl1g=; b=4aaXQtDnTXmskscFORsd+r0WC7okZlA3D1kZIB7V+PiNN1ZcjGWT9gUujuBSoO3WPuzB4O JhTc6BeBenXT2HWEfqGf76MQqlTj9vhZDtbRnxbL2iQIQ3oo5pz880WzN2byWn9Ag1lDYC brokVP+TVVe/UFACAv130ER1hW0SH7I= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=sent.com header.s=fm1 header.b=QqdKC9Fa; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=AN0P2K2R; dmarc=pass (policy=none) header.from=sent.com; spf=pass (imf16.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=1694536116; a=rsa-sha256; cv=none; b=u+WD63QVsoU1N7YQU3tVs0wnNfp5P7WODxhr+lJUF0WrZtwaRVFsVEtP7gcr8mr+du8dS4 GRqgzFk+YZU/aOBQW0/Vi4HU8RPhcMHHfmnL3UHtBmexT2vm7ySIRlRvFL8RlMkw7xuLKM 5sVbXOei9kJqKgY4pVEYNuc+un8up0g= 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 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 1B52B180031 X-Stat-Signature: irpygxsmisfw7h9fadxehbdjf3gttbfd X-HE-Tag: 1694536115-135356 X-HE-Meta: U2FsdGVkX18PJgHkPtVf1pL0FYEsIq0SbHTdbwgrJ0VdKbg/Z0SfrC8vhCMCrcx2wOgCyu+BTM5dpsB1mfYCktbunyE6xiG0KriGv/KXsAPEo5eDO1H5P5A76GJustzsDXQfhTNe58y8IKG1AA4LqODV8H4nSvVkB8q+9kjR/IteQGDs5MzMgmHOOsNLIQeepoHw05i36nJ/zTr8DNfg5BXC1gDIUlxPe2JrH4JrPwmlp1UTGqb0JagYE1n5aV6QcbeeygPJcYd1zjMRVu6biBJWm7DrelhFCqcmrCTx1QN4wJuXWLtW0E/RilK6yBKOHnp2UmmX3k4rYp8NL8xXELLuJLQDkfyej0WTuNwg0ucL3fDI4qitupAQB/6nc2riF66mhs/VJisDyWVcyH+Ls8o/yYYGVn0yhQgvqPc/JqhxT2eV6V0sitMOC+fBnctmDtDOqY3QZIBfWyqCwCStiOb3TcXUqGsUUtyiBo/NU7Zi1uX0Uyg0M+0cTmsJUm0CAHbVt/cIGVr2HneAqfUWhrsyI/pI0OUc4snhkECnlDPKDlJgeY/kZy7dOJn+EMfxqR9Xr17fdfAhrgKnVXXbgj4RvGKkyG024D6E58wYOWOdo7jOddQzmvZb8m318wcUriGzDZtE7V+CTvB0tLGKHoe+bb3dlOs4JKzDRaZod1qG2tx8/f2vJRsxd6nmpnIp/H6O48+YZonwjzcFdVo1YZbwiVyuKkOFssW29L3KMiIHfT6MxuVihHbGz6cw7VAKWYoKSett1+PKWORw+9cu/4ULJC8Q9rUBdtcMTsqbh2S6UHYFRPuwHbgrxrTOobtgV0wbQjCQdTPaO2UFMiGGa11chKiXvWGjfaPy9g9HmLC8/RWVcFNT3jkeA1yWN/J8LWM1XdAB9i0Rqti9LLhP3nghmjnclpAY0iz84nvTU6hUvok4hZ6v5GBeeBSwEJe+Fircd6SEBQZ21sQWNsV 2M4P7kG6 UyCnyyxwCU6cifZGC84jI/doZTII2HLiDE8fxTzpVZW+n6R0ecHTGNa+pHMYTrbP6KFTwG4XQqd7J0VfOqOWoksVtvKHq13Gz3E1ga50O1HNl1y/9FVR7PTzSPR4zc80jLHrINGxr3ro9KKDCvPgvOZkcIAtGYQty4+s4NxBtaCXHlfUpO1uy6UM41K7Flm6a0T+B1Dx2ijundATEixe9g4dhUgDNOCMb8frDCf+W7mKKL/w6X0mHuVKIPdh5iQM6/O60enJrP36zvjSgzzvwRnK4DgYaFEaMeTl1j752aTXPDXFqqABrWtMQjRrcEHYa0ctG3tITLN+4FuCCgHoynMqs0wG0KfgXD9rI3aY7nXGSy3Yl0ZX9YbQlYZWVGCm9jyuhNe1pfgnuzBO3yEWPbdUTyFpnso8q96JFJvW/UXjZied2YDLxMRghAN0g7rPep11LSNZ6W6s1h3RcQlxQ3yAFUaYuBGIL4whpIY70gQlRTjPX7UgUIDNqpdoNflKJDzREJK2gVIsoUpHJqIQW0maDxCf3oGv1THIYGn5994t2mzk= 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: 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: 13381935 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 18D98CA0EF1 for ; Tue, 12 Sep 2023 16:28:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A53F76B012F; Tue, 12 Sep 2023 12:28:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A044D6B0130; Tue, 12 Sep 2023 12:28:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 87ECA6B0131; Tue, 12 Sep 2023 12:28:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 77EC46B012F for ; Tue, 12 Sep 2023 12:28:39 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 475A2B3EED for ; Tue, 12 Sep 2023 16:28:39 +0000 (UTC) X-FDA: 81228478758.27.47E683D Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) by imf26.hostedemail.com (Postfix) with ESMTP id 1FB6614001C for ; Tue, 12 Sep 2023 16:28:36 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=sent.com header.s=fm1 header.b=u5uNvQki; dkim=pass header.d=messagingengine.com header.s=fm1 header.b="VvFvl65/"; spf=pass (imf26.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=1694536117; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=TwEWLaTSuiPfXSyZQQREOyn/d6B8hR8gYLYTWMqOU5E=; b=IS5ZOcY8R3N31u7uWjw6sgKYRpvyT8vfzECQ4I15TUL3hNUA7552iSvO5IMSxsU7QcgP7F eer24JBJXS1I+cNKd/FwZ5QthwxDqkQwYt7EcfKemgj+ZwkmE5tbUpUMujXWAiEIe25I6F 7CRMnQ67Rv/1meQblC1ebc39IGw4YLA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694536117; a=rsa-sha256; cv=none; b=36PYi2lm9iJY/WEOk9xJlNetU4nzKer8mv06UR5cN3XeqEk//fi36t2FhQ90Jig2mgOXLj QBYzJe5LuQAnh7q+0tO4QpqAkmleMdiAMGVjEX/dl+ECc3YBZgtoaVeJIooS3nzmpL5vot bJBOttPgcF3AFqRErFbzpkSJ+rxp8kQ= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=sent.com header.s=fm1 header.b=u5uNvQki; dkim=pass header.d=messagingengine.com header.s=fm1 header.b="VvFvl65/"; spf=pass (imf26.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 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 X-Rspamd-Queue-Id: 1FB6614001C X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: tbiiq1b1mxkxr4b3iasojbxmnmcaqibp X-HE-Tag: 1694536116-897181 X-HE-Meta: U2FsdGVkX1+yRoe36Gqp1x2O2Bn9un0baSwAfz0cPNwE1gDvfVvRcdM1/Ft/XQFVjJuEgAf3QyQG9NL1kGY9gwfNktJRiDfExemQGNXhdO7RiiwxUyRzaRNfXrX704C4PE3WyYFTXL6cgDSLUxRdBjR3vRQBDe9oRBrNaE36x+t+WL2HFQdBELVFSIbSU5Nq8lsYXPh8yYuv47aJbKX21sEZ/dIXXLul7NPoQz6A30FQl10Zgcy0blmob/Xv83OaJzz8JVUjqU98A9XgpCS8T2ENNe6pPyRN3NXik1JjHPxeK68iIXe0HV8DBySnjVkjFvfb9rLuWWgfD9CwvohLAp0ABRZR/CzVuf/xwKVI8Di6W8MRlae6xZxO9T/nE6uQgVIGN/B6bpKOfgrpTf+Z2yObskriqCP8/IBp+qamsBVBPJK/6lItW2fcUgMp1RRIi5lRNc4uVmFP4tZ2/SSZdWTUB/c9RztMa3IQ2n/BaUfMWdTC9XJZzvuhfo0qCi040Q24RThH6+X9oEA3SK51Vlk8fqF//eec+zTxx7olJPRi9UdLlrwJz7Smu5mAzFYxHE5i0WgbO9cUsCPjL8KrvtoYWFuIyOcqQWvpBFJ9JMuIHw6EK4TX1mbN9lwUBKeJRzir4GI4pYs5uytZaXMtFb7H591/xaS7oV71vyXXpYajDSHo4cup+Gut7JFTEiRESrzO/LGoMZ9YtVG4fLXqcJftIRu2co6khMq1jLEs156Q436pke+XNEO6mtWXYrb1dIlv18SPtZazmhCcMN8PkVmaZpiT+k7teaJ6yl1uR+AVEn+izy3E81UyVVPKNDKqHfmkoinQv4KfyxldHMKY90hmxM+bSJwqy/a8Gjo6GoUXKjTZqzD8wB14nGSA/Tp4JsNG32qSI4WDJj135AO646Yob5QehIgCqYkFcNU9LKQw0F1tlLR8EFj8BBE7YxA+6mY68x4oDQipHqXDoKu nThsfSwC Ki8QA1R/GwL9Nmo4WtPDqBmbNJ0KGqoQv5HPcY+V9AWis9YvQ0LOeG0NmNVEQc78u3UUX1mE3saq6j2lh3nOkLPEiliMRs7zMKg3ta8HLNLsaeKR+zNXOslWAG8z1OYKKjyRqZzfCjTZ2oMISQfHLBFkGgotXV23pWMGYwdwbIOZo3AZh2rLDNjOEeyRN3HWY0p75RcmnAN5XioQKURtj+tolAovZ/7p27p1D/ZszNXs/sQi7LK2l9yhVkGoX+eaWJ7ftcKOed0cFjh19yJH3ImrMsSuXnkUgkg5VCD5VQcnaLjPpNozS31oQV42dC6bhPXwetGpgeR9+Y34Z0NBnDodXsuUoT+zAsXMbxHfIcebMyFGoTAstgvUzy4QzPQp0TwAKMMSxn+JaWMOU3CgwyEQSXofAl20a3c3SAZrbST0LG9GWiSbmrmXN04H0qYKLhKYXPF4TDPEEmukAhGWZlID0CQ== 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: 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 */