When a task zaps mappings (e.g., MADV_DONTNEED), it can drop the PT lock
and defer dropping the folio references. In the meantime, page faults
can refault pagecache folios, creating more references for the same
folios. These deferred references can build up over multiple VMAs.
Let's just request a flush after enqueueing folios whose refcount reached
a certain threshold. Start flushing well before new references are refused,
regardless of the caller's privileges.
When returning "true" from __tlb_remove_folio_pages_size(), PTE zapping
will flush the TLB before dropping the PT lock, but drop the references
afterwards. Refaults can still race with that, but flushing early reduces
the risk of letting others hit the limit.
This is a temporary measure until we have something better.
Reported-by: Chris Mason <[email protected]>
Fixes: 800d8c63b2 ("shmem: add huge pages support")
Fixes: 99cb0dbd47 ("mm,thp: add read-only THP support for (non-shmem) FS")
Fixes: 793917d997 ("mm/readahead: Add large folio readahead")
Cc: [email protected]
Reviewed-by: Jose A. Perez de Azpillaga <[email protected]>
Reviewed-by: Lance Yang <[email protected]>
Reviewed-by: Pedro Falcato <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: David Hildenbrand (Arm) <[email protected]>