Commit 657d4f79 authored by Barry Song's avatar Barry Song Committed by Linus Torvalds

mm/gup_benchmark: use pin_user_pages for FOLL_LONGTERM flag

According to Documentation/core-api/pin_user_pages.rst, FOLL_PIN is a
prerequisite to FOLL_LONGTERM.  Another way of saying that is,
FOLL_LONGTERM is a specific case, more restrictive case of FOLL_PIN.

Almost all kernel modules are using pin_user_pages() with FOLL_LONGTERM,
mm/gup_benchmark.c seems to the only exception in which FOLL_PIN is not a
prerequisite to FOLL_LONGTERM.
Signed-off-by: default avatarBarry Song <song.bao.hua@hisilicon.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Reviewed-by: default avatarJohn Hubbard <jhubbard@nvidia.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Jérôme Glisse <jglisse@redhat.com>
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Dave Chinner <david@fromorbit.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Vlastimil Babka <vbabka@suse.cz>
Link: http://lkml.kernel.org/r/20200815122056.29508-1-song.bao.hua@hisilicon.comSigned-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 4c6cd03e
...@@ -6,10 +6,10 @@ ...@@ -6,10 +6,10 @@
#include <linux/debugfs.h> #include <linux/debugfs.h>
#define GUP_FAST_BENCHMARK _IOWR('g', 1, struct gup_benchmark) #define GUP_FAST_BENCHMARK _IOWR('g', 1, struct gup_benchmark)
#define GUP_LONGTERM_BENCHMARK _IOWR('g', 2, struct gup_benchmark) #define GUP_BENCHMARK _IOWR('g', 2, struct gup_benchmark)
#define GUP_BENCHMARK _IOWR('g', 3, struct gup_benchmark) #define PIN_FAST_BENCHMARK _IOWR('g', 3, struct gup_benchmark)
#define PIN_FAST_BENCHMARK _IOWR('g', 4, struct gup_benchmark) #define PIN_BENCHMARK _IOWR('g', 4, struct gup_benchmark)
#define PIN_BENCHMARK _IOWR('g', 5, struct gup_benchmark) #define PIN_LONGTERM_BENCHMARK _IOWR('g', 5, struct gup_benchmark)
struct gup_benchmark { struct gup_benchmark {
__u64 get_delta_usec; __u64 get_delta_usec;
...@@ -28,7 +28,6 @@ static void put_back_pages(unsigned int cmd, struct page **pages, ...@@ -28,7 +28,6 @@ static void put_back_pages(unsigned int cmd, struct page **pages,
switch (cmd) { switch (cmd) {
case GUP_FAST_BENCHMARK: case GUP_FAST_BENCHMARK:
case GUP_LONGTERM_BENCHMARK:
case GUP_BENCHMARK: case GUP_BENCHMARK:
for (i = 0; i < nr_pages; i++) for (i = 0; i < nr_pages; i++)
put_page(pages[i]); put_page(pages[i]);
...@@ -36,6 +35,7 @@ static void put_back_pages(unsigned int cmd, struct page **pages, ...@@ -36,6 +35,7 @@ static void put_back_pages(unsigned int cmd, struct page **pages,
case PIN_FAST_BENCHMARK: case PIN_FAST_BENCHMARK:
case PIN_BENCHMARK: case PIN_BENCHMARK:
case PIN_LONGTERM_BENCHMARK:
unpin_user_pages(pages, nr_pages); unpin_user_pages(pages, nr_pages);
break; break;
} }
...@@ -50,6 +50,7 @@ static void verify_dma_pinned(unsigned int cmd, struct page **pages, ...@@ -50,6 +50,7 @@ static void verify_dma_pinned(unsigned int cmd, struct page **pages,
switch (cmd) { switch (cmd) {
case PIN_FAST_BENCHMARK: case PIN_FAST_BENCHMARK:
case PIN_BENCHMARK: case PIN_BENCHMARK:
case PIN_LONGTERM_BENCHMARK:
for (i = 0; i < nr_pages; i++) { for (i = 0; i < nr_pages; i++) {
page = pages[i]; page = pages[i];
if (WARN(!page_maybe_dma_pinned(page), if (WARN(!page_maybe_dma_pinned(page),
...@@ -101,11 +102,6 @@ static int __gup_benchmark_ioctl(unsigned int cmd, ...@@ -101,11 +102,6 @@ static int __gup_benchmark_ioctl(unsigned int cmd,
nr = get_user_pages_fast(addr, nr, gup->flags, nr = get_user_pages_fast(addr, nr, gup->flags,
pages + i); pages + i);
break; break;
case GUP_LONGTERM_BENCHMARK:
nr = get_user_pages(addr, nr,
gup->flags | FOLL_LONGTERM,
pages + i, NULL);
break;
case GUP_BENCHMARK: case GUP_BENCHMARK:
nr = get_user_pages(addr, nr, gup->flags, pages + i, nr = get_user_pages(addr, nr, gup->flags, pages + i,
NULL); NULL);
...@@ -118,6 +114,11 @@ static int __gup_benchmark_ioctl(unsigned int cmd, ...@@ -118,6 +114,11 @@ static int __gup_benchmark_ioctl(unsigned int cmd,
nr = pin_user_pages(addr, nr, gup->flags, pages + i, nr = pin_user_pages(addr, nr, gup->flags, pages + i,
NULL); NULL);
break; break;
case PIN_LONGTERM_BENCHMARK:
nr = pin_user_pages(addr, nr,
gup->flags | FOLL_LONGTERM,
pages + i, NULL);
break;
default: default:
kvfree(pages); kvfree(pages);
ret = -EINVAL; ret = -EINVAL;
...@@ -162,10 +163,10 @@ static long gup_benchmark_ioctl(struct file *filep, unsigned int cmd, ...@@ -162,10 +163,10 @@ static long gup_benchmark_ioctl(struct file *filep, unsigned int cmd,
switch (cmd) { switch (cmd) {
case GUP_FAST_BENCHMARK: case GUP_FAST_BENCHMARK:
case GUP_LONGTERM_BENCHMARK:
case GUP_BENCHMARK: case GUP_BENCHMARK:
case PIN_FAST_BENCHMARK: case PIN_FAST_BENCHMARK:
case PIN_BENCHMARK: case PIN_BENCHMARK:
case PIN_LONGTERM_BENCHMARK:
break; break;
default: default:
return -EINVAL; return -EINVAL;
......
...@@ -15,12 +15,12 @@ ...@@ -15,12 +15,12 @@
#define PAGE_SIZE sysconf(_SC_PAGESIZE) #define PAGE_SIZE sysconf(_SC_PAGESIZE)
#define GUP_FAST_BENCHMARK _IOWR('g', 1, struct gup_benchmark) #define GUP_FAST_BENCHMARK _IOWR('g', 1, struct gup_benchmark)
#define GUP_LONGTERM_BENCHMARK _IOWR('g', 2, struct gup_benchmark) #define GUP_BENCHMARK _IOWR('g', 2, struct gup_benchmark)
#define GUP_BENCHMARK _IOWR('g', 3, struct gup_benchmark)
/* Similar to above, but use FOLL_PIN instead of FOLL_GET. */ /* Similar to above, but use FOLL_PIN instead of FOLL_GET. */
#define PIN_FAST_BENCHMARK _IOWR('g', 4, struct gup_benchmark) #define PIN_FAST_BENCHMARK _IOWR('g', 3, struct gup_benchmark)
#define PIN_BENCHMARK _IOWR('g', 5, struct gup_benchmark) #define PIN_BENCHMARK _IOWR('g', 4, struct gup_benchmark)
#define PIN_LONGTERM_BENCHMARK _IOWR('g', 5, struct gup_benchmark)
/* Just the flags we need, copied from mm.h: */ /* Just the flags we need, copied from mm.h: */
#define FOLL_WRITE 0x01 /* check pte is writable */ #define FOLL_WRITE 0x01 /* check pte is writable */
...@@ -52,6 +52,9 @@ int main(int argc, char **argv) ...@@ -52,6 +52,9 @@ int main(int argc, char **argv)
case 'b': case 'b':
cmd = PIN_BENCHMARK; cmd = PIN_BENCHMARK;
break; break;
case 'L':
cmd = PIN_LONGTERM_BENCHMARK;
break;
case 'm': case 'm':
size = atoi(optarg) * MB; size = atoi(optarg) * MB;
break; break;
...@@ -67,9 +70,6 @@ int main(int argc, char **argv) ...@@ -67,9 +70,6 @@ int main(int argc, char **argv)
case 'T': case 'T':
thp = 0; thp = 0;
break; break;
case 'L':
cmd = GUP_LONGTERM_BENCHMARK;
break;
case 'U': case 'U':
cmd = GUP_BENCHMARK; cmd = GUP_BENCHMARK;
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment