KVM: selftests: Use EPOLL in userfaultfd_util reader threads
authorAnish Moorthy <amoorthy@google.com>
Thu, 15 Feb 2024 23:54:03 +0000 (23:54 +0000)
committerSean Christopherson <seanjc@google.com>
Tue, 9 Apr 2024 21:30:14 +0000 (14:30 -0700)
commit0cba6442e9e2dfabea042b899c99f5bfda5ab582
treebc3eef423ca61cd4b116fd8eca8f0cd9bfb7af77
parentdf4ec5aada9da30486d5464f34ffc80acd0373d6
KVM: selftests: Use EPOLL in userfaultfd_util reader threads

With multiple reader threads POLLing a single UFFD, the demand paging test
suffers from the thundering herd problem: performance degrades as the
number of reader threads is increased. Solve this issue [1] by switching
the the polling mechanism to EPOLL + EPOLLEXCLUSIVE.

Also, change the error-handling convention of uffd_handler_thread_fn.
Instead of just printing errors and returning early from the polling
loop, check for them via TEST_ASSERT(). "return NULL" is reserved for a
successful exit from uffd_handler_thread_fn, i.e. one triggered by a
write to the exit pipe.

Performance samples generated by the command in [2] are given below.

Num Reader Threads, Paging Rate (POLL), Paging Rate (EPOLL)
1      249k      185k
2      201k      235k
4      186k      155k
16     150k      217k
32     89k       198k

[1] Single-vCPU performance does suffer somewhat.
[2] ./demand_paging_test -u MINOR -s shmem -v 4 -o -r <num readers>

Signed-off-by: Anish Moorthy <amoorthy@google.com>
Acked-by: James Houghton <jthoughton@google.com>
Link: https://lore.kernel.org/r/20240215235405.368539-13-amoorthy@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
tools/testing/selftests/kvm/demand_paging_test.c
tools/testing/selftests/kvm/lib/userfaultfd_util.c