From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B29E8E7717F for ; Tue, 10 Dec 2024 19:40:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 456998D0013; Tue, 10 Dec 2024 14:40:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 406A98D000B; Tue, 10 Dec 2024 14:40:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2803F8D0013; Tue, 10 Dec 2024 14:40:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 0A29F8D000B for ; Tue, 10 Dec 2024 14:40:04 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id ADEBE80A76 for ; Tue, 10 Dec 2024 19:40:03 +0000 (UTC) X-FDA: 82880064666.11.367F19A Received: from mail-ed1-f44.google.com (mail-ed1-f44.google.com [209.85.208.44]) by imf01.hostedemail.com (Postfix) with ESMTP id DE9D240011 for ; Tue, 10 Dec 2024 19:39:44 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=DqXwpaS0; spf=pass (imf01.hostedemail.com: domain of shy828301@gmail.com designates 209.85.208.44 as permitted sender) smtp.mailfrom=shy828301@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733859579; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=IRTnbzohup0wCZkD2CjtRfmdnuYKFBQ3yOoD8MNis+g=; b=uRknOMcwBXdREsqijW03dZ2Cw1NV+EUaw9jq/tI0QMyEi7eBNI1uxp3XJrVqVB4TlYwbLS 8fJOL51lN+fhao5qCfV5Y5ECyVKNZNR0xdrauUCaXUekdSfn0b82Cd8vI+N5WIS4A1365o DxoWFQ3/A7620JW8ll1r8ffts5MRkvY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733859579; a=rsa-sha256; cv=none; b=ziejtTRJMp+AGyXTVNAFjKyFCK5nUEWwYJijnfKwd6o3Fs3dRoF5uD9pyUky0hdHa2ZT+I Errl0a4A1QM/ND0v06Lh09py3/JDfeHq/I4XhFoh7MZEYpt5e6NoLcgIDJ9VXlKW9cabvu 6XVOZ+lbiSe8m9+iTyK5BRa0eBgNE7k= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=DqXwpaS0; spf=pass (imf01.hostedemail.com: domain of shy828301@gmail.com designates 209.85.208.44 as permitted sender) smtp.mailfrom=shy828301@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-ed1-f44.google.com with SMTP id 4fb4d7f45d1cf-5d3ecae02beso4005543a12.0 for ; Tue, 10 Dec 2024 11:40:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733859600; x=1734464400; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=IRTnbzohup0wCZkD2CjtRfmdnuYKFBQ3yOoD8MNis+g=; b=DqXwpaS0xXXcWF7ceSPn7NmOHbnYqSNyT+t4Kr65VFAj1SpbQAuSYT7OMHIybhX51C wW8oADqGcSnJe9RdgX9s11bI2IcCLTML7R52+Tt4wywojYtx+JoGJMkmpHc6h/wet5vy vtUHO8jTf5KxDndcC7Xn4u3nvp11Fc3ixN/jnEaWWUWDts4wvinRkZ4gYB5Tw4dodf6M xx6f8fNLDkuqcglbACwiBhlOSyYbPEr7ssTy1NN//lYTrQ6R81QP/FKs4fDS1JbzGo6Q JUpgqwGb3otU0U4HdQvPeLXr0KXnBoQPBBe9eYw7mKpEJ5+jgSKjiJ7faEFLZlv3kY9X zd4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733859600; x=1734464400; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IRTnbzohup0wCZkD2CjtRfmdnuYKFBQ3yOoD8MNis+g=; b=Zw0B69cuEZ789icuomBdaio63hUb9jwd0gBo18g8AzvrBc/0l0kIKP9NzrfC/aWq6K LO+AZ2w6gROH3sD22BGe8KTT5XZ8Zl0B1eXQ1NW+ezsjsmT38ZE3jIO2spqZmQqqhwmu KMWjVGGxjlpy9rGZ9C7NV+wBohjNVd8S85q95GiBGIFV4R8K3u0c+4n7x1iPuUJpaGpb qw3qFvidvy+6T1NOFAukwMxuP/VLNMck8Fwo0uhCsyJ67nP4yr4qK3fG9oZS4xZNSzUG /VPEA7AX55xly6sNeWREcQ4JsnY6IOy27K0LsovM5+SjgRIqHi536qtaGUudRKnjcUwp fSJg== X-Forwarded-Encrypted: i=1; AJvYcCWaGbwwsPEFEHybq9LkvghiURzzm9RXmSdld2V75arGyUWHRGZzqUeKJWzwieygsvoX4XI3Pv+95g==@kvack.org X-Gm-Message-State: AOJu0YxLNd2a9CXEFQEuzV3h5fRbFF8wlPEHfLe5kJ7t5sBqKUfx0PTO TJoD0ys5CV0/ZR7DmrGPG819x3cD9P5ru2LV7fIoXmw0TV8Ix+yb7jdJWj3jTY39GFqLfmCzz5b wMmE7KruM1zJFhodm89wDgZTcOPo= X-Gm-Gg: ASbGncsn/sD6AghEJWSMHXHMRJjx05iEBKIwOW4XvcAQNafIAREM7Mw/WAyk/eHBiC0 a4rAJf7RIXsrpaIrwqCfTKKQth3EuyXF4MzR69w== X-Google-Smtp-Source: AGHT+IGn1TGMw5Q3ZRvX4tSkpBgSMsKO1aElzvBulPGolgowmhm7A7II8tzVQjdTXusigtkhjHD3HA/xYigxPDvvUCI= X-Received: by 2002:a05:6402:5299:b0:5d0:c9e6:30bc with SMTP id 4fb4d7f45d1cf-5d4330814d0mr38059a12.10.1733859599911; Tue, 10 Dec 2024 11:39:59 -0800 (PST) MIME-Version: 1.0 References: <20241210024119.2488608-1-kaleshsingh@google.com> <20241210024119.2488608-18-kaleshsingh@google.com> In-Reply-To: From: Yang Shi Date: Tue, 10 Dec 2024 11:39:48 -0800 Message-ID: Subject: Re: [PATCH mm-unstable 17/17] mm: Respect mmap hint before THP alignment if allocation is possible To: Kalesh Singh 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: DE9D240011 X-Rspam-User: X-Rspamd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pq1k0XzOddXN5mIe7qmdqdmfPQevnm8PebOutHTNmFaYtJYUonXMtic4hwf01nHOJhn66mgL0HoSvitviX2WJd2ZUy6P6Hr2Sv+Ek13UL4nGfNZNpHucAQ0hMDI33pVfM06J1w2zB+XjKto8nxrNQUmu7sPbvjmvcgJvU/m7JmiYW2/Lj05MJNrZ2I8r7wV6kNNXhMSpRXT5pqTp/sWTCUqU4jP4ucgkWxlLtscIUDozbbd7I7eRfB+94U5e0tPZy0Hw87SIzLWAkDG0AZ8ghFt5MYVGnHSdAouHXXbn/RqoklrZRVq2ftL8Zm8486vG06mNe/SLvqlJ2lQvKaYhiZ5M85kEuDY50uGK5o5FGlhhGzDNQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.070118, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Tue, Dec 10, 2024 at 9:34=E2=80=AFAM Kalesh Singh wrote: > > On Mon, Dec 9, 2024 at 7:37=E2=80=AFPM Yang Shi wro= te: > > > > On Mon, Dec 9, 2024 at 6:45=E2=80=AFPM Kalesh Singh 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 us= er > > > -- 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 mappin= gs > > > where the hint address were being ignored in some cases; due to commi= t > > > 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 > > > --- > > > 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(s= truct file *filp, > > > loff_t off_align =3D round_up(off, size); > > > unsigned long len_pad, ret, off_sub; > > > > > > + /* > > > + * If allocation at the address hint succeeds; respect the hi= nt and > > > + * don't try to align to THP boundary. > > > + */ > > > + addr =3D 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 =3D=3D 0. Aha, yeah, I missed addr is going to be reset if arch_mmap_hint() fails to find a suitable area. > > Thanks, > Kalesh > > > > > if (!IS_ENABLED(CONFIG_64BIT) || in_compat_syscall()) > > > return 0; > > > > > > @@ -1117,13 +1125,6 @@ static unsigned long __thp_get_unmapped_area(s= truct file *filp, > > > if (IS_ERR_VALUE(ret)) > > > return 0; > > > > > > - /* > > > - * Do not try to align to THP boundary if allocation at the a= ddress > > > - * hint succeeds. > > > - */ > > > - if (ret =3D=3D addr) > > > - return addr; > > > - > > > off_sub =3D (off - ret) & (size - 1); > > > > > > if (test_bit(MMF_TOPDOWN, ¤t->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 l= ong addr, unsigned long len, > > > if (get_area) { > > > addr =3D 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 ali= gned. */ > > > addr =3D thp_get_unmapped_area_vmflags(file, addr, le= n, > > > -- > > > 2.47.0.338.g60cca15819-goog > > > > > >