Skip to content

refactor mremap and fix bug

Lorenzo Stoakes linux-mm lkml 3 versions – Applied

Status from this message: [merged mm-stable] mm-mremap-thread-state-through-move-page-table-operation.patch removed from -mm tree

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest7 patches 6 repliesApplied 7/7
  2. v27 patches 12 repliesSuperseded
  3. v17 patches 20 repliesSuperseded

Changes in v3 from the cover letter

* Propagate tags (thanks Vlastimil et al.!)
* Fix issue reported by test bot/trinity where, for length 0 input mappings of a VMA mapped entirely onto itself, vma_lookup() may consequently fail.
* Fixed incomplete sentence in comment as per Vlastimil.
* Reworded comment in internal.h around pagetable_move_control as per Vlastimil.
* Reworded reference to page table boundary for clarity as per Vlastimil.
* Dropped misleading reference to old_end in 6/7 as per Vlastimil.
* Improved should_take_rmap_locks() as per Vlastimil.

Patches in v3 All 7 applied

#Subject and filesSizeRepliesApplied
1/7mm/mremap: correctly handle partial mremap() of VMA starting at 0mm/mremap.c+5 -50 repliesApplied
2/7mm/mremap: refactor mremap() system call implementationmm/mremap.c+251 -1540 repliesApplied
3/7mm/mremap: introduce and use vma_remap_struct threaded statemm/mremap.c+363 -2071 replyApplied
4/7mm/mremap: initial refactor of move_vma()mm/mremap.c+122 -645 repliesApplied
5/7mm/mremap: complete refactor of move_vma()mm/mremap.c+204 -890 repliesApplied
6/7mm/mremap: refactor move_page_tables(), abstracting statemm/internal.h mm/mmap.c mm/mremap.c+168 -520 repliesApplied
7/7mm/mremap: thread state through move page table operationmm/internal.h mm/mremap.c+116 -830 repliesApplied

Reviews trailers per patch

All 7 patches have a Reviewed-by or Acked-by.

PatchHarry YooVlastimil BabkaLiam R. Howlett
1/7R-b R-b R-b
2/7R-b R-b
3/7R-b R-b
4/7R-b A-b R-b
5/7R-b
6/7R-b
7/7R-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 3 reviewers.

Read the v3 thread

Cover letter [PATCH v3 0/7] refactor mremap and fix bug

The existing mremap() logic has grown organically over a very long period of time, resulting in code that is in many parts, very difficult to follow and full of subtleties and sources of confusion.

In addition, it is difficult to thread state through the operation correctly, as function arguments have expanded, some parameters are expected to be temporarily altered during the operation, others are intended to remain static and some can be overridden.

This series completely refactors the mremap implementation, sensibly separating functions, adding comments to explain the more subtle aspects of the implementation and making use of small structs to thread state through everything.

The reason for doing so is to lay the groundwork for planned future changes to the mremap logic, changes which require the ability to easily pass around state.

Additionally, it would be unhelpful to add yet more logic to code that is already difficult to follow without first refactoring it like this.

The first patch in this series additionally fixes a bug when a VMA with start address zero is partially remapped.

Tested on real hardware under heavy workload and all self tests are passing.

v3:
* Propagate tags (thanks Vlastimil et al.!)
* Fix issue reported by test bot/trinity where, for length 0 input mappings of a VMA mapped entirely onto itself, vma_lookup() may consequently fail.
* Fixed incomplete sentence in comment as per Vlastimil.
* Reworded comment in internal.h around pagetable_move_control as per Vlastimil.
* Reworded reference to page table boundary for clarity as per Vlastimil.
* Dropped misleading reference to old_end in 6/7 as per Vlastimil.
* Improved should_take_rmap_locks() as per Vlastimil.

v2:
* Folded Andrew's fix for move_huge_pud() stub that I missed in v1.
* Folded Andrew's fix for err initialisation in prep_move_vma() that I missed in v1.
* Propagated tags (thanks everyone!)
* Aligned comments vertically as per Liam, tidied them up a bit.
* Renamed mremap_operation to mremap_type for consistency.
* Added MREMAP_INVALID as default mremap operation state, and set on initialisation as per Liam.
* Renamed 'locked' to 'mlocked' whenever referring to mlock state as per Liam.
* Dropped unnecessary vrm_set_remap_type() function as per Liam.
* Corrected redundant comment about iterator invalidation as per Liam.
* Corrected confusing vertical alignment on may_expand_vm() invocation as per Liam.
https://lore.kernel.org/all/[email protected]/

v1:
https://lore.kernel.org/all/[email protected]/

Lorenzo Stoakes (7):
mm/mremap: correctly handle partial mremap() of VMA starting at 0 mm/mremap: refactor mremap() system call implementation mm/mremap: introduce and use vma_remap_struct threaded state mm/mremap: initial refactor of move_vma()
mm/mremap: complete refactor of move_vma()
mm/mremap: refactor move_page_tables(), abstracting state mm/mremap: thread state through move page table operation

 mm/internal.h |   46 +-
 mm/mmap.c     |    5 +-
 mm/mremap.c   | 1448 +++++++++++++++++++++++++++++++++----------------
 3 files changed, 1037 insertions(+), 462 deletions(-)

--
2.48.1