mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [RFC] Unconditionally lock folios when calling rmap_walk()
@ 2025-08-21  4:23 Lokesh Gidra
  2025-08-21  4:29 ` Lokesh Gidra
  0 siblings, 1 reply; 8+ messages in thread
From: Lokesh Gidra @ 2025-08-21  4:23 UTC (permalink / raw)
  To: linux-mm
  Cc: Peter Xu, Barry Song, David Hildenbrand, Suren Baghdasaryan,
	Kalesh Singh, Andrew Morton, android-mm, linux-kernel, Jann Horn

Hi all,

Currently, some callers of rmap_walk() conditionally avoid try-locking
non-ksm anon folios. This necessitates serialization through anon_vma
write-lock when folio->mapping and/or folio->index (fields involved in
rmap_walk()) are to be updated. This hurts scalability due to coarse
granularity of the lock. For instance, when multiple threads invoke
userfaultfd’s MOVE ioctl simultaneously to move distinct pages from
the same src VMA, they all contend for the corresponding anon_vma’s
lock. Field traces for arm64 android devices reveal over 30ms of
uninterruptible sleep in the main UI thread, leading to janky user
interactions.

Among all rmap_walk() callers that don’t lock anon folios,
folio_referenced() is the most critical (others are
page_idle_clear_pte_refs(), damon_folio_young(), and
damon_folio_mkold()). The relevant code in folio_referenced() is:

if (!is_locked && (!folio_test_anon(folio) || folio_test_ksm(folio))) {
        we_locked = folio_trylock(folio);
        if (!we_locked)
                return 1;
}

It’s unclear why locking anon_vma (when updating folio->mapping) is
beneficial over locking the folio here. It’s in the reclaim path, so
should not be a critical path that necessitates some special
treatment, unless I’m missing something.

Therefore, I propose simplifying the locking mechanism by
unconditionally try-locking the folio in such cases. This helps avoid
locking anon_vma when updating folio->mapping, which, for instance,
will help eliminate the uninterruptible sleep observed in the field
traces mentioned earlier. Furthermore, it enables us to simplify the
code in folio_lock_anon_vma_read() by removing the re-check to ensure
that the field hasn’t changed under us.

Thanks,
Lokesh

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-08-22 17:16 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-08-21  4:23 [RFC] Unconditionally lock folios when calling rmap_walk() Lokesh Gidra
2025-08-21  4:29 ` Lokesh Gidra
2025-08-21 12:01   ` Barry Song
2025-08-21 16:13     ` Zi Yan
2025-08-21 17:56       ` Lokesh Gidra
2025-08-22 10:36         ` Harry Yoo
2025-08-22 10:50           ` Lorenzo Stoakes
2025-08-22 17:16             ` Lokesh Gidra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®