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 60910C83F17 for ; Tue, 15 Jul 2025 20:04:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C73C96B0096; Tue, 15 Jul 2025 16:04:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C4B486B0099; Tue, 15 Jul 2025 16:04:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B61846B009A; Tue, 15 Jul 2025 16:04:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id A25E76B0096 for ; Tue, 15 Jul 2025 16:04:01 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 56F80C01A8 for ; Tue, 15 Jul 2025 20:04:01 +0000 (UTC) X-FDA: 83667575082.20.15E294A Received: from mail-yb1-f172.google.com (mail-yb1-f172.google.com [209.85.219.172]) by imf22.hostedemail.com (Postfix) with ESMTP id 71877C0016 for ; Tue, 15 Jul 2025 20:03:59 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=So2+v+54; spf=pass (imf22.hostedemail.com: domain of hughd@google.com designates 209.85.219.172 as permitted sender) smtp.mailfrom=hughd@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=1752609839; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=gLzCTDimsLXvC+jdo33w/q/KLfPuAvI4MactKfhPqLo=; b=sw9ZDozRSGP3NH2sY28rSG75l5ZndOX3uF71JoHmKchW9shPBMsrywJPDdl/T2Ab5KLnwc Z1SzOxnKdJJ0NSt47900UKDwjgJRo4LqB+zhpmmyg7ErQWvG/6JEzCuwQ6PY9K/mjSOtMG jKHgBDr5y7VJyfq+3B8w+rExNCdMK38= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=So2+v+54; spf=pass (imf22.hostedemail.com: domain of hughd@google.com designates 209.85.219.172 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1752609839; a=rsa-sha256; cv=none; b=EqOaM7fJgECVRT5/5D5Vgqmba5Q/SaMusFWExU0Pjz3AUnMpnO1fkwP5IdRpXECiF1GdGx /eue7rZBQz1l1Qk/KDkby/CQY4e7o42qrW2K4/z/vze7v6uEfOSuhHonUWEJxOKpGk5yRq 5I1zC7ZPbPQhDnGibapDjh20gWIRH+c= Received: by mail-yb1-f172.google.com with SMTP id 3f1490d57ef6-e8bbfef1fffso420140276.1 for ; Tue, 15 Jul 2025 13:03:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752609838; x=1753214638; darn=kvack.org; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=gLzCTDimsLXvC+jdo33w/q/KLfPuAvI4MactKfhPqLo=; b=So2+v+54mamTze64KgKxWBeDERW/zvAGMvFEq0rWDgNmWKpnMqwAkhj0mASjwLtVuU dYPsphDAwIuNZ5noZNjKGOTBL8rki7lnNw4cSKsBmSQGJuvAIn7UzWJ7Jyh39iBp6QNj QBf6hQw/tiMOGMQKltD4w8mqkMMORHCcJT4CVQ9EzA99q2B75EceDedSsmscYa0ubdTF LoQdCAoU1xoexzvOdUmy6++lKiMF9i8S5HDXeKbML/fWkqMBUIyvGcHAT6F8LS6E53Cx woHqNlEy1OP1s676UywNqbpf3Jf4kU63tVWDTRn1ajyw2gHK/hr6uqZL9YAhyQZ4M2WN 4vTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752609838; x=1753214638; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=gLzCTDimsLXvC+jdo33w/q/KLfPuAvI4MactKfhPqLo=; b=Z1zl7+leoUbtJ+LrjklL/uYYbM5/RKSgvY3kSTrcgUyvuaDHkDz3SwE1UqW/4zok3V 0IJp4SsVh1pulgz7YaueGgPEgq50pkZdzqCqAMDvWpoaFW1GN1g4uxgd7w4yKaimYTS9 REGqyExlu7yqmaEoEQrVcrz9GNJ53x4uXLLirT+QrKzfVfdSPL6MBl+AUgUTkZE+nCyh mCpAybd4XScwyb3iSH8Y4oSAlZj7nAxJ8AxIWeo5ITO2izV3edHL3ugRmXfutMRdidEm sZ4rVjltEBKgRDCqkjXjRB9iYUT5ENJ6oYVig5nEqjjTWV3Eek6bnGzrcGwwTJ44QbC2 WfbQ== X-Forwarded-Encrypted: i=1; AJvYcCWooLR9/oZ8MTPQ18xh3YLnzitNdbuC4aH8X1KDQclPKQPvkJIAKUroQe02AgZpYqHEkJDYor6pgQ==@kvack.org X-Gm-Message-State: AOJu0Yz9ydqmQfmyLCyPsdgh1Zjx+GgN5RRdmgGOYpHrnTIW6MWZIR6B 9DuGUHvIeX0l9NhdbSCbG28pURr1JGhG+Y9lEJEsYfmc84pI/7jRyVf4SqmD9me+3A== X-Gm-Gg: ASbGncv9hTMVntHQkanTfyclTJOdk0r6eBD6GbzKCOw4bHdod/avNA7zL77/lGGVECf awUxe3gOu/aCte3UgTSlhqbvLiS+TWCwlPX6d0/lHB8HHgT+jjCSt9L52k0eA1BCEhy+dYRGTY2 7MV+8URIJssTXe6i+50yMyPBeh49Y3JuyjUQwBS6tD/Bu6q13KUYwSPiOkXLXtRydaJbCRdWgSH U5gGyKpFYF4hrEzIoxgUhZRBTCyk4nguabk6dSwdmcnu2ZJiPKHw2XsunxqLbnDrA8H2GUi62f3 +NZ7KjyXEjHxZ1mBthYdK6tlfnldE2XdeqIUSdoSw/wSIKSC3dXTY9f397aB7+OdLnHsei6oGMk Uor9g1kszAx8NGs1lVjJUfEUbIL+nNQkA0T1BOU9GXnfFHLD6ToI34w4el5Q8Y9mAYOSmKVpk5/ 1AP4GiO6c= X-Google-Smtp-Source: AGHT+IE8e8oTp/srzMadQ4RpA3XUHOZCYJ3r0yBdYsSop60esVd23h5obNFSbNqhcNyVsOhQHAseDA== X-Received: by 2002:a05:6902:220d:b0:e8b:c02e:385b with SMTP id 3f1490d57ef6-e8bc2530fccmr240593276.46.1752609838129; Tue, 15 Jul 2025 13:03:58 -0700 (PDT) Received: from darker.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e8b7afcd1d2sm3729461276.45.2025.07.15.13.03.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jul 2025 13:03:57 -0700 (PDT) Date: Tue, 15 Jul 2025 13:03:40 -0700 (PDT) From: Hugh Dickins To: Lorenzo Stoakes , Andrew Morton cc: Baolin Wang , Matthew Wilcox , hughd@google.com, david@redhat.com, ziy@nvidia.com, Liam.Howlett@oracle.com, npache@redhat.com, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, vbabka@suse.cz, rppt@kernel.org, surenb@google.com, mhocko@suse.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] mm: fault in complete folios instead of individual pages for tmpfs In-Reply-To: Message-ID: <3bf50873-4d1b-a7c7-112e-3a17ac16077f@google.com> References: <440940e78aeb7430c5cc8b6d2088ae98265b9809.1751599072.git.baolin.wang@linux.alibaba.com> <20250704151858.73d35a24b4c2f53bdb0c1b85@linux-foundation.org> <4c055849-d7dd-4b9f-9666-fcb0bccf8681@linux.alibaba.com> <007c4a94-c94a-418e-9907-7510422f8ca4@lucifer.local> <23f1c3ab-16ca-41db-b008-22448d9e08f2@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Stat-Signature: u9z74wndrncquj67md58ce1ushsjhcfe X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 71877C0016 X-Rspam-User: X-HE-Tag: 1752609839-188212 X-HE-Meta: U2FsdGVkX18vQgaCjEK+XAFlfXw5FiBc7lFcGTyEKgCnRhdXrSROS00A8+nLukULuVq0OZJcLYw/2xdubvfL+QwStHY3I8MtKQZCtqbL0ROjo+L0FjY5lMb7XmeSOm9tU1gVOlpZc60I0qZjlqzaMUvp5yIwmtZfAA5Sku3gxcjtIKf4PQEmfr0yj2WLzTMUkiJdsDO377zbaGYkYTP7vAYWGFDYuVVuBOIqWOPodsWlzt8d1fdLFP2MYcfp6BQ1SbJlYzTuPh9NbIJw8pqz4mMc4WxaRw86ibF1VPn3wb5Y9jB1kwcS7iBJr+JxtMxD0WN+pxaqrlpzr0g0Nhk5iWARi5u94fpyfaTJaQuUfBGRABe3Kz1Xl2OdjvfpFaSVVVxCo0XYkcTyxnq93yIubURwFshnC2wmTIi/WBvEUt3g9tpPQAXP2Fb6yu4qEG7PvXSQ0KC+Lie3BWXkbbs+mm+JEHGUyWpFb1j90y5bkc8pJ8UkWHDhpVCr16SL62ymoVnsaQBWfrZ0inTd480gtK6uzqXTHHpFwphsIQKz4+JNIPo2y80Bw35+0t0qUweVD+vWiIqLwOg1FuaBnRhytbzDwM5z9JeUdXqC6mwOW8N3u3IKQYu4EZFjbVhpZaqgfbOXyoCL3kQcT4o3DP0PRxoz5HYYIjHhqvPSvITCpb/2gtN4MrpDru7saIf3PrbNiQSu/5t1bu0w7Kyp7C15UJWpspYAH3o6i+Br3kprjRvi3DCXgy9rN5ZZAmH3SOTLRkmOF8veP0oTjD1RbJt/nJaEiuuHfGFmgBq56W28NIOdRwihhGt2oLSZ315xioYen0WnznvGZSJtkLSRHIwVahh6Z+lZLq9VAl2S6P559QkuYevgKhEQYM2NOhBGrUp8UkYNdgLLekpDEXGE74mbh/HXWmryZh8OPGKcXkJoGiVLgCCD612GkFGe8r5EP4+/wSUyViz469FqtcsDZdh KI7d3Lg6 zWSLkPyu9TW8xJG34tb5lTYks3sjaEw9ByAI3syOVQyIWFFw1fs3tbhnhzdPD8BXb3PwAMS3ylBiDJJfuAqkhu4n2r6RX1PA5Ef2NLOH9AYujOkD5tjLHuInKm6cn4Q9G6cGCX6vg/MNZGt4N3EQsbsPj1tEz5kc3JUcGEl57txLV+015/M/XcpXUsMyVcRjqHh6yAf7RHwo3l68G6WiWM3E9cgI5S1emgKi0xm2/9tTEYwjU5hDEtU0uIhKZIBTuGo0hEM7mGa6N/9BWqZCXjqhjcFK3qVfv7JosOYfvjMWCbs6jUEdnBGqOVFWuZUvgaUC8jve/pL32uNFl1vKmGGCo/aerid7TPSORBwz/+SA/9mutkq19Rn6sIQc72OSXN1vc X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, 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, 9 Jul 2025, Lorenzo Stoakes wrote: > On Tue, Jul 08, 2025 at 03:53:56PM +0800, Baolin Wang wrote: > > On 2025/7/7 21:33, Lorenzo Stoakes wrote: > > > On Sun, Jul 06, 2025 at 10:02:35AM +0800, Baolin Wang wrote: > > > > On 2025/7/5 06:18, Andrew Morton wrote: > > > > > On Fri, 4 Jul 2025 11:19:26 +0800 Baolin Wang wrote: > > > > > > > > > > > After commit acd7ccb284b8 ("mm: shmem: add large folio support for tmpfs"), > > > > > > tmpfs can also support large folio allocation (not just PMD-sized large > > > > > > folios). > > > > > > > > > > > > However, when accessing tmpfs via mmap(), although tmpfs supports large folios, > > > > > > we still establish mappings at the base page granularity, which is unreasonable. > > > > > > > > > > > > We can map multiple consecutive pages of a tmpfs folios at once according to > > > > > > the size of the large folio. On one hand, this can reduce the overhead of page > > > > > > faults; on the other hand, it can leverage hardware architecture optimizations > > > > > > to reduce TLB misses, such as contiguous PTEs on the ARM architecture. > > > > > > > > > > > > Moreover, tmpfs mount will use the 'huge=' option to control large folio > > > > > > allocation explicitly. So it can be understood that the process's RSS statistics > > > > > > might increase, and I think this will not cause any obvious effects for users. > > > > > > > > > > > > Performance test: > > > > > > I created a 1G tmpfs file, populated with 64K large folios, and write-accessed it > > > > > > sequentially via mmap(). I observed a significant performance improvement: > > > > > > > > > > That doesn't sound like a crazy thing to do. > > > > > > > > > > > Before the patch: > > > > > > real 0m0.158s > > > > > > user 0m0.008s > > > > > > sys 0m0.150s > > > > > > > > > > > > After the patch: > > > > > > real 0m0.021s > > > > > > user 0m0.004s > > > > > > sys 0m0.017s > > > > > > > > > > And look at that. > > > > > > > > > > > diff --git a/mm/memory.c b/mm/memory.c > > > > > > index 0f9b32a20e5b..9944380e947d 100644 > > > > > > --- a/mm/memory.c > > > > > > +++ b/mm/memory.c > > > > > > @@ -5383,10 +5383,10 @@ vm_fault_t finish_fault(struct vm_fault *vmf) > > > > > > /* > > > > > > * Using per-page fault to maintain the uffd semantics, and same > > > > > > - * approach also applies to non-anonymous-shmem faults to avoid > > > > > > + * approach also applies to non shmem/tmpfs faults to avoid > > > > > > * inflating the RSS of the process. > > > > > > */ > > > > > > - if (!vma_is_anon_shmem(vma) || unlikely(userfaultfd_armed(vma)) || > > > > > > + if (!vma_is_shmem(vma) || unlikely(userfaultfd_armed(vma)) || > > > > > > unlikely(needs_fallback)) { > > > > > > nr_pages = 1; > > > > > > } else if (nr_pages > 1) { > > > > > > > > > > and that's it? > > > > > > > > > > I'm itching to get this into -stable, really. What LTS user wouldn't > > > > > want this? > > > > > > > > This is an improvement rather than a bugfix, so I don't think it needs to go > > > > into LTS. > > > > > > > > Could it be viewed as correcting an oversight in > > > > > acd7ccb284b8? > > > > > > > > Yes, I should have added this optimization in the series of the commit > > > > acd7ccb284b8. But obviously, I missed this :(. > > > > > > Buuut if this was an oversight for that patch that causes an unnecessary > > > perf degradation, surely this should have fixes tag + cc stable no? > > > > IMO, this commit acd7ccb284b8 won't cause perf degradation, instead it is > > used to introduce a new feature, while the current patch is a further > > reasonable optimization. As I mentioned, this is an improvement, not a > > bugfix or a patch to address performance regression. > > 4Well :) you say yourself it was an oversight, and it very clearly has a perf > _impact_, which if you compare backwards to acd7ccb284b8 is a degradation, but I > get your point. > > However, since you say 'oversight' this seems to me that you really meant to > have included it but hadn't noticed, and additionally, since it just seems to be > an unequivical good - let's maybe flip this round - why NOT backport it to > stable? I strongly agree with Baolin: this patch is good, thank you, but it is a performance improvement, a new feature, not a candidate for the stable tree. I'm surprised anyone thinks otherwise: Andrew, please delete that stable tag before advancing the patch from mm-unstable to mm-stable. And the Fixee went into 6.14, so it couldn't go to 6.12 LTS anyway. An unequivocal good? I'm not so sure. I expect it ought to be limited, by fault_around_bytes (or suchlike). If I understand all the mTHP versus large folio versus PMD-huge handling correctly (and of course I do not, I'm still weeks if not months away from understanding most of it), the old vma_is_anon_shmem() case would be limited by the shmem mTHP tunables, and one can reasonably argue that they would already take fault_around_bytes-like considerations into account; but the newly added file-written cases are governed by huge= mount options intended for PMD-size, but (currently) permitting all lesser orders. I don't think that mounting a tmpfs huge=always implies that mapping 256 PTEs for one fault is necessarily a good strategy. But looking in the opposite direction, why is there now a vma_is_shmem() check there in finish_fault() at all? If major filesystems are using large folios, why aren't they also allowed to benefit from mapping multiple PTEs at once (in this shared-writable case which the existing fault-around does not cover - I presume to avoid write amplification, but that's not an issue when the folio is large already). It's fine to advance cautiously, keeping this to shmem in coming release; but I think it should be extended soon (without any backport to stable), and consideration given to limiting it. Hugh