2017-11-18 07:31:22 +08:00
|
|
|
#include <fcntl.h>
|
2022-04-29 14:16:10 +08:00
|
|
|
#include <errno.h>
|
2017-11-18 07:31:22 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
2022-04-29 14:16:10 +08:00
|
|
|
#include <dirent.h>
|
2017-11-18 07:31:22 +08:00
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
2021-06-29 10:36:33 +08:00
|
|
|
#include <pthread.h>
|
|
|
|
#include <assert.h>
|
2022-08-20 03:19:29 +08:00
|
|
|
#include <mm/gup_test.h>
|
2022-04-29 14:16:10 +08:00
|
|
|
#include "../kselftest.h"
|
2023-04-13 00:41:20 +08:00
|
|
|
#include "vm_util.h"
|
2022-03-25 09:09:46 +08:00
|
|
|
|
2017-11-18 07:31:22 +08:00
|
|
|
#define MB (1UL << 20)
|
|
|
|
|
2020-01-31 14:13:32 +08:00
|
|
|
/* Just the flags we need, copied from mm.h: */
|
|
|
|
#define FOLL_WRITE 0x01 /* check pte is writable */
|
2021-05-05 09:39:27 +08:00
|
|
|
#define FOLL_TOUCH 0x02 /* mark page accessed */
|
2020-01-31 14:13:32 +08:00
|
|
|
|
2022-05-10 09:20:47 +08:00
|
|
|
#define GUP_TEST_FILE "/sys/kernel/debug/gup_test"
|
|
|
|
|
2021-06-29 10:36:33 +08:00
|
|
|
static unsigned long cmd = GUP_FAST_BENCHMARK;
|
|
|
|
static int gup_fd, repeats = 1;
|
|
|
|
static unsigned long size = 128 * MB;
|
|
|
|
/* Serialize prints */
|
|
|
|
static pthread_mutex_t print_mutex = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
|
2020-12-15 11:05:17 +08:00
|
|
|
static char *cmd_to_str(unsigned long cmd)
|
|
|
|
{
|
|
|
|
switch (cmd) {
|
|
|
|
case GUP_FAST_BENCHMARK:
|
|
|
|
return "GUP_FAST_BENCHMARK";
|
|
|
|
case PIN_FAST_BENCHMARK:
|
|
|
|
return "PIN_FAST_BENCHMARK";
|
|
|
|
case PIN_LONGTERM_BENCHMARK:
|
|
|
|
return "PIN_LONGTERM_BENCHMARK";
|
|
|
|
case GUP_BASIC_TEST:
|
|
|
|
return "GUP_BASIC_TEST";
|
|
|
|
case PIN_BASIC_TEST:
|
|
|
|
return "PIN_BASIC_TEST";
|
selftests/vm: gup_test: introduce the dump_pages() sub-test
For quite a while, I was doing a quick hack to gup_test.c (previously,
gup_benchmark.c) whenever I wanted to try out my changes to dump_page().
This makes that hack unnecessary, and instead allows anyone to easily get
the same coverage from a user space program. That saves a lot of time
because you don't have to change the kernel, in order to test different
pages and options.
The new sub-test takes advantage of the existing gup_test infrastructure,
which already provides a simple user space program, some allocated user
space pages, an ioctl call, pinning of those pages (via either
get_user_pages or pin_user_pages) and a corresponding kernel-side test
invocation. There's not much more required, mainly just a couple of
inputs from the user.
In fact, the new test re-uses the existing command line options in order
to get various helpful combinations (THP or normal, _fast or slow gup, gup
vs. pup, and more).
New command line options are: which pages to dump, and what type of
"get/pin" to use.
In order to figure out which pages to dump, the logic is:
* If the user doesn't specify anything, the page 0 (the first page in
the address range that the program sets up for testing) is dumped.
* Or, the user can type up to 8 page indices anywhere on the command
line. If you type more than 8, then it uses the first 8 and ignores the
remaining items.
For example:
./gup_test -ct -F 1 0 19 0x1000
Meaning:
-c: dump pages sub-test
-t: use THP pages
-F 1: use pin_user_pages() instead of get_user_pages()
0 19 0x1000: dump pages 0, 19, and 4096
Link: https://lkml.kernel.org/r/20201026064021.3545418-7-jhubbard@nvidia.com
Signed-off-by: John Hubbard <jhubbard@nvidia.com>
Cc: Jérôme Glisse <jglisse@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
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>
2020-12-15 11:05:21 +08:00
|
|
|
case DUMP_USER_PAGES_TEST:
|
|
|
|
return "DUMP_USER_PAGES_TEST";
|
2020-12-15 11:05:17 +08:00
|
|
|
}
|
|
|
|
return "Unknown command";
|
|
|
|
}
|
|
|
|
|
2021-06-29 10:36:33 +08:00
|
|
|
void *gup_thread(void *data)
|
|
|
|
{
|
|
|
|
struct gup_test gup = *(struct gup_test *)data;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Only report timing information on the *_BENCHMARK commands: */
|
|
|
|
if ((cmd == PIN_FAST_BENCHMARK) || (cmd == GUP_FAST_BENCHMARK) ||
|
|
|
|
(cmd == PIN_LONGTERM_BENCHMARK)) {
|
|
|
|
for (i = 0; i < repeats; i++) {
|
|
|
|
gup.size = size;
|
|
|
|
if (ioctl(gup_fd, cmd, &gup))
|
|
|
|
perror("ioctl"), exit(1);
|
|
|
|
|
|
|
|
pthread_mutex_lock(&print_mutex);
|
|
|
|
printf("%s: Time: get:%lld put:%lld us",
|
|
|
|
cmd_to_str(cmd), gup.get_delta_usec,
|
|
|
|
gup.put_delta_usec);
|
|
|
|
if (gup.size != size)
|
|
|
|
printf(", truncated (size: %lld)", gup.size);
|
|
|
|
printf("\n");
|
|
|
|
pthread_mutex_unlock(&print_mutex);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
gup.size = size;
|
|
|
|
if (ioctl(gup_fd, cmd, &gup)) {
|
|
|
|
perror("ioctl");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
pthread_mutex_lock(&print_mutex);
|
|
|
|
printf("%s: done\n", cmd_to_str(cmd));
|
|
|
|
if (gup.size != size)
|
|
|
|
printf("Truncated (size: %lld)\n", gup.size);
|
|
|
|
pthread_mutex_unlock(&print_mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-11-18 07:31:22 +08:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
selftests/vm: gup_test: introduce the dump_pages() sub-test
For quite a while, I was doing a quick hack to gup_test.c (previously,
gup_benchmark.c) whenever I wanted to try out my changes to dump_page().
This makes that hack unnecessary, and instead allows anyone to easily get
the same coverage from a user space program. That saves a lot of time
because you don't have to change the kernel, in order to test different
pages and options.
The new sub-test takes advantage of the existing gup_test infrastructure,
which already provides a simple user space program, some allocated user
space pages, an ioctl call, pinning of those pages (via either
get_user_pages or pin_user_pages) and a corresponding kernel-side test
invocation. There's not much more required, mainly just a couple of
inputs from the user.
In fact, the new test re-uses the existing command line options in order
to get various helpful combinations (THP or normal, _fast or slow gup, gup
vs. pup, and more).
New command line options are: which pages to dump, and what type of
"get/pin" to use.
In order to figure out which pages to dump, the logic is:
* If the user doesn't specify anything, the page 0 (the first page in
the address range that the program sets up for testing) is dumped.
* Or, the user can type up to 8 page indices anywhere on the command
line. If you type more than 8, then it uses the first 8 and ignores the
remaining items.
For example:
./gup_test -ct -F 1 0 19 0x1000
Meaning:
-c: dump pages sub-test
-t: use THP pages
-F 1: use pin_user_pages() instead of get_user_pages()
0 19 0x1000: dump pages 0, 19, and 4096
Link: https://lkml.kernel.org/r/20201026064021.3545418-7-jhubbard@nvidia.com
Signed-off-by: John Hubbard <jhubbard@nvidia.com>
Cc: Jérôme Glisse <jglisse@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
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>
2020-12-15 11:05:21 +08:00
|
|
|
struct gup_test gup = { 0 };
|
2021-06-29 10:36:33 +08:00
|
|
|
int filed, i, opt, nr_pages = 1, thp = -1, write = 1, nthreads = 1, ret;
|
2021-05-05 09:39:27 +08:00
|
|
|
int flags = MAP_PRIVATE, touch = 0;
|
2018-10-27 06:10:02 +08:00
|
|
|
char *file = "/dev/zero";
|
2021-06-29 10:36:33 +08:00
|
|
|
pthread_t *tid;
|
2017-11-18 07:31:22 +08:00
|
|
|
char *p;
|
|
|
|
|
2021-06-29 10:36:33 +08:00
|
|
|
while ((opt = getopt(argc, argv, "m:r:n:F:f:abcj:tTLUuwWSHpz")) != -1) {
|
2017-11-18 07:31:22 +08:00
|
|
|
switch (opt) {
|
2020-04-02 12:05:41 +08:00
|
|
|
case 'a':
|
|
|
|
cmd = PIN_FAST_BENCHMARK;
|
|
|
|
break;
|
|
|
|
case 'b':
|
2020-12-15 11:05:17 +08:00
|
|
|
cmd = PIN_BASIC_TEST;
|
2020-04-02 12:05:41 +08:00
|
|
|
break;
|
2020-10-14 07:51:54 +08:00
|
|
|
case 'L':
|
|
|
|
cmd = PIN_LONGTERM_BENCHMARK;
|
|
|
|
break;
|
selftests/vm: gup_test: introduce the dump_pages() sub-test
For quite a while, I was doing a quick hack to gup_test.c (previously,
gup_benchmark.c) whenever I wanted to try out my changes to dump_page().
This makes that hack unnecessary, and instead allows anyone to easily get
the same coverage from a user space program. That saves a lot of time
because you don't have to change the kernel, in order to test different
pages and options.
The new sub-test takes advantage of the existing gup_test infrastructure,
which already provides a simple user space program, some allocated user
space pages, an ioctl call, pinning of those pages (via either
get_user_pages or pin_user_pages) and a corresponding kernel-side test
invocation. There's not much more required, mainly just a couple of
inputs from the user.
In fact, the new test re-uses the existing command line options in order
to get various helpful combinations (THP or normal, _fast or slow gup, gup
vs. pup, and more).
New command line options are: which pages to dump, and what type of
"get/pin" to use.
In order to figure out which pages to dump, the logic is:
* If the user doesn't specify anything, the page 0 (the first page in
the address range that the program sets up for testing) is dumped.
* Or, the user can type up to 8 page indices anywhere on the command
line. If you type more than 8, then it uses the first 8 and ignores the
remaining items.
For example:
./gup_test -ct -F 1 0 19 0x1000
Meaning:
-c: dump pages sub-test
-t: use THP pages
-F 1: use pin_user_pages() instead of get_user_pages()
0 19 0x1000: dump pages 0, 19, and 4096
Link: https://lkml.kernel.org/r/20201026064021.3545418-7-jhubbard@nvidia.com
Signed-off-by: John Hubbard <jhubbard@nvidia.com>
Cc: Jérôme Glisse <jglisse@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
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>
2020-12-15 11:05:21 +08:00
|
|
|
case 'c':
|
|
|
|
cmd = DUMP_USER_PAGES_TEST;
|
|
|
|
/*
|
|
|
|
* Dump page 0 (index 1). May be overridden later, by
|
|
|
|
* user's non-option arguments.
|
|
|
|
*
|
|
|
|
* .which_pages is zero-based, so that zero can mean "do
|
|
|
|
* nothing".
|
|
|
|
*/
|
|
|
|
gup.which_pages[0] = 1;
|
|
|
|
break;
|
selftests/vm: gup_test: fix test flag
In gup_test both gup_flags and test_flags use the same flags field.
This is broken.
Farther, in the actual gup_test.c all the passed gup_flags are erased
and unconditionally replaced with FOLL_WRITE.
Which means that test_flags are ignored, and code like this always
performs pin dump test:
155 if (gup->flags & GUP_TEST_FLAG_DUMP_PAGES_USE_PIN)
156 nr = pin_user_pages(addr, nr, gup->flags,
157 pages + i, NULL);
158 else
159 nr = get_user_pages(addr, nr, gup->flags,
160 pages + i, NULL);
161 break;
Add a new test_flags field, to allow raw gup_flags to work. Add a new
subcommand for DUMP_USER_PAGES_TEST to specify that pin test should be
performed.
Remove unconditional overwriting of gup_flags via FOLL_WRITE. But,
preserve the previous behaviour where FOLL_WRITE was the default flag,
and add a new option "-W" to unset FOLL_WRITE.
Rename flags with gup_flags.
With the fix, dump works like this:
root@virtme:/# gup_test -c
---- page #0, starting from user virt addr: 0x7f8acb9e4000
page:00000000d3d2ee27 refcount:2 mapcount:1 mapping:0000000000000000
index:0x0 pfn:0x100bcf
anon flags: 0x300000000080016(referenced|uptodate|lru|swapbacked)
raw: 0300000000080016 ffffd0e204021608 ffffd0e208df2e88 ffff8ea04243ec61
raw: 0000000000000000 0000000000000000 0000000200000000 0000000000000000
page dumped because: gup_test: dump_pages() test
DUMP_USER_PAGES_TEST: done
root@virtme:/# gup_test -c -p
---- page #0, starting from user virt addr: 0x7fd19701b000
page:00000000baed3c7d refcount:1025 mapcount:1 mapping:0000000000000000
index:0x0 pfn:0x108008
anon flags: 0x300000000080014(uptodate|lru|swapbacked)
raw: 0300000000080014 ffffd0e204200188 ffffd0e205e09088 ffff8ea04243ee71
raw: 0000000000000000 0000000000000000 0000040100000000 0000000000000000
page dumped because: gup_test: dump_pages() test
DUMP_USER_PAGES_TEST: done
Refcount shows the difference between pin vs no-pin case.
Also change type of nr from int to long, as it counts number of pages.
Link: https://lkml.kernel.org/r/20210215161349.246722-14-pasha.tatashin@soleen.com
Signed-off-by: Pavel Tatashin <pasha.tatashin@soleen.com>
Reviewed-by: John Hubbard <jhubbard@nvidia.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Ira Weiny <ira.weiny@intel.com>
Cc: James Morris <jmorris@namei.org>
Cc: Jason Gunthorpe <jgg@nvidia.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Sasha Levin <sashal@kernel.org>
Cc: Steven Rostedt (VMware) <rostedt@goodmis.org>
Cc: Tyler Hicks <tyhicks@linux.microsoft.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2021-05-05 09:39:23 +08:00
|
|
|
case 'p':
|
|
|
|
/* works only with DUMP_USER_PAGES_TEST */
|
|
|
|
gup.test_flags |= GUP_TEST_FLAG_DUMP_PAGES_USE_PIN;
|
|
|
|
break;
|
selftests/vm: gup_test: introduce the dump_pages() sub-test
For quite a while, I was doing a quick hack to gup_test.c (previously,
gup_benchmark.c) whenever I wanted to try out my changes to dump_page().
This makes that hack unnecessary, and instead allows anyone to easily get
the same coverage from a user space program. That saves a lot of time
because you don't have to change the kernel, in order to test different
pages and options.
The new sub-test takes advantage of the existing gup_test infrastructure,
which already provides a simple user space program, some allocated user
space pages, an ioctl call, pinning of those pages (via either
get_user_pages or pin_user_pages) and a corresponding kernel-side test
invocation. There's not much more required, mainly just a couple of
inputs from the user.
In fact, the new test re-uses the existing command line options in order
to get various helpful combinations (THP or normal, _fast or slow gup, gup
vs. pup, and more).
New command line options are: which pages to dump, and what type of
"get/pin" to use.
In order to figure out which pages to dump, the logic is:
* If the user doesn't specify anything, the page 0 (the first page in
the address range that the program sets up for testing) is dumped.
* Or, the user can type up to 8 page indices anywhere on the command
line. If you type more than 8, then it uses the first 8 and ignores the
remaining items.
For example:
./gup_test -ct -F 1 0 19 0x1000
Meaning:
-c: dump pages sub-test
-t: use THP pages
-F 1: use pin_user_pages() instead of get_user_pages()
0 19 0x1000: dump pages 0, 19, and 4096
Link: https://lkml.kernel.org/r/20201026064021.3545418-7-jhubbard@nvidia.com
Signed-off-by: John Hubbard <jhubbard@nvidia.com>
Cc: Jérôme Glisse <jglisse@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
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>
2020-12-15 11:05:21 +08:00
|
|
|
case 'F':
|
|
|
|
/* strtol, so you can pass flags in hex form */
|
selftests/vm: gup_test: fix test flag
In gup_test both gup_flags and test_flags use the same flags field.
This is broken.
Farther, in the actual gup_test.c all the passed gup_flags are erased
and unconditionally replaced with FOLL_WRITE.
Which means that test_flags are ignored, and code like this always
performs pin dump test:
155 if (gup->flags & GUP_TEST_FLAG_DUMP_PAGES_USE_PIN)
156 nr = pin_user_pages(addr, nr, gup->flags,
157 pages + i, NULL);
158 else
159 nr = get_user_pages(addr, nr, gup->flags,
160 pages + i, NULL);
161 break;
Add a new test_flags field, to allow raw gup_flags to work. Add a new
subcommand for DUMP_USER_PAGES_TEST to specify that pin test should be
performed.
Remove unconditional overwriting of gup_flags via FOLL_WRITE. But,
preserve the previous behaviour where FOLL_WRITE was the default flag,
and add a new option "-W" to unset FOLL_WRITE.
Rename flags with gup_flags.
With the fix, dump works like this:
root@virtme:/# gup_test -c
---- page #0, starting from user virt addr: 0x7f8acb9e4000
page:00000000d3d2ee27 refcount:2 mapcount:1 mapping:0000000000000000
index:0x0 pfn:0x100bcf
anon flags: 0x300000000080016(referenced|uptodate|lru|swapbacked)
raw: 0300000000080016 ffffd0e204021608 ffffd0e208df2e88 ffff8ea04243ec61
raw: 0000000000000000 0000000000000000 0000000200000000 0000000000000000
page dumped because: gup_test: dump_pages() test
DUMP_USER_PAGES_TEST: done
root@virtme:/# gup_test -c -p
---- page #0, starting from user virt addr: 0x7fd19701b000
page:00000000baed3c7d refcount:1025 mapcount:1 mapping:0000000000000000
index:0x0 pfn:0x108008
anon flags: 0x300000000080014(uptodate|lru|swapbacked)
raw: 0300000000080014 ffffd0e204200188 ffffd0e205e09088 ffff8ea04243ee71
raw: 0000000000000000 0000000000000000 0000040100000000 0000000000000000
page dumped because: gup_test: dump_pages() test
DUMP_USER_PAGES_TEST: done
Refcount shows the difference between pin vs no-pin case.
Also change type of nr from int to long, as it counts number of pages.
Link: https://lkml.kernel.org/r/20210215161349.246722-14-pasha.tatashin@soleen.com
Signed-off-by: Pavel Tatashin <pasha.tatashin@soleen.com>
Reviewed-by: John Hubbard <jhubbard@nvidia.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Ira Weiny <ira.weiny@intel.com>
Cc: James Morris <jmorris@namei.org>
Cc: Jason Gunthorpe <jgg@nvidia.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Sasha Levin <sashal@kernel.org>
Cc: Steven Rostedt (VMware) <rostedt@goodmis.org>
Cc: Tyler Hicks <tyhicks@linux.microsoft.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2021-05-05 09:39:23 +08:00
|
|
|
gup.gup_flags = strtol(optarg, 0, 0);
|
selftests/vm: gup_test: introduce the dump_pages() sub-test
For quite a while, I was doing a quick hack to gup_test.c (previously,
gup_benchmark.c) whenever I wanted to try out my changes to dump_page().
This makes that hack unnecessary, and instead allows anyone to easily get
the same coverage from a user space program. That saves a lot of time
because you don't have to change the kernel, in order to test different
pages and options.
The new sub-test takes advantage of the existing gup_test infrastructure,
which already provides a simple user space program, some allocated user
space pages, an ioctl call, pinning of those pages (via either
get_user_pages or pin_user_pages) and a corresponding kernel-side test
invocation. There's not much more required, mainly just a couple of
inputs from the user.
In fact, the new test re-uses the existing command line options in order
to get various helpful combinations (THP or normal, _fast or slow gup, gup
vs. pup, and more).
New command line options are: which pages to dump, and what type of
"get/pin" to use.
In order to figure out which pages to dump, the logic is:
* If the user doesn't specify anything, the page 0 (the first page in
the address range that the program sets up for testing) is dumped.
* Or, the user can type up to 8 page indices anywhere on the command
line. If you type more than 8, then it uses the first 8 and ignores the
remaining items.
For example:
./gup_test -ct -F 1 0 19 0x1000
Meaning:
-c: dump pages sub-test
-t: use THP pages
-F 1: use pin_user_pages() instead of get_user_pages()
0 19 0x1000: dump pages 0, 19, and 4096
Link: https://lkml.kernel.org/r/20201026064021.3545418-7-jhubbard@nvidia.com
Signed-off-by: John Hubbard <jhubbard@nvidia.com>
Cc: Jérôme Glisse <jglisse@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
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>
2020-12-15 11:05:21 +08:00
|
|
|
break;
|
2021-06-29 10:36:33 +08:00
|
|
|
case 'j':
|
|
|
|
nthreads = atoi(optarg);
|
|
|
|
break;
|
2017-11-18 07:31:22 +08:00
|
|
|
case 'm':
|
|
|
|
size = atoi(optarg) * MB;
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
repeats = atoi(optarg);
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
nr_pages = atoi(optarg);
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
thp = 1;
|
|
|
|
break;
|
|
|
|
case 'T':
|
|
|
|
thp = 0;
|
|
|
|
break;
|
2018-10-27 06:09:56 +08:00
|
|
|
case 'U':
|
2020-12-15 11:05:17 +08:00
|
|
|
cmd = GUP_BASIC_TEST;
|
2018-10-27 06:09:56 +08:00
|
|
|
break;
|
2020-04-02 12:05:41 +08:00
|
|
|
case 'u':
|
|
|
|
cmd = GUP_FAST_BENCHMARK;
|
|
|
|
break;
|
2017-11-18 07:31:22 +08:00
|
|
|
case 'w':
|
|
|
|
write = 1;
|
2018-10-27 06:09:59 +08:00
|
|
|
break;
|
selftests/vm: gup_test: fix test flag
In gup_test both gup_flags and test_flags use the same flags field.
This is broken.
Farther, in the actual gup_test.c all the passed gup_flags are erased
and unconditionally replaced with FOLL_WRITE.
Which means that test_flags are ignored, and code like this always
performs pin dump test:
155 if (gup->flags & GUP_TEST_FLAG_DUMP_PAGES_USE_PIN)
156 nr = pin_user_pages(addr, nr, gup->flags,
157 pages + i, NULL);
158 else
159 nr = get_user_pages(addr, nr, gup->flags,
160 pages + i, NULL);
161 break;
Add a new test_flags field, to allow raw gup_flags to work. Add a new
subcommand for DUMP_USER_PAGES_TEST to specify that pin test should be
performed.
Remove unconditional overwriting of gup_flags via FOLL_WRITE. But,
preserve the previous behaviour where FOLL_WRITE was the default flag,
and add a new option "-W" to unset FOLL_WRITE.
Rename flags with gup_flags.
With the fix, dump works like this:
root@virtme:/# gup_test -c
---- page #0, starting from user virt addr: 0x7f8acb9e4000
page:00000000d3d2ee27 refcount:2 mapcount:1 mapping:0000000000000000
index:0x0 pfn:0x100bcf
anon flags: 0x300000000080016(referenced|uptodate|lru|swapbacked)
raw: 0300000000080016 ffffd0e204021608 ffffd0e208df2e88 ffff8ea04243ec61
raw: 0000000000000000 0000000000000000 0000000200000000 0000000000000000
page dumped because: gup_test: dump_pages() test
DUMP_USER_PAGES_TEST: done
root@virtme:/# gup_test -c -p
---- page #0, starting from user virt addr: 0x7fd19701b000
page:00000000baed3c7d refcount:1025 mapcount:1 mapping:0000000000000000
index:0x0 pfn:0x108008
anon flags: 0x300000000080014(uptodate|lru|swapbacked)
raw: 0300000000080014 ffffd0e204200188 ffffd0e205e09088 ffff8ea04243ee71
raw: 0000000000000000 0000000000000000 0000040100000000 0000000000000000
page dumped because: gup_test: dump_pages() test
DUMP_USER_PAGES_TEST: done
Refcount shows the difference between pin vs no-pin case.
Also change type of nr from int to long, as it counts number of pages.
Link: https://lkml.kernel.org/r/20210215161349.246722-14-pasha.tatashin@soleen.com
Signed-off-by: Pavel Tatashin <pasha.tatashin@soleen.com>
Reviewed-by: John Hubbard <jhubbard@nvidia.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Ira Weiny <ira.weiny@intel.com>
Cc: James Morris <jmorris@namei.org>
Cc: Jason Gunthorpe <jgg@nvidia.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Sasha Levin <sashal@kernel.org>
Cc: Steven Rostedt (VMware) <rostedt@goodmis.org>
Cc: Tyler Hicks <tyhicks@linux.microsoft.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2021-05-05 09:39:23 +08:00
|
|
|
case 'W':
|
|
|
|
write = 0;
|
|
|
|
break;
|
2018-10-27 06:10:02 +08:00
|
|
|
case 'f':
|
|
|
|
file = optarg;
|
|
|
|
break;
|
2018-10-27 06:10:08 +08:00
|
|
|
case 'S':
|
|
|
|
flags &= ~MAP_PRIVATE;
|
|
|
|
flags |= MAP_SHARED;
|
|
|
|
break;
|
2018-10-27 06:10:12 +08:00
|
|
|
case 'H':
|
2019-11-06 13:16:24 +08:00
|
|
|
flags |= (MAP_HUGETLB | MAP_ANONYMOUS);
|
2018-10-27 06:10:12 +08:00
|
|
|
break;
|
2021-05-05 09:39:27 +08:00
|
|
|
case 'z':
|
|
|
|
/* fault pages in gup, do not fault in userland */
|
|
|
|
touch = 1;
|
|
|
|
break;
|
2017-11-18 07:31:22 +08:00
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
selftests/vm: gup_test: introduce the dump_pages() sub-test
For quite a while, I was doing a quick hack to gup_test.c (previously,
gup_benchmark.c) whenever I wanted to try out my changes to dump_page().
This makes that hack unnecessary, and instead allows anyone to easily get
the same coverage from a user space program. That saves a lot of time
because you don't have to change the kernel, in order to test different
pages and options.
The new sub-test takes advantage of the existing gup_test infrastructure,
which already provides a simple user space program, some allocated user
space pages, an ioctl call, pinning of those pages (via either
get_user_pages or pin_user_pages) and a corresponding kernel-side test
invocation. There's not much more required, mainly just a couple of
inputs from the user.
In fact, the new test re-uses the existing command line options in order
to get various helpful combinations (THP or normal, _fast or slow gup, gup
vs. pup, and more).
New command line options are: which pages to dump, and what type of
"get/pin" to use.
In order to figure out which pages to dump, the logic is:
* If the user doesn't specify anything, the page 0 (the first page in
the address range that the program sets up for testing) is dumped.
* Or, the user can type up to 8 page indices anywhere on the command
line. If you type more than 8, then it uses the first 8 and ignores the
remaining items.
For example:
./gup_test -ct -F 1 0 19 0x1000
Meaning:
-c: dump pages sub-test
-t: use THP pages
-F 1: use pin_user_pages() instead of get_user_pages()
0 19 0x1000: dump pages 0, 19, and 4096
Link: https://lkml.kernel.org/r/20201026064021.3545418-7-jhubbard@nvidia.com
Signed-off-by: John Hubbard <jhubbard@nvidia.com>
Cc: Jérôme Glisse <jglisse@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
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>
2020-12-15 11:05:21 +08:00
|
|
|
if (optind < argc) {
|
|
|
|
int extra_arg_count = 0;
|
|
|
|
/*
|
|
|
|
* For example:
|
|
|
|
*
|
|
|
|
* ./gup_test -c 0 1 0x1001
|
|
|
|
*
|
|
|
|
* ...to dump pages 0, 1, and 4097
|
|
|
|
*/
|
|
|
|
|
|
|
|
while ((optind < argc) &&
|
|
|
|
(extra_arg_count < GUP_TEST_MAX_PAGES_TO_DUMP)) {
|
|
|
|
/*
|
|
|
|
* Do the 1-based indexing here, so that the user can
|
|
|
|
* use normal 0-based indexing on the command line.
|
|
|
|
*/
|
|
|
|
long page_index = strtol(argv[optind], 0, 0) + 1;
|
|
|
|
|
|
|
|
gup.which_pages[extra_arg_count] = page_index;
|
|
|
|
extra_arg_count++;
|
|
|
|
optind++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-27 06:10:02 +08:00
|
|
|
filed = open(file, O_RDWR|O_CREAT);
|
|
|
|
if (filed < 0) {
|
|
|
|
perror("open");
|
|
|
|
exit(filed);
|
|
|
|
}
|
|
|
|
|
2017-11-18 07:31:22 +08:00
|
|
|
gup.nr_pages_per_call = nr_pages;
|
2020-01-31 14:13:32 +08:00
|
|
|
if (write)
|
selftests/vm: gup_test: fix test flag
In gup_test both gup_flags and test_flags use the same flags field.
This is broken.
Farther, in the actual gup_test.c all the passed gup_flags are erased
and unconditionally replaced with FOLL_WRITE.
Which means that test_flags are ignored, and code like this always
performs pin dump test:
155 if (gup->flags & GUP_TEST_FLAG_DUMP_PAGES_USE_PIN)
156 nr = pin_user_pages(addr, nr, gup->flags,
157 pages + i, NULL);
158 else
159 nr = get_user_pages(addr, nr, gup->flags,
160 pages + i, NULL);
161 break;
Add a new test_flags field, to allow raw gup_flags to work. Add a new
subcommand for DUMP_USER_PAGES_TEST to specify that pin test should be
performed.
Remove unconditional overwriting of gup_flags via FOLL_WRITE. But,
preserve the previous behaviour where FOLL_WRITE was the default flag,
and add a new option "-W" to unset FOLL_WRITE.
Rename flags with gup_flags.
With the fix, dump works like this:
root@virtme:/# gup_test -c
---- page #0, starting from user virt addr: 0x7f8acb9e4000
page:00000000d3d2ee27 refcount:2 mapcount:1 mapping:0000000000000000
index:0x0 pfn:0x100bcf
anon flags: 0x300000000080016(referenced|uptodate|lru|swapbacked)
raw: 0300000000080016 ffffd0e204021608 ffffd0e208df2e88 ffff8ea04243ec61
raw: 0000000000000000 0000000000000000 0000000200000000 0000000000000000
page dumped because: gup_test: dump_pages() test
DUMP_USER_PAGES_TEST: done
root@virtme:/# gup_test -c -p
---- page #0, starting from user virt addr: 0x7fd19701b000
page:00000000baed3c7d refcount:1025 mapcount:1 mapping:0000000000000000
index:0x0 pfn:0x108008
anon flags: 0x300000000080014(uptodate|lru|swapbacked)
raw: 0300000000080014 ffffd0e204200188 ffffd0e205e09088 ffff8ea04243ee71
raw: 0000000000000000 0000000000000000 0000040100000000 0000000000000000
page dumped because: gup_test: dump_pages() test
DUMP_USER_PAGES_TEST: done
Refcount shows the difference between pin vs no-pin case.
Also change type of nr from int to long, as it counts number of pages.
Link: https://lkml.kernel.org/r/20210215161349.246722-14-pasha.tatashin@soleen.com
Signed-off-by: Pavel Tatashin <pasha.tatashin@soleen.com>
Reviewed-by: John Hubbard <jhubbard@nvidia.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Ira Weiny <ira.weiny@intel.com>
Cc: James Morris <jmorris@namei.org>
Cc: Jason Gunthorpe <jgg@nvidia.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Sasha Levin <sashal@kernel.org>
Cc: Steven Rostedt (VMware) <rostedt@goodmis.org>
Cc: Tyler Hicks <tyhicks@linux.microsoft.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2021-05-05 09:39:23 +08:00
|
|
|
gup.gup_flags |= FOLL_WRITE;
|
2017-11-18 07:31:22 +08:00
|
|
|
|
2022-06-10 04:32:17 +08:00
|
|
|
gup_fd = open(GUP_TEST_FILE, O_RDWR);
|
2021-06-29 10:36:33 +08:00
|
|
|
if (gup_fd == -1) {
|
2022-04-29 14:16:10 +08:00
|
|
|
switch (errno) {
|
|
|
|
case EACCES:
|
|
|
|
if (getuid())
|
|
|
|
printf("Please run this test as root\n");
|
|
|
|
break;
|
|
|
|
case ENOENT:
|
|
|
|
if (opendir("/sys/kernel/debug") == NULL) {
|
|
|
|
printf("mount debugfs at /sys/kernel/debug\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
printf("check if CONFIG_GUP_TEST is enabled in kernel config\n");
|
|
|
|
break;
|
|
|
|
default:
|
2022-06-10 04:32:17 +08:00
|
|
|
perror("failed to open " GUP_TEST_FILE);
|
2022-04-29 14:16:10 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
exit(KSFT_SKIP);
|
2020-08-25 12:56:26 +08:00
|
|
|
}
|
2017-11-18 07:31:22 +08:00
|
|
|
|
2018-10-27 06:10:08 +08:00
|
|
|
p = mmap(NULL, size, PROT_READ | PROT_WRITE, flags, filed, 0);
|
2020-08-25 12:56:26 +08:00
|
|
|
if (p == MAP_FAILED) {
|
|
|
|
perror("mmap");
|
|
|
|
exit(1);
|
|
|
|
}
|
2017-11-18 07:31:22 +08:00
|
|
|
gup.addr = (unsigned long)p;
|
|
|
|
|
|
|
|
if (thp == 1)
|
|
|
|
madvise(p, size, MADV_HUGEPAGE);
|
|
|
|
else if (thp == 0)
|
|
|
|
madvise(p, size, MADV_NOHUGEPAGE);
|
|
|
|
|
2021-05-05 09:39:27 +08:00
|
|
|
/*
|
|
|
|
* FOLL_TOUCH, in gup_test, is used as an either/or case: either
|
|
|
|
* fault pages in from the kernel via FOLL_TOUCH, or fault them
|
|
|
|
* in here, from user space. This allows comparison of performance
|
|
|
|
* between those two cases.
|
|
|
|
*/
|
|
|
|
if (touch) {
|
|
|
|
gup.gup_flags |= FOLL_TOUCH;
|
|
|
|
} else {
|
2023-04-13 00:41:20 +08:00
|
|
|
for (; (unsigned long)p < gup.addr + size; p += psize())
|
2021-05-05 09:39:27 +08:00
|
|
|
p[0] = 0;
|
|
|
|
}
|
2017-11-18 07:31:22 +08:00
|
|
|
|
2021-06-29 10:36:33 +08:00
|
|
|
tid = malloc(sizeof(pthread_t) * nthreads);
|
|
|
|
assert(tid);
|
|
|
|
for (i = 0; i < nthreads; i++) {
|
|
|
|
ret = pthread_create(&tid[i], NULL, gup_thread, &gup);
|
|
|
|
assert(ret == 0);
|
|
|
|
}
|
|
|
|
for (i = 0; i < nthreads; i++) {
|
|
|
|
ret = pthread_join(tid[i], NULL);
|
|
|
|
assert(ret == 0);
|
2017-11-18 07:31:22 +08:00
|
|
|
}
|
2021-06-29 10:36:33 +08:00
|
|
|
free(tid);
|
2017-11-18 07:31:22 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|