Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mm/gup_benchmark: rename to mm/gup_test

Patch series "selftests/vm: gup_test, hmm-tests, assorted improvements", v3.

Summary: This series provides two main things, and a number of smaller
supporting goodies. The two main points are:

1) Add a new sub-test to gup_test, which in turn is a renamed version
of gup_benchmark. This sub-test allows nicer testing of dump_pages(),
at least on user-space pages.

For quite a while, I was doing a quick hack to gup_test.c whenever I
wanted to try out changes to dump_page(). Then Matthew Wilcox asked me
what I meant when I said "I used my dump_page() unit test", and I
realized that it might be nice to check in a polished up version of
that.

Details about how it works and how to use it are in the commit
description for patch #6 ("selftests/vm: gup_test: introduce the
dump_pages() sub-test").

2) Fixes a limitation of hmm-tests: these tests are incredibly useful,
but only if people actually build and run them. And it turns out that
libhugetlbfs is a little too effective at throwing a wrench in the
works, there. So I've added a little configuration check that removes
just two of the 21 hmm-tests, if libhugetlbfs is not available.

Further details in the commit description of patch #8
("selftests/vm: hmm-tests: remove the libhugetlbfs dependency").

Other smaller things that this series does:

a) Remove code duplication by creating gup_test.h.

b) Clear up the sub-test organization, and their invocation within
run_vmtests.sh.

c) Other minor assorted improvements.

[1] v2 is here:
https://lore.kernel.org/linux-doc/20200929212747.251804-1-jhubbard@nvidia.com/

[2] https://lore.kernel.org/r/CAHk-=wgh-TMPHLY3jueHX7Y2fWh3D+nMBqVS__AZm6-oorquWA@mail.gmail.com

This patch (of 9):

Rename nearly every "gup_benchmark" reference and file name to "gup_test".
The one exception is for the actual gup benchmark test itself.

The current code already does a *little* bit more than benchmarking, and
definitely covers more than get_user_pages_fast(). More importantly,
however, subsequent patches are about to add some functionality that is
non-benchmark related.

Closely related changes:

* Kconfig: in addition to renaming the options from GUP_BENCHMARK to
GUP_TEST, update the help text to reflect that it's no longer a
benchmark-only test.

Link: https://lkml.kernel.org/r/20201026064021.3545418-1-jhubbard@nvidia.com
Link: https://lkml.kernel.org/r/20201026064021.3545418-2-jhubbard@nvidia.com
Signed-off-by: John Hubbard <jhubbard@nvidia.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Jérôme Glisse <jglisse@redhat.com>
Cc: Ralph Campbell <rcampbell@nvidia.com>
Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

John Hubbard and committed by
Linus Torvalds
9c84f229 800bca7c

+49 -44
+3 -3
Documentation/core-api/pin_user_pages.rst
··· 221 221 ============ 222 222 This file:: 223 223 224 - tools/testing/selftests/vm/gup_benchmark.c 224 + tools/testing/selftests/vm/gup_test.c 225 225 226 226 has the following new calls to exercise the new pin*() wrapper functions: 227 227 228 - * PIN_FAST_BENCHMARK (./gup_benchmark -a) 229 - * PIN_BENCHMARK (./gup_benchmark -b) 228 + * PIN_FAST_BENCHMARK (./gup_test -a) 229 + * PIN_BENCHMARK (./gup_test -b) 230 230 231 231 You can monitor how many total dma-pinned pages have been acquired and released 232 232 since the system was booted, via two new /proc/vmstat entries: ::
+1 -1
arch/s390/configs/debug_defconfig
··· 102 102 CONFIG_DEFERRED_STRUCT_PAGE_INIT=y 103 103 CONFIG_IDLE_PAGE_TRACKING=y 104 104 CONFIG_PERCPU_STATS=y 105 - CONFIG_GUP_BENCHMARK=y 105 + CONFIG_GUP_TEST=y 106 106 CONFIG_NET=y 107 107 CONFIG_PACKET=y 108 108 CONFIG_PACKET_DIAG=m
+1 -1
arch/s390/configs/defconfig
··· 95 95 CONFIG_DEFERRED_STRUCT_PAGE_INIT=y 96 96 CONFIG_IDLE_PAGE_TRACKING=y 97 97 CONFIG_PERCPU_STATS=y 98 - CONFIG_GUP_BENCHMARK=y 98 + CONFIG_GUP_TEST=y 99 99 CONFIG_NET=y 100 100 CONFIG_PACKET=y 101 101 CONFIG_PACKET_DIAG=m
+10 -5
mm/Kconfig
··· 821 821 information includes global and per chunk statistics, which can 822 822 be used to help understand percpu memory usage. 823 823 824 - config GUP_BENCHMARK 825 - bool "Enable infrastructure for get_user_pages() and related calls benchmarking" 824 + config GUP_TEST 825 + bool "Enable infrastructure for get_user_pages()-related unit tests" 826 826 help 827 - Provides /sys/kernel/debug/gup_benchmark that helps with testing 828 - performance of get_user_pages() and related calls. 827 + Provides /sys/kernel/debug/gup_test, which in turn provides a way 828 + to make ioctl calls that can launch kernel-based unit tests for 829 + the get_user_pages*() and pin_user_pages*() family of API calls. 829 830 830 - See tools/testing/selftests/vm/gup_benchmark.c 831 + These tests include benchmark testing of the _fast variants of 832 + get_user_pages*() and pin_user_pages*(), as well as smoke tests of 833 + the non-_fast variants. 834 + 835 + See tools/testing/selftests/vm/gup_test.c 831 836 832 837 config GUP_GET_PTE_LOW_HIGH 833 838 bool
+1 -1
mm/Makefile
··· 90 90 obj-$(CONFIG_MEMCG) += memcontrol.o vmpressure.o 91 91 obj-$(CONFIG_MEMCG_SWAP) += swap_cgroup.o 92 92 obj-$(CONFIG_CGROUP_HUGETLB) += hugetlb_cgroup.o 93 - obj-$(CONFIG_GUP_BENCHMARK) += gup_benchmark.o 93 + obj-$(CONFIG_GUP_TEST) += gup_test.o 94 94 obj-$(CONFIG_MEMORY_FAILURE) += memory-failure.o 95 95 obj-$(CONFIG_HWPOISON_INJECT) += hwpoison-inject.o 96 96 obj-$(CONFIG_DEBUG_KMEMLEAK) += kmemleak.o
+18 -18
mm/gup_benchmark.c mm/gup_test.c
··· 5 5 #include <linux/ktime.h> 6 6 #include <linux/debugfs.h> 7 7 8 - #define GUP_FAST_BENCHMARK _IOWR('g', 1, struct gup_benchmark) 9 - #define GUP_BENCHMARK _IOWR('g', 2, struct gup_benchmark) 10 - #define PIN_FAST_BENCHMARK _IOWR('g', 3, struct gup_benchmark) 11 - #define PIN_BENCHMARK _IOWR('g', 4, struct gup_benchmark) 12 - #define PIN_LONGTERM_BENCHMARK _IOWR('g', 5, struct gup_benchmark) 8 + #define GUP_FAST_BENCHMARK _IOWR('g', 1, struct gup_test) 9 + #define GUP_BENCHMARK _IOWR('g', 2, struct gup_test) 10 + #define PIN_FAST_BENCHMARK _IOWR('g', 3, struct gup_test) 11 + #define PIN_BENCHMARK _IOWR('g', 4, struct gup_test) 12 + #define PIN_LONGTERM_BENCHMARK _IOWR('g', 5, struct gup_test) 13 13 14 - struct gup_benchmark { 14 + struct gup_test { 15 15 __u64 get_delta_usec; 16 16 __u64 put_delta_usec; 17 17 __u64 addr; ··· 56 56 if (WARN(!page_maybe_dma_pinned(page), 57 57 "pages[%lu] is NOT dma-pinned\n", i)) { 58 58 59 - dump_page(page, "gup_benchmark failure"); 59 + dump_page(page, "gup_test failure"); 60 60 break; 61 61 } 62 62 } ··· 64 64 } 65 65 } 66 66 67 - static int __gup_benchmark_ioctl(unsigned int cmd, 68 - struct gup_benchmark *gup) 67 + static int __gup_test_ioctl(unsigned int cmd, 68 + struct gup_test *gup) 69 69 { 70 70 ktime_t start_time, end_time; 71 71 unsigned long i, nr_pages, addr, next; ··· 164 164 return ret; 165 165 } 166 166 167 - static long gup_benchmark_ioctl(struct file *filep, unsigned int cmd, 167 + static long gup_test_ioctl(struct file *filep, unsigned int cmd, 168 168 unsigned long arg) 169 169 { 170 - struct gup_benchmark gup; 170 + struct gup_test gup; 171 171 int ret; 172 172 173 173 switch (cmd) { ··· 184 184 if (copy_from_user(&gup, (void __user *)arg, sizeof(gup))) 185 185 return -EFAULT; 186 186 187 - ret = __gup_benchmark_ioctl(cmd, &gup); 187 + ret = __gup_test_ioctl(cmd, &gup); 188 188 if (ret) 189 189 return ret; 190 190 ··· 194 194 return 0; 195 195 } 196 196 197 - static const struct file_operations gup_benchmark_fops = { 197 + static const struct file_operations gup_test_fops = { 198 198 .open = nonseekable_open, 199 - .unlocked_ioctl = gup_benchmark_ioctl, 199 + .unlocked_ioctl = gup_test_ioctl, 200 200 }; 201 201 202 - static int gup_benchmark_init(void) 202 + static int gup_test_init(void) 203 203 { 204 - debugfs_create_file_unsafe("gup_benchmark", 0600, NULL, NULL, 205 - &gup_benchmark_fops); 204 + debugfs_create_file_unsafe("gup_test", 0600, NULL, NULL, 205 + &gup_test_fops); 206 206 207 207 return 0; 208 208 } 209 209 210 - late_initcall(gup_benchmark_init); 210 + late_initcall(gup_test_init);
+1 -1
tools/testing/selftests/vm/.gitignore
··· 15 15 mlock-intersect-test 16 16 mlock-random-test 17 17 virtual_address_range 18 - gup_benchmark 18 + gup_test 19 19 va_128TBswitch 20 20 map_fixed_noreplace 21 21 write_to_hugetlbfs
+1 -1
tools/testing/selftests/vm/Makefile
··· 23 23 CFLAGS = -Wall -I ../../../../usr/include $(EXTRA_CFLAGS) 24 24 LDLIBS = -lrt 25 25 TEST_GEN_FILES = compaction_test 26 - TEST_GEN_FILES += gup_benchmark 26 + TEST_GEN_FILES += gup_test 27 27 TEST_GEN_FILES += hmm-tests 28 28 TEST_GEN_FILES += hugepage-mmap 29 29 TEST_GEN_FILES += hugepage-shm
+1 -1
tools/testing/selftests/vm/config
··· 3 3 CONFIG_TEST_VMALLOC=m 4 4 CONFIG_DEVICE_PRIVATE=y 5 5 CONFIG_TEST_HMM=m 6 - CONFIG_GUP_BENCHMARK=y 6 + CONFIG_GUP_TEST=y
+8 -8
tools/testing/selftests/vm/gup_benchmark.c tools/testing/selftests/vm/gup_test.c
··· 14 14 #define MB (1UL << 20) 15 15 #define PAGE_SIZE sysconf(_SC_PAGESIZE) 16 16 17 - #define GUP_FAST_BENCHMARK _IOWR('g', 1, struct gup_benchmark) 18 - #define GUP_BENCHMARK _IOWR('g', 2, struct gup_benchmark) 17 + #define GUP_FAST_BENCHMARK _IOWR('g', 1, struct gup_test) 18 + #define GUP_BENCHMARK _IOWR('g', 2, struct gup_test) 19 19 20 20 /* Similar to above, but use FOLL_PIN instead of FOLL_GET. */ 21 - #define PIN_FAST_BENCHMARK _IOWR('g', 3, struct gup_benchmark) 22 - #define PIN_BENCHMARK _IOWR('g', 4, struct gup_benchmark) 23 - #define PIN_LONGTERM_BENCHMARK _IOWR('g', 5, struct gup_benchmark) 21 + #define PIN_FAST_BENCHMARK _IOWR('g', 3, struct gup_test) 22 + #define PIN_BENCHMARK _IOWR('g', 4, struct gup_test) 23 + #define PIN_LONGTERM_BENCHMARK _IOWR('g', 5, struct gup_test) 24 24 25 25 /* Just the flags we need, copied from mm.h: */ 26 26 #define FOLL_WRITE 0x01 /* check pte is writable */ 27 27 28 - struct gup_benchmark { 28 + struct gup_test { 29 29 __u64 get_delta_usec; 30 30 __u64 put_delta_usec; 31 31 __u64 addr; ··· 37 37 38 38 int main(int argc, char **argv) 39 39 { 40 - struct gup_benchmark gup; 40 + struct gup_test gup; 41 41 unsigned long size = 128 * MB; 42 42 int i, fd, filed, opt, nr_pages = 1, thp = -1, repeats = 1, write = 0; 43 43 int cmd = GUP_FAST_BENCHMARK, flags = MAP_PRIVATE; ··· 104 104 if (write) 105 105 gup.flags |= FOLL_WRITE; 106 106 107 - fd = open("/sys/kernel/debug/gup_benchmark", O_RDWR); 107 + fd = open("/sys/kernel/debug/gup_test", O_RDWR); 108 108 if (fd == -1) { 109 109 perror("open"); 110 110 exit(1);
+4 -4
tools/testing/selftests/vm/run_vmtests
··· 124 124 fi 125 125 126 126 echo "--------------------------------------------" 127 - echo "running 'gup_benchmark -U' (normal/slow gup)" 127 + echo "running 'gup_test -U' (normal/slow gup)" 128 128 echo "--------------------------------------------" 129 - ./gup_benchmark -U 129 + ./gup_test -U 130 130 if [ $? -ne 0 ]; then 131 131 echo "[FAIL]" 132 132 exitcode=1 ··· 135 135 fi 136 136 137 137 echo "------------------------------------------" 138 - echo "running gup_benchmark -b (pin_user_pages)" 138 + echo "running gup_test -b (pin_user_pages)" 139 139 echo "------------------------------------------" 140 - ./gup_benchmark -b 140 + ./gup_test -b 141 141 if [ $? -ne 0 ]; then 142 142 echo "[FAIL]" 143 143 exitcode=1