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 17/17] mm: Respect mmap hint before THP alignment if allocation is possible
Date: Tue, 10 Dec 2024 09:34:01 -0800	[thread overview]
Message-ID: <CAC_TJvdReRHzBSgg2iqOw3Kw6BBOtwGE=8nB2Hsw-nsmkxN0+g@mail.gmail.com> (raw)
In-Reply-To: <CAHbLzkq2SNaqzx4d981H2QfQvtObS3X0pPL8=oqFsFbMditWPA@mail.gmail.com>

On Mon, Dec 9, 2024 at 7:37 PM Yang Shi <shy828301@gmail.com> wrote:
>
> On Mon, Dec 9, 2024 at 6:45 PM Kalesh Singh <kaleshsingh@google.com> wrote:
> >
> > Commit 249608ee4713 ("mm: respect mmap hint address when aligning for THP")
> > fallsback to PAGE_SIZE alignment instead of THP alignment
> > for anonymous mapping as long as a hint address is provided by the user
> > -- even if we weren't able to allocate the unmapped area at the hint
> > address in the end.
> >
> > This was done to address the immediate regression in anonymous mappings
> > where the hint address were being ignored in some cases; due to commit
> > efa7df3e3bb5 ("mm: align larger anonymous mappings on THP boundaries").
> >
> > It was later pointed out that this issue also existed for file-backed
> > mappings from file systems that use thp_get_unmapped_area() for their
> > .get_unmapped_area() file operation.
> >
> > The same fix was not applied for file-backed mappings since it would
> > mean any mmap requests that provide a hint address would be only
> > PAGE_SIZE-aligned regardless of whether allocation was successful at
> > the hint address or not.
> >
> > Instead, use arch_mmap_hint() to first attempt allocation at the hint
> > address and fallback to THP alignment if that fails.
>
> Thanks for taking time to try to fix this.
>
> >
> > Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
> > ---
> >  mm/huge_memory.c | 15 ++++++++-------
> >  mm/mmap.c        |  1 -
> >  2 files changed, 8 insertions(+), 8 deletions(-)
> >
> > diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> > index 137abeda8602..f070c89dafc9 100644
> > --- a/mm/huge_memory.c
> > +++ b/mm/huge_memory.c
> > @@ -1097,6 +1097,14 @@ static unsigned long __thp_get_unmapped_area(struct file *filp,
> >         loff_t off_align = round_up(off, size);
> >         unsigned long len_pad, ret, off_sub;
> >
> > +       /*
> > +        * If allocation at the address hint succeeds; respect the hint and
> > +        * don't try to align to THP boundary.
> > +        */
> > +       addr = arch_mmap_hint(filp, addr, len, off, flags);
> > +       if (addr)
> > +               return addr;
> > +

Hi Yang,

Thanks for the comments.

>
> IIUC, arch_mmap_hint() will be called in arch_get_unmapped_area() and
> arch_get_unmapped_area_topdown() again. So we will actually look up
> maple tree twice. It sounds like the second hint address search is
> pointless. You should be able to set addr to 0 before calling
> mm_get_unmapped_area_vmflags() in order to skip the second hint
> address search.

You are right that it would call into arch_mmap_hint() twice but it
only attempts the lookup once since on the second attempt addr == 0.

Thanks,
Kalesh
>
> >         if (!IS_ENABLED(CONFIG_64BIT) || in_compat_syscall())
> >                 return 0;
> >
> > @@ -1117,13 +1125,6 @@ static unsigned long __thp_get_unmapped_area(struct file *filp,
> >         if (IS_ERR_VALUE(ret))
> >                 return 0;
> >
> > -       /*
> > -        * Do not try to align to THP boundary if allocation at the address
> > -        * hint succeeds.
> > -        */
> > -       if (ret == addr)
> > -               return addr;
> > -
> >         off_sub = (off - ret) & (size - 1);
> >
> >         if (test_bit(MMF_TOPDOWN, &current->mm->flags) && !off_sub)
> > diff --git a/mm/mmap.c b/mm/mmap.c
> > index 59bf7d127aa1..6bfeec80152a 100644
> > --- a/mm/mmap.c
> > +++ b/mm/mmap.c
> > @@ -807,7 +807,6 @@ __get_unmapped_area(struct file *file, unsigned long addr, unsigned long len,
> >         if (get_area) {
> >                 addr = get_area(file, addr, len, pgoff, flags);
> >         } else if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) && !file
> > -                  && !addr /* no hint */
> >                    && IS_ALIGNED(len, PMD_SIZE)) {
> >                 /* Ensures that larger anonymous mappings are THP aligned. */
> >                 addr = thp_get_unmapped_area_vmflags(file, addr, len,
> > --
> > 2.47.0.338.g60cca15819-goog
> >
> >


  reply	other threads:[~2024-12-10 17:34 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
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 [this message]
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_TJvdReRHzBSgg2iqOw3Kw6BBOtwGE=8nB2Hsw-nsmkxN0+g@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