Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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.


[akpm@linux-foundation.org: remove now-unused local]
[lorenzo.stoakes@oracle.com: rephrase the changelog]
Link: https://lkml.kernel.org/r/20241024093347.18057-1-richard.weiyang@gmail.com
Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Jann Horn <jannh@google.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Liam R. Howlett <Liam.Howlett@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Wei Yang and committed by
Andrew Morton
642c66d8 5ac87a88

-3
-3
mm/vma.c
··· 962 962 { 963 963 struct vm_area_struct *prev = vmg->prev; 964 964 struct vm_area_struct *next = vmg->next; 965 - unsigned long start = vmg->start; 966 965 unsigned long end = vmg->end; 967 - pgoff_t pglen = PHYS_PFN(end - start); 968 966 bool can_merge_left, can_merge_right; 969 967 bool just_expand = vmg->merge_flags & VMG_FLAG_JUST_EXPAND; 970 968 ··· 984 986 if (can_merge_right) { 985 987 vmg->end = next->vm_end; 986 988 vmg->vma = next; 987 - vmg->pgoff = next->vm_pgoff - pglen; 988 989 } 989 990 990 991 /* If we can merge with the previous VMA, adjust vmg accordingly. */