Re: [PATCH] mm/userfaultfd: fix likely/unlikely annotation in move_pages()

From: David Hildenbrand (Arm)

Date: Thu Feb 12 2026 - 07:48:45 EST


On 2/4/26 15:58, Matthew Wilcox wrote:
On Wed, Feb 04, 2026 at 02:23:50PM +0000, Aswin Kumar wrote:
All other userfaultfd paths use unlikely() for the mmap_changing check,

No they don't?

$ git grep mmap_changing mm
mm/userfaultfd.c: if (atomic_read(&ctx->mmap_changing))
mm/userfaultfd.c: if (atomic_read(&ctx->mmap_changing))
mm/userfaultfd.c: if (atomic_read(&ctx->mmap_changing))
mm/userfaultfd.c: if (likely(atomic_read(&ctx->mmap_changing)))

This is a performance-only fix - the logic is correct but the branch
prediction annotation is wrong, potentially causing a minor performance
penalty on the fast path.

Can you measure it? Bet you can't.

Honestly, I'd just remove the likely() annotation, not change it to
unlikely().

Agreed.

--
Cheers,

David