linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 00/39] mm/rmap: interface overhaul
@ 2023-12-11 15:56 David Hildenbrand
  2023-12-11 15:56 ` [PATCH v1 01/39] mm/rmap: rename hugepage_add* to hugetlb_add* David Hildenbrand
                   ` (38 more replies)
  0 siblings, 39 replies; 70+ messages in thread
From: David Hildenbrand @ 2023-12-11 15:56 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-mm, David Hildenbrand, Andrew Morton,
	Matthew Wilcox (Oracle),
	Hugh Dickins, Ryan Roberts, Yin Fengwei, Mike Kravetz,
	Muchun Song, Peter Xu

This series overhauls the rmap interface, to get rid of the "bool compound"
/ RMAP_COMPOUND parameter with the goal of making the interface less error
prone, more future proof, and more natural to extend to "batching". Also,
this converts the interface to always consume folio+subpage, which speeds
up operations on large folios.

Further, this series adds PTE-batching variants for 4 rmap functions,
whereby only folio_add_anon_rmap_ptes() is used for batching in this series
when PTE-remapping a PMD-mapped THP. folio_remove_rmap_ptes(),
folio_try_dup_anon_rmap_ptes() and folio_dup_file_rmap_ptes() will soon
come in handy[1,2].

This series performs a lot of folio conversion along the way. Most of the
added LOC in the diff are only due to documentation.

As we're moving to a pte/pmd interface where we clearly express the
mapping granularity we are dealing with, we first get the remainder of
hugetlb out of the way, as it is special and expected to remain special: it
treats everything as a "single logical PTE" and only currently allows
entire mappings.

Even if we'd ever support partial mappings, I strongly assume the interface
and implementation will still differ heavily: hopefull we can avoid working
on subpages/subpage mapcounts completely and only add a "count" parameter
for them to enable batching.

New (extended) hugetlb interface that operates on entire folio:
 * hugetlb_add_new_anon_rmap() -> Already existed
 * hugetlb_add_anon_rmap() -> Already existed
 * hugetlb_try_dup_anon_rmap()
 * hugetlb_try_share_anon_rmap()
 * hugetlb_add_file_rmap()
 * hugetlb_remove_rmap()

New "ordinary" interface for small folios / THP::
 * folio_add_new_anon_rmap() -> Already existed
 * folio_add_anon_rmap_[pte|ptes|pmd]()
 * folio_try_dup_anon_rmap_[pte|ptes|pmd]()
 * folio_try_share_anon_rmap_[pte|pmd]()
 * folio_add_file_rmap_[pte|ptes|pmd]()
 * folio_dup_file_rmap_[pte|ptes|pmd]()
 * folio_remove_rmap_[pte|ptes|pmd]()

folio_add_new_anon_rmap() will always map at the largest granularity
possible (currently, a single PMD to cover a PMD-sized THP). Could be
extended if ever required.

In the future, we might want "_pud" variants and eventually "_pmds"
variants for batching.

I ran some simple microbenchmarks on an Intel(R) Xeon(R) Silver 4210R:
measuring munmap(), fork(), cow, MADV_DONTNEED on each PTE ... and PTE
remapping PMD-mapped THPs on 1 GiB of memory.

For small folios, there is barely a change (< 1%).

For PTE-mapped THP:
* PTE-remapping a PMD-mapped THP is more than 10% faster.
* fork() is more than 4% faster.
* MADV_DONTNEED is 2% faster
* COW when writing only a single byte on a COW-shared PTE is 1% faster
* munmap() barely changes (< 1%).

[1] https://lkml.kernel.org/r/20230810103332.3062143-1-ryan.roberts@arm.com
[2] https://lkml.kernel.org/r/20231204105440.61448-1-ryan.roberts@arm.com

---

Based on current mm/mm-unstable. Compile-tested with/wihout THP on x86-64
and with defconig on a bunch more. Tested on x86-64.

RFC -> v1:
* Rebased on top of mm-unstable (containing mTHP)
* Use switch()-case and _always_inline for helper functions
* Fixed some (intermittend) compile issues and some smaller stuff
* folio_try_dup_anon_rmap_[pte|ptes|pmd]() rewrite
* Pass nr_pages consistently as "int"
* Simplify sanity checks
* Added RBs

Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>
Cc: Hugh Dickins <hughd@google.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Yin Fengwei <fengwei.yin@intel.com>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Peter Xu <peterx@redhat.com>


David Hildenbrand (39):
  mm/rmap: rename hugepage_add* to hugetlb_add*
  mm/rmap: introduce and use hugetlb_remove_rmap()
  mm/rmap: introduce and use hugetlb_add_file_rmap()
  mm/rmap: introduce and use hugetlb_try_dup_anon_rmap()
  mm/rmap: introduce and use hugetlb_try_share_anon_rmap()
  mm/rmap: add hugetlb sanity checks
  mm/rmap: convert folio_add_file_rmap_range() into
    folio_add_file_rmap_[pte|ptes|pmd]()
  mm/memory: page_add_file_rmap() -> folio_add_file_rmap_[pte|pmd]()
  mm/huge_memory: page_add_file_rmap() -> folio_add_file_rmap_pmd()
  mm/migrate: page_add_file_rmap() -> folio_add_file_rmap_pte()
  mm/userfaultfd: page_add_file_rmap() -> folio_add_file_rmap_pte()
  mm/rmap: remove page_add_file_rmap()
  mm/rmap: factor out adding folio mappings into __folio_add_rmap()
  mm/rmap: introduce folio_add_anon_rmap_[pte|ptes|pmd]()
  mm/huge_memory: batch rmap operations in __split_huge_pmd_locked()
  mm/huge_memory: page_add_anon_rmap() -> folio_add_anon_rmap_pmd()
  mm/migrate: page_add_anon_rmap() -> folio_add_anon_rmap_pte()
  mm/ksm: page_add_anon_rmap() -> folio_add_anon_rmap_pte()
  mm/swapfile: page_add_anon_rmap() -> folio_add_anon_rmap_pte()
  mm/memory: page_add_anon_rmap() -> folio_add_anon_rmap_pte()
  mm/rmap: remove page_add_anon_rmap()
  mm/rmap: remove RMAP_COMPOUND
  mm/rmap: introduce folio_remove_rmap_[pte|ptes|pmd]()
  kernel/events/uprobes: page_remove_rmap() -> folio_remove_rmap_pte()
  mm/huge_memory: page_remove_rmap() -> folio_remove_rmap_pmd()
  mm/khugepaged: page_remove_rmap() -> folio_remove_rmap_pte()
  mm/ksm: page_remove_rmap() -> folio_remove_rmap_pte()
  mm/memory: page_remove_rmap() -> folio_remove_rmap_pte()
  mm/migrate_device: page_remove_rmap() -> folio_remove_rmap_pte()
  mm/rmap: page_remove_rmap() -> folio_remove_rmap_pte()
  Documentation: stop referring to page_remove_rmap()
  mm/rmap: remove page_remove_rmap()
  mm/rmap: convert page_dup_file_rmap() to
    folio_dup_file_rmap_[pte|ptes|pmd]()
  mm/rmap: introduce folio_try_dup_anon_rmap_[pte|ptes|pmd]()
  mm/huge_memory: page_try_dup_anon_rmap() ->
    folio_try_dup_anon_rmap_pmd()
  mm/memory: page_try_dup_anon_rmap() -> folio_try_dup_anon_rmap_pte()
  mm/rmap: remove page_try_dup_anon_rmap()
  mm: convert page_try_share_anon_rmap() to
    folio_try_share_anon_rmap_[pte|pmd]()
  mm/rmap: rename COMPOUND_MAPPED to ENTIRELY_MAPPED

 Documentation/mm/transhuge.rst       |   4 +-
 Documentation/mm/unevictable-lru.rst |   4 +-
 include/linux/mm.h                   |   6 +-
 include/linux/rmap.h                 | 398 +++++++++++++++++++-----
 kernel/events/uprobes.c              |   2 +-
 mm/filemap.c                         |  10 +-
 mm/gup.c                             |   2 +-
 mm/huge_memory.c                     |  85 +++---
 mm/hugetlb.c                         |  21 +-
 mm/internal.h                        |  12 +-
 mm/khugepaged.c                      |  17 +-
 mm/ksm.c                             |  15 +-
 mm/memory-failure.c                  |   4 +-
 mm/memory.c                          |  60 ++--
 mm/migrate.c                         |  12 +-
 mm/migrate_device.c                  |  41 +--
 mm/mmu_gather.c                      |   2 +-
 mm/rmap.c                            | 433 ++++++++++++++++-----------
 mm/swapfile.c                        |   2 +-
 mm/userfaultfd.c                     |   2 +-
 20 files changed, 740 insertions(+), 392 deletions(-)

-- 
2.43.0



^ permalink raw reply	[flat|nested] 70+ messages in thread

end of thread, other threads:[~2023-12-19  8:42 UTC | newest]

Thread overview: 70+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-11 15:56 [PATCH v1 00/39] mm/rmap: interface overhaul David Hildenbrand
2023-12-11 15:56 ` [PATCH v1 01/39] mm/rmap: rename hugepage_add* to hugetlb_add* David Hildenbrand
2023-12-11 16:14   ` Ryan Roberts
2023-12-11 16:24   ` Matthew Wilcox
2023-12-11 15:56 ` [PATCH v1 02/39] mm/rmap: introduce and use hugetlb_remove_rmap() David Hildenbrand
2023-12-11 16:15   ` Ryan Roberts
2023-12-11 16:33   ` Matthew Wilcox
2023-12-11 16:35     ` David Hildenbrand
2023-12-11 15:56 ` [PATCH v1 03/39] mm/rmap: introduce and use hugetlb_add_file_rmap() David Hildenbrand
2023-12-11 16:17   ` Ryan Roberts
2023-12-11 15:56 ` [PATCH v1 04/39] mm/rmap: introduce and use hugetlb_try_dup_anon_rmap() David Hildenbrand
2023-12-11 16:25   ` Ryan Roberts
2023-12-11 15:56 ` [PATCH v1 05/39] mm/rmap: introduce and use hugetlb_try_share_anon_rmap() David Hildenbrand
2023-12-11 16:29   ` Ryan Roberts
2023-12-11 15:56 ` [PATCH v1 06/39] mm/rmap: add hugetlb sanity checks David Hildenbrand
2023-12-11 16:29   ` Ryan Roberts
2023-12-13  9:03   ` David Hildenbrand
2023-12-11 15:56 ` [PATCH v1 07/39] mm/rmap: convert folio_add_file_rmap_range() into folio_add_file_rmap_[pte|ptes|pmd]() David Hildenbrand
2023-12-13  5:33   ` Yin Fengwei
2023-12-13  8:47     ` David Hildenbrand
2023-12-18 15:48   ` Ryan Roberts
2023-12-11 15:56 ` [PATCH v1 08/39] mm/memory: page_add_file_rmap() -> folio_add_file_rmap_[pte|pmd]() David Hildenbrand
2023-12-18 15:56   ` Ryan Roberts
2023-12-11 15:56 ` [PATCH v1 09/39] mm/huge_memory: page_add_file_rmap() -> folio_add_file_rmap_pmd() David Hildenbrand
2023-12-18 15:58   ` Ryan Roberts
2023-12-11 15:56 ` [PATCH v1 10/39] mm/migrate: page_add_file_rmap() -> folio_add_file_rmap_pte() David Hildenbrand
2023-12-18 15:58   ` Ryan Roberts
2023-12-11 15:56 ` [PATCH v1 11/39] mm/userfaultfd: " David Hildenbrand
2023-12-18 15:59   ` Ryan Roberts
2023-12-11 15:56 ` [PATCH v1 12/39] mm/rmap: remove page_add_file_rmap() David Hildenbrand
2023-12-18 16:00   ` Ryan Roberts
2023-12-11 15:56 ` [PATCH v1 13/39] mm/rmap: factor out adding folio mappings into __folio_add_rmap() David Hildenbrand
2023-12-18 16:07   ` Ryan Roberts
2023-12-18 17:06     ` David Hildenbrand
2023-12-19  8:40       ` Ryan Roberts
2023-12-11 15:56 ` [PATCH v1 14/39] mm/rmap: introduce folio_add_anon_rmap_[pte|ptes|pmd]() David Hildenbrand
2023-12-15  2:26   ` Yin, Fengwei
2023-12-15 15:16     ` David Hildenbrand
2023-12-18 16:26   ` Ryan Roberts
2023-12-18 17:02     ` David Hildenbrand
2023-12-11 15:56 ` [PATCH v1 15/39] mm/huge_memory: batch rmap operations in __split_huge_pmd_locked() David Hildenbrand
2023-12-15  2:27   ` Yin, Fengwei
2023-12-15  2:39   ` Yin, Fengwei
2023-12-18 16:22   ` Ryan Roberts
2023-12-18 17:03     ` David Hildenbrand
2023-12-19  8:42       ` Ryan Roberts
2023-12-11 15:56 ` [PATCH v1 16/39] mm/huge_memory: page_add_anon_rmap() -> folio_add_anon_rmap_pmd() David Hildenbrand
2023-12-11 15:56 ` [PATCH v1 17/39] mm/migrate: page_add_anon_rmap() -> folio_add_anon_rmap_pte() David Hildenbrand
2023-12-11 15:56 ` [PATCH v1 18/39] mm/ksm: " David Hildenbrand
2023-12-11 15:56 ` [PATCH v1 19/39] mm/swapfile: " David Hildenbrand
2023-12-11 15:56 ` [PATCH v1 20/39] mm/memory: " David Hildenbrand
2023-12-11 15:56 ` [PATCH v1 21/39] mm/rmap: remove page_add_anon_rmap() David Hildenbrand
2023-12-11 15:56 ` [PATCH v1 22/39] mm/rmap: remove RMAP_COMPOUND David Hildenbrand
2023-12-11 15:56 ` [PATCH v1 23/39] mm/rmap: introduce folio_remove_rmap_[pte|ptes|pmd]() David Hildenbrand
2023-12-11 15:56 ` [PATCH v1 24/39] kernel/events/uprobes: page_remove_rmap() -> folio_remove_rmap_pte() David Hildenbrand
2023-12-11 15:56 ` [PATCH v1 25/39] mm/huge_memory: page_remove_rmap() -> folio_remove_rmap_pmd() David Hildenbrand
2023-12-11 15:56 ` [PATCH v1 26/39] mm/khugepaged: page_remove_rmap() -> folio_remove_rmap_pte() David Hildenbrand
2023-12-11 15:56 ` [PATCH v1 27/39] mm/ksm: " David Hildenbrand
2023-12-11 15:56 ` [PATCH v1 28/39] mm/memory: " David Hildenbrand
2023-12-11 15:56 ` [PATCH v1 29/39] mm/migrate_device: " David Hildenbrand
2023-12-11 15:56 ` [PATCH v1 30/39] mm/rmap: " David Hildenbrand
2023-12-11 15:56 ` [PATCH v1 31/39] Documentation: stop referring to page_remove_rmap() David Hildenbrand
2023-12-11 15:56 ` [PATCH v1 32/39] mm/rmap: remove page_remove_rmap() David Hildenbrand
2023-12-11 15:56 ` [PATCH v1 33/39] mm/rmap: convert page_dup_file_rmap() to folio_dup_file_rmap_[pte|ptes|pmd]() David Hildenbrand
2023-12-11 15:56 ` [PATCH v1 34/39] mm/rmap: introduce folio_try_dup_anon_rmap_[pte|ptes|pmd]() David Hildenbrand
2023-12-11 15:56 ` [PATCH v1 35/39] mm/huge_memory: page_try_dup_anon_rmap() -> folio_try_dup_anon_rmap_pmd() David Hildenbrand
2023-12-11 15:56 ` [PATCH v1 36/39] mm/memory: page_try_dup_anon_rmap() -> folio_try_dup_anon_rmap_pte() David Hildenbrand
2023-12-11 15:56 ` [PATCH v1 37/39] mm/rmap: remove page_try_dup_anon_rmap() David Hildenbrand
2023-12-11 15:56 ` [PATCH v1 38/39] mm: convert page_try_share_anon_rmap() to folio_try_share_anon_rmap_[pte|pmd]() David Hildenbrand
2023-12-11 15:56 ` [PATCH v1 39/39] mm/rmap: rename COMPOUND_MAPPED to ENTIRELY_MAPPED David Hildenbrand

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox