Skip to content

mm: Break COW for pinned pages during fork()

Peter Xu linux-mm lkml 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest4 patches 7 repliesIn review
  2. v15 patches 103 repliesSuperseded

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4mm: Introduce mm_struct.has_pinnedinclude/linux/mm_types.h kernel/fork.c mm/gup.c+17 -00 replies
2/4mm/fork: Pass new vma pointer into copy_page_range()include/linux/mm.h kernel/fork.c mm/memory.c+11 -72 replies
3/4mm: Do early cow for pinned pages during fork() for ptesmm/memory.c+156 -163 replies
4/4mm/thp: Split huge pmds/puds if they're pinned when fork()mm/huge_memory.c+28 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH v2 0/4] mm: Break COW for pinned pages during fork()

Due to the rebase to latest rc6, the major pte copy patch changed a lot. So maybe not that useful to write a changelog any more. However all the comments should be addressed as long as discussed in previous thread. Please shoot if I missed anything important.

This series is majorly inspired by the previous discussion on the list [1], starting from the report from Jason on the rdma test failure. Linus proposed the solution, which seems to be a very nice approach to avoid the breakage of userspace apps that didn't use MADV_DONTFORK properly before. More information can be found in that thread too.

I tested it myself with fork() after vfio pinning a bunch of device pages, and I verified that the new copy pte logic worked as expected at least in the most general path. However I didn't test thp case yet because afaict vfio does not support thp backed dma pages. Luckily, the pmd/pud thp patch is much more straightforward than the pte one, so hopefully it can be directly verified by some code review plus some more heavy-weight rdma tests.

Patch 1:      Introduce mm.has_pinned
Patch 2:      Preparation patch
Patch 3:      Early cow solution for pte copy for pinned pages
Patch 4:      Same as above, but for thp (pmd/pud).

Hugetlbfs fix is still missing, but as planned, that's not urgent so we can work upon. Comments greatly welcomed.

[1] https://lore.kernel.org/lkml/[email protected]/

Thanks.

Peter Xu (4):
mm: Introduce mm_struct.has_pinned
mm/fork: Pass new vma pointer into copy_page_range()
mm: Do early cow for pinned pages during fork() for ptes mm/thp: Split huge pmds/puds if they're pinned when fork()

 include/linux/mm.h       |   2 +-
 include/linux/mm_types.h |  10 +++
 kernel/fork.c            |   3 +-
 mm/gup.c                 |   6 ++
 mm/huge_memory.c         |  28 ++++++
 mm/memory.c              | 186 ++++++++++++++++++++++++++++++++++-----
 6 files changed, 212 insertions(+), 23 deletions(-)
Signature · 1 line
2.26.2