diff mbox series

[v1,1/3] selftests/mm: Fix half_ufd_size_MB calculation

Message ID 20250318174343.243631-1-ryan.roberts@arm.com (mailing list archive)
State New
Headers show
Series [v1,1/3] selftests/mm: Fix half_ufd_size_MB calculation | expand

Commit Message

Ryan Roberts March 18, 2025, 5:43 p.m. UTC
$half_ufd_size_MB is supposed to be half of the available hugetlb memory
expressed in MB. But previously it was calculated in pages since
$freepgs is the number of free pages.

When huge pages are 2M it doesn't make a whole lot of difference; the
number of pages that get used is just halved. But on arm64 with 16K or
64K base pages, the PMD size (and default hugetlb size) is 32M and 512M
respectively. So in this case we end up passing a number of MB that is
smaller than a single hugetlb page and the test raises an error.

Fixes: 2e47a445d7b3 ("selftests/mm: run_vmtests.sh: fix hugetlb mem size calculation")
Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
---
 tools/testing/selftests/mm/run_vmtests.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--
2.43.0

Comments

Peter Xu March 18, 2025, 7:54 p.m. UTC | #1
On Tue, Mar 18, 2025 at 05:43:39PM +0000, Ryan Roberts wrote:
> $half_ufd_size_MB is supposed to be half of the available hugetlb memory
> expressed in MB. But previously it was calculated in pages since
> $freepgs is the number of free pages.
> 
> When huge pages are 2M it doesn't make a whole lot of difference; the
> number of pages that get used is just halved. But on arm64 with 16K or
> 64K base pages, the PMD size (and default hugetlb size) is 32M and 512M
> respectively. So in this case we end up passing a number of MB that is
> smaller than a single hugetlb page and the test raises an error.
> 
> Fixes: 2e47a445d7b3 ("selftests/mm: run_vmtests.sh: fix hugetlb mem size calculation")
> Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>

There's a similar fix already in akpm/mm-hotfixes-stable:

67a2f86846f2 selftests/mm: run_vmtests.sh: fix half_ufd_size_MB calculation

Thanks,

> ---
>  tools/testing/selftests/mm/run_vmtests.sh | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/mm/run_vmtests.sh b/tools/testing/selftests/mm/run_vmtests.sh
> index da7e26668103..14fa9d40d574 100755
> --- a/tools/testing/selftests/mm/run_vmtests.sh
> +++ b/tools/testing/selftests/mm/run_vmtests.sh
> @@ -304,7 +304,7 @@ 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))
> +half_ufd_size_MB=$(((freepgs * hpgsize_KB / 2) / 1024))
>  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
> --
> 2.43.0
>
Rafael Aquini March 18, 2025, 9:49 p.m. UTC | #2
On Tue, Mar 18, 2025 at 05:43:39PM +0000, Ryan Roberts wrote:
> $half_ufd_size_MB is supposed to be half of the available hugetlb memory
> expressed in MB. But previously it was calculated in pages since
> $freepgs is the number of free pages.
> 
> When huge pages are 2M it doesn't make a whole lot of difference; the
> number of pages that get used is just halved. But on arm64 with 16K or
> 64K base pages, the PMD size (and default hugetlb size) is 32M and 512M
> respectively. So in this case we end up passing a number of MB that is
> smaller than a single hugetlb page and the test raises an error.
> 
> Fixes: 2e47a445d7b3 ("selftests/mm: run_vmtests.sh: fix hugetlb mem size calculation")
> Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
> ---
>  tools/testing/selftests/mm/run_vmtests.sh | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/mm/run_vmtests.sh b/tools/testing/selftests/mm/run_vmtests.sh
> index da7e26668103..14fa9d40d574 100755
> --- a/tools/testing/selftests/mm/run_vmtests.sh
> +++ b/tools/testing/selftests/mm/run_vmtests.sh
> @@ -304,7 +304,7 @@ 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))
> +half_ufd_size_MB=$(((freepgs * hpgsize_KB / 2) / 1024))
>  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
> --
> 2.43.0
> 
> 

this one is already fixed in linux-next, see commit
67a2f86846f2 ("selftests/mm: run_vmtests.sh: fix half_ufd_size_MB calculation")

-- Rafael
Ryan Roberts March 18, 2025, 10:05 p.m. UTC | #3
On 18/03/2025 19:54, Peter Xu wrote:
> On Tue, Mar 18, 2025 at 05:43:39PM +0000, Ryan Roberts wrote:
>> $half_ufd_size_MB is supposed to be half of the available hugetlb memory
>> expressed in MB. But previously it was calculated in pages since
>> $freepgs is the number of free pages.
>>
>> When huge pages are 2M it doesn't make a whole lot of difference; the
>> number of pages that get used is just halved. But on arm64 with 16K or
>> 64K base pages, the PMD size (and default hugetlb size) is 32M and 512M
>> respectively. So in this case we end up passing a number of MB that is
>> smaller than a single hugetlb page and the test raises an error.
>>
>> Fixes: 2e47a445d7b3 ("selftests/mm: run_vmtests.sh: fix hugetlb mem size calculation")
>> Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
> 
> There's a similar fix already in akpm/mm-hotfixes-stable:
> 
> 67a2f86846f2 selftests/mm: run_vmtests.sh: fix half_ufd_size_MB calculation

Oops, my bad, forgot to check mm branches. This was just a drive-by fix while
working in another context.

Hopefully Andrew is ok to take the other 2 patches and drop this one? If not,
let me know and I'll resend the two other patches on their own.

Thanks,
Ryan

> 
> Thanks,
> 
>> ---
>>  tools/testing/selftests/mm/run_vmtests.sh | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/tools/testing/selftests/mm/run_vmtests.sh b/tools/testing/selftests/mm/run_vmtests.sh
>> index da7e26668103..14fa9d40d574 100755
>> --- a/tools/testing/selftests/mm/run_vmtests.sh
>> +++ b/tools/testing/selftests/mm/run_vmtests.sh
>> @@ -304,7 +304,7 @@ 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))
>> +half_ufd_size_MB=$(((freepgs * hpgsize_KB / 2) / 1024))
>>  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
>> --
>> 2.43.0
>>
>
diff mbox series

Patch

diff --git a/tools/testing/selftests/mm/run_vmtests.sh b/tools/testing/selftests/mm/run_vmtests.sh
index da7e26668103..14fa9d40d574 100755
--- a/tools/testing/selftests/mm/run_vmtests.sh
+++ b/tools/testing/selftests/mm/run_vmtests.sh
@@ -304,7 +304,7 @@  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))
+half_ufd_size_MB=$(((freepgs * hpgsize_KB / 2) / 1024))
 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