linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Kalesh Singh <kaleshsingh@google.com>
To: Yang Shi <shy828301@gmail.com>
Cc: akpm@linux-foundation.org, vbabka@suse.cz,
	yang@os.amperecomputing.com,  riel@surriel.com, david@redhat.com,
	linux@armlinux.org.uk,  tsbogend@alpha.franken.de,
	James.Bottomley@hansenpartnership.com,
	 ysato@users.sourceforge.jp, dalias@libc.org,
	glaubitz@physik.fu-berlin.de,  davem@davemloft.net,
	andreas@gaisler.com, tglx@linutronix.de, bp@alien8.de,
	 dave.hansen@linux.intel.com, x86@kernel.org, chris@zankel.net,
	 jcmvbkbc@gmail.com, bhelgaas@google.com, jason.andryuk@amd.com,
	 leitao@debian.org, linux-alpha@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	 linux-snps-arc@lists.infradead.org,
	linux-arm-kernel@lists.infradead.org,
	 linux-csky@vger.kernel.org, loongarch@lists.linux.dev,
	 linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org,
	 linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org,
	 linux-sh@vger.kernel.org, sparclinux@vger.kernel.org,
	linux-mm@kvack.org,  kernel-team@android.com,
	android-mm@google.com
Subject: Re: [PATCH mm-unstable 01/17] mm: Introduce generic_mmap_hint()
Date: Tue, 10 Dec 2024 09:55:27 -0800	[thread overview]
Message-ID: <CAC_TJvc5SU_khaBf7NS1VvD+d5PJ4X1DwKWbO92j-dZ+rEuc9A@mail.gmail.com> (raw)
In-Reply-To: <CAHbLzkpCRGF+-WXkHVEutkEGHSWydmpb1CwkvHZRTH-f773J-w@mail.gmail.com>

On Mon, Dec 9, 2024 at 7:27 PM Yang Shi <shy828301@gmail.com> wrote:
>
> On Mon, Dec 9, 2024 at 6:41 PM Kalesh Singh <kaleshsingh@google.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@google.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
> >
> >


  reply	other threads:[~2024-12-10 17:55 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-10  2:41 [PATCH mm-unstable 00/17] mm: Introduce arch_mmap_hint() Kalesh Singh
2024-12-10  2:41 ` [PATCH mm-unstable 01/17] mm: Introduce generic_mmap_hint() Kalesh Singh
2024-12-10  3:27   ` Yang Shi
2024-12-10 17:55     ` Kalesh Singh [this message]
2024-12-10  2:41 ` [PATCH mm-unstable 02/17] mm: x86: Introduce arch_mmap_hint() Kalesh Singh
2024-12-10  2:41 ` [PATCH mm-unstable 03/17] mm: arm: " Kalesh Singh
2024-12-10  2:41 ` [PATCH mm-unstable 04/17] mm: alpha: " Kalesh Singh
2024-12-10  2:41 ` [PATCH mm-unstable 05/17] mm: arc: Use generic_mmap_hint() Kalesh Singh
2024-12-10  2:41 ` [PATCH mm-unstable 06/17] mm: csky: Introduce arch_mmap_hint() Kalesh Singh
2024-12-10  2:41 ` [PATCH mm-unstable 07/17] mm: loongarch: " Kalesh Singh
2024-12-10  2:41 ` [PATCH mm-unstable 08/17] mm: mips: Introduce arch_align_mmap_hint() Kalesh Singh
2024-12-10  2:41 ` [PATCH mm-unstable 09/17] mm: parisc: " Kalesh Singh
2024-12-10  2:41 ` [PATCH mm-unstable 10/17] mm: s390: Introduce arch_mmap_hint() Kalesh Singh
2024-12-10  2:41 ` [PATCH mm-unstable 11/17] mm: sh: " Kalesh Singh
2024-12-10  2:41 ` [PATCH mm-unstable 12/17] mm: sparc32: " Kalesh Singh
2024-12-10  2:41 ` [PATCH mm-unstable 13/17] mm: sparc64: " Kalesh Singh
2024-12-10  2:41 ` [PATCH mm-unstable 14/17] mm: xtensa: " Kalesh Singh
2024-12-10  2:41 ` [PATCH mm-unstable 15/17] mm: powerpc: " Kalesh Singh
2024-12-10  2:41 ` [PATCH mm-unstable 16/17] mm: Fallback to generic_mmap_hint() Kalesh Singh
2024-12-10  2:41 ` [PATCH mm-unstable 17/17] mm: Respect mmap hint before THP alignment if allocation is possible Kalesh Singh
2024-12-10  3:37   ` Yang Shi
2024-12-10 17:34     ` Kalesh Singh
2024-12-10 19:39       ` Yang Shi

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=CAC_TJvc5SU_khaBf7NS1VvD+d5PJ4X1DwKWbO92j-dZ+rEuc9A@mail.gmail.com \
    --to=kaleshsingh@google.com \
    --cc=James.Bottomley@hansenpartnership.com \
    --cc=akpm@linux-foundation.org \
    --cc=andreas@gaisler.com \
    --cc=android-mm@google.com \
    --cc=bhelgaas@google.com \
    --cc=bp@alien8.de \
    --cc=chris@zankel.net \
    --cc=dalias@libc.org \
    --cc=dave.hansen@linux.intel.com \
    --cc=davem@davemloft.net \
    --cc=david@redhat.com \
    --cc=glaubitz@physik.fu-berlin.de \
    --cc=jason.andryuk@amd.com \
    --cc=jcmvbkbc@gmail.com \
    --cc=kernel-team@android.com \
    --cc=leitao@debian.org \
    --cc=linux-alpha@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-csky@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-parisc@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=linux-sh@vger.kernel.org \
    --cc=linux-snps-arc@lists.infradead.org \
    --cc=linux@armlinux.org.uk \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=loongarch@lists.linux.dev \
    --cc=riel@surriel.com \
    --cc=shy828301@gmail.com \
    --cc=sparclinux@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=tsbogend@alpha.franken.de \
    --cc=vbabka@suse.cz \
    --cc=x86@kernel.org \
    --cc=yang@os.amperecomputing.com \
    --cc=ysato@users.sourceforge.jp \
    /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