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 BA8C4D41C33 for ; Wed, 13 Nov 2024 11:28:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 562C76B00B5; Wed, 13 Nov 2024 06:28:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 512BF6B00BA; Wed, 13 Nov 2024 06:28:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 38E108D0003; Wed, 13 Nov 2024 06:28:01 -0500 (EST) 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 112CE6B00B5 for ; Wed, 13 Nov 2024 06:28:01 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 763B7A0842 for ; Wed, 13 Nov 2024 11:28:00 +0000 (UTC) X-FDA: 82780845336.07.53B1007 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf25.hostedemail.com (Postfix) with ESMTP id 0538FA0003 for ; Wed, 13 Nov 2024 11:27:26 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=A10VmPMm; spf=pass (imf25.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731497084; 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=jKjCQkphQmFo+ScqcVseRncxjnhuRXf+9pZ1ptYICpU=; b=Zt9jA9xWsb7+0P3/CUA+irasAV2yItuFV5SmksxUZR5ToBlxQBOB0r8qqD9K/317CG/rAp PclPqOP4sxLA4KoqXtqST0SNnvlHt6v4pM/NQbWxtzZnGODWpT+9pDbpQ767FDrp2Hr2vf 2bswU/IU1/kVut5rcIzRYsbnzI0GvEw= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=A10VmPMm; spf=pass (imf25.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731497084; a=rsa-sha256; cv=none; b=X5bXs+5YS0Yo9o6cV4iPN0+w+LedMM+vzppnjC1MGj4+rI8Huds87knyUbUYWPvT+APlKl Oa9W3Si2Fln2G8ZgceasOITLihgF93zvD9aCdaCSJR1IFq/d4cMELnWmdIhuEFtakketXD 2Y8VX/S/rZk9/IpWSObGhi+W3L/NSck= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1731497277; h=from:from: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:autocrypt:autocrypt; bh=jKjCQkphQmFo+ScqcVseRncxjnhuRXf+9pZ1ptYICpU=; b=A10VmPMmwiCAI3Vz4ADruc1bZ8TD/tTk0JHAT5vN0Bn4ly3php7AHx0fbNw3KISR0d9aOd fdmTN6w/balbaWteygYeV6VxtdgF4TIX93nlxZoDuZwMkmR2GE92grOQgE4B1VCmrDYHJz 5UuwJbro6hOFwoeAgGOqGml5AnZiWok= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-584-oeAcNSVTNCuTWRCYQ3qJ1w-1; Wed, 13 Nov 2024 06:27:56 -0500 X-MC-Unique: oeAcNSVTNCuTWRCYQ3qJ1w-1 X-Mimecast-MFC-AGG-ID: oeAcNSVTNCuTWRCYQ3qJ1w Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4327bd6bd60so50442225e9.1 for ; Wed, 13 Nov 2024 03:27:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731497275; x=1732102075; h=content-transfer-encoding:in-reply-to:organization:autocrypt :content-language:from:references:cc:to:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=jKjCQkphQmFo+ScqcVseRncxjnhuRXf+9pZ1ptYICpU=; b=GTZ/dtvmZbxc4jWoQwO5KJRGWAsVTxeydRS3LQCeicyyvLHXJRM3GLpV4ECeGYcy40 Tmz8Q7U8F++B8ysWsk1+iFhW6Sws+b+xJ2YRF1nMPBPiMlEXC8kh7iZYq0g+KWtZSCWo p/zuVSUefNkjJETbWyhNcyDXHR1sl7h5DfbRyEdqpmYvPEhGfN2H2hNi6i97kfadupfr hh7Bwpbk17ry0pSz/tYX1s00betbyhLycKPbch3RCo/eS6eBkJDJWSDLQ1Z/Bos5Pqc9 MStfecyuVmx1Q77GuyfEVpDsMxyFdMJ0jlGwG2LjcwjU9w0D9/Hhap+Ach1PPMA5yBRG 72Lw== X-Forwarded-Encrypted: i=1; AJvYcCWnr8sq2IvKQDhj8Um27lBjPZUiEAETPvWgdUZkf5/n7Y9C23/L9MAkESQNXTcmpMAe9PmyXwtbWA==@kvack.org X-Gm-Message-State: AOJu0YxqASR2kK0cv2gPPd64J9KlCpueowP6RIulgFGZBaYe2T7Mlbq1 V07Ku/bktsmwl1vOSdn41+Dp8r5EJQAK6aZeki5mf3WuLGqDEZ9b5kpvmD7kpbU5RrqVJhwiL+M o0Kfsy9cnIn/r79/IKSd/rGb4K4Tt7Aotqf29kJMnuEZpYVFy X-Received: by 2002:a05:600c:35cc:b0:430:5356:ac8e with SMTP id 5b1f17b1804b1-432b74fcb49mr169394735e9.5.1731497274833; Wed, 13 Nov 2024 03:27:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IGlZiH7H1WOOf1drhTdYK7lR0xwkTBxGft1Ue4jpn4askc7OCbMThxEK0JL9VykUTzfvwV7WA== X-Received: by 2002:a05:600c:35cc:b0:430:5356:ac8e with SMTP id 5b1f17b1804b1-432b74fcb49mr169394325e9.5.1731497274371; Wed, 13 Nov 2024 03:27:54 -0800 (PST) Received: from ?IPV6:2003:cb:c708:1500:d584:7ad8:d3f7:5539? (p200300cbc7081500d5847ad8d3f75539.dip0.t-ipconnect.de. [2003:cb:c708:1500:d584:7ad8:d3f7:5539]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432d55520e5sm20682465e9.41.2024.11.13.03.27.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 13 Nov 2024 03:27:53 -0800 (PST) Message-ID: <9e5e9bc1-dfd9-490a-bbcd-044d2971df5f@redhat.com> Date: Wed, 13 Nov 2024 12:27:52 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH v1 00/10] mm: Introduce and use folio_owner_ops To: Matthew Wilcox Cc: Jason Gunthorpe , Fuad Tabba , linux-mm@kvack.org, kvm@vger.kernel.org, nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org, rppt@kernel.org, jglisse@redhat.com, akpm@linux-foundation.org, muchun.song@linux.dev, simona@ffwll.ch, airlied@gmail.com, pbonzini@redhat.com, seanjc@google.com, jhubbard@nvidia.com, ackerleytng@google.com, vannapurve@google.com, mail@maciej.szmigiero.name, kirill.shutemov@linux.intel.com, quic_eberman@quicinc.com, maz@kernel.org, will@kernel.org, qperret@google.com, keirf@google.com, roypat@amazon.co.uk References: <20241108162040.159038-1-tabba@google.com> <20241108170501.GI539304@nvidia.com> <9dc212ac-c4c3-40f2-9feb-a8bcf71a1246@redhat.com> <20241112135348.GA28228@nvidia.com> <430b6a38-facf-4127-b1ef-5cfe7c495d63@redhat.com> From: David Hildenbrand Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91XuSBdz0uOyU/S8kM1+ag0wvsGlpBVxRR/xw/E8M7TEwuCZQArqqTCmkG6HGcXFT0V9 PXFNNgV5jXMQRwU0O/ztJIQqsE5LsUomE//bLwzj9IVsaQpKDqW6TAPjcdBDPLHvriq7kGjt WhVhdl0qEYB8lkBEU7V2Yb+SYhmhpDrti9Fq1EsmhiHSkxJcGREoMK/63r9WLZYI3+4W2rAc UucZa4OT27U5ZISjNg3Ev0rxU5UH2/pT4wJCfxwocmqaRr6UYmrtZmND89X0KigoFD/XSeVv jwBRNjPAubK9/k5NoRrYqztM9W6sJqrH8+UWZ1Idd/DdmogJh0gNC0+N42Za9yBRURfIdKSb B3JfpUqcWwE7vUaYrHG1nw54pLUoPG6sAA7Mehl3nd4pZUALHwARAQABzSREYXZpZCBIaWxk ZW5icmFuZCA8ZGF2aWRAcmVkaGF0LmNvbT7CwZgEEwEIAEICGwMGCwkIBwMCBhUIAgkKCwQW AgMBAh4BAheAAhkBFiEEG9nKrXNcTDpGDfzKTd4Q9wD/g1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sUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: hqkymUL9hZcVeeqX4fLeSf-eX0BAbQwTvzhSpM1H9D0_1731497275 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 0538FA0003 X-Stat-Signature: a7p1aoe1ferx8j3imszw7ey9o7nfux6b X-Rspam-User: X-HE-Tag: 1731497246-224313 X-HE-Meta: U2FsdGVkX1/3TWZ4+wX2h7pzqbs4vVnvzMp+2U6WN0G5G5HWEkI+WkKh35B2K54IpcuOHBHhX0ind/jNN3Kz1ERlNTxtPIe4VaYIuB23X6cG5/hpnm/hrD6BKYqQnpDdADsFwijy6kVPlqp80yAiKWygbXPG7RuC+ny6gbHlNcbPIUzxjVV9y9Kz0BHBjZTDshxUDRiKRfNMBs9NQ4HbEWCOY9Jf8JFZ2KOdbiQSgOnTEF1AAYLtX3eKt9t7+N3PWx0K4ZsQ1SA2Rqa2nkZDviE2obqBnHqqkIAqJaEu2zJZlyCiKKb/JvJxS6gs6RPBu42P1XYRhOCF5RutiYym198ZzwzesGGqyWkJJ5+CWISEzR+Ja+w1sggtygTyCiXekwgRM4C/SvyzUCJIseBCXnbfsunLsoITrmlo6FpYEKGgisYI4xyrAJZyBER5XbJIC/dbEXqDXDknTUbUqKQxZIhYPjHu7POXF/gaC9j05wwkJ1c6Xv/mUid/Hf4Wn+i9Hu4pKJV24x5uxhNj04UQNtscsTNVmzHutfc1/DJkciae596gkuTWwOHqwnCMAm2xCkynBg7WUNCooI7eepsWEy2XP6e6XrGgP4ydbkUUZDDSukVMXhhEXkNonc6oPxqp11PclBcY5nnmDFAkv/5IT/viIegNLwsZxjlpJt10W7/Gb8/NnO4oTUZFZrRoN9jMuUu3HOivtHw4sykURNJAcoL0t5gzSuZpIynDca4t+ao4yO2T8RGiUQV+27P9kGBeSZI26YOJU2Qq/GoFTmHRaA9qPO2IqM45eG4v0ZFIkL4UK08NOO1uzxoNxy5awGnSwxTnw+nItoM0MfD9UUzeUsFwS80UNKPTpUejUueNGPx7pCbMDNSuzCmLU15LQ/tJE2SBJKIpACB2iTpMOWBGmyCxQmVnQTYA+OxsJVQXtK7/n3TBehJz2i8tz/QISE3M5PgdwLFl71aTwWuGXWA 8n0RHLf5 D5sBsduoZ03mEnU93JDyqReGVI90T0Xl0yygLjka5Q+0vtV+DwkIwqYV9jBiEzCBbHBhQArAM5xWn47NaC35rLvRlfd8mNxpFJmCLXBkr1xlEOJ7ga4mal6R7VoWq0ynqBBxfI/Dmous/U2OulV/iVNO3hCZRGNNnYRUaoEJYXHvURq9vBBT/V+DMSB+VLEgmElsQYD3KXMMRwbGTu7uhieMpPwtuoGh6h7LlfWl/CURJu7bPnZHGb+us3bn6NwecK8uTG7bNssiTDNG9HwWrKEx4F4KZJuzorI9lcXZjFf5i+twVrvcrUiHTI9uvFz2lWghBgZgdK4QApn6Fu/sfqfJ3PHyyLH2gu3mmOGS0IF0bo+MyKxx5JqqKo6sGJpW/AIU5HGLV5L7yn15PCxTEzBjXAJl8PZd/k3dpjwpIfrmDsNiviunr1RCHlMHMMPW8JSeV0/nxTCqJBazTom1wL1v1hOjlqnmfS96CCH6giiMWANkEC1IlpUQfKsnNvyB2XsDk5tGHDyZLwHg= 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 13.11.24 05:57, Matthew Wilcox wrote: > On Tue, Nov 12, 2024 at 03:22:46PM +0100, David Hildenbrand wrote: >> On 12.11.24 14:53, Jason Gunthorpe wrote: >>> On Tue, Nov 12, 2024 at 10:10:06AM +0100, David Hildenbrand wrote: >>>> On 12.11.24 06:26, Matthew Wilcox wrote: >>>>> I don't want you to respin. I think this is a bad idea. >>>> >>>> I'm hoping you'll find some more time to explain what exactly you don't >>>> like, because this series only refactors what we already have. >>>> >>>> I enjoy seeing the special casing (especially hugetlb) gone from mm/swap.c. > > I don't. The list of 'if's is better than the indirect function call. > That's terribly expensive, and the way we reuse the lru.next field > is fragile. Not to mention that it introduces a new thing for the > hardening people to fret over. Right, indirect calls are nasty and probably more fragile/insecure, but this is really what ZONE_DEVICE is already using internally ... but I agree that is less desirable to abstract that. [...] >> We'll need some reliable way to identify these folios that need care. >> guest_memfd will be using folio->mapcount for now, so for now we couldn't >> set a page type like hugetlb does. > > If hugetlb can set lru.next at a certain point, then guestmemfd could > set a page type at a similar point, no? The main problem is that we will have to set it on small folios that can be mapped to user space. As long as mapcount overlays page_type, that's ... not going to work. We won't be truncating+freeing the folio as long as it is mapped to user space, though. So one workaround would be to set the page type only as long as it isn't mapped to user space. Won't win a beauty price, but could be one workaround until we decoupled the type from the mapcount. [...] > >> guest_memfd and hugetlb would be operating on folios (at least for now), >> which contain the refcount,lru,private, ... so nothing special there. >> >> Once we actually decoupled "struct folio" from "struct page", we *might* >> have to play less tricks, because we could just have a callback pointer >> there. But well, maybe we also want to save some space in there. >> >> Do we want dedicated memdescs for hugetlb/guest_memfd that extend folios in >> the future? I don't know, maybe. > > I've certainly considered going so far as a per-fs folio. So we'd > have an ext4_folio, an btrfs_folio, an iomap_folio, etc. That'd let us > get rid of folio->private, but I'm not sure that C's type system can > really handle this nicely. Maybe in a Rust world ;-) :) > > What I'm thinking about is that I'd really like to be able to declare > that all the functions in ext4_aops only accept pointers to ext4_folio, > so ext4_dirty_folio() can't be called with pointers to _any_ folio, > but specifically folios which were previously allocated for ext4. Yes, that sounds reasonable. hugetlb definetly might be another such candidate. > > I don't know if Rust lets you do something like that. > >> I'm currently wondering if we can use folio->private for the time being. >> Either >> >> (a) If folio->private is still set once the refcount drops to 0, it >> indicates that there is a freeing callback/owner_ops. We'll have to make >> hugetlb not use folio->private and convert others to clear folio->private >> before freeing. >> >> (b) Use bitX of folio->private to indicate that this has "owner_ops" >> meaning. We'll have to make hugetlb not use folio->private and make others >> not use bitX. Might be harder and overkill, because right now we only really >> need the callback when refcount==0. >> >> (c) Use some other indication that folio->private contains folio_ops. > > I really don't want to use folio_ops / folio_owner_ops. Yes, and I understand your reasoning. It was one approach to work around the page_type vs. mapcount issue and avoiding more checks on the freeing path. If we manage to make the page type fly, the following could work and leave the ordinary folio freeing path as fast as before (and allow me to add the PGTY_offline handling :) ): From 5a55e4bcf4d6cfa64d3383a7cf6649042cedcecb Mon Sep 17 00:00:00 2001 From: David Hildenbrand Date: Wed, 13 Nov 2024 12:20:58 +0100 Subject: [PATCH] tmp Signed-off-by: David Hildenbrand --- include/linux/page-flags.h | 11 +++++++++++ mm/swap.c | 27 ++++++++++++++++++++++----- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index e80665bc51fac..ebf89075eeb5f 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -950,6 +950,7 @@ enum pagetype { PGTY_slab = 0xf5, PGTY_zsmalloc = 0xf6, PGTY_unaccepted = 0xf7, + PGTY_guestmem = 0xf8, PGTY_mapcount_underflow = 0xff }; @@ -970,6 +971,16 @@ static inline bool page_has_type(const struct page *page) return page_mapcount_is_type(data_race(page->page_type)); } +static inline bool folio_has_type(const struct folio *folio) +{ + return page_has_type(&folio->page); +} + +static inline int folio_get_type(const struct folio *folio) +{ + return folio->page.page_type >> 24; +} + #define FOLIO_TYPE_OPS(lname, fname) \ static __always_inline bool folio_test_##fname(const struct folio *folio) \ { \ diff --git a/mm/swap.c b/mm/swap.c index 10decd9dffa17..bf4efc7bba18a 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -94,6 +94,22 @@ static void page_cache_release(struct folio *folio) unlock_page_lruvec_irqrestore(lruvec, flags); } +static void free_typed_folio(struct folio *folio) +{ + switch (folio_get_type(folio)) { + case PGTY_hugetlb: + free_huge_folio(folio); + return; + case PGTY_offline: + /* Nothing to do, it's offline. */ + return; + case PGTY_guestmem: + // free_guestmem_folio(folio); + default: + WARN_ON_ONCE(1); + } +} + void __folio_put(struct folio *folio) { if (unlikely(folio_is_zone_device(folio))) { @@ -101,8 +117,8 @@ void __folio_put(struct folio *folio) return; } - if (folio_test_hugetlb(folio)) { - free_huge_folio(folio); + if (unlikely(folio_has_type(folio))) { + free_typed_folio(folio); return; } @@ -934,15 +950,16 @@ void folios_put_refs(struct folio_batch *folios, unsigned int *refs) if (!folio_ref_sub_and_test(folio, nr_refs)) continue; - /* hugetlb has its own memcg */ - if (folio_test_hugetlb(folio)) { + if (unlikely(folio_has_type(folio))) { + /* typed folios have their own memcg, if any */ if (lruvec) { unlock_page_lruvec_irqrestore(lruvec, flags); lruvec = NULL; } - free_huge_folio(folio); + free_typed_folio(folio); continue; } + folio_unqueue_deferred_split(folio); __page_cache_release(folio, &lruvec, &flags); -- 2.47.0 I read > https://lore.kernel.org/all/CAGtprH_JP2w-4rq02h_Ugvq5KuHX7TUvegOS7xUs_iy5hriE7g@mail.gmail.com/ > and I still don't understand what you're trying to do. It's a bunch of related issues (e.g., one idea is also having another "global" pool of large pages that are not owned by hugetlb), but the biggest thing we want to sort out is the following: We allocated a large folio from somewhere (hugetlb, another global pool). We might have to split this folio internally in some cases (for example, because we need precise per-page refcounts/mapcounts) and we: (a) Really have to return the whole re-collapsed folio to the original allocator. (b) Might have to clean up some stuff (e.g., restore original page type) before handing the folio back to the original allocator. (c) Want to re-collapse (parts of?) the folio when we don't need the split anymore. Re-collapsing is one problem because of possible GUP pins (for parts that were exposed to user space) and speculative references. As an example during (a): we might have truncated the whole split thing, but some reference on a split folio prevents us from re-collapsing the whole thing synchronously during truncation. As soon as that last reference is put, we can collapse the thing and return it to the original allocator. Similar during (c), just that we want to "freeze" all refcounts as the last references are put, so we can just collapse it once we are notified that it is now possible -- and that no other speculative references can show up as the refcount is 0. > > Would it work to use aops->free_folio() to notify you when the folio is > being removed from the address space? We really have to know when the last reference is gone, and intercept that to cleanup and prepare the large folio to go back to its original allocator. As always, thanks for taking your time and the detailed response Willy! -- Cheers, David / dhildenb