Re: [PATCH 09/10] mm/mmap: start distinguishing if vma can be removed in mergeability test

From: Vlastimil Babka
Date: Thu Mar 16 2023 - 06:57:09 EST



On 3/15/23 23:05, Lorenzo Stoakes wrote:
> On Thu, Mar 09, 2023 at 12:12:57PM +0100, Vlastimil Babka wrote:
>> --- a/mm/mmap.c
>> +++ b/mm/mmap.c
>> @@ -742,12 +742,13 @@ int vma_shrink(struct vma_iterator *vmi, struct vm_area_struct *vma,
>>
>> /*
>> * If the vma has a ->close operation then the driver probably needs to release
>> - * per-vma resources, so we don't attempt to merge those.
>> + * per-vma resources, so we don't attempt to merge those in case the caller
>> + * indicates the current vma may be removed as part of the merge.
>
> Nit: 'in case the caller indicates' -> 'if the caller indicates'

Ok, -fix patch below.

...

>> - if (is_mergeable_vma(vma, file, vm_flags, vm_userfaultfd_ctx, anon_name) &&
>> + if (is_mergeable_vma(vma, file, vm_flags, vm_userfaultfd_ctx, anon_name, false) &&
>> is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
>> pgoff_t vm_pglen;
>> vm_pglen = vma_pages(vma);
>> --
>> 2.39.2
>>
>
> I wonder whether this might be moved later into the actual vma_merge() logic so
> we only abort a merge at the point a VMA with ->close() would otherwise be
> removed? But obviously that would probably need some further clean up to make it
> not add yet more complexity to an already very complicated bit of logic.

Yeah, can try that later to cover the remaining cases where
->close prevents merging unnecessarily.

> Otherwise, very nice, clear + conservative so,
>
> Reviewed-By: Lorenzo Stoakes <lstoakes@xxxxxxxxx>

Thanks!

----8<----