# \[patch 033/192\] userfaultfd/selftests: only dump counts if mode enabled

- From: Andrew Morton \<akpm@linux-foundation.org\>
- Date: 2021-07-01 01:48:55 
- List: linux-mm
- Page: https://ratatoskr.run/linux-mm/2021/07/6509426
- Thread: https://ratatoskr.run/linux-mm/2021/07/6509393/t.md

```text
From: Peter Xu <peterx@redhat.com>
Subject: userfaultfd/selftests: only dump counts if mode enabled

WP and MINOR modes are conditionally enabled on specific memory types. 
This patch avoids dumping tons of zeros for those cases when the modes are
not supported at all.

Link: https://lkml.kernel.org/r/20210412232753.1012412-5-peterx@redhat.com
Signed-off-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Axel Rasmussen <axelrasmussen@google.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Andrea Arcangeli <redacted>
Cc: Brian Geffon <redacted>
Cc: "Dr . David Alan Gilbert" <redacted>
Cc: Hugh Dickins <hughd@google.com>
Cc: Jerome Glisse <redacted>
Cc: Joe Perches <joe@perches.com>
Cc: Kirill A. Shutemov <redacted>
Cc: Lokesh Gidra <redacted>
Cc: Mike Kravetz <redacted>
Cc: Mike Rapoport <redacted>
Cc: Mina Almasry <redacted>
Cc: Oliver Upton <redacted>
Cc: Shaohua Li <redacted>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Stephen Rothwell <redacted>
Cc: Wang Qing <redacted>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 tools/testing/selftests/vm/userfaultfd.c |   30 ++++++++++++++-------
 1 file changed, 20 insertions(+), 10 deletions(-)

--- a/tools/testing/selftests/vm/userfaultfd.c~userfaultfd-selftests-only-dump-counts-if-mode-enabled
+++ a/tools/testing/selftests/vm/userfaultfd.c
@@ -171,16 +171,26 @@ static void uffd_stats_report(struct uff
 		minor_total += stats[i].minor_faults;
 	}
 
-	printf("userfaults: %llu missing (", miss_total);
-	for (i = 0; i < n_cpus; i++)
-		printf("%lu+", stats[i].missing_faults);
-	printf("\b), %llu wp (", wp_total);
-	for (i = 0; i < n_cpus; i++)
-		printf("%lu+", stats[i].wp_faults);
-	printf("\b), %llu minor (", minor_total);
-	for (i = 0; i < n_cpus; i++)
-		printf("%lu+", stats[i].minor_faults);
-	printf("\b)\n");
+	printf("userfaults: ");
+	if (miss_total) {
+		printf("%llu missing (", miss_total);
+		for (i = 0; i < n_cpus; i++)
+			printf("%lu+", stats[i].missing_faults);
+		printf("\b) ");
+	}
+	if (wp_total) {
+		printf("%llu wp (", wp_total);
+		for (i = 0; i < n_cpus; i++)
+			printf("%lu+", stats[i].wp_faults);
+		printf("\b) ");
+	}
+	if (minor_total) {
+		printf("%llu minor (", minor_total);
+		for (i = 0; i < n_cpus; i++)
+			printf("%lu+", stats[i].minor_faults);
+		printf("\b)");
+	}
+	printf("\n");
 }
 
 static int anon_release_pages(char *rel_area)
_

```
