mm-further-refactor-commit_merge.patch removed from -mm tree
The quilt patch titled
Subject: mm: further refactor commit_merge()
has been removed from the -mm tree. Its filename was
mm-further-refactor-commit_merge.patch
This patch was dropped because it was merged into the mm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
------------------------------------------------------
From: Lorenzo Stoakes <[email protected]>
Subject: mm: further refactor commit_merge()
Date: Fri, 31 Jan 2025 12:31:50 +0000
The current VMA merge mechanism contains a number of confusing mechanisms around removal of VMAs on merge and the shrinking of the VMA adjacent to vma->target in the case of merges which result in a partial merge with that adjacent VMA.
Since we now have a STABLE set of VMAs - prev, middle, next - we are now able to have the caller of commit_merge() explicitly tell us which VMAs need deleting, using newly introduced internal VMA merge flags.
Doing so allows us to embed this state within the VMG and remove the confusing remove, remove2 parameters from commit_merge().
We additionally are able to eliminate the highly confusing and misleading 'expanded' parameter - a parameter that in reality refers to whether or not the return VMA is the target one or the one immediately adjacent.
We can infer which is the case from whether or not the adj_start parameter is negative. This also allows us to simplify further logic around iterator configuration and VMA iterator stores.
Doing so means we can also eliminate the adjust parameter, as we are able to infer which VMA ought to be adjusted from adj_start - a positive value implies we adjust the start of 'middle', a negative one implies we adjust the start of 'next'.
We are then able to have commit_merge() explicitly return the target VMA, or NULL on inability to pre-allocate memory. Errors were previously filtered so behaviour does not change.
We additionally move from the slightly odd use of a bitwise-flag enum vmg->merge_flags field to vmg bitfields.
This patch has no change in functional behaviour.
---
mm/debug.c | 6 +- mm/vma.c | 101 +++++++++++++++++++------------------- mm/vma.h | 38 +++++++++----- tools/testing/vma/vma.c | 9 ++- 4 files changed, 87 insertions(+), 67 deletions(-)
mm/debug.c renamed from mm/debug.c~mm-further-refactor-commit_merge +4 -2
@@ -266,7 +266,8 @@ void dump_vmg(const struct vma_merge_str"file %px anon_vma %px policy %px\n" "uffd_ctx %px\n" "anon_name %px\n" -"merge_flags %x state %x\n" , +"state %x\n" +"just_expand %d __remove_middle %d __remove_next %d\n" , vmg, vmg->mm, vmg->pgoff, vmg->vmi, vmg->vmi ?vma_iter_addr (vmg->vmi) :0 , vmg->vmi ? vma_iter_end(vmg->vmi) : 0,
@@ -279,7 +280,8 @@ void dump_vmg(const struct vma_merge_str (void *)0 , #endif vmg->anon_name, - (int)vmg->merge_flags, (int)vmg->state); + (int )vmg->state, + vmg->just_expand, vmg->__remove_middle, vmg->__remove_next);if (vmg->mm) {pr_warn ("vmg %px mm:\n" , vmg);
mm/vma.c renamed from mm/vma.c~mm-further-refactor-commit_merge +52 -49
251 lines not on this page · raw message
mm/vma.h renamed from mm/vma.h~mm-further-refactor-commit_merge +24 -14
@@ -58,17 +58,6 @@ enum vma_merge_state { VMA_MERGE_SUCCESS, }; -enum vma_merge_flags { -VMG_FLAG_DEFAULT =0 , -/* -* If we can expand, simply do so. We know there is nothing to merge to -* the right. Does not reset state upon failure to merge. The VMA -* iterator is assumed to be positioned at the previous VMA, rather than -* at the gap. -*/ -VMG_FLAG_JUST_EXPAND =1 <<0 , -}; -/* * Describes a VMA merge operation and is threaded throughout it. *
@@ -117,8 +106,31 @@ struct vma_merge_struct {struct mempolicy *policy;struct vm_userfaultfd_ctx uffd_ctx;struct anon_vma_name *anon_name; -enum vma_merge_flags merge_flags;enum vma_merge_state state; + +/* Flags which callers can use to modify merge behaviour: */ + +/* +* If we can expand, simply do so. We know there is nothing to merge to +* the right. Does not reset state upon failure to merge. The VMA +* iterator is assumed to be positioned at the previous VMA, rather than +* at the gap. +*/ + bool just_expand :1; + +/* Internal flags set during merge process: */ + +/* +* Internal flag used during the merge operation to indicate we will +* remove vmg->middle. +*/ + bool __remove_middle :1; +/* +* Internal flag used during the merge operationr to indicate we will +* remove vmg->next. +*/ + bool __remove_next :1; + };static inline bool vmg_nomem (struct vma_merge_struct *vmg)
@@ -142,7 +154,6 @@ static inline pgoff_t vma_pgoff_offset(s .flags = flags_, \ .pgoff = pgoff_, \ .state = VMA_MERGE_START, \ - .merge_flags = VMG_FLAG_DEFAULT, \ }#define VMG_VMA_STATE (name, vmi_, prev_, vma_, start_, end_) \
@@ -162,7 +173,6 @@ static inline pgoff_t vma_pgoff_offset(s .uffd_ctx = vma_->vm_userfaultfd_ctx, \ .anon_name = anon_vma_name(vma_), \ .state = VMA_MERGE_START, \ - .merge_flags = VMG_FLAG_DEFAULT, \ }#ifdef CONFIG_DEBUG_VM_MAPLE_TREE
tools/testing/vma/vma.c renamed from tools/testing/vma/vma.c~mm-further-refactor-commit_merge +7 -2
@@ -149,11 +149,16 @@ static void vmg_set_range(struct vma_mer vmg->prev =NULL ; vmg->middle =NULL ; vmg->next =NULL ; + vmg->target =NULL ; vmg->start = start; vmg->end = end; vmg->pgoff = pgoff; vmg->flags = flags; + + vmg->just_expand = false; + vmg->__remove_middle = false; + vmg->__remove_next = false; }/*
@@ -1546,7 +1551,7 @@ static bool test_expand_only_mode(void)/* * Place a VMA prior to the one we're expanding so we assert that we do * not erroneously try to traverse to the previous VMA even though we -* have, through the use of VMG_FLAG_JUST_EXPAND, indicated we do not +* have, through the use of the just_expand flag, indicated we do not * need to do so. */ alloc_and_link_vma (&mm,0 ,0x2000 ,0 , flags);
@@ -1558,7 +1563,7 @@ static bool test_expand_only_mode(void)vma_iter_set (&vmi,0x3000 ); vma_prev =alloc_and_link_vma (&mm,0x3000 ,0x5000 ,3 , flags); vmg.prev = vma_prev; - vmg.merge_flags =VMG_FLAG_JUST_EXPAND ; + vmg.just_expand = true; vma =vma_merge_new_range (&vmg);ASSERT_NE (vma,NULL );
_
Patches currently in -mm which might be from [email protected] are
mm-mremap-correctly-handle-partial-mremap-of-vma-starting-at-0.patch mm-mremap-refactor-mremap-system-call-implementation.patch mm-mremap-introduce-and-use-vma_remap_struct-threaded-state.patch mm-mremap-initial-refactor-of-move_vma.patch mm-mremap-complete-refactor-of-move_vma.patch mm-mremap-refactor-move_page_tables-abstracting-state.patch mm-mremap-thread-state-through-move-page-table-operation.patch