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 2D280C83030 for ; Sun, 6 Jul 2025 02:02:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B150B6B8076; Sat, 5 Jul 2025 22:02:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AEC8D6B8074; Sat, 5 Jul 2025 22:02:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A025F6B8076; Sat, 5 Jul 2025 22:02:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 89F556B8074 for ; Sat, 5 Jul 2025 22:02:45 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 35B7410CFC2 for ; Sun, 6 Jul 2025 02:02:45 +0000 (UTC) X-FDA: 83632191090.16.9F66CAB Received: from out30-124.freemail.mail.aliyun.com (out30-124.freemail.mail.aliyun.com [115.124.30.124]) by imf15.hostedemail.com (Postfix) with ESMTP id 26136A000E for ; Sun, 6 Jul 2025 02:02:41 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=hPoNrRwl; spf=pass (imf15.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.124 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=1751767363; 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=vKqkCgAf7cYzIMgHnnwt59iT3vK6UK8KUiIkhUoH3to=; b=xBgJmdJkSBYW6LGbzUAeanIw09fGSIp0k3MeoohSkug9+qu/ZjYLzu5gEL3YqjqASvmJY2 fzNgDzmgKqHtqX+2beKXUs3bdll56HzP9mOyr37NBc2M0IHhprgPv062+8AbjK3MHmOOwd m5K1lCgOM+Zumtip8s3nJXqigvX7c/0= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=hPoNrRwl; spf=pass (imf15.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.124 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=1751767363; a=rsa-sha256; cv=none; b=Xa62p6Fh+5VpXs39wlf3tfMzzWspxdV3dIhBGEuz1rUhE8Ty7+CUaDT1ceRwkyc10f1tqA C1eJd+Lw7XbRh6Z3T9W9wCwHmoiTFvb3D3u+p75gTr+ZOsHUHK/VUAJVLrrp1fFwOutqML 6IbWItEa+cxVdv5RE+u2/Eu0eEgEhiA= DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1751767359; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=vKqkCgAf7cYzIMgHnnwt59iT3vK6UK8KUiIkhUoH3to=; b=hPoNrRwlGXYIWkTpsFImUk0cNTovAMPfGrIhnoy8DVXTZujXLjQuF9ekb4wc19hOQDVDpvrWhJsOkx/XUBQ4eDOOCgAW3dITiDgMB4sPwXen8TgrZeCK6Rtm8JmhvSy7mAWbFyBtVIhhnVcKj7ie4WnY4d3q8eDl3w+MLYyI2RU= Received: from 30.134.69.216(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0Whi6eBO_1751767356 cluster:ay36) by smtp.aliyun-inc.com; Sun, 06 Jul 2025 10:02:37 +0800 Message-ID: <4c055849-d7dd-4b9f-9666-fcb0bccf8681@linux.alibaba.com> Date: Sun, 6 Jul 2025 10:02:35 +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: Andrew Morton Cc: hughd@google.com, david@redhat.com, ziy@nvidia.com, lorenzo.stoakes@oracle.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> From: Baolin Wang In-Reply-To: <20250704151858.73d35a24b4c2f53bdb0c1b85@linux-foundation.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Stat-Signature: pdazgg91pozki5ythpx3djq85arc5q35 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 26136A000E X-HE-Tag: 1751767361-280913 X-HE-Meta: U2FsdGVkX1/QXjk9cnwHwqwpXQy624nidWrJb4RnGvGV4P3hdfVHqYN5kfnAUFqBIR3R3nTsUGsKcaGb03bI2qjfFwDLfKITbdfB6sJgAD8c943zK5Oj9eLEFG2y37pkEOYY7CjeqVF3PDltiCmM0gklxy9vD1HmW98RJMJXwpWu19ggEmDB7J5sQSOU8+0qiYp2A5VE9D4eitXZ4cqKxbKPUEOcmbCe4k3phDtV02PxdN2OPJRxeqOeQtXKDfNaDQdB1CwvgJwMf1CdfugSTTIsXZhQvIpsFwZWiyyYeamKkrt7veSCyXq8TEeR9JnLH+2jZOnKx0NlZn+KMtFw+tGh9DbHnjZtW2oU7b2fEXqIm9gJGIRqULq0PO33XgGp3CHps1mQMGqrJvpX0wluzfUV6UVyBpEAqAJD+XUgPg662qdgTX2VwibRJb/vEmRRzhqbLphvr5mEux8T68b/2WXc7gyb8pELAMH0B4DnbaHoKsG9Xunfk8uZcg9tFzhd1oafSfWxkI4d380/ggD/iX02EaS+aVIbtTEmHzd+r+cBY8CWkQhAOcKceGvoTfXvUEk72G/OinroCO0ggvDYYK1xuhdxc8T4XW9YMKfFazbNCxcES7GcjIFQOF3K5bf50Jr979SDt45Rt+rltXmJ9QjnC6vpxJD4NwRPwN5wz75MJKwwRb221z8AN6WgeaU3SOJ+2BD6PLplkwx+Z5W5vyknxu9W1faBlN4newcWKHpmI5lodx+mzMQCMHxnFdDndm8QubKT2DBm8x0oAEsWzHovPAi4ULKNJQeAd/jbgtum2iioU302Ino5Y+decoP5m/b0z4M33vG88gfzihbN4R6OhL9JX+3X/RipHR9nyE6GmJQZ4oTBYrzSn+duZBg9jh6O5Crss6HTKQ/AChLSdD7GtQIRSZG0OGKMiTrroQw2YN75lVuZsKWID+FdyC2qrp1q5R+HDYZeOBZuObO I6VL2hB6 Kq5WOo2DABrm9gksSJoqB/58uw9vitrOa9lENe2G0J06LlMKaGkMuymjEhkJE5krx/C6IBvDNDhSD9KRJeBDu9TOzNRAnYIf35nZqGzFUGUpqLHoUJ5gnzw/dM18Hw0sKoKt0iss7CimPRzJZ+3mfn+qjCdFpZeTInLrBoF9a+UG3V6cvMcOoZPpSVHy0vq2wULSFn1gE6qBp6saOs+V5NtvF9Ew8fYOPAl21jh+ZZBHI1jq/Q6nOXXVrd8Dag1gsSDwroE/+E4ffK+HsCQ3OK9HfXwcKihjflnEnyj9Au2VpB8YINhOUJITWdg== 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/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 :(.