On 4/29/26 2:12 AM, Mike Rapoport wrote:
> From: "Mike Rapoport (Microsoft)" <[email protected]>
>
> uffd-stress skips HugeTLB tests if there are no free huge pages prepared
> by a wrapper script.
>
> Add setup of HugeTLB pages to the test and make sure that the original
> settings are restored on the test exit.
>
> Signed-off-by: Mike Rapoport (Microsoft) <[email protected]>
I ran the test using ./uffd-stress hugetlb 16 20
Before the patch, the test skipped with "not enough hugepages". After
the patch, the test correctly allocates the required hugepages and
passes successfully, restoring the original settings at exit.
Tested-by: Sarthak Sharma <[email protected]>
> ---
> tools/testing/selftests/mm/uffd-stress.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/tools/testing/selftests/mm/uffd-stress.c
> b/tools/testing/selftests/mm/uffd-stress.c
> index 7e37cf3d27f6..9693d042f16f 100644
> --- a/tools/testing/selftests/mm/uffd-stress.c
> +++ b/tools/testing/selftests/mm/uffd-stress.c
> @@ -479,9 +479,12 @@ int main(int argc, char **argv)
> * Ensure nr_parallel - 1 hugepages on top of that to account
> * for racy extra reservation of hugepages.
> */
> - if (gopts->test_type == TEST_HUGETLB &&
> - hugetlb_free_default_pages() < 2 * (bytes / gopts->page_size) +
> gopts->nr_parallel - 1)
> - ksft_exit_skip("Skipping userfaultfd... not enough
> hugepages\n");
> + if (gopts->test_type == TEST_HUGETLB) {
> + unsigned long nr = 2 * (bytes / gopts->page_size) +
> gopts->nr_parallel - 1;
> +
> + if (!hugetlb_setup_default(nr))
> + ksft_exit_skip("Skipping userfaultfd... not enough
> hugepages\n");
> + }
>
> gopts->nr_pages_per_cpu = bytes / gopts->page_size / gopts->nr_parallel;
> if (!gopts->nr_pages_per_cpu) {