Skip to contentSkip to conversation

selftests/mm: run_vmtests.sh: fix half_ufd_size_MB calculation

PATCH Applied Rafael Aquini 3 participants 3 messages Feb 18, 2025 – Feb 19, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests/mm: run_vmtests.sh: fix half_ufd_size_MB calculation

From: Rafael Aquini <[email protected]>

We noticed that uffd-stress test was always failing to run when invoked for the hugetlb profiles on x86_64 systems with a processor count of 64 or bigger:
...
# ------------------------------------

  # running ./uffd-stress hugetlb 128 32
  # ------------------------------------
  # ERROR: invalid MiB (errno=9, @uffd-stress.c:459)
  ...
  # [FAIL]
  not ok 3 uffd-stress hugetlb 128 32 # exit=1
  ...

The problem boils down to how run_vmtests.sh (mis)calculates the size of the region it feeds to uffd-stress. The latter expects to see an amount of MiB while the former is just giving out the number of free hugepages halved down. This measurement discrepancy ends up violating uffd-stress' assertion on number of hugetlb pages allocated per CPU, causing it to bail out with the error above.

This commit fixes that issue by adjusting run_vmtests.sh's half_ufd_size_MB calculation so it properly renders the region size in MiB, as expected, while maintaining all of its original constraints in place.

Fixes 2e47a445d7b3 ("selftests/mm: run_vmtests.sh: fix hugetlb mem size calculation")
---
 tools/testing/selftests/mm/run_vmtests.sh | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tools/testing/selftests/mm/run_vmtests.sh +3 -1
index 333c468c2699..157d07e5aaa3 100755
@@ -304,7 +304,9 @@ uffd_stress_bin=./uffd-stress
 CATEGORY="userfaultfd" run_test ${uffd_stress_bin} anon 20 16
 # Hugetlb tests require source and destination huge pages. Pass in half
 # the size of the free pages we have, which is used for *each*.
-half_ufd_size_MB=$((freepgs / 2))
+# uffd-stress expects a region expressed in MiB, so we adjust
+# half_ufd_size_MB accordingly.
+half_ufd_size_MB=$(((freepgs * hpgsize_KB) / 1024 / 2))
 CATEGORY="userfaultfd" run_test ${uffd_stress_bin} hugetlb "$half_ufd_size_MB" 32
 CATEGORY="userfaultfd" run_test ${uffd_stress_bin} hugetlb-private "$half_ufd_size_MB" 32
 CATEGORY="userfaultfd" run_test ${uffd_stress_bin} shmem 20 16
Signature · 1 line
2.47.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 37 lines · Rafael Aquini

From: Rafael Aquini <[email protected]>

We noticed that uffd-stress test was always failing to run when invoked for the hugetlb profiles on x86_64 systems with a processor count of 64 or bigger:

   ...
   # ------------------------------------
   # running ./uffd-stress hugetlb 128 32
   # ------------------------------------
   # ERROR: invalid MiB (errno=9, @uffd-stress.c:459)
   ...
   # [FAIL]
   not ok 3 uffd-stress hugetlb 128 32 # exit=1
   ...

The problem boils down to how run_vmtests.sh (mis)calculates the size of the region it feeds to uffd-stress. The latter expects to see an amount of MiB while the former is just giving out the number of free hugepages halved down. This measurement discrepancy ends up violating uffd-stress' assertion on number of hugetlb pages allocated per CPU, causing it to bail out with the error above.

This commit fixes that issue by adjusting run_vmtests.sh's half_ufd_size_MB calculation so it properly renders the region size in MiB, as expected, while maintaining all of its original constraints in place.

Fixes 2e47a445d7b3 ("selftests/mm: run_vmtests.sh: fix hugetlb mem size calculation")
---
  tools/testing/selftests/mm/run_vmtests.sh | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
tools/testing/selftests/mm/run_vmtests.sh +0 -0
index 333c468c2699..157d07e5aaa3 100755

tools/testing/selftests/mm/run_vmtests.sh uffd_stress_bin=./uffd-stress · line 309

Quoted 7 lines
tools/testing/selftests/mm/run_vmtests.sh +3 -1
@@ -304,7 +304,9 @@ uffd_stress_bin=./uffd-stress
  CATEGORY="userfaultfd" run_test ${uffd_stress_bin} anon 20 16
  # Hugetlb tests require source and destination huge pages. Pass in half
  # the size of the free pages we have, which is used for *each*.
-half_ufd_size_MB=$((freepgs / 2))
+# uffd-stress expects a region expressed in MiB, so we adjust
+# half_ufd_size_MB accordingly.
+half_ufd_size_MB=$(((freepgs * hpgsize_KB) / 1024 / 2))

LGTM

Signature · 3 lines
Cheers,

David / dhildenb
Reviewed-by on v1 1/1
#2 lore raw
In reply to Rafael Aquini
Quoted 22 lines · Rafael Aquini

From: Rafael Aquini <[email protected]>

We noticed that uffd-stress test was always failing to run when invoked for the hugetlb profiles on x86_64 systems with a processor count of 64 or bigger:
...
# ------------------------------------

  # running ./uffd-stress hugetlb 128 32
  # ------------------------------------
  # ERROR: invalid MiB (errno=9, @uffd-stress.c:459)
  ...
  # [FAIL]
  not ok 3 uffd-stress hugetlb 128 32 # exit=1
  ...

The problem boils down to how run_vmtests.sh (mis)calculates the size of the region it feeds to uffd-stress. The latter expects to see an amount of MiB while the former is just giving out the number of free hugepages halved down. This measurement discrepancy ends up violating uffd-stress' assertion on number of hugetlb pages allocated per CPU, causing it to bail out with the error above.

Quoted 6 lines

This commit fixes that issue by adjusting run_vmtests.sh's half_ufd_size_MB calculation so it properly renders the region size in MiB, as expected, while maintaining all of its original constraints in place.

Fixes 2e47a445d7b3 ("selftests/mm: run_vmtests.sh: fix hugetlb mem size calculation")

Oops.. thanks!

Signature · 1 line
Peter Xu