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

From: Matthew Wilcox

Date: Wed Feb 04 2026 - 10:02:20 EST


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().