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 A696FE77180 for ; Thu, 12 Dec 2024 20:12:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 35D6E6B00A4; Thu, 12 Dec 2024 15:12:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 30D536B00A5; Thu, 12 Dec 2024 15:12:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1D6086B00A6; Thu, 12 Dec 2024 15:12:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id F41A46B00A4 for ; Thu, 12 Dec 2024 15:12:07 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 7547212086E for ; Thu, 12 Dec 2024 20:12:07 +0000 (UTC) X-FDA: 82887402528.06.662ED31 Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) by imf21.hostedemail.com (Postfix) with ESMTP id 4C0C81C0017 for ; Thu, 12 Dec 2024 20:11:18 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=PWeRjs6K; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf21.hostedemail.com: domain of shy828301@gmail.com designates 209.85.218.41 as permitted sender) smtp.mailfrom=shy828301@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734034313; a=rsa-sha256; cv=none; b=f1GTF/yfLkECxv9dQTF2IDKNunwOet4OcVRsjDPAzm+HDIjQFeY3kSA6xxRzxRT5F284sO gnKoA850yZY1w5TJKPegagWLT1BcwuePh9VhnBugZI3BJFJSpLb+w1kEAFySIlTRCnZHBQ 4n6poq5F2a2wIjCmOiZ8G/BwFBUO9oU= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=PWeRjs6K; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf21.hostedemail.com: domain of shy828301@gmail.com designates 209.85.218.41 as permitted sender) smtp.mailfrom=shy828301@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734034313; 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=ccEjllC2XhoGMyYqcFrLm7vpFIY0Cm+U6Sao32tSe/w=; b=RXPkDz5ICBTCyAcuThK9wol0hV5Vk8WdAkiGH0SgIp3vNOP+MfVQqRHV1xacEmLRVQE2Wv U1xei5o4AlBmV5HT/lCxhriphEfQtE5x3FoHxe04MnhUj03ka7iJs59ETtmAJIDWMFuJU8 23ykjp8OCyPmEtRZ/qyHvZzP33IQqyM= Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-a9ec267b879so86243266b.2 for ; Thu, 12 Dec 2024 12:12:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734034324; x=1734639124; 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=ccEjllC2XhoGMyYqcFrLm7vpFIY0Cm+U6Sao32tSe/w=; b=PWeRjs6KJh1w8nOewokVEjOLfhkn2H+3fnII2GJ1mFagPsL9QBPjh1jPA9cN6/urQ6 JIJH0fRrSFPpKuuM0F2xdYHNp1W4eX91nBFCJFBZpTj91dusp8Ab7h0+9/H4Tuq0V4al 70jS1SbvRXa9fbhgRlDWE55/fV24HUMkYL3iZw6OoB9P4aBvwYiU/HL+P8MUrtcrdLyd yTw6c26yZH6H3kAGvP9jz8RfQmsBiRSBprM7jcggHb/OZ7rc8JEPlscAvLTZB8iPWHiU 9VsISduxkRI9Yqh21/Y9dzOQIWlpLeHy88ib3eQU8rLl2rR9JpJ0Jxs+OM8vpCYzq4O4 aWfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734034324; x=1734639124; 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=ccEjllC2XhoGMyYqcFrLm7vpFIY0Cm+U6Sao32tSe/w=; b=mAtW73O6DArfFLqUU7boA5TZLoDC+VhpcoMGe1GDBXaBaVbb0EvZ4hqbPzxSHT3SLW oi6qG+UyTIr3eAskMaiCen49V/WJC09l9LHFfC1hHjXlhgy+uNi8h8/PY4PmCwPq1LPC tpkA1GmfZ6y2XSZI1z/MPuBYDKTw5gWfxH+fQaM9Zh0xg+UnoPOZ44Gh6+IAeUyKRqWc gaeO98+xz31K2zqvJxvldPdx9/wSZ73u0CJkZ7HSggRhvTRFxmVWLyjxBgQMKTlpUH0z ZDMSn1/yNRvL21Rwg4naxuw3P5SHZ0QdYsQdtDpZjZ/1J8cE5n+e3lMM16gcNPxo2ezy T8Yg== X-Forwarded-Encrypted: i=1; AJvYcCWqr4ZGyNE8xf+JE+F3c9ixlFXZzB8BRw5uhpF461xWxeUi2d5vLPQlsFXkzsMS8Fcu3vVtJNvKCQ==@kvack.org X-Gm-Message-State: AOJu0Yx9zj6hP7CVYwypCLWL0zDR17F0EwtmdMoSsE0jSy2qKp7qGNoI RFO46o1C5jE6M2KszvTMk4CIG/u0l5D5Q/fBWipcbl4TDlIPpQvOuY9KsDTsOm/G9qpw5iqLJUX VusFs/KPTYItDa6P7bw1qk9C+gx4= X-Gm-Gg: ASbGncstyKkaHR3M5hZf0kPUa3f6TG++RUqdan/U0oOG0vLjXqEu0TUPHQy0qIsFc0V BFC2hjyfpTbdwoJ8EIq8AfUR7mhjfayog6qRaTQuQ X-Google-Smtp-Source: AGHT+IF7qx5Z1/fQb+D9Nv/8CkFXoKyEEzLktdUfd+sTUwFi+n5jfhaKRcSctFjQDfGrQzxwJV8DWyyLGWYjEOqOZ4M= X-Received: by 2002:a17:906:7304:b0:aa6:94c0:f755 with SMTP id a640c23a62f3a-aab778c1eaemr4266066b.1.1734034323514; Thu, 12 Dec 2024 12:12:03 -0800 (PST) MIME-Version: 1.0 References: <20241211232754.1583023-1-kaleshsingh@google.com> <20241211232754.1583023-17-kaleshsingh@google.com> In-Reply-To: <20241211232754.1583023-17-kaleshsingh@google.com> From: Yang Shi Date: Thu, 12 Dec 2024 12:11:51 -0800 Message-ID: Subject: Re: [PATCH mm-unstable v2 16/16] 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, minchan@kernel.org, jyescas@google.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-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 4C0C81C0017 X-Stat-Signature: cjh7zpmpn94de84qns515zqkdt61qq1q X-HE-Tag: 1734034278-65212 X-HE-Meta: U2FsdGVkX1/lBfVq8Of91fe8Tki3gOUT/ACWZ+3+69gLzwmh3PJeLVxyc2i4kEsiQU8Q0FOAInoZVGNapjPYEEHAuG40+PEeROQU8iCYdzj0kMvmbuJCU70H8/T2whnRSI1qutcrVOIf1zIMAA3ESQo+vgdNrWNc47Es4M2XlCbswx8jmR+xWzp9WC9PWtPAjCs0/dVJDiGUX4wmY2fu/bbtyG7rlfJMIz8KYhL64TO9L3C5lMJIBC6okjd4CqFNI+8JuJHzY6hANucdh8PT6Ym4rYnwggMvbPvKM0QWoT2zERHgw6+HIwzSk+a7kAoER1+KtvONZa0HZx0Nz6BzKeR7YXZpISVEU8rB7vUcVVXD9A3Xb4KC1HTxUavD5XW2Y5v/4g3V1lIgBPcLX9Sot24GXgRvBjS3C19WwpOZSx0iNYpWjdE82ZNtj9uX2Z6boRtFdGXxuO+l3HgpK907xMFHxq2RH3nEc1d0523GyzUdErLwjAWuQdv6ZwfF/Ub3N23IRVCA7a6qvA2kBlpHu0zeQ2K00OMFooUJjvOmeg6yh6EWcRCuMFT1MVKa7dWFTovZjiDkyQvUdJFb2FzmvwSh8fVxISCnBzLhl90ayUImrBi4bEZ25lb+eG9qbsXMgNaaRIf2+VEhCqJsxs4jqG7+zJ3Dfa32DsD7jyIMjJ39d9/GrRZnRCvj/qJzmFaQ36ZtrkmjKQUKrp+LYess6YsiR1ZYTzQLd/WYrZ9g65z6cU5ZT2f8GBmpUW0pYXpDT26GfXurbet+tKKJ64pUPn+rFF5Z9cYW5VsJ184c2O67qb6gyw7ojtiLNlt25e8TaVCnRr1XrWpT4Q0U2OTiETvSO2QxXoHH5sGZCJeeH+54NKBb95S1mnJbs/9rcnX3qBuanyOzw7e3Uxo9nmlwli1m7vvrmQ0Wa5DAgWfTc2n/80dZQsu/1mxxH+m/9bP78Ntdfq0lor4F8XYxnkX lPBvCTP4 TaXFw1mK2NYZc0WO9l0ay8rrsYKBF8lg3au/M2xLZuzICIFh3zsA4tZaAnJSXmQvZLB41EXUtglNSQHdBDNn9mcFsc6O19S//+b9zzzbndlVfX1PBonBjKVfVc4zUzAdq+eR958jipM4MHEEDVHquVGvlFuCnJKIpCLl/Si1w8l4nV/q2ykTgIXhKn+mSJNOkyLN9NQp8gYJrE9c7hFZeTkra1RzMd4Z5E8sbxfzEwpidHcJuvGfYZk0eamay5iGhtBRj3N9RhKBYGlenjfoYU604mX3CpwDpWJYYirGGZJYMBqDpujMCIuWCDhIXhY2PflqWCsZNnSgreR9AkfPGdDubO1sGeN87W9lFvNd538MX3LQx5DMNV+1T8Q== X-Bogosity: Ham, tests=bogofilter, spamicity=0.069485, 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 Wed, Dec 11, 2024 at 3:31=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 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 there isn't sufficient VA space > to satisfy the allocation at the hint address. > > Signed-off-by: Kalesh Singh Reviewed-by: Yang Shi > --- > mm/huge_memory.c | 17 ++++++++++------- > mm/mmap.c | 1 - > 2 files changed, 10 insertions(+), 8 deletions(-) > > diff --git a/mm/huge_memory.c b/mm/huge_memory.c > index 2da5520bfe24..426761a30aff 100644 > --- a/mm/huge_memory.c > +++ b/mm/huge_memory.c > @@ -1097,6 +1097,16 @@ static unsigned long __thp_get_unmapped_area(struc= t 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 hint a= nd > + * don't try to align to THP boundary; > + * > + * Or if an the requested extent is invalid return the error imme= diately. > + */ > + addr =3D arch_mmap_hint(filp, addr, len, off, flags); > + if (addr) > + return addr; > + > if (!IS_ENABLED(CONFIG_64BIT) || in_compat_syscall()) > return 0; > > @@ -1117,13 +1127,6 @@ static unsigned long __thp_get_unmapped_area(struc= t file *filp, > if (IS_ERR_VALUE(ret)) > return 0; > > - /* > - * Do not try to align to THP boundary if allocation at the addre= ss > - * 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 76dd6acdf051..3286fdff26f2 100644 > --- a/mm/mmap.c > +++ b/mm/mmap.c > @@ -814,7 +814,6 @@ __get_unmapped_area(struct file *file, unsigned long = 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 aligned= . */ > addr =3D thp_get_unmapped_area_vmflags(file, addr, len, > -- > 2.47.0.338.g60cca15819-goog > >