From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E31E131E832; Thu, 9 Apr 2026 18:47:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775760438; cv=none; b=uoeAO6bZLUxIWc3P92ixceBvNZRX+lG5vU7rrsLEBcOD8rnJULRL0hQyCycLYFiCAWI2YT6A9v8K/F2UuTCcsSj0F94c017CGW79SZrKbWgx4IgNWO5R6cRMT/yGV3EnJz0FiV+qxU5qJPkE/zSJYf1rwdUqytFs3AgQZVE3xoM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775760438; c=relaxed/simple; bh=wN7F9fKA4JbTA7CrHbrx+JQKhgCNMy1dmZE3mrBVygs=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=RguChvrP5cG/D5YYRq4a3PtEvJfaqsqe6WbqV1ZTfInOcBWkGCM6TZDzQpyQ1OcEbfbLwAXJRXvEsXWYYkjHrrktEY04v3AA4dsq2KnwqcXH4PR+D8oSw0tEuyS4U1VXDnCiMIwUMUrp1sKsFphxHwBUejjIoqcLUIyd8LhyRd8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=owuKJyaN; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="owuKJyaN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 375EBC4CEF7; Thu, 9 Apr 2026 18:47:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775760437; bh=wN7F9fKA4JbTA7CrHbrx+JQKhgCNMy1dmZE3mrBVygs=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=owuKJyaNvfKZGn7M9p437+zqIiaBIW/76VhQXhB5XG4mopCJ0v7M3eZfMO8GBmg4f pXYEKtK3X6JByMf6/K5Kz4GQmE3fVh5OnPMmfyV7O1rfWrQ5escXD9UKfMdeyIeMnD bIMM5TfxCVqRqvluSTqQ6SpTcfaJO5JrfXsW4cOEyX5aeol6ot1VhTjo+Nip2jz0jS pBBBkfb6T5o49dZPSNnXXTPmS2C9nqAenKbw78Z7/IwAHi+MHWMGeVdkEbcNBxGLT8 Jb4NiKlMCy/tNQn4pL68drhnCCPrmlLiwBFNQFhUGtc31v/H9nCrk309ydrD3oAUvt QJOtzGeE1OjZA== Message-ID: <4edea589-26b0-486a-9703-3b8c2d528a42@kernel.org> Date: Thu, 9 Apr 2026 20:47:07 +0200 Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH 0/5] Separate compound page from folio To: Zi Yan Cc: Jason Gunthorpe , Matthew Wilcox , Alistair Popple , Balbir Singh , Andrew Morton , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Jens Axboe , Baolin Wang , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Muchun Song , Oscar Salvador , Brendan Jackman , Johannes Weiner , linux-mm@kvack.org, linux-kernel@vger.kernel.org, io-uring@vger.kernel.org References: <20260130034818.472804-1-ziy@nvidia.com> <3C342301-A8E4-4EC4-BB9E-9C8246F8D6F7@nvidia.com> From: "David Hildenbrand (Arm)" Content-Language: en-US Autocrypt: addr=david@kernel.org; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZg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BdZ5eEkj1dCyx+t/ga6x2rHyc8Sl86oK1tvAkwBNsfKou3v+jP/l14a7DGBvrmlYjO 59o3t6inu6H7pt7OL6u6BQj7DoMAEQEAAcLBfAQYAQgAJgIbDBYhBBvZyq1zXEw6Rg38yk3e EPcA/4NaBQJonNqrBQkmWAihAAoJEE3eEPcA/4NaKtMQALAJ8PzprBEXbXcEXwDKQu+P/vts IfUb1UNMfMV76BicGa5NCZnJNQASDP/+bFg6O3gx5NbhHHPeaWz/VxlOmYHokHodOvtL0WCC 8A5PEP8tOk6029Z+J+xUcMrJClNVFpzVvOpb1lCbhjwAV465Hy+NUSbbUiRxdzNQtLtgZzOV Zw7jxUCs4UUZLQTCuBpFgb15bBxYZ/BL9MbzxPxvfUQIPbnzQMcqtpUs21CMK2PdfCh5c4gS sDci6D5/ZIBw94UQWmGpM/O1ilGXde2ZzzGYl64glmccD8e87OnEgKnH3FbnJnT4iJchtSvx yJNi1+t0+qDti4m88+/9IuPqCKb6Stl+s2dnLtJNrjXBGJtsQG/sRpqsJz5x1/2nPJSRMsx9 5YfqbdrJSOFXDzZ8/r82HgQEtUvlSXNaXCa95ez0UkOG7+bDm2b3s0XahBQeLVCH0mw3RAQg r7xDAYKIrAwfHHmMTnBQDPJwVqxJjVNr7yBic4yfzVWGCGNE4DnOW0vcIeoyhy9vnIa3w1uZ 3iyY2Nsd7JxfKu1PRhCGwXzRw5TlfEsoRI7V9A8isUCoqE2Dzh3FvYHVeX4Us+bRL/oqareJ CIFqgYMyvHj7Q06kTKmauOe4Nf0l0qEkIuIzfoLJ3qr5UyXc2hLtWyT9Ir+lYlX9efqh7mOY qIws/H2t In-Reply-To: <3C342301-A8E4-4EC4-BB9E-9C8246F8D6F7@nvidia.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sorry for the late reply on this. >> As discussed, the issue is still that interpret non-folio page >> allocations as folios, which can also be compound pages. >> >> Now, there are PFN walkers that do that, but also page table handling code. >> >> Most prominently, when mapping such pages through vm_insert_pages(), we >> will call into folio_add_file_rmap_pte() and essentially touch mapcount >> related stuff. >> >> Once in the page tables, users can GUP them and modify the pincount. >> Other page table walkers can just similarly find them and look them up. >> >> To stop messing with mapcounts is easy once we can reliably identify >> such pages when mapping/unmapping them. > > My current way of doing that is to mark every page “NotRmappable” page_type > in post_alloc_hook() and clear this page_type at page_rmappable_folio(). > Any user wants to set their own page_type can overwrite “NotRmappable”. > And folio_test_rmappable() is just !folio_has_type(). One exception > is hugetlb, since it has page_type and is rmappable. Fortunately or > unfortunately, rmap.c has special handling code for hugetlb, so there > should be no problem. > > I did some test using io_uring (via nvim), which uses compound page instead of > folio and does vm_insert*(). At least no crash was present. > We discussed that in the meantime elsewhere. :) >> >> GUP and other page table walkers are more problematic and need more >> thought (and work :( ). >> >> Essentially, vm_normal_folio() would have to fail on these pages. But >> what to do about vm_normal_page() users? The page_folio() would have to >> fail. But then we must keep some page table walkers working. >> >> And we have to figure out what to do with GUP. > > Since _pincount will not be present after my change, GUP cannot be applied > on these pages. > > OK, my memory comes back. I think my original proposal of separating > compound page from folio might not be right, since that defeats the > purpose of folio, which is a group of pages managed as a whole. > > Basically a compound page should still be regarded as a folio, but rmappable > related fields (e.g., _large_mapcount, _nr_pages_mapped, _mm_ids) > should not be initialized and user is free to use them differently. > In this way, _pincount can be a common folio field to initialize and use. At least long term a non-folio page should not be regarded a folio. There are quite some changes required to teach page table walkers (incl. GUP) about that. In GUP code, we would not mess with the _pincount for non-folio things. It will be a bit tricky. Handling the rmap (skip it) as a first step might be easier. > >> >> So compound pages are just the tip of the iceberg :) >> >> >> We could maybe forbid mapping them through vm_insert_pages() in the >> first place, requiring all callers to do order-0 page allocations. Hm. >> >> Then at least they would not end up in user page tables. > > Will it kill performance? If only order-0 pages are allowed. I don't think this is really performance-relevant for the vm_insert_pages() interface. We never get PMD-THPs either way. But yea, if we could keep that compound pages working that would also make our life easier. > >> >> But there is other code where compound pages are interpreted as folios >> and the other way around that must be sorted out. > > I think we might want to have some sub-class of folios, like rmappable folios, > not rmappable folios, and others, otherwise, we are going back > to mixing page and folio. I think it's pretty clear that a folio will be mappable. If you want something that is not mappable, then you shouldn't be allcoating a folio that carries metadata for storing all that information. -- Cheers, David