Re: [PATCH v3 5/9] mm/gup: limit pagecache folio refcount when grabbing references

From: David Hildenbrand (Arm)

Date: Thu Nov 12 2026 - 11:16:40 EST


On 11/12/26 14:12, Pedro Falcato wrote:
> On Tue, Nov 10, 2026 at 09:35:45PM +0100, David Hildenbrand (Arm) wrote:
>> Let's add a folio_ref_count_over_limit() check in fast and slow GUP
>> before acquiring additional references or pins.
>>
>> Keep it simple and use the check for all folio types.
>>
>> Also propagate try_grab_folio() errors when grabbing additional
>> references in __get_user_pages() and in memfd_pin_folios(), so hitting
>> the limit returns -ENOMEM instead of -EFAULT and -EINVAL, respectively.
>>
>> Keep the existing invalid-refcount warnings.
>>
>> Fixes: 800d8c63b2e9 ("shmem: add huge pages support")
>> Fixes: 99cb0dbd47a1 ("mm,thp: add read-only THP support for (non-shmem) FS")
>> Fixes: 793917d997df ("mm/readahead: Add large folio readahead")
>> Cc: stable@xxxxxxxxxxxxxxx
>> Reviewed-by: Jose A. Perez de Azpillaga <azpijr@xxxxxxxxx>
>> Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
>
> Same points about funny weird inefficiency applies, in any case:

Yes, thanks. Adding a second function that consumes folio+refcount was easy, so
I did that in patch #2.

--
Cheers,

David