[PATCH v2 7/9] selftests/mm: Don't fail uffd-stress if too many CPUs

From: Brendan Jackman
Date: Fri Feb 21 2025 - 13:28:08 EST


This calculation divides a fixed parameter by an environment-dependent
parameter i.e. the number of CPUs.

The simple way to avoid machine-specific failures here is to just put a
cap on the max value of the latter.

Suggested-by: Mateusz Guzik <mjguzik@xxxxxxxxx>
Signed-off-by: Brendan Jackman <jackmanb@xxxxxxxxxx>
---
tools/testing/selftests/mm/uffd-stress.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/mm/uffd-stress.c b/tools/testing/selftests/mm/uffd-stress.c
index be0c93f24fccd618f52d54ff36d9a5540f420e46..cfadac801ed43e8b6dc331b343b6dc4030048f9b 100644
--- a/tools/testing/selftests/mm/uffd-stress.c
+++ b/tools/testing/selftests/mm/uffd-stress.c
@@ -434,6 +434,7 @@ static void sigalrm(int sig)

int main(int argc, char **argv)
{
+ unsigned long nr_cpus;
size_t bytes;

if (argc < 4)
@@ -452,7 +453,15 @@ int main(int argc, char **argv)
return KSFT_SKIP;
}

- nr_threads = sysconf(_SC_NPROCESSORS_ONLN);
+ nr_cpus = sysconf(_SC_NPROCESSORS_ONLN);
+ if (nr_cpus > 32) {
+ /* Don't let calculation below go to zero. */
+ ksft_print_msg("_SC_NPROCESSORS_ONLN (%lu) too large, capping nr_threads to 32\n",
+ nr_cpus);
+ nr_threads = 32;
+ } else {
+ nr_cpus = nr_threads;
+ }

nr_pages_per_cpu = bytes / page_size / nr_threads;
if (!nr_pages_per_cpu) {

--
2.48.1.601.g30ceb7b040-goog