From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794601000; b=WiA8zPZi3YgAETNsBTgZ2YpXgGQH03/fEjdvpxWRHVm1JB6MoDq2yzf0/emuc+QdSCtF w2zse1ejO42Vjn4U22tStndda4DHzpzkTANYGfMzjJtcCPozTta8ERIq8l2EIxpnYQsSA 8uBXuNTvj4tFRYqA9/w6mITx8WDpu07eqQjmMIefcKQ38gYSyGPSy2tZU4ebh5zE74asy HjPlalqiynALtSEGo8QGv4t6IMLmef4FFegxCa1y+ruyua5WuiPnz1q2xaks7S6RCqO+A uU65sc40lwKxo/JJyyZ6kM+aLGmaChpnhc1IcjsuQQSB/pPTG3FqOOrkatUigbHuxuA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794601000; h=Received:DKIM-Signature:Message-ID:Date:MIME-Version:User-Agent: Subject:To:Cc:References:From:Content-Language:Autocrypt:In-Reply-To: Content-Type:Content-Transfer-Encoding; bh=XKkv9aRrifNAGJc7MyvqqHZiCveTQdE+78aZDKlRtY0=; b=cAr0qyTZq3KDzf0WVSE6HO4d4qTZIDxKHikhSYc4emkkPtFW0Ynu5PJMjL0AT6gJMf5B +8xgybuj4HgR8L55cIZdjwZB8chDi+sjENBnHpPqM8Q4yV81igC+L9FDlYc5waj2GW+oe gi/wp4XyPV93x12m19OEOh0u2/wQDzaqOkV87FL+ZYxbRMijdDApaRgD3sixM6fTSQHMk RqLcSg9LaKwfVnxtCGbPAyotABs5fMxJtUMrO+FkFziL74YLaLxnXKt20mhLtjGkMbpyi CSvugSS4lD8CysVCM0vSw7cXcFrlPVtS3qz+HUIENxyoqSSvyuQO9ueK1Fv2R1rpuNQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=MlJaG+26; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 87DBD606A8A3 for ; Fri, 13 Nov 2026 20:16:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=MlJaG+26 Received: by smtp.kernel.org (Postfix) with ESMTPSA id CC9021F000C6; Fri, 13 Nov 2026 20:16:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794601000; bh=XKkv9aRrifNAGJc7MyvqqHZiCveTQdE+78aZDKlRtY0=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=MlJaG+26pUn/pdo1RaZ9nEujevXFvGBMFdUcVls6aQJjSIjiWHUQuEp5CD3UR/yr2 Skup1V3gUNFG3v6+1obY1FN1BkZfbo0+tzLJ6Y/exf2o+80pB+GDyGvRTT7iPLuMMh eTjQGaZe588wJGyiWu/I56o1vYlSBLJD0ZrhINkL7KbdrVuCs0smZfYVzeO+bN6KKK TiBEsjzZGAsx2D1wULksACe+AbAJjWNYgpVzB25nzbRGCFQKhlNqem9AibWGfzTQ5Z Ic6KqIRnYbD4DgZTlSGYLFXX8C6V2RCHAbWXBT1f8zfXd5cRJrUQsJks/Qb3Oy6fO+ emQKqpNvt3Tyw== Message-ID: <3744f956-8179-45f3-9d87-c99c82b2f8db@kernel.org> Date: Fri, 13 Nov 2026 21:16:33 +0100 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH 0/2] mm/huge_memory: find partially mapped shared folios with NO_PAGE_MAPCOUNT To: "Jose A. Perez de Azpillaga" , Zi Yan , Andrew Morton , Lorenzo Stoakes Cc: Baolin Wang , "Liam R. Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Usama Arif , Kiryl Shutsemau , Rik van Riel , Vlastimil Babka , Harry Yoo , Jann Horn , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Joanne Koong References: <20261111113535.330078-1-azpijr@gmail.com> <4411389c-2246-4af6-9b34-10d3f259aeb4@kernel.org> From: "David Hildenbrand (Arm)" Content-Language: en-US Autocrypt: addr=david@kernel.org; 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 B3JfpUqcWwE7vUaYrHG1nw54pLUoPG6sAA7Mehl3nd4pZUALHwARAQAB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DPJwVqxJjVNr7yBic4yfzVWGCGNE4DnOW0vcIeoyhy9vnIa3w1uZ 3iyY2Nsd7JxfKu1PRhCGwXzRw5TlfEsoRI7V9A8isUCoqE2Dzh3FvYHVeX4Us+bRL/oqareJ CIFqgYMyvHj7Q06kTKmauOe4Nf0l0qEkIuIzfoLJ3qr5UyXc2hLtWyT9Ir+lYlX9efqh7mOY qIws/H2t In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 11/12/26 14:03, Jose A. Perez de Azpillaga wrote: > On 11/12/26 1:46 PM, David Hildenbrand (Arm) wrote: >> On 11/11/26 12:31, Jose A. Perez de Azpillaga wrote: >>> With CONFIG_NO_PAGE_MAPCOUNT, an anon large folio mapped by several MMs >>> isn't seen as partially mapped while its mapcount stays at or above the >>> number of pages. If parent and child zap the same half of a THP after >>> fork(), that half is mapped by nobody, the folio is never queued for >>> deferred split, and the memory stays allocated until every mapper is >>> gone. >> >> If you follow the history on this, in e.g., some raised in my talk >> >> https://share.daveh.de/s/bQsDpD7xigJ6wD8/download?path=&files=LSF_MM%2726_+Deferred_folio_splitting.pdf >> >> There are a lot of questions around this. >> >> In particular >> >> (a) Is it really relevant in practice. The only way you can trigger this if a >> folio becomes partially mapped *after* fork (by parent and child unmapping the >> same pages), and the child stays alive. Once the child is gone, the folio is >> only mapped by one process (e.g., child quit), the folio is properly detected as >> partially mapped. > > I don't have any relevant evidence in practice. found it by just reading > and testing in qemu. that is why I sent it as RFC. Ok. Because I would really be interested in real-life scenarios where it is a problem. It's only relevant for long-running parent+child combinations. For short-lived children (e.g., fork+exec) it's irrelevant. > >> >> So you need a long-running parent+child, and have them both do questionable things. >> >> (b) What is the overhead from having way too many folios in the deferred split list. >> > > I don't know yet. I only measured the walk in a TCG guest, nothing on > how long the list gets That would be really interesting. I assume there are some cases where a simple fork+exec would already add pages to the deferred split list even thought they are briefly after fully mapped by the parent. > >>> >>> Patch 1 moves the split_underused_thp check out of >>> deferred_split_folio(). Patch 2 queues such folios as candidates and has >>> the shrinker walk the rmap to see which pages are still mapped. >>> >>> 512 MB of THPs with the same half zapped by every mapper, memory freed >>> by the shrinker: >>> >>> before after >>> 2M, 2 processes 0 MB 252 MB >>> 2M, 3 processes 0 MB 237 MB >>> 2M, 2 children + parent PMD 0 MB 244 MB >>> 64K, 2 processes 0 MB 252 MB >>> 64K, 3 processes 0 MB 252 MB >>> >> >> Again, we can create nice scenarios that are likely not relevant in practice >> (such as 512 MB THPs, lol), but so far I doubted that this is relevant in practice. > > that's 512 MB in total, not the folio size. maybe I should have > clarified it. Ah, 512MiB of THPs, not 512MB THP, Yes, that makes sense. [...] >> >> Maybe one could track it a bit broader? "any page in this set of 16 pages is >> present". Reclaiming a single 4k page from a 2M folios is barely worth it. >> > > yes, that works. maybe with the group size scaled to the folio, so the > map is one long on the stack and 64K folio still gets one bit per page? > As an alternative, could we also just look for the next page incrementally? Like, start with offset 0. When we see that, move to offset 1, when we see that, move to offset 2 ... and once we saw all pages that way, stop the walk. I'd assume that, as long as VMAs don't get remapped, that should likely work in most cases, right? > however, maybe if I don't have real evidence, better drop it? I'd be very interested in an efficient way to test if a folio is partially mapped, and where the holes are. Knowing about the holes could guide a targeted buddy-like folio split. There was also the idea of letting folio_referenced() for that purpose, when we area already doing an rmap walk. -- Cheers, David