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 19BF8D5B158 for ; Mon, 28 Oct 2024 21:56:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8D42B8D0006; Mon, 28 Oct 2024 17:56:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 883288D0003; Mon, 28 Oct 2024 17:56:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 74AAE8D0006; Mon, 28 Oct 2024 17:56:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 577968D0003 for ; Mon, 28 Oct 2024 17:56:21 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id C190380542 for ; Mon, 28 Oct 2024 21:56:20 +0000 (UTC) X-FDA: 82724369238.06.24231D9 Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) by imf13.hostedemail.com (Postfix) with ESMTP id 1E0F520006 for ; Mon, 28 Oct 2024 21:55:53 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=kruces-com.20230601.gappssmtp.com header.s=20230601 header.b="2a/tb1/S"; spf=pass (imf13.hostedemail.com: domain of d@kruces.com designates 209.85.218.52 as permitted sender) smtp.mailfrom=d@kruces.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730152524; 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=b3YInCy/u1fqsZj0Shaluhv41U/l3cQiYFh5DB7oUVw=; b=uVpZtfIATO8rSlBG8QJKEmcV42DZ4TG8NK7xOQF0yWHkHEvVS5/nHUQ1pE1LDEA8gJIZ60 6GW2tJzipagO7gmiFZ31p5wkT368+3CWahGx7w++W8mlt2VgmSSsfKz4lUBhsK18KLgj76 jJO2cPuBb8FXjSf6xEGKwiX3Z6rNGsw= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=kruces-com.20230601.gappssmtp.com header.s=20230601 header.b="2a/tb1/S"; spf=pass (imf13.hostedemail.com: domain of d@kruces.com designates 209.85.218.52 as permitted sender) smtp.mailfrom=d@kruces.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730152524; a=rsa-sha256; cv=none; b=MUxtOrcCOjvPidd4I/sCDaEu8agCeJ/8/mfDC7vPhshn9wYoYbJ78yqP3WU9VCp80elitR KU5tcICy+gSiGrAR/krGO8UaRanpX7n/3t/gBxza6yQ6x0J/ZSj+nNF8ubxjUSpP84PJS7 7dAkPWn14bAmW37+eIqiUeapNeq7aGM= Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-a99f629a7aaso762619266b.1 for ; Mon, 28 Oct 2024 14:56:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kruces-com.20230601.gappssmtp.com; s=20230601; t=1730152577; x=1730757377; darn=kvack.org; h=in-reply-to:references:from:to:cc:subject:message-id:date :content-transfer-encoding:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=b3YInCy/u1fqsZj0Shaluhv41U/l3cQiYFh5DB7oUVw=; b=2a/tb1/S2m2z8rweyfLIKL0PInlNTypZnU3iNU1BpB3uzNgwH3SxJYKP8gTa+mVfrD zda9S6asEdWDiE3bmOOVFccBGID7QDnrcVpRNjiH8cBTWOqI6oZZHUT4hANumnKZD1f+ A6mKFhzvLhmnEyhJG38a+SqIJR+HlPiuXG1g+nrZTcV11qGMYxNHffrDni0C5QnJlA0a z2aRfA3nsYIDSPURe2keGQFW+Eyb0vpcpgf0EGCE+o/ZFKfc0mwWKqnr7xAa/6lT38n1 J9Lu+XssISl+1sY0vvJJyE+rsYlo7FIP4z2iZ+UxmzQE0x6Cpl/P/qZDA9E4zC5CSoWO Vjeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730152577; x=1730757377; h=in-reply-to:references:from:to:cc:subject:message-id:date :content-transfer-encoding:mime-version:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=b3YInCy/u1fqsZj0Shaluhv41U/l3cQiYFh5DB7oUVw=; b=Aaz+BVIGv2aVwxhwu0F93UPRhIMlCGv8mSWADMBD5awDieiWgI7bz24oumsgPz4kWh ammLhn3uN2S5UK2q/T51uLbu5dojKI2lcSGJlgmbYri5S2kujWIhUqgZD4FjmkmH3F7o PNIUvwwF5BT4n+WEHgnJhMaaboiXyruV+enCvZq1QLXktHs7LnSt38QzIAanCeUGqlzH +8Dg3rW06eunVuw45GGOARKcJluBfZcj9+Dlrqn2ruQIdI5o5tezfs+zY39iPDtCwy5t R1sJvhY3sR+ofwKHrcgZmBVKkVGU9qf+QXPL92S7BB+HTE8rV8wWb7QPhfUT2A1hy2eb vSDg== X-Forwarded-Encrypted: i=1; AJvYcCWkBmRIBNHSciczCpd2jL2GNAOSuIhRHTcfcSBbn6qSscl0TVoHEwVmDZe/bd56zoJawOEEoKi8Bw==@kvack.org X-Gm-Message-State: AOJu0YwbKiddhS5MUULam1r+kJ1yX2I1uNSyGdZ4K4iBJWIbwI7UHXqq U1IYtESvhIcXjSn+1GhcOWsq8JGfpDwgwecCuof/RP7PG8GeonAxe1YAPgsVKsU= X-Google-Smtp-Source: AGHT+IERPrEOhpPVB7RdZhvQZ/Zjp5f2pTrwA6ldA/PVGUWSwSABELjXqI9J3It3J6qGSNvLvWOPdg== X-Received: by 2002:a17:906:6a14:b0:a99:4e74:52aa with SMTP id a640c23a62f3a-a9e22b3b4acmr109292766b.33.1730152576931; Mon, 28 Oct 2024 14:56:16 -0700 (PDT) Received: from localhost (89-23-255-189.ip4.fiberby.net. [89.23.255.189]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9b1f29a934sm409096466b.118.2024.10.28.14.56.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 28 Oct 2024 14:56:16 -0700 (PDT) Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Mon, 28 Oct 2024 22:56:14 +0100 Message-Id: Subject: Re: [RFC PATCH v3 0/4] Support large folios for tmpfs Cc: "Matthew Wilcox" , , , , <21cnbao@gmail.com>, , , , , "Kirill A . Shutemov" To: "David Hildenbrand" , "Baolin Wang" , "Daniel Gomez" , "Kirill A. Shutemov" From: "Daniel Gomez" X-Mailer: aerc 0.18.2 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> In-Reply-To: X-Rspam-User: X-Stat-Signature: nukhgpjqc1ejckxp8kmru8d4ea6qsyqz X-Rspamd-Queue-Id: 1E0F520006 X-Rspamd-Server: rspam11 X-HE-Tag: 1730152553-162087 X-HE-Meta: U2FsdGVkX1/esaHbxIaM89rNzUefJiewv2o/Svtvj2pqTj8/qW/aRFjwlHO4Edf1kbhdrP4UwGgaFb/IX5b7ScGUON729UnvhaluaSh/lBDJvFTffkSr7LqC4xyxvEznkKVsxejRw35lVuldp1tnF+PL1eU4IXs14AY24P7o0NTE8XrdJOBRzTVaXtf0m3JsfMccf68ETtr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5fFmt9DG16A3L8G0JFbNoEKBPQvVqRRuJmx+Xwm/DN1jNQupXoK3kCxv1hG/+gcUCVqYJqTTOs6eiT2X3BTybIRt1oSUbTvKg+YpM0ENvseFIvJU9JvYliP/w2KgArqb7mYX2oWOrvpHeutO8e72Q== 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 Fri Oct 25, 2024 at 10:21 PM CEST, David Hildenbrand wrote: > Sorry for the late reply! > > >>>>> IMHO, as I discussed with Kirill, we still need maintain compatibil= ity > >>>>> with the 'huge=3D' mount option. This means that if 'huge=3Dnever' = is set > >>>>> for tmpfs, huge page allocation will still be prohibited (which can > >>>>> address Hugh's request?). However, if 'huge=3D' is not set, we can > >>>>> allocate large folios based on the write size. > >=20 > > So, in order to make tmpfs behave like other filesystems, we need to > > allocate large folios by default. Not setting 'huge=3D' is the same as > > setting it to 'huge=3Dnever' as per documentation. But 'huge=3D' is mea= nt to > > control THP, not large folios, so it should not have a conflict here, o= r > > else, what case are you thinking? > > I think we really have to move away from "huge/thp =3D=3D PMD", that's a= =20 > historical artifact. Everything else will simply be inconsistent and=20 > confusing in the future -- and I don't see any real need for that. For=20 > anonymous memory and anon shmem we managed the transition. (there is a=20 > 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=20 > other file system .. except it sometimes really isn't and behaves much=20 > more like (swappable) anonymous memory. (or mlocked files) > > There are many systems out there that run without swap enabled, or with= =20 > extremely minimal swap (IIRC until recently kubernetes was completely=20 > incompatible with swapping). Swap can even be disabled today for shmem=20 > using a mount option. > > That's a big difference to all other file systems where you are=20 > guaranteed to have backend storage where you can simply evict under=20 > memory pressure (might temporarily fail, of course). > > I *think* that's the reason why we have the "huge=3D" parameter that also= =20 > controls the THP allocations during page faults (IOW possible memory=20 > over-allocation). Maybe also because it was a new feature, and we only=20 > had a single THP size. > > There is, of course also the "fallocate() might not free up memory if=20 > there is an unexpected reference on the page because splitting it will=20 > fail" problem, that even exists when not over-allocating memory in the=20 > first place ... > > > So ...I don't think tmpfs behaves like other file system in some cases.= =20 > And I don't think ignoring these points is a good idea. Assuming a system without swap, what's the difference you are concern about between using the current tmpfs allocation method vs large folios implementation? > > Fortunately I don't maintain that code :) > > > If we don't want to go with the shmem_enabled toggles, we should=20 > probably still extend the documentation to cover "all THP sizes", like=20 > we did elsewhere. > > huge=3Dnever: no THPs of any size > huge=3Dalways: THPs of any size (fault/write/etc) > huge=3Dfadvise: like "always" but only with fadvise/madvise > huge=3Dwithin_size: like "fadvise" but respect i_size > > We could think about adding a "nowaste" extension and try make it the=20 > default. > > For example > > "huge=3Dalways:nowaste: THPs of any size as long as we don't over-allocat= e=20 > memory (write)" This is the default behaviour in other fs too. I don't think is necessary to make it explicit. > > The sysfs toggles have their beauty as well and could be useful (I'm=20 > pretty sure they will be useful :) ): > > "huge=3Dalways;sysfs": THPs of any size (fault/write/etc) as configured i= n=20 > sysfs. > > Too many options here to explore, too little time I have to spend on=20 > this. Just to throw out some ideas. > > What I can really suggest is not making this one of the remaining=20 > interfaces where "huge" means "PMD-sized" once other sizes exist. > > >=20 > >>>> > >>>> I consider allocating large folios in shmem/tmpfs on the write path = less > >>>> controversial than allocating them on the page fault path -- especia= lly > >>>> as long as we stay within the size to-be-written. > >>>> > >>>> I think in RHEL THP on shmem/tmpfs are disabled as default (e.g., > >>>> shmem_enabled=3Dnever). Maybe because of some rather undesired > >>>> side-effects (maybe some are historical?): I recall issues with VMs = with > >>>> THP+ memory ballooning, as we cannot reclaim pages of folios if > >>>> splitting fails). I assume most of these problematic use cases don't= use > >>>> tmpfs as an ordinary file system (write()/read()), but mmap() the wh= ole > >>>> thing. > >>>> > >>>> Sadly, I don't find any information about shmem/tmpfs + THP in the R= HEL > >>>> documentation; most documentation is only concerned about anon THP. > >>>> Which makes me conclude that they are not suggested as of now. > >>>> > >>>> I see more issues with allocating them on the page fault path and no= t > >>>> having a way to disable it -- compared to allocating them on the wri= te() > >>>> path. > >>> > >>> I may not understand your issues. IIUC, you can disable allocating hu= ge > >>> pages on the page fault path by using the 'huge=3Dnever' mount option= or > >>> setting shmem_enabled=3Ddeny. No? > >> > >> That's what I am saying: if there is some way to disable it that will > >> keep working, great. > >=20 > > I agree. That aligns with what I recall Hugh requested. However, I > > believe if that is the way to go, we shouldn't limit it to tmpfs. > > Otherwise, why should tmpfs be prevented from allocating large folios i= f > > other filesystems in the system are allowed to allocate them? > > See above. On systems without/little swap you might not want them for=20 > shmem/tmpfs, but would happily use them elsewhere. > > The "write() won't waste memory" case is really interesting, the=20 > "fallocate cannot free the memory" still exists. A shrinker might help. The previous implementation with large folios allocation was wrong and was actually wasting memory by rounding up while trying to find the order. Matthew already pointed it out [1]. So, with that fixed, we should not end up wasting memory. https://lore.kernel.org/all/ZvVQoY8Tn_BNc79T@casper.infradead.org/