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 869BAE77180 for ; Tue, 10 Dec 2024 17:34:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 107A36B0129; Tue, 10 Dec 2024 12:34:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0912B6B012B; Tue, 10 Dec 2024 12:34:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E73F66B012D; Tue, 10 Dec 2024 12:34:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id C4E7D6B0129 for ; Tue, 10 Dec 2024 12:34:17 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 772281C7603 for ; Tue, 10 Dec 2024 17:34:17 +0000 (UTC) X-FDA: 82879747272.06.011341F Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by imf30.hostedemail.com (Postfix) with ESMTP id 7DBBD8001B for ; Tue, 10 Dec 2024 17:33:33 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=mWNXTqhj; spf=pass (imf30.hostedemail.com: domain of kaleshsingh@google.com designates 209.85.214.181 as permitted sender) smtp.mailfrom=kaleshsingh@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733852033; 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=RArVkKSCeMH/NY6o3gQIWtxTREQOsCr1U+SuNtxbEwg=; b=YBMs/Iv7jL29ak6EC7Hejuqxwp45kOEKzNXiV0SYexvsuZPRgMxLJE4qPn9mIV4drzUTC5 w1sEK7RHqJ8PDhnRyUGqk0UjO4KHp7tEcxQa0MNew/FA1V9K8WvgqtvBTvgu+mvtc04qww r9sYoBsoFBKd9C8SeXdzY5ugrhM7zv4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733852033; a=rsa-sha256; cv=none; b=n4A/32CX2qbu+QJfLjruiu8sLDR/e61u5RwRHYdrq0Y1+u1Y8g+iQyAXQw9foxbDy3U4uJ hImVdeIIBBOoJozfGzWDSwnNjqPI9v9ased/DL6tpE2AlJrDmSHyHcetwLseVaF7M02039 Yky+N9ei9CCgmrcd4lMx85JnX9KSTKM= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=mWNXTqhj; spf=pass (imf30.hostedemail.com: domain of kaleshsingh@google.com designates 209.85.214.181 as permitted sender) smtp.mailfrom=kaleshsingh@google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-2155c25e9a4so137315ad.1 for ; Tue, 10 Dec 2024 09:34:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733852054; x=1734456854; 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=RArVkKSCeMH/NY6o3gQIWtxTREQOsCr1U+SuNtxbEwg=; b=mWNXTqhj5A0g0Z+zqrjlB1cxdhMg16ruzdaODtkmtXRxzKHb7PgiI97JxAUcW//YAN zfM5PrtMvCdPh+Vge/fDmczS38Ape5d8gb7Ddbkh2BYCisyTo/oRHB0cLZifvNCvig4o sczuvIFslETK39pes+M5pzvaSuKZj+Pk8AVhazVqXT0GJvxVjREv2WYTtoKRYC7pPapq 3MKlDuCQzHNZ35XD99DQe3yb61vwjB/22MFqr1NyN8Ddz9vvA/rFVXhV0D009gYYZawT ChGPwHFusQOznD1WWRpCOJubwZtoFrlFlG9KWLvDeLBrpVfwEZ+tYq/OjQAa1y2X3iP4 7Gvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733852054; x=1734456854; 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=RArVkKSCeMH/NY6o3gQIWtxTREQOsCr1U+SuNtxbEwg=; b=JbuizBjH/T2+vpnNBOkGxHbmHuYWc8l7e6fdDQSS6f2omW8efif1BUYHe1eu4yr1W3 623vbLVpJYhANh0HOKvshYbcJZ0liDP3iTYCJn5tMIO+vHW17mpvXwCJ7nFxjVePbzHq ajcAZcpwHALE4IigpX0+ayxPg7CI8qa/bqXOqjcQ1CbR4S7aDVNrP004HHqp2WBWBYIU 5gOPCuiBhvmZH3Guqo7j+ODQMAq2NAltjrjwR4zXevMDLiV18kBtwvA+iNV4EYwjTyrq urDAWFn0H5uEzzi5hrDJ6vM9g+pS2YH87f+ydwXk1gCJMLf3C9z4OMxv/TpAFGZINKbj cizQ== X-Forwarded-Encrypted: i=1; AJvYcCW88ELZ0Bpriponw4QBru1V1eVoRJ/8smL5+/l1tnFOkWYmn3hFQJfYhfXBn24t7uAWY5RaaY+Jvw==@kvack.org X-Gm-Message-State: AOJu0YwQKj9fmqBwpnwYTLjOQQ918WWBfnXg3415IL8BjfaoS6UfEcAF eIS+tGMHh6IgUsG+57OCE729eFs+WNqzJWUsCngcQceFjYvgQSmr3tTVR+sfeWkKllAFgH6SRC9 aZnUdIwmtVLzMbI9rB+7cBNrkc0vrQ2AW+KDY X-Gm-Gg: ASbGncuYefkfVft1CPHWW6Gs5RzkcQmbGoZzjdOZYpwHV1vrU1sgzyVU26WlqC2H0Kg nQkxzRv9UmtEo+RRFJ+IhPQ+22XjPtCryPZHdBkpl+utlTcP7k543do1qRFjjaB1E X-Google-Smtp-Source: AGHT+IEDudBnir5+jttzQm+7tNnzRHUlcioRTO8j0Dis2V+coMoC8sfWSozH23fEnrYfZy4bwgZvjEwIXStM7LatHiM= X-Received: by 2002:a17:903:4403:b0:215:9d29:1aba with SMTP id d9443c01a7336-21674cbdb12mr2775015ad.1.1733852054062; Tue, 10 Dec 2024 09:34:14 -0800 (PST) MIME-Version: 1.0 References: <20241210024119.2488608-1-kaleshsingh@google.com> <20241210024119.2488608-18-kaleshsingh@google.com> In-Reply-To: From: Kalesh Singh Date: Tue, 10 Dec 2024 09:34:01 -0800 Message-ID: Subject: Re: [PATCH mm-unstable 17/17] mm: Respect mmap hint before THP alignment if allocation is possible To: Yang Shi 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: 7DBBD8001B X-Rspam-User: X-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MvsV43HgnuSBHbL514UN/ml1dxCq4L0UCTdoBza64Ck24dyPvA/2KUm/QP8RkKBgjHhKb9unukzv4zZV0//9Bie7jDDfYuAjXCwGP3jn6VTLrJFA5hzzDLUEEBtC8Ciyna+jBS1E7Sk9sT+ukSqoVgWli7MEOjO9nm8+08j/ZcQ5PrVv0A5qSnBc7n3yb3yecia/6v1cfvHBvWqmDOIutc7QufI8ogzisYZBXzOT+MEdWm3Kg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.287941, 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 Mon, Dec 9, 2024 at 7:37=E2=80=AFPM Yang Shi wrote= : > > On Mon, Dec 9, 2024 at 6:45=E2=80=AFPM Kalesh Singh wrote: > > > > Commit 249608ee4713 ("mm: respect mmap hint address when aligning for T= HP") > > 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 > > --- > > 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(str= uct 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= 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. Thanks, Kalesh > > > if (!IS_ENABLED(CONFIG_64BIT) || in_compat_syscall()) > > return 0; > > > > @@ -1117,13 +1125,6 @@ static unsigned long __thp_get_unmapped_area(str= uct file *filp, > > if (IS_ERR_VALUE(ret)) > > return 0; > > > > - /* > > - * Do not try to align to THP boundary if allocation at the add= ress > > - * 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 lon= g 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 align= ed. */ > > addr =3D thp_get_unmapped_area_vmflags(file, addr, len, > > -- > > 2.47.0.338.g60cca15819-goog > > > >