[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAC_TJvc5SU_khaBf7NS1VvD+d5PJ4X1DwKWbO92j-dZ+rEuc9A@mail.gmail.com>
Date: Tue, 10 Dec 2024 09:55:27 -0800
From: Kalesh Singh <kaleshsingh@...gle.com>
To: Yang Shi <shy828301@...il.com>
Cc: akpm@...ux-foundation.org, vbabka@...e.cz, yang@...amperecomputing.com,
riel@...riel.com, david@...hat.com, linux@...linux.org.uk,
tsbogend@...ha.franken.de, James.Bottomley@...senpartnership.com,
ysato@...rs.sourceforge.jp, dalias@...c.org, glaubitz@...sik.fu-berlin.de,
davem@...emloft.net, andreas@...sler.com, tglx@...utronix.de, bp@...en8.de,
dave.hansen@...ux.intel.com, x86@...nel.org, chris@...kel.net,
jcmvbkbc@...il.com, bhelgaas@...gle.com, jason.andryuk@....com,
leitao@...ian.org, linux-alpha@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-snps-arc@...ts.infradead.org, linux-arm-kernel@...ts.infradead.org,
linux-csky@...r.kernel.org, loongarch@...ts.linux.dev,
linux-mips@...r.kernel.org, linux-parisc@...r.kernel.org,
linuxppc-dev@...ts.ozlabs.org, linux-s390@...r.kernel.org,
linux-sh@...r.kernel.org, sparclinux@...r.kernel.org, linux-mm@...ck.org,
kernel-team@...roid.com, android-mm@...gle.com
Subject: Re: [PATCH mm-unstable 01/17] mm: Introduce generic_mmap_hint()
On Mon, Dec 9, 2024 at 7:27 PM Yang Shi <shy828301@...il.com> wrote:
>
> On Mon, Dec 9, 2024 at 6:41 PM Kalesh Singh <kaleshsingh@...gle.com> 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@...gle.com>
> > ---
> > 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
> >
> >
Powered by blists - more mailing lists