Skip to content

mm: remove nth_page()

David Hildenbrand dri-devel intel-gfx io-uring kvm linux-arm-kernel linux-crypto linux-ide linux-iommu linux-kselftest linux-mips linux-mm linux-mmc linux-riscv linux-s390 linux-scsi linuxppc-dev lkml netdev virtualization wireguard 2 versions – Applied

Status from this message: Applied this one, actually. Thank you.

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest37 patches 33 repliesApplied 36/37
  2. v136 patches 105 repliesSuperseded

Changes in v2 from the cover letter

* "fs: hugetlbfs: cleanup folio in adjust_range_hwpoison()" -> Add comment for loop and remove comment of function regarding

Patches in v2 Applied · 36/37

#Subject and filesSizeRepliesApplied
1/37mm: stop making SPARSEMEM_VMEMMAP user-selectablemm/Kconfig+1 -20 repliesApplied
2/37arm64: Kconfig: drop superfluous "select SPARSEMEM_VMEMMAP"arch/arm64/Kconfig+0 -10 repliesApplied
3/37s390/Kconfig: drop superfluous "select SPARSEMEM_VMEMMAP"arch/s390/Kconfig+0 -10 repliesApplied
4/37x86/Kconfig: drop superfluous "select SPARSEMEM_VMEMMAP"arch/x86/Kconfig+0 -10 repliesApplied
5/37wireguard: selftests: remove CONFIG_SPARSEMEM_VMEMMAP=y from qemu kernel configtools/testing/selftests/wireguard/qemu/kernel.config+0 -11 replyApplied
6/37mm/page_alloc: reject unreasonable folio/compound page sizes in alloc_contig_range_noprof()include/linux/mm.h mm/page_alloc.c+13 -30 repliesApplied
7/37mm/memremap: reject unreasonable folio/compound page sizes in memremap_pages()mm/memremap.c+3 -00 repliesApplied
8/37mm/hugetlb: check for unreasonable folio sizes when registering hstatemm/hugetlb.c+2 -011 repliesApplied
9/37mm/mm_init: make memmap_init_compound() look more like prep_compound_page()mm/mm_init.c+7 -80 repliesApplied
10/37mm: sanity-check maximum folio size in folio_set_order()mm/internal.h+1 -00 repliesApplied
11/37mm: limit folio/compound page sizes in problematic kernel configsinclude/linux/mm.h+18 -40 repliesApplied
12/37mm: simplify folio_page() and folio_page_idx()include/linux/mm.h include/linux/page-flags.h+18 -30 repliesApplied
13/37mm/hugetlb: cleanup hugetlb_folio_init_tail_vmemmap()mm/hugetlb.c+12 -80 repliesApplied
14/37mm/mm/percpu-km: drop nth_page() usage within single allocationmm/percpu-km.c+1 -10 repliesApplied
15/37fs: hugetlbfs: remove nth_page() usage within folio in adjust_range_hwpoison()fs/hugetlbfs/inode.c+1 -10 repliesApplied
16/37fs: hugetlbfs: cleanup folio in adjust_range_hwpoison()fs/hugetlbfs/inode.c+12 -240 repliesApplied
17/37mm/pagewalk: drop nth_page() usage within folio in folio_walk_start()mm/pagewalk.c+1 -10 repliesApplied
18/37mm/gup: drop nth_page() usage within folio when recording subpagesmm/gup.c+3 -40 repliesApplied
19/37mm/gup: remove record_subpages()mm/gup.c+8 -1718 repliesApplied
20/37io_uring/zcrx: remove nth_page() usage within folioio_uring/zcrx.c+2 -20 repliesApplied
21/37mips: mm: convert __flush_dcache_pages() to __flush_dcache_folio_pages()arch/mips/include/asm/cacheflush.h arch/mips/mm/cache.c+11 -80 repliesApplied
22/37mm/cma: refuse handing out non-contiguous page rangesinclude/linux/mm.h mm/cma.c mm/util.c+65 -151 reply
23/37dma-remap: drop nth_page() in dma_common_contiguous_remap()kernel/dma/remap.c+1 -10 repliesApplied
24/37scatterlist: disallow non-contigous page ranges in a single SG entryinclude/linux/scatterlist.h mm/util.c+3 -10 repliesApplied
25/37ata: libata-sff: drop nth_page() usage within SG entrydrivers/ata/libata-sff.c+3 -30 repliesApplied
26/37drm/i915/gem: drop nth_page() usage within SG entrydrivers/gpu/drm/i915/gem/i915_gem_pages.c+1 -12 repliesApplied
27/37mspro_block: drop nth_page() usage within SG entrydrivers/memstick/core/mspro_block.c+1 -20 repliesApplied
28/37memstick: drop nth_page() usage within SG entrydrivers/memstick/host/jmb38x_ms.c drivers/memstick/host/tifm_ms.c+2 -40 repliesApplied
29/37mmc: drop nth_page() usage within SG entrydrivers/mmc/host/tifm_sd.c drivers/mmc/host/usdhi6rol0.c+4 -40 repliesApplied
30/37scsi: scsi_lib: drop nth_page() usage within SG entrydrivers/scsi/scsi_lib.c+1 -20 repliesApplied
31/37scsi: sg: drop nth_page() usage within SG entrydrivers/scsi/sg.c+1 -20 repliesApplied
32/37vfio/pci: drop nth_page() usage within SG entrydrivers/vfio/pci/pds/lm.c drivers/vfio/pci/virtio/migrate.c+2 -40 repliesApplied
33/37crypto: remove nth_page() usage within SG entrycrypto/ahash.c crypto/scompress.c include/crypto/scatterwalk.h+8 -80 repliesApplied
34/37mm/gup: drop nth_page() usage in unpin_user_page_range_dirty_lock()mm/gup.c+7 -10 repliesApplied
35/37kfence: drop nth_page() usagemm/kfence/core.c+7 -50 repliesApplied
36/37block: update comment of "struct bio_vec" regarding nth_page()include/linux/bvec.h+2 -50 repliesApplied
37/37mm: remove nth_page()include/linux/mm.h tools/testing/scatterlist/linux/mm.h+0 -30 repliesApplied

Reviews trailers per patch

36 of 37 patches have a Reviewed-by or Acked-by.

PatchZi YanMike Rapoport (Microsoft)SeongJae ParkWei YangLorenzo StoakesLiam R. HowlettCatalin MarinasDave HansenPavel BegunkovAlexandru EliseiMarek SzyprowskiDamien Le MoalUlf HanssonBart Van AsscheMartin K. PetersenAlex WilliamsonBrett CreeleyHerbert XuMarco Elver
1/37A-b A-b A-b R-b R-b R-b
2/37R-b R-b R-b A-b
3/37R-b R-b R-b
4/37R-b R-b R-b A-b
5/37A-b R-b R-b
6/37R-b A-b R-b R-b R-b
7/37A-b R-b R-b
8/37R-b R-b R-b
9/37R-b R-b R-b A-b
10/37R-b R-b R-b R-b
11/37R-b A-b R-b R-b R-b
12/37R-b R-b R-b
13/37R-b R-b A-b
14/37R-b A-b
15/37R-b R-b
16/37R-b R-b
17/37R-b R-b
18/37R-b
19/37R-b
20/37R-b R-b
21/37
22/37R-b R-b
23/37R-b A-b
24/37R-b A-b
25/37R-b A-b
26/37R-b
27/37R-b A-b
28/37R-b A-b
29/37R-b A-b
30/37R-b R-b R-b
31/37R-b R-b R-b
32/37R-b R-b R-b
33/37R-b A-b
34/37R-b
35/37R-b R-b
36/37R-b
37/37R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 19 reviewers.

Read the v2 thread

Cover letter [PATCH v2 00/37] mm: remove nth_page()

This is based on mm-unstable.

I will only CC non-MM folks on the cover letter and the respective patch to not flood too many inboxes (the lists receive all patches).

--

As discussed recently with Linus, nth_page() is just nasty and we would like to remove it.

To recap, the reason we currently need nth_page() within a folio is because on some kernel configs (SPARSEMEM without SPARSEMEM_VMEMMAP), the memmap is allocated per memory section.

While buddy allocations cannot cross memory section boundaries, hugetlb and dax folios can.

So crossing a memory section means that "page++" could do the wrong thing. Instead, nth_page() on these problematic configs always goes from page->pfn, to the go from (++pfn)->page, which is rather nasty.

Likely, many people have no idea when nth_page() is required and when it might be dropped.

We refer to such problematic PFN ranges and "non-contiguous pages". If we only deal with "contiguous pages", there is not need for nth_page().

Besides that "obvious" folio case, we might end up using nth_page() within CMA allocations (again, could span memory sections), and in one corner case (kfence) when processing memblock allocations (again, could span memory sections).

So let's handle all that, add sanity checks, and remove nth_page().

Patch #1 -> #5 : stop making SPARSEMEM_VMEMMAP user-selectable + cleanups
Patch #6 -> #13 : disallow folios to have non-contiguous pages Patch #14 -> #20 : remove nth_page() usage within folios
Patch #22 : disallow CMA allocations of non-contiguous pages
Patch #23 -> #33 : sanity+check + remove nth_page() usage within SG entry
Patch #34 : sanity-check + remove nth_page() usage in
unpin_user_page_range_dirty_lock()

Patch #35        : remove nth_page() in kfence
Patch #36        : adjust stale comment regarding nth_page
Patch #37        : mm: remove nth_page()

A lot of this is inspired from the discussion at [1] between Linus, Jason and me, so cudos to them.

[1] https://lore.kernel.org/all/CAHk-=wiCYfNp4AJLBORU-c7ZyRBUp66W2-Et6cdQ4REx-GyQ_A@mail.gmail.com/T/#u

v1 -> v2:
* "fs: hugetlbfs: cleanup folio in adjust_range_hwpoison()" -> Add comment for loop and remove comment of function regarding

    copy_page_to_iter().

* Various smaller patch description tweaks I am not going to list for my sanity
* "mips: mm: convert __flush_dcache_pages() to __flush_dcache_folio_pages()"
-> Fix flush_dcache_page()
-> Drop "extern"
* "mm/gup: remove record_subpages()"
-> Added
* "mm/hugetlb: check for unreasonable folio sizes when registering hstate" -> Refine comment
* "mm/cma: refuse handing out non-contiguous page ranges"
-> Add comment above loop
* "mm/page_alloc: reject unreasonable folio/compound page sizes in alloc_contig_range_noprof()"
-> Added comment above check
* "mm/gup: drop nth_page() usage in unpin_user_page_range_dirty_lock()" -> Refined comment

RFC -> v1:
* "wireguard: selftests: remove CONFIG_SPARSEMEM_VMEMMAP=y from qemu kernel config"
-> Mention that it was never really relevant for the test
* "mm/mm_init: make memmap_init_compound() look more like prep_compound_page()"
-> Mention the setup of page links
* "mm: limit folio/compound page sizes in problematic kernel configs" -> Improve comment for PUD handling, mentioning hugetlb and dax
* "mm: simplify folio_page() and folio_page_idx()"
-> Call variable "n"
* "mm/hugetlb: cleanup hugetlb_folio_init_tail_vmemmap()"
-> Keep __init_single_page() and refer to the usage of
memblock_reserved_mark_noinit()
* "fs: hugetlbfs: cleanup folio in adjust_range_hwpoison()"
* "fs: hugetlbfs: remove nth_page() usage within folio in adjust_range_hwpoison()"
-> Separate nth_page() removal from cleanups
-> Further improve cleanups
* "io_uring/zcrx: remove nth_page() usage within folio"
-> Keep the io_copy_cache for now and limit to nth_page() removal
* "mm/gup: drop nth_page() usage within folio when recording subpages" -> Cleanup record_subpages as bit
* "mm/cma: refuse handing out non-contiguous page ranges"
-> Replace another instance of "pfn_to_page(pfn)" where we already have
the page
* "scatterlist: disallow non-contigous page ranges in a single SG entry" -> We have to EXPORT the symbol. I thought about moving it to mm_inline.h, but I really don't want to include that in include/linux/scatterlist.h
* "ata: libata-eh: drop nth_page() usage within SG entry"
* "mspro_block: drop nth_page() usage within SG entry"
* "memstick: drop nth_page() usage within SG entry"
* "mmc: drop nth_page() usage within SG entry"
-> Keep PAGE_SHIFT
* "scsi: scsi_lib: drop nth_page() usage within SG entry"
* "scsi: sg: drop nth_page() usage within SG entry"
-> Split patches, Keep PAGE_SHIFT
* "crypto: remove nth_page() usage within SG entry"
-> Keep PAGE_SHIFT
* "kfence: drop nth_page() usage"
-> Keep modifying i and use "start_pfn" only instead

David Hildenbrand (37):
mm: stop making SPARSEMEM_VMEMMAP user-selectable
arm64: Kconfig: drop superfluous "select SPARSEMEM_VMEMMAP" s390/Kconfig: drop superfluous "select SPARSEMEM_VMEMMAP" x86/Kconfig: drop superfluous "select SPARSEMEM_VMEMMAP"
wireguard: selftests: remove CONFIG_SPARSEMEM_VMEMMAP=y from qemu
kernel config
mm/page_alloc: reject unreasonable folio/compound page sizes in
alloc_contig_range_noprof()
mm/memremap: reject unreasonable folio/compound page sizes in
memremap_pages()
mm/hugetlb: check for unreasonable folio sizes when registering hstate mm/mm_init: make memmap_init_compound() look more like
prep_compound_page()
mm: sanity-check maximum folio size in folio_set_order()
mm: limit folio/compound page sizes in problematic kernel configs
mm: simplify folio_page() and folio_page_idx()
mm/hugetlb: cleanup hugetlb_folio_init_tail_vmemmap() mm/mm/percpu-km: drop nth_page() usage within single allocation
fs: hugetlbfs: remove nth_page() usage within folio in
adjust_range_hwpoison()
fs: hugetlbfs: cleanup folio in adjust_range_hwpoison() mm/pagewalk: drop nth_page() usage within folio in folio_walk_start() mm/gup: drop nth_page() usage within folio when recording subpages mm/gup: remove record_subpages()
io_uring/zcrx: remove nth_page() usage within folio
mips: mm: convert __flush_dcache_pages() to
__flush_dcache_folio_pages()
mm/cma: refuse handing out non-contiguous page ranges
dma-remap: drop nth_page() in dma_common_contiguous_remap()
scatterlist: disallow non-contigous page ranges in a single SG entry
ata: libata-sff: drop nth_page() usage within SG entry drm/i915/gem: drop nth_page() usage within SG entry
mspro_block: drop nth_page() usage within SG entry
memstick: drop nth_page() usage within SG entry
mmc: drop nth_page() usage within SG entry
scsi: scsi_lib: drop nth_page() usage within SG entry
scsi: sg: drop nth_page() usage within SG entry
vfio/pci: drop nth_page() usage within SG entry
crypto: remove nth_page() usage within SG entry
mm/gup: drop nth_page() usage in unpin_user_page_range_dirty_lock()
kfence: drop nth_page() usage
block: update comment of "struct bio_vec" regarding nth_page()
mm: remove nth_page()

 arch/arm64/Kconfig                            |  1 -
 arch/mips/include/asm/cacheflush.h            | 11 +++--
 arch/mips/mm/cache.c                          |  8 ++--
 arch/s390/Kconfig                             |  1 -
 arch/x86/Kconfig                              |  1 -
 crypto/ahash.c                                |  4 +-
 crypto/scompress.c                            |  8 ++--
 drivers/ata/libata-sff.c                      |  6 +--
 drivers/gpu/drm/i915/gem/i915_gem_pages.c     |  2 +-
 drivers/memstick/core/mspro_block.c           |  3 +-
 drivers/memstick/host/jmb38x_ms.c             |  3 +-
 drivers/memstick/host/tifm_ms.c               |  3 +-
 drivers/mmc/host/tifm_sd.c                    |  4 +-
 drivers/mmc/host/usdhi6rol0.c                 |  4 +-
 drivers/scsi/scsi_lib.c                       |  3 +-
 drivers/scsi/sg.c                             |  3 +-
 drivers/vfio/pci/pds/lm.c                     |  3 +-
 drivers/vfio/pci/virtio/migrate.c             |  3 +-
 fs/hugetlbfs/inode.c                          | 36 +++++---------
 include/crypto/scatterwalk.h                  |  4 +-
 include/linux/bvec.h                          |  7 +--
 include/linux/mm.h                            | 48 +++++++++++++++----
 include/linux/page-flags.h                    |  5 +-
 include/linux/scatterlist.h                   |  3 +-
 io_uring/zcrx.c                               |  4 +-
 kernel/dma/remap.c                            |  2 +-
 mm/Kconfig                                    |  3 +-
 mm/cma.c                                      | 39 +++++++++------
 mm/gup.c                                      | 36 +++++++-------
 mm/hugetlb.c                                  | 22 +++++----
 mm/internal.h                                 |  1 +
 mm/kfence/core.c                              | 12 +++--
 mm/memremap.c                                 |  3 ++
 mm/mm_init.c                                  | 15 +++---
 mm/page_alloc.c                               | 10 +++-
 mm/pagewalk.c                                 |  2 +-
 mm/percpu-km.c                                |  2 +-
 mm/util.c                                     | 36 ++++++++++++++
 tools/testing/scatterlist/linux/mm.h          |  1 -
 .../selftests/wireguard/qemu/kernel.config    |  1 -
 40 files changed, 217 insertions(+), 146 deletions(-)

base-commit: b73c6f2b5712809f5f386780ac46d1d78c31b2e6

Signature · 1 line
2.50.1