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 06F60E6894D for ; Thu, 31 Oct 2024 03:43:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 183606B0083; Wed, 30 Oct 2024 23:43:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 133ED6B0095; Wed, 30 Oct 2024 23:43:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 022AC6B0098; Wed, 30 Oct 2024 23:43:17 -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 D88A36B0095 for ; Wed, 30 Oct 2024 23:43:17 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 53014A126D for ; Thu, 31 Oct 2024 03:43:17 +0000 (UTC) X-FDA: 82732501236.22.87916F8 Received: from out30-110.freemail.mail.aliyun.com (out30-110.freemail.mail.aliyun.com [115.124.30.110]) by imf18.hostedemail.com (Postfix) with ESMTP id 2650A1C000A for ; Thu, 31 Oct 2024 03:43:00 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=C7ZoZKiK; spf=pass (imf18.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=1730346018; 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=hY/BROjL9uyLBnQrHr87O2iu41QP3pQ9lVSaFNpvhuM=; b=osT6dPg3Lbok9lmzGyIP1S5xmEr/Sg74MYkGqyaRGMM4Dq01WWViWDby1JwIxnXDk0eEa5 /knUKJuy3QuG/isA7wMj5Zzz0ELaMS1Dv1ElE+AHa5MM3H41II2D/qHfnulvy47906UvUG Wz5ND93btmzXwuS2pkmOhYk9ooSUXWs= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=C7ZoZKiK; spf=pass (imf18.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=1730346018; a=rsa-sha256; cv=none; b=tttXYeJXQzHqXN2MzjDMuNObsGv7Pb9ZABiP5xP2NuCmuJONFnNkimB4LVqaK9+wu4jNOP NcvaDvR2TrTdfcFSYwUf5wxUbg7oIGeGjhkbgPIwWktsC0ZXQtrbp52JCt3q47EgNJmpL1 OUj3ACH4osaZFnHNrmPhIaXSbOFZYZY= DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1730346188; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=hY/BROjL9uyLBnQrHr87O2iu41QP3pQ9lVSaFNpvhuM=; b=C7ZoZKiK5ViMsK5xgRRlhH3Z6yf+ALBUC6KM9kr4HTDbO3MzKODfeZmnYK3g7m+GD/izZGOqgV8FJ2u5KtzUprZsWBxA5XtrutZ+iSI8HPbvV4oreKxtvZi3uq9fE1NsfqITNKtSrbsgalk2gODc4Te675riv0/fHZ6MHRS48QI= Received: from 30.74.144.119(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WIGvBCH_1730346185 cluster:ay36) by smtp.aliyun-inc.com; Thu, 31 Oct 2024 11:43:06 +0800 Message-ID: <0b7671fd-3fea-4086-8a85-fe063a62fa80@linux.alibaba.com> Date: Thu, 31 Oct 2024 11:43:04 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH v3 0/4] Support large folios for tmpfs To: David Hildenbrand , Daniel Gomez , Daniel Gomez , "Kirill A. Shutemov" Cc: Matthew Wilcox , akpm@linux-foundation.org, hughd@google.com, wangkefeng.wang@huawei.com, 21cnbao@gmail.com, ryan.roberts@arm.com, ioworker0@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Kirill A . Shutemov" References: <6dohx7zna7x6hxzo4cwnwarep3a7rohx4qxubds3uujfb7gp3c@2xaubczl2n6d> <8e48cf24-83e1-486e-b89c-41edb7eeff3e@linux.alibaba.com> <486a72c6-5877-4a95-a587-2a32faa8785d@redhat.com> <7eb412d1-f90e-4363-8c7b-072f1124f8a6@linux.alibaba.com> <1b0f9f94-06a6-48ac-a68e-848bce1008e9@redhat.com> <7ca333ba-f9bc-4f78-8f5b-1035ca91c2d5@redhat.com> From: Baolin Wang In-Reply-To: <7ca333ba-f9bc-4f78-8f5b-1035ca91c2d5@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 2650A1C000A X-Stat-Signature: xgm7t8po4sxcudjhuuoiobd17d19894i X-Rspam-User: X-HE-Tag: 1730346180-421731 X-HE-Meta: U2FsdGVkX19JL7arASLW93tC6i0f+ASMMzDqfx5aKJq7z3yw5Fh1pZgHYzr9RIraPoPnL+Is84QW9d6ZMgDW2YKEncsHhDyyL2IWut1udaoSVxaJvd7z+yHtOUAsLHrdSJ71YxNzZr3HJ1rXJ5vtNpB4KQI2lNNqvy7qpqZp+TTqF7tYsGdxqnZ+o+7EfrgF36PeI2/Azavv7lTzafZIIX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: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Sorry for late reply. On 2024/10/28 17:48, David Hildenbrand wrote: > On 25.10.24 22:21, David Hildenbrand wrote: >> Sorry for the late reply! >> >>>>>>> IMHO, as I discussed with Kirill, we still need maintain >>>>>>> compatibility >>>>>>> with the 'huge=' mount option. This means that if 'huge=never' is >>>>>>> set >>>>>>> for tmpfs, huge page allocation will still be prohibited (which can >>>>>>> address Hugh's request?). However, if 'huge=' is not set, we can >>>>>>> allocate large folios based on the write size. >>> >>> So, in order to make tmpfs behave like other filesystems, we need to >>> allocate large folios by default. Not setting 'huge=' is the same as >>> setting it to 'huge=never' as per documentation. But 'huge=' is meant to >>> control THP, not large folios, so it should not have a conflict here, or >>> else, what case are you thinking? >> >> I think we really have to move away from "huge/thp == PMD", that's a >> historical artifact. Everything else will simply be inconsistent and >> confusing in the future -- and I don't see any real need for that. For >> anonymous memory and anon shmem we managed the transition. (there is a >> longer writeup from me about this topic, so I won't go into detail). >> >> >> I think I raised this in the past, but tmpfs/shmem is just like any >> other file system .. except it sometimes really isn't and behaves much >> more like (swappable) anonymous memory. (or mlocked files) >> >> There are many systems out there that run without swap enabled, or with >> extremely minimal swap (IIRC until recently kubernetes was completely >> incompatible with swapping). Swap can even be disabled today for shmem >> using a mount option. >> >> That's a big difference to all other file systems where you are >> guaranteed to have backend storage where you can simply evict under >> memory pressure (might temporarily fail, of course). >> >> I *think* that's the reason why we have the "huge=" parameter that also >> controls the THP allocations during page faults (IOW possible memory >> over-allocation). Maybe also because it was a new feature, and we only >> had a single THP size. >> >> There is, of course also the "fallocate() might not free up memory if >> there is an unexpected reference on the page because splitting it will >> fail" problem, that even exists when not over-allocating memory in the >> first place ... >> >> >> So ...I don't think tmpfs behaves like other file system in some cases. >> And I don't think ignoring these points is a good idea. >> >> Fortunately I don't maintain that code :) >> >> >> If we don't want to go with the shmem_enabled toggles, we should >> probably still extend the documentation to cover "all THP sizes", like >> we did elsewhere. >> >> huge=never: no THPs of any size >> huge=always: THPs of any size (fault/write/etc) >> huge=fadvise: like "always" but only with fadvise/madvise >> huge=within_size: like "fadvise" but respect i_size > > Thinking some more about that over the weekend, this is likely the way > to go, paired with conditionally changing the default to > always/within_size. I suggest a kconfig option for that. I am still worried about adding a new kconfig option, which might complicate the tmpfs controls further. > That should probably do as a first shot; I assume people will want more > control over which size to use, especially during page faults, but that > can likely be added later. After some discussions, I think the first step is to achieve two goals: 1) Try to make tmpfs use large folios like other file systems, that means we should avoid adding more complex control options (per Matthew). 2) Still need maintain compatibility with the 'huge=' mount option (per Kirill), as I also remembered we have customers who use 'huge=within_size' to allocate THPs for better performance. Based on these considerations, my first step is to neither add a new 'huge=' option parameter nor introduce the mTHP interfaces control for tmpfs, but rather to change the default huge allocation behavior for tmpfs. That is to say, when 'huge=' option is not configured, we will allow the huge folios allocation based on the write size. As a result, the behavior of huge pages for tmpfs will change as follows: no 'huge=' set: can allocate any size huge folios based on write size huge=never: no any size huge folios huge=always: only PMD sized THP allocation as before huge=fadvise: like "always" but only with fadvise/madvise huge=within_size: like "fadvise" but respect i_size The next step is to continue discussing whether to add a new Kconfig option or FADV_* in the future. So what do you think?