Re: [PATCH v10 13/69] mm/mmap: use maple tree for unmapped_area{_topdown}

From: Liam Howlett
Date: Wed Jul 13 2022 - 20:47:36 EST


* David Hildenbrand <david@xxxxxxxxxx> [220623 13:26]:
> On 21.06.22 22:46, Liam Howlett wrote:
> > From: "Liam R. Howlett" <Liam.Howlett@xxxxxxxxxx>
> >
> > The maple tree code was added to find the unmapped area in a previous
> > commit and was checked against what the rbtree returned, but the actual
> > result was never used. Start using the maple tree implementation and
> > remove the rbtree code.
> >
> > Add kernel documentation comment for these functions.
> >
> > Link: https://lkml.kernel.org/r/20220504010716.661115-15-Liam.Howlett@xxxxxxxxxx
> > Signed-off-by: Liam R. Howlett <Liam.Howlett@xxxxxxxxxx>
> > Cc: Catalin Marinas <catalin.marinas@xxxxxxx>
> > Cc: David Howells <dhowells@xxxxxxxxxx>
> > Cc: "Matthew Wilcox (Oracle)" <willy@xxxxxxxxxxxxx>
> > Cc: SeongJae Park <sj@xxxxxxxxxx>
> > Cc: Vlastimil Babka <vbabka@xxxxxxx>
> > Cc: Will Deacon <will@xxxxxxxxxx>
> > Cc: Davidlohr Bueso <dave@xxxxxxxxxxxx>
> > Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
> > ---
> > mm/mmap.c | 253 +++++++-----------------------------------------------
> > 1 file changed, 32 insertions(+), 221 deletions(-)
> >
> > diff --git a/mm/mmap.c b/mm/mmap.c
> > index 08845a0317bf..b91d22329418 100644
> > --- a/mm/mmap.c
> > +++ b/mm/mmap.c
> > @@ -2053,250 +2053,61 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
> > return error;
> > }
> >
> > +/* unmapped_area() Find an area between the low_limit and the high_limit with
>
> /**
> * unmapped_area() - ...

ack.

>
> > + * the correct alignment and offset, all from @info. Note: current->mm is used
> > + * for the search.
> > + *
> > + * @info: The unmapped area information including the range (low_limit -
> > + * hight_limit), the alignment offset and mask.
> > + *
> > + * Return: A memory address or -ENOMEM.
> > + */
> > static unsigned long unmapped_area(struct vm_unmapped_area_info *info)
> > {
>
> ...
>
> >
> > +/* unmapped_area_topdown() Find an area between the low_limit and the
>
> \Dito

ack.

>
> > + * high_limit with * the correct alignment and offset at the highest available
> > + * address, all from * @info. Note: current->mm is used for the search.
>
> I'm confused about the "*" in the text, but maybe I'm just tired :)

So was my auto-formatting, I guess. I'll fix this.

>
> > + *
> > + * @info: The unmapped area information including the range (low_limit -
> > + * hight_limit), the alignment offset and mask.
> > + *
> > + * Return: A memory address or -ENOMEM.
> > + */
> > static unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
> > {
>
> [...]
>
> > -found:
> > - /* We found a suitable gap. Clip it with the original high_limit. */
> > - if (gap_end > info->high_limit)
> > - gap_end = info->high_limit;
> > -
> > -found_highest:
> > - /* Compute highest gap address at the desired alignment */
> > - gap_end -= info->length;
> > - gap_end -= (gap_end - info->align_offset) & info->align_mask;
> > -
> > - VM_BUG_ON(gap_end < info->low_limit);
> > - VM_BUG_ON(gap_end < gap_start);
>
> Can we leave some of these in, please? (same applies to other function)
>
> I keep getting confused by align_offset. vs align_mask. I *think* this
> is correct, but some checks that we stay in limits and actually have
> proper alignment would be reasonable.

Right, so in the version that existed with both rbtree and maple tree
had a BUG_ON if my calculation wasn't the same as the rbtree
calculation. I'll re-add the VM_BUG_ON() statements as you suggest for
good measure.

Thanks,
Liam

>
>
> --
> Thanks,
>
> David / dhildenb
>