mm/vma: the pgoff is correct if can_merge_right
Subsystems (2)
PATCH v2 1/1 mm/vma: the pgoff is correct if can_merge_right
By this point can_vma_merge_right() must have returned true, which implies can_vma_merge_before() also returned true, which already asserts that the pgoff is as expected for a merge with the following VMA, thus this assignment is redundant.
Below is a more detail explanation.
Current definition of can_vma_merge_right() is:
static bool can_vma_merge_right(struct vma_merge_struct *vmg,
bool can_merge_left)
{
if (!vmg->next || vmg->end != vmg->next->vm_start ||
!can_vma_merge_before(vmg))
return false;
...
}And:
static bool can_vma_merge_before(struct vma_merge_struct *vmg)
{
pgoff_t pglen = PHYS_PFN(vmg->end - vmg->start);
...
if (vmg->next->vm_pgoff == vmg->pgoff + pglen)
return true;
...
}Which implies vmg->pgoff == vmg->next->vm_pgoff - pglen.
None of these values are changed between the check and prior assignment, so this was an entirely redundant assignment.
[lorenzo: rephrase the change log]
---
v2: rephrase the change log per Lorenzo's suggestion.
--- mm/vma.c | 2 -- 1 file changed, 2 deletions(-)
mm/vma.c +0 -2
@@ -915,7 +915,6 @@ struct vm_area_struct *vma_merge_new_range(struct vma_merge_struct *vmg)unsigned long start = vmg->start;unsigned long end = vmg->end;pgoff_t pgoff = vmg->pgoff; -pgoff_t pglen =PHYS_PFN (end - start);bool can_merge_left, can_merge_right;mmap_assert_write_locked (vmg->mm);
@@ -936,7 +935,6 @@ struct vm_area_struct *vma_merge_new_range(struct vma_merge_struct *vmg)if (can_merge_right) { vmg->end = next->vm_end; vmg->vma = next; - vmg->pgoff = next->vm_pgoff - pglen; }/* If we can merge with the previous VMA, adjust vmg accordingly. */
Signature · 1 line
2.34.1
Quoted 29 lines · Wei Yang
By this point
can_vma_merge_right()must have returned true, which impliescan_vma_merge_before()also returned true, which already asserts that the pgoff is as expected for a merge with the following VMA, thus this assignment is redundant.Below is a more detail explanation.
Current definition of
can_vma_merge_right()is:static bool can_vma_merge_right(struct vma_merge_struct *vmg, bool can_merge_left) { if (!vmg->next || vmg->end != vmg->next->vm_start || !can_vma_merge_before(vmg)) return false; ... }And:
static bool can_vma_merge_before(struct vma_merge_struct *vmg) { pgoff_t pglen = PHYS_PFN(vmg->end - vmg->start); ... if (vmg->next->vm_pgoff == vmg->pgoff + pglen) return true; ... }
Quoted 6 lines
Which implies
vmg->pgoff==vmg->next->vm_pgoff- pglen.None of these values are changed between the check and prior assignment, so this was an entirely redundant assignment.
[lorenzo: rephrase the change log]
Thanks for this, LGTM!
Quoted 35 lines
Signed-off-by Wei Yang <[email protected]>CC Lorenzo Stoakes <[email protected]>Reviewed-by Lorenzo Stoakes <[email protected]>---
v2: rephrase the change log per Lorenzo's suggestion.--- mm/vma.c | 2 -- 1 file changed, 2 deletions(-)mm/vma.c +0
-3@@ -915,7 +915,6 @@ struct vm_area_struct *vma_merge_new_range(struct vma_merge_struct *vmg)unsigned long start = vmg->start;unsigned long end = vmg->end;pgoff_t pgoff = vmg->pgoff; -pgoff_t pglen =PHYS_PFN (end - start);bool can_merge_left, can_merge_right;mmap_assert_write_locked (vmg->mm);@@ -936,7 +935,6 @@ struct vm_area_struct *vma_merge_new_range(struct vma_merge_struct *vmg)if (can_merge_right) { vmg->end = next->vm_end; vmg->vma = next; - vmg->pgoff = next->vm_pgoff - pglen; }/* If we can merge with the previous VMA, adjust vmg accordingly. */ --2.34.1