Re: [PATCH mm-unstable 01/17] mm: Introduce generic_mmap_hint()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Dec 9, 2024 at 7:27 PM Yang Shi <shy828301@xxxxxxxxx> wrote:
>
> On Mon, Dec 9, 2024 at 6:41 PM Kalesh Singh <kaleshsingh@xxxxxxxxxx> wrote:
> >
> > Consolidate the hint searches from both direcitons (topdown and
> > bottomup) into generic_mmap_hint().
> >
> > No functional change is introduced.
> >
> > Signed-off-by: Kalesh Singh <kaleshsingh@xxxxxxxxxx>
> > ---
> >  include/linux/sched/mm.h |  4 ++++
> >  mm/mmap.c                | 45 ++++++++++++++++++++++++----------------
> >  2 files changed, 31 insertions(+), 18 deletions(-)
> >
> > diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h
> > index 928a626725e6..edeec19d1708 100644
> > --- a/include/linux/sched/mm.h
> > +++ b/include/linux/sched/mm.h
> > @@ -201,6 +201,10 @@ unsigned long mm_get_unmapped_area_vmflags(struct mm_struct *mm,
> >                                            unsigned long flags,
> >                                            vm_flags_t vm_flags);
> >
> > +unsigned long generic_mmap_hint(struct file *filp, unsigned long addr,
> > +                               unsigned long len, unsigned long pgoff,
> > +                               unsigned long flags);
> > +
> >  unsigned long
> >  generic_get_unmapped_area(struct file *filp, unsigned long addr,
> >                           unsigned long len, unsigned long pgoff,
> > diff --git a/mm/mmap.c b/mm/mmap.c
> > index df9154b15ef9..e97eb8bf4889 100644
> > --- a/mm/mmap.c
> > +++ b/mm/mmap.c
> > @@ -620,6 +620,27 @@ unsigned long vm_unmapped_area(struct vm_unmapped_area_info *info)
> >         return addr;
> >  }
> >
> > +unsigned long generic_mmap_hint(struct file *filp, unsigned long addr,
> > +                               unsigned long len, unsigned long pgoff,
> > +                               unsigned long flags)
> > +{
> > +       struct mm_struct *mm = current->mm;
> > +       struct vm_area_struct *vma, *prev;
> > +       const unsigned long mmap_end = arch_get_mmap_end(addr, len, flags);
> > +
> > +       if (!addr)
> > +               return 0;
> > +
> > +       addr = PAGE_ALIGN(addr);
> > +       vma = find_vma_prev(mm, addr, &prev);
> > +       if (mmap_end - len >= addr && addr >= mmap_min_addr &&
> > +           (!vma || addr + len <= vm_start_gap(vma)) &&
> > +           (!prev || addr >= vm_end_gap(prev)))
> > +               return addr;
> > +
> > +       return 0;
> > +}
> > +
> >  /* Get an address range which is currently unmapped.
> >   * For shmat() with addr=0.
> >   *
> > @@ -637,7 +658,6 @@ generic_get_unmapped_area(struct file *filp, unsigned long addr,
> >                           unsigned long flags, vm_flags_t vm_flags)
> >  {
> >         struct mm_struct *mm = current->mm;
> > -       struct vm_area_struct *vma, *prev;
> >         struct vm_unmapped_area_info info = {};
> >         const unsigned long mmap_end = arch_get_mmap_end(addr, len, flags);
> >
> > @@ -647,14 +667,9 @@ generic_get_unmapped_area(struct file *filp, unsigned long addr,
> >         if (flags & MAP_FIXED)
> >                 return addr;
>
> It seems you also can move the MAP_FIXED case into generic_mmap_hint(), right?

I think that could be done too. we'll need a new name :) Let me take a
look at it ...

-- Kalesh

>
> >
> > -       if (addr) {
> > -               addr = PAGE_ALIGN(addr);
> > -               vma = find_vma_prev(mm, addr, &prev);
> > -               if (mmap_end - len >= addr && addr >= mmap_min_addr &&
> > -                   (!vma || addr + len <= vm_start_gap(vma)) &&
> > -                   (!prev || addr >= vm_end_gap(prev)))
> > -                       return addr;
> > -       }
> > +       addr = generic_mmap_hint(filp, addr, len, pgoff, flags);
> > +       if (addr)
> > +               return addr;
> >
> >         info.length = len;
> >         info.low_limit = mm->mmap_base;
> > @@ -685,7 +700,6 @@ generic_get_unmapped_area_topdown(struct file *filp, unsigned long addr,
> >                                   unsigned long len, unsigned long pgoff,
> >                                   unsigned long flags, vm_flags_t vm_flags)
> >  {
> > -       struct vm_area_struct *vma, *prev;
> >         struct mm_struct *mm = current->mm;
> >         struct vm_unmapped_area_info info = {};
> >         const unsigned long mmap_end = arch_get_mmap_end(addr, len, flags);
> > @@ -698,14 +712,9 @@ generic_get_unmapped_area_topdown(struct file *filp, unsigned long addr,
> >                 return addr;
> >
> >         /* requesting a specific address */
> > -       if (addr) {
> > -               addr = PAGE_ALIGN(addr);
> > -               vma = find_vma_prev(mm, addr, &prev);
> > -               if (mmap_end - len >= addr && addr >= mmap_min_addr &&
> > -                               (!vma || addr + len <= vm_start_gap(vma)) &&
> > -                               (!prev || addr >= vm_end_gap(prev)))
> > -                       return addr;
> > -       }
> > +       addr = generic_mmap_hint(filp, addr, len, pgoff, flags);
> > +       if (addr)
> > +               return addr;
> >
> >         info.flags = VM_UNMAPPED_AREA_TOPDOWN;
> >         info.length = len;
> > --
> > 2.47.0.338.g60cca15819-goog
> >
> >





[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Kernel Development]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite Info]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Linux Media]     [Device Mapper]

  Powered by Linux