From: "Mike Rapoport (Microsoft)" <[email protected]>

hugetlb-madvise test skips testing 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.

Tested-by: Luiz Capitulino <[email protected]>
Tested-by: Sarthak Sharma <[email protected]>
Signed-off-by: Mike Rapoport (Microsoft) <[email protected]>
---
 tools/testing/selftests/mm/hugetlb-madvise.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/tools/testing/selftests/mm/hugetlb-madvise.c 
b/tools/testing/selftests/mm/hugetlb-madvise.c
index 8adcd91d078d..555b4b3d1430 100644
--- a/tools/testing/selftests/mm/hugetlb-madvise.c
+++ b/tools/testing/selftests/mm/hugetlb-madvise.c
@@ -4,12 +4,6 @@
  *
  * Basic functional testing of madvise MADV_DONTNEED and MADV_REMOVE
  * on hugetlb mappings.
- *
- * Before running this test, make sure the administrator has pre-allocated
- * at least MIN_FREE_PAGES hugetlb pages and they are free.  In addition,
- * the test takes an argument that is the path to a file in a hugetlbfs
- * filesystem.  Therefore, a hugetlbfs filesystem must be mounted on some
- * directory.
  */
 
 #define _GNU_SOURCE
@@ -68,9 +62,9 @@ int main(int argc, char **argv)
        if (!base_page_size)
                ksft_exit_fail_msg("Unable to determine base page size\n");
 
+       if (!hugetlb_setup_default(MIN_FREE_PAGES))
+               ksft_exit_skip("Not enough free huge pages (have %lu, need 
%d)\n", hugetlb_free_default_pages(), MIN_FREE_PAGES);
        free_hugepages = hugetlb_free_default_pages();
-       if (free_hugepages < MIN_FREE_PAGES)
-               ksft_exit_skip("Not enough free huge pages (have %lu, need 
%d)\n", free_hugepages, MIN_FREE_PAGES);
 
        fd = memfd_create(argv[0], MFD_HUGETLB);
        if (fd < 0)
-- 
2.53.0


Reply via email to