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 CAA8BC8303C for ; Tue, 8 Jul 2025 07:54:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1A4796B0257; Tue, 8 Jul 2025 03:54:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0E0B96B0251; Tue, 8 Jul 2025 03:54:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F114F6B0365; Tue, 8 Jul 2025 03:54:05 -0400 (EDT) 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 DF5176B024E for ; Tue, 8 Jul 2025 03:54:05 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 7FE7EC0349 for ; Tue, 8 Jul 2025 07:54:05 +0000 (UTC) X-FDA: 83640334050.22.3767BDC Received: from out30-110.freemail.mail.aliyun.com (out30-110.freemail.mail.aliyun.com [115.124.30.110]) by imf08.hostedemail.com (Postfix) with ESMTP id 6B005160009 for ; Tue, 8 Jul 2025 07:54:02 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=mNy2f5P5; spf=pass (imf08.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.110 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1751961243; 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=DNfi3XvvaPQFWN6RIuvca87fevIPOyq+CtUUka0qa+g=; b=Lnps+vT6WZZ7nNoJO+xJj/p2lGOKxxcz0A58LMBvpI/5vaGrEySZqrBWcPHZBwyWC9rFP5 n2J0RR0UGNNFJzCzz/ivRtmbly/gLn6k0DvjzMtqjYDeR4ZGEjgIHEpyOkK+bIXb+C1y6m uqgd43vSFKCEVvTQ3+Wjb+qgNSeqeAo= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=mNy2f5P5; spf=pass (imf08.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.110 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1751961243; a=rsa-sha256; cv=none; b=yYopc64Ye2cVbRKzdCBS1KySB7VIeLLxHs9m+AmAX+M89Lkn4WayoMipyDmMzLPOA11dTe TPW3YTLR6qIZLh1zr3oc+22zZtqR27gOn8esDpCnyM3CnFLK/XGdbSMpGi/m86yMouxxAl jJKSSYYqRrzEgsxw/bDShlKmouGeT8I= DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1751961239; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=DNfi3XvvaPQFWN6RIuvca87fevIPOyq+CtUUka0qa+g=; b=mNy2f5P5NEUV540Ng+TQkuzQdtWSBcfol28wgWsfSADKf6T3629medG5kJhQIS5da+aBv3UQs6LrC7zFMz1bCPn+qSkhusiPcAju07BK+apr3ftVCHxwR+XJEtcB5hYw5WXOv3ZVLzJU+OB/Pf8Dw0CkzNGI3Z8oKG1D4WPJX60= Received: from 30.74.144.119(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WiLpkEF_1751961236 cluster:ay36) by smtp.aliyun-inc.com; Tue, 08 Jul 2025 15:53:57 +0800 Message-ID: <23f1c3ab-16ca-41db-b008-22448d9e08f2@linux.alibaba.com> Date: Tue, 8 Jul 2025 15:53:56 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] mm: fault in complete folios instead of individual pages for tmpfs To: Lorenzo Stoakes Cc: Andrew Morton , 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 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> From: Baolin Wang In-Reply-To: <007c4a94-c94a-418e-9907-7510422f8ca4@lucifer.local> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Stat-Signature: 5xyqqu797trg63m3ba1auxg7kpix5p4i X-Rspamd-Queue-Id: 6B005160009 X-Rspamd-Server: rspam11 X-Rspam-User: X-HE-Tag: 1751961242-153933 X-HE-Meta: U2FsdGVkX1+ZrUvR2IGFPDt6ta6/OLNlY9hXZvasHGY/4e3KMhcjw9cEARpskNd5XYmzcoHy1bDF6BsU/kWxoaUQKR5isYyGIh8hEjShM//Jb9PC1uPYvF47OrJ9Z+J953DtOJhV6eNlZNNFQ9Sl6QcHQgBDwB0CA5EFQJf5DItlLzdG22ik2hhKdS9t4sEqkIbalRRf4u9Yu/zNi29+lwOEndIobh/+6fF+AEJtFGngk1bDwfqGUcqtFDtx8UafuzgG6rY/2bea7aDhbaG5dNi8Lp8jwaCVYzx0uP7wMpC4R0WIzbGhL6ZwRlpOYB1dzq7HZiJzUb/9YucYLvSoDi/peyBqV/LMdFDC/aI3sLdxcoP2CPyp+hoOd3fPUzPIH3lKj569+6bQhStSIPSqdhfg1RspPpTui1RCmhkVdiwrISmJ9W8jN/YdQdSRLOwCPl72qcoEb/IMOBiSUhOxdBzS2z+b3Xg2WMPKUzkzcUPNY8TFbJLcskbku246C0IghQJw6L0a6SKh+TS3gXxw0LeEvM347lE8JzhIliHjkoz2q1OMos/g8pu6Mmwh4bo+5XEB9fg7/vFHDqyF8L5l2frlc7enuRnwXLhtzZONkx59tf41EMoftFzWXfaMJC21bHoaBXAi8Uqjw8Ui+IEZyIjrarOwrlENYb+So784AK19eMDOodER1cnhJWcIEcuHrKSsXjUmHkEg+RsUuhqg69ROoTpgUnMsd615V+KOm05UJMSDZWxSPTyEKMbLSdvwaFu5CopnsOmMQK6EjBFBIKV2EwoL8x0SkygKqyjRvJtktvFY6Kf5fKxcz3oG2o7I8SC5ublYcEdRNcEX63Uk6XXH3ZJz5bOym79XO6PdMDmZsI+6cpG240AYu6TPsXyD8SUQgVaX3yhMuwTA+lPtVOx6koHKBtsyc/aMr39BlGpN461gN9rfWKwwd3jqL9CMZOFQ2FvZ4GYw2KYZnJA 4yGnZbWV YgPvwtQMLqrsxZcPyanfpUG0tNwpVKwJ31tHHagehLICVY19LamG3Op05ewR/72AIG0VgVuKv7U4leb/3lCfcXbKVeHwqj0XIASbzsgxQLeILLTNlNgpzPcuuYh4ogbZBPdAyYJsmrIZPcT/WGN9HQDPyQ//uyMwOrIdGliP3t68bCjZatPvH3unn1JR/FDF3blh8WTXwrx6HsW/ZyALHbxdUFZezPYFWuwZSJwG8yyQyA04GdpkGgJlYGU1/oau1JKkopKk7JNw7iE+ycGI6QV092PYj/ktBfe1QNVIzPKvK+1eLaSixQUCEUQ== 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 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.