From: Vlastimil Babka <vbabka@suse.cz>
To: Lorenzo Stoakes <lstoakes@gmail.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>,
Alexander Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>
Cc: "=Liam R . Howlett" <Liam.Howlett@oracle.com>,
linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH 4/4] mm: abstract VMA extension and merge into vma_merge_extend() helper
Date: Mon, 9 Oct 2023 18:30:02 +0200 [thread overview]
Message-ID: <fe147a1e-6fe5-309f-b2e7-48f5f3c97bae@suse.cz> (raw)
In-Reply-To: <1ed3d1ba0069104e1685298aa2baf980c38a85ff.1696795837.git.lstoakes@gmail.com>
On 10/8/23 22:23, Lorenzo Stoakes wrote:
> mremap uses vma_merge() in the case where a VMA needs to be extended. This
> can be significantly simplified and abstracted.
>
> This makes it far easier to understand what the actual function is doing,
> avoids future mistakes in use of the confusing vma_merge() function and
> importantly allows us to make future changes to how vma_merge() is
> implemented by knowing explicitly which merge cases each invocation uses.
>
> Note that in the mremap() extend case, we perform this merge only when
> old_len == vma->vm_end - addr. The extension_start, i.e. the start of the
> extended portion of the VMA is equal to addr + old_len, i.e. vma->vm_end.
>
> With this refactoring, vma_merge() is no longer required anywhere except
> mm/mmap.c, so mark it static.
>
> Signed-off-by: Lorenzo Stoakes <lstoakes@gmail.com>
Reviewed-by: Vlastimil Babka <vbabka@suse.cz>
Nit:
> @@ -2546,6 +2546,24 @@ static struct vm_area_struct *vma_merge_new_vma(struct vma_iterator *vmi,
> vma->vm_userfaultfd_ctx, anon_vma_name(vma));
> }
>
> +/*
> + * Expand vma by delta bytes, potentially merging with an immediately adjacent
> + * VMA with identical properties.
> + */
> +struct vm_area_struct *vma_merge_extend(struct vma_iterator *vmi,
> + struct vm_area_struct *vma,
> + unsigned long delta)
> +{
> + pgoff_t pgoff = vma->vm_pgoff +
> + ((vma->vm_end - vma->vm_start) >> PAGE_SHIFT);
could use vma_pages() here
> +
> + /* vma is specified as prev, so case 1 or 2 will apply. */
> + return vma_merge(vmi, vma->vm_mm, vma, vma->vm_end, vma->vm_end + delta,
> + vma->vm_flags, vma->anon_vma, vma->vm_file, pgoff,
> + vma_policy(vma), vma->vm_userfaultfd_ctx,
> + anon_vma_name(vma));
> +}
> +
> /*
> * do_vmi_align_munmap() - munmap the aligned region from @start to @end.
> * @vmi: The vma iterator
next prev parent reply other threads:[~2023-10-09 16:30 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-08 20:23 [PATCH 0/4] Abstract vma_merge() and split_vma() Lorenzo Stoakes
2023-10-08 20:23 ` [PATCH 1/4] mm: abstract the vma_merge()/split_vma() pattern for mprotect() et al Lorenzo Stoakes
2023-10-09 15:22 ` Vlastimil Babka
2023-10-09 18:19 ` Lorenzo Stoakes
2023-10-08 20:23 ` [PATCH 2/4] mm: make vma_merge() and split_vma() internal Lorenzo Stoakes
2023-10-09 15:45 ` Vlastimil Babka
2023-10-09 18:20 ` Lorenzo Stoakes
2023-10-08 20:23 ` [PATCH 3/4] mm: abstract merge for new VMAs into vma_merge_new_vma() Lorenzo Stoakes
2023-10-09 16:04 ` Vlastimil Babka
2023-10-09 18:21 ` Lorenzo Stoakes
2023-10-08 20:23 ` [PATCH 4/4] mm: abstract VMA extension and merge into vma_merge_extend() helper Lorenzo Stoakes
2023-10-09 16:30 ` Vlastimil Babka [this message]
2023-10-09 18:22 ` Lorenzo Stoakes
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=fe147a1e-6fe5-309f-b2e7-48f5f3c97bae@suse.cz \
--to=vbabka@suse.cz \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=brauner@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lstoakes@gmail.com \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox