The patch titled Subject: mm: allow deferred splitting of arbitrary large anon folios has been added to the -mm mm-unstable branch. Its filename is mm-allow-deferred-splitting-of-arbitrary-large-anon-folios.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-allow-deferred-splitting-of-arbitrary-large-anon-folios.patch This patch will later appear in the mm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: Ryan Roberts <ryan.roberts@xxxxxxx> Subject: mm: allow deferred splitting of arbitrary large anon folios Date: Thu, 10 Aug 2023 15:29:38 +0100 Patch series "variable-order, large folios for anonymous memory", v5. A series to implement variable order, large folios for anonymous memory. (currently called "LARGE_ANON_FOLIO", previously called "FLEXIBLE_THP"). The objective of this is to improve performance by allocating larger chunks of memory during anonymous page faults: 1) Since SW (the kernel) is dealing with larger chunks of memory than base pages, there are efficiency savings to be had; fewer page faults, batched PTE and RMAP manipulation, reduced lru list, etc. In short, we reduce kernel overhead. This should benefit all architectures. 2) Since we are now mapping physically contiguous chunks of memory, we can take advantage of HW TLB compression techniques. A reduction in TLB pressure speeds up kernel and user space. arm64 systems have 2 mechanisms to coalesce TLB entries; "the contiguous bit" (architectural) and HPA (uarch). This patchset deals with the SW side of things (1). (2) is being tackled in a separate series. The new behaviour is hidden behind a new Kconfig switch, LARGE_ANON_FOLIO, which is disabled by default. Although the eventual aim is to enable it by default. My hope is that we are pretty much there with the changes at this point; hopefully this is sufficient to get an initial version merged so that we can scale up characterization efforts. Although they should not be merged until the prerequisites are complete. These are in progress and tracked at [5]. Testing ------- This version adds patches to mm selftests so that the cow tests explicitly test large anon folios, in the same way that thp is tested. When enabled you should see something similar at the start of the test suite: # [INFO] detected large anon folio size: 32 KiB Then the following results are expected. The fails and skips are due to existing issues in mm-unstable: # Totals: pass:291 fail:16 xfail:0 xpass:0 skip:1 error:0 Existing mm selftests reveal 1 regression in khugepaged tests when LARGE_ANON_FOLIO is enabled: Run test: collapse_max_ptes_none (khugepaged:anon) Maybe collapse with max_ptes_none exceeded.... Fail Unexpected huge page I believe this is because khugepaged currently skips non-order-0 pages when looking for collapse opportunities and should get fixed with the help of DavidH's work to create a mechanism to precisely determine shared vs exclusive pages. [1] https://lore.kernel.org/linux-mm/20230626171430.3167004-1-ryan.roberts@xxxxxxx/ [2] https://lore.kernel.org/linux-mm/20230703135330.1865927-1-ryan.roberts@xxxxxxx/ [3] https://lore.kernel.org/linux-mm/20230714160407.4142030-1-ryan.roberts@xxxxxxx/ [4] https://lore.kernel.org/linux-mm/20230726095146.2826796-1-ryan.roberts@xxxxxxx/ [5] https://lore.kernel.org/linux-mm/f8d47176-03a8-99bf-a813-b5942830fd73@xxxxxxx/ This patch (of 5): In preparation for the introduction of large folios for anonymous memory, we would like to be able to split them when they have unmapped subpages, in order to free those unused pages under memory pressure. So remove the artificial requirement that the large folio needed to be at least PMD-sized. Link: https://lkml.kernel.org/r/20230810142942.3169679-1-ryan.roberts@xxxxxxx Link: https://lkml.kernel.org/r/20230810142942.3169679-2-ryan.roberts@xxxxxxx Signed-off-by: Ryan Roberts <ryan.roberts@xxxxxxx> Reviewed-by: Yu Zhao <yuzhao@xxxxxxxxxx> Reviewed-by: Yin Fengwei <fengwei.yin@xxxxxxxxx> Reviewed-by: Matthew Wilcox (Oracle) <willy@xxxxxxxxxxxxx> Reviewed-by: David Hildenbrand <david@xxxxxxxxxx> Cc: Anshuman Khandual <anshuman.khandual@xxxxxxx> Cc: Catalin Marinas <catalin.marinas@xxxxxxx> Cc: Huang, Ying <ying.huang@xxxxxxxxx> Cc: Itaru Kitayama <itaru.kitayama@xxxxxxxxx> Cc: Kirill A. Shutemov <kirill.shutemov@xxxxxxxxxxxxxxx> Cc: Luis Chamberlain <mcgrof@xxxxxxxxxx> Cc: Yang Shi <shy828301@xxxxxxxxx> Cc: Zi Yan <ziy@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- mm/rmap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/mm/rmap.c~mm-allow-deferred-splitting-of-arbitrary-large-anon-folios +++ a/mm/rmap.c @@ -1446,11 +1446,11 @@ void page_remove_rmap(struct page *page, __lruvec_stat_mod_folio(folio, idx, -nr); /* - * Queue anon THP for deferred split if at least one + * Queue anon large folio for deferred split if at least one * page of the folio is unmapped and at least one page * is still mapped. */ - if (folio_test_pmd_mappable(folio) && folio_test_anon(folio)) + if (folio_test_large(folio) && folio_test_anon(folio)) if (!compound || nr < nr_pmdmapped) deferred_split_folio(folio); } _ Patches currently in -mm which might be from ryan.roberts@xxxxxxx are selftests-line-buffer-test-programs-stdout.patch selftests-line-buffer-test-programs-stdout-fix.patch selftests-mm-skip-soft-dirty-tests-on-arm64.patch selftests-mm-enable-mrelease_test-for-arm64.patch selftests-mm-fix-thuge-gen-test-bugs.patch selftests-mm-va_high_addr_switch-should-skip-unsupported-arm64-configs.patch selftests-mm-make-migration-test-robust-to-failure.patch selftests-mm-optionally-pass-duration-to-transhuge-stress.patch selftests-mm-run-all-tests-from-run_vmtestssh.patch mm-allow-deferred-splitting-of-arbitrary-large-anon-folios.patch mm-non-pmd-mappable-large-folios-for-folio_add_new_anon_rmap.patch mm-large_anon_folio-for-improved-performance.patch selftests-mm-cow-generalize-do_run_with_thp-helper.patch selftests-mm-cow-add-large-anon-folio-tests.patch