Skip to content

Commit

Permalink
mm: gup: use get_user_pages_unlocked within get_user_pages_fast
Browse files Browse the repository at this point in the history
This allows the get_user_pages_fast slow path to release the mmap_sem
before blocking.

Signed-off-by: Andrea Arcangeli <[email protected]>
Reviewed-by: Kirill A. Shutemov <[email protected]>
Cc: Andres Lagar-Cavilla <[email protected]>
Cc: Peter Feiner <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
aagit authored and torvalds committed Feb 12, 2015
1 parent 0fd71a5 commit a7b7807
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 33 deletions.
8 changes: 3 additions & 5 deletions arch/mips/mm/gup.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,9 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
start += nr << PAGE_SHIFT;
pages += nr;

down_read(&mm->mmap_sem);
ret = get_user_pages(current, mm, start,
(end - start) >> PAGE_SHIFT,
write, 0, pages, NULL);
up_read(&mm->mmap_sem);
ret = get_user_pages_unlocked(current, mm, start,
(end - start) >> PAGE_SHIFT,
write, 0, pages);

/* Have to be a bit careful with return values */
if (nr > 0) {
Expand Down
6 changes: 2 additions & 4 deletions arch/s390/mm/gup.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,8 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
/* Try to get the remaining pages with get_user_pages */
start += nr << PAGE_SHIFT;
pages += nr;
down_read(&mm->mmap_sem);
ret = get_user_pages(current, mm, start,
nr_pages - nr, write, 0, pages, NULL);
up_read(&mm->mmap_sem);
ret = get_user_pages_unlocked(current, mm, start,
nr_pages - nr, write, 0, pages);
/* Have to be a bit careful with return values */
if (nr > 0)
ret = (ret < 0) ? nr : ret + nr;
Expand Down
6 changes: 2 additions & 4 deletions arch/sh/mm/gup.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,8 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
start += nr << PAGE_SHIFT;
pages += nr;

down_read(&mm->mmap_sem);
ret = get_user_pages(current, mm, start,
(end - start) >> PAGE_SHIFT, write, 0, pages, NULL);
up_read(&mm->mmap_sem);
ret = get_user_pages_unlocked(current, mm, start,
(end - start) >> PAGE_SHIFT, write, 0, pages);

/* Have to be a bit careful with return values */
if (nr > 0) {
Expand Down
6 changes: 2 additions & 4 deletions arch/sparc/mm/gup.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,8 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
start += nr << PAGE_SHIFT;
pages += nr;

down_read(&mm->mmap_sem);
ret = get_user_pages(current, mm, start,
(end - start) >> PAGE_SHIFT, write, 0, pages, NULL);
up_read(&mm->mmap_sem);
ret = get_user_pages_unlocked(current, mm, start,
(end - start) >> PAGE_SHIFT, write, 0, pages);

/* Have to be a bit careful with return values */
if (nr > 0) {
Expand Down
7 changes: 3 additions & 4 deletions arch/x86/mm/gup.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,10 +388,9 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
start += nr << PAGE_SHIFT;
pages += nr;

down_read(&mm->mmap_sem);
ret = get_user_pages(current, mm, start,
(end - start) >> PAGE_SHIFT, write, 0, pages, NULL);
up_read(&mm->mmap_sem);
ret = get_user_pages_unlocked(current, mm, start,
(end - start) >> PAGE_SHIFT,
write, 0, pages);

/* Have to be a bit careful with return values */
if (nr > 0) {
Expand Down
6 changes: 2 additions & 4 deletions mm/gup.c
Original file line number Diff line number Diff line change
Expand Up @@ -1243,10 +1243,8 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
start += nr << PAGE_SHIFT;
pages += nr;

down_read(&mm->mmap_sem);
ret = get_user_pages(current, mm, start,
nr_pages - nr, write, 0, pages, NULL);
up_read(&mm->mmap_sem);
ret = get_user_pages_unlocked(current, mm, start,
nr_pages - nr, write, 0, pages);

/* Have to be a bit careful with return values */
if (nr > 0) {
Expand Down
10 changes: 2 additions & 8 deletions mm/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,8 @@ int __weak get_user_pages_fast(unsigned long start,
int nr_pages, int write, struct page **pages)
{
struct mm_struct *mm = current->mm;
int ret;

down_read(&mm->mmap_sem);
ret = get_user_pages(current, mm, start, nr_pages,
write, 0, pages, NULL);
up_read(&mm->mmap_sem);

return ret;
return get_user_pages_unlocked(current, mm, start, nr_pages,
write, 0, pages);
}
EXPORT_SYMBOL_GPL(get_user_pages_fast);

Expand Down

0 comments on commit a7b7807

Please sign in to comment.