From: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
To: Vlastimil Babka <vbabka@suse.cz>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
"Andrew Morton" <akpm@linux-foundation.org>,
"Liam R . Howlett" <Liam.Howlett@oracle.com>,
"Petr Tesařík" <petr@tesarici.cz>
Subject: Re: [PATCH 08/10] mm: introduce commit_merge(), abstracting merge operation
Date: Fri, 9 Aug 2024 11:53:47 +0100 [thread overview]
Message-ID: <289329d9-98f5-46e3-81c8-9e522b303028@lucifer.local> (raw)
In-Reply-To: <1f446461-8858-429a-8a0e-cb6b24c6a0c8@suse.cz>
On Fri, Aug 09, 2024 at 12:15:24PM GMT, Vlastimil Babka wrote:
> On 8/5/24 14:13, Lorenzo Stoakes wrote:
> > Pull this operation into its own function and have vma_expand() call
> > commit_merge() instead.
> >
> > This lays the groundwork for a subsequent patch which replaces vma_merge()
> > with a simpler function which can share the same code.
> >
> > Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
>
> In general,
>
> Acked-by: Vlastimil Babka <vbabka@suse.cz>
>
> If you consider the following suggestions, great:
>
> > ---
> > mm/vma.c | 57 ++++++++++++++++++++++++++++++++++++++++++++------------
> > 1 file changed, 45 insertions(+), 12 deletions(-)
> >
> > diff --git a/mm/vma.c b/mm/vma.c
> > index a404cf718f9e..b7e3c64d5d68 100644
> > --- a/mm/vma.c
> > +++ b/mm/vma.c
> > @@ -564,6 +564,49 @@ void validate_mm(struct mm_struct *mm)
> > }
> > #endif /* CONFIG_DEBUG_VM_MAPLE_TREE */
> >
> > +/* Actually perform the VMA merge operation. */
> > +static int commit_merge(struct vma_merge_struct *vmg,
> > + struct vm_area_struct *adjust,
> > + struct vm_area_struct *remove,
> > + struct vm_area_struct *remove2,
> > + long adj_start,
> > + bool expanded)
>
> I've read the subthread with Petr. I understand it's hard to organize such
> big changes in self-contained units. But maybe it would still be possible to
> introduce this function now without the parameters, and as part of the the
> next patch add the two parameters and the code using them. Maybe it would
> even make git detect the added code as code move from where it's now, so it
> would be more obviousl.
Since both you and Petr make the same point (sorry Petr, I should have
perhaps been a little less resistant to this), I will do this.
As discussed on IRC my position on this is that we're introducing a _really
fundamental_ and important bit of the logic here, intentionally broken out
as a separate commit, and this is why I preferred to introduce it 'fully
formed'.
This function is absolutely fundamental to eliminating the duplication in
do_brk_flags() + mmap_region() and to maintain two separate new/modified
vma versions of vma_merge().
HOWEVER, I totally accept that this makes review much more of a pain in the
arse, and in practice almost certainly the only thing that matters is
reviewability here as to how I structure this.
So TL;DR: I'll do what you both ask and introduce new params only when we
use them.
>
> > +{
> > + struct vma_prepare vp;
> > +
> > + init_multi_vma_prep(&vp, vmg->vma, adjust, remove, remove2);
> > +
> > + if (expanded) {
> > + vma_iter_config(vmg->vmi, vmg->start, vmg->end);
>
> This originally had a comment
>
> /* Note: vma iterator must be pointing to 'start' */
>
> and now it's gone.
Will check and re-add if it makes sense. I mean we're now setting the iterator
to start anyway so I don't see that this has value? Maybe I'm missing something
and Liam has thoughts...
>
> > + } else {
> > + vma_iter_config(vmg->vmi, adjust->vm_start + adj_start,
> > + adjust->vm_end);
>
> And this less obvious one has none either :(
I will add a comment.
>
> > + }
> > +
> > + if (vma_iter_prealloc(vmg->vmi, vmg->vma))
> > + return -ENOMEM;
> > +
> > + vma_prepare(&vp);
> > + vma_adjust_trans_huge(vmg->vma, vmg->start, vmg->end, adj_start);
> > + vma_set_range(vmg->vma, vmg->start, vmg->end, vmg->pgoff);
> > +
> > + if (expanded)
> > + vma_iter_store(vmg->vmi, vmg->vma);
> > +
> > + if (adj_start) {
> > + adjust->vm_start += adj_start;
> > + adjust->vm_pgoff += PHYS_PFN(adj_start);
> > + if (adj_start < 0) {
> > + WARN_ON(expanded);
> > + vma_iter_store(vmg->vmi, adjust);
> > + }
> > + }
> > +
> > + vma_complete(&vp, vmg->vmi, vmg->vma->vm_mm);
> > +
> > + return 0;
> > +}
> > +
> > /*
> > * vma_merge_new_vma - Attempt to merge a new VMA into address space
> > *
> > @@ -700,7 +743,6 @@ int vma_expand(struct vma_merge_struct *vmg)
> > bool remove_next = false;
> > struct vm_area_struct *vma = vmg->vma;
> > struct vm_area_struct *next = vmg->next;
> > - struct vma_prepare vp;
> >
> > vma_start_write(vma);
> > if (next && (vma != next) && (vmg->end == next->vm_end)) {
> > @@ -713,24 +755,15 @@ int vma_expand(struct vma_merge_struct *vmg)
> > return ret;
> > }
> >
> > - init_multi_vma_prep(&vp, vma, NULL, remove_next ? next : NULL, NULL);
> > /* Not merging but overwriting any part of next is not handled. */
> > - VM_WARN_ON(next && !vp.remove &&
> > + VM_WARN_ON(next && !remove_next &&
> > next != vma && vmg->end > next->vm_start);
> > /* Only handles expanding */
> > VM_WARN_ON(vma->vm_start < vmg->start || vma->vm_end > vmg->end);
> >
> > - /* Note: vma iterator must be pointing to 'start' */
> > - vma_iter_config(vmg->vmi, vmg->start, vmg->end);
> > - if (vma_iter_prealloc(vmg->vmi, vma))
> > + if (commit_merge(vmg, NULL, remove_next ? next : NULL, NULL, 0, true))
> > goto nomem;
> >
> > - vma_prepare(&vp);
> > - vma_adjust_trans_huge(vma, vmg->start, vmg->end, 0);
> > - vma_set_range(vma, vmg->start, vmg->end, vmg->pgoff);
> > - vma_iter_store(vmg->vmi, vma);
> > -
> > - vma_complete(&vp, vmg->vmi, vma->vm_mm);
> > return 0;
> >
> > nomem:
>
next prev parent reply other threads:[~2024-08-09 10:54 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-05 12:13 [PATCH 00/10] mm: remove vma_merge() Lorenzo Stoakes
2024-08-05 12:13 ` [PATCH 01/10] tools: improve vma test Makefile Lorenzo Stoakes
2024-08-05 12:13 ` [PATCH 02/10] mm: introduce vma_merge_struct and abstract merge parameters Lorenzo Stoakes
2024-08-06 12:47 ` Petr Tesařík
2024-08-06 13:43 ` Lorenzo Stoakes
2024-08-06 14:06 ` Petr Tesařík
2024-08-06 14:20 ` Lorenzo Stoakes
2024-08-06 14:32 ` Petr Tesařík
2024-08-08 12:49 ` Vlastimil Babka
2024-08-08 17:18 ` Lorenzo Stoakes
2024-08-08 20:07 ` Liam R. Howlett
2024-08-09 10:11 ` Lorenzo Stoakes
2024-08-05 12:13 ` [PATCH 03/10] mm: abstract duplicated policy comparison Lorenzo Stoakes
2024-08-06 12:50 ` Petr Tesařík
2024-08-05 12:13 ` [PATCH 04/10] mm: abstract parameters for vma_expand/shrink() Lorenzo Stoakes
2024-08-06 12:54 ` Petr Tesařík
[not found] ` <f12608ec-9c40-4977-a5a6-479f86b44e80@kernel.org>
2024-08-08 15:45 ` Lorenzo Stoakes
2024-08-08 20:20 ` Liam R. Howlett
2024-08-09 10:18 ` Lorenzo Stoakes
2024-08-14 13:53 ` Lorenzo Stoakes
2024-08-05 12:13 ` [PATCH 05/10] mm: abstract vma_merge_new_vma() to use vma_merge_struct Lorenzo Stoakes
[not found] ` <82b802e0-94fd-4cca-ad8f-ea2d85bcae64@kernel.org>
2024-08-08 15:52 ` Lorenzo Stoakes
2024-08-05 12:13 ` [PATCH 06/10] tools: add VMA merge tests Lorenzo Stoakes
2024-08-05 12:13 ` [PATCH 07/10] mm: avoid using vma_merge() for new VMAs Lorenzo Stoakes
2024-08-06 13:04 ` Petr Tesařík
2024-08-06 13:44 ` Lorenzo Stoakes
2024-08-08 16:45 ` Vlastimil Babka
2024-08-08 18:02 ` Lorenzo Stoakes
2024-08-08 18:34 ` Liam R. Howlett
2024-08-08 19:06 ` Liam R. Howlett
2024-08-09 10:14 ` Lorenzo Stoakes
2024-08-09 15:23 ` Liam R. Howlett
2024-08-09 17:20 ` Lorenzo Stoakes
2024-08-05 12:13 ` [PATCH 08/10] mm: introduce commit_merge(), abstracting merge operation Lorenzo Stoakes
2024-08-06 13:41 ` Petr Tesařík
2024-08-06 13:48 ` Lorenzo Stoakes
2024-08-06 14:13 ` Petr Tesařík
2024-08-06 14:30 ` Lorenzo Stoakes
2024-08-06 14:39 ` Petr Tesařík
2024-08-09 10:15 ` Vlastimil Babka
2024-08-09 10:53 ` Lorenzo Stoakes [this message]
2024-08-05 12:13 ` [PATCH 09/10] mm: refactor vma_merge() into modify-only vma_merge_modified() Lorenzo Stoakes
2024-08-06 13:42 ` Petr Tesařík
2024-08-06 13:52 ` Lorenzo Stoakes
2024-08-09 13:44 ` Vlastimil Babka
2024-08-09 13:57 ` Lorenzo Stoakes
2024-08-05 12:13 ` [PATCH 10/10] mm: rework vm_ops->close() handling on VMA merge Lorenzo Stoakes
2024-08-06 13:55 ` Petr Tesařík
2024-08-06 14:08 ` Lorenzo Stoakes
2024-08-06 14:21 ` Petr Tesařík
2024-08-06 14:42 ` Lorenzo Stoakes
2024-08-09 14:25 ` Vlastimil Babka
2024-08-09 14:37 ` 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=289329d9-98f5-46e3-81c8-9e522b303028@lucifer.local \
--to=lorenzo.stoakes@oracle.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=petr@tesarici.cz \
--cc=vbabka@suse.cz \
/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