IB/umem: use get_user_pages_fast() to pin DMA pages
Subsystems (2)
cover IB/umem: use get_user_pages_fast() to pin DMA pages
Hi Jason, Andrew,
Jason: Here is the change to get_user_pages_fast(), that you requested during the review of "mm/gup: track dma-pinned pages: FOLL_PIN, FOLL_LONGTERM" [1].
This is a stand-alone patch that applies to today's 5.4.0-rc6 linux.git.
If anyone could please provide any run-time testing (and of course, Reviewed-by's), that would be huge. I've compiled and run it, but bpftrace tells me (as I already knew) that my current anemic IB setup is not actually exercising this code path.
Andrew: unless instructed otherwise, I plan to also re-post this as part of the next (v3) version of [1], and hopefully have the whole series go through your tree. That would avoid merge conflicts, and as I understand it, there is no particular urgency for this patch, so we might as well do it the easy way.
John Hubbard (1):
IB/umem: use get_user_pages_fast() to pin DMA pages
drivers/infiniband/core/umem.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-)
Signature · 1 line
2.24.0
PATCH 1/1 IB/umem: use get_user_pages_fast() to pin DMA pages
And get rid of the mmap_sem calls, as part of that. Note that get_user_pages_fast() will, if necessary, fall back to __gup_longterm_unlocked(), which takes the mmap_sem as needed.
--- drivers/infiniband/core/umem.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-)
drivers/infiniband/core/umem.c +6 -11
@@ -271,16 +271,13 @@ struct ib_umem *ib_umem_get(struct ib_udata *udata, unsigned long addr, sg = umem->sg_head.sgl;while (npages) { -down_read (&mm->mmap_sem); - ret =get_user_pages (cur_base, - min_t(unsigned long, npages, -PAGE_SIZE /sizeof (struct page *)), - gup_flags |FOLL_LONGTERM , - page_list,NULL ); -if (ret <0 ) { -up_read (&mm->mmap_sem); + ret =get_user_pages_fast (cur_base, + min_t(unsigned long, npages, +PAGE_SIZE / +sizeof (struct page *)), + gup_flags |FOLL_LONGTERM , page_list); +if (ret <0 ) goto umem_release; - } cur_base += ret *PAGE_SIZE ; npages -= ret;
@@ -288,8 +285,6 @@ struct ib_umem *ib_umem_get(struct ib_udata *udata, unsigned long addr, sg =ib_umem_add_sg_table (sg, page_list, ret,dma_get_max_seg_size (context->device->dma_device), &umem->sg_nents); - -up_read (&mm->mmap_sem); }sg_mark_end (sg);
Signature · 1 line
2.24.0
Quoted 6 lines · John Hubbard
And get rid of the
mmap_semcalls, as part of that. Note thatget_user_pages_fast()will, if necessary, fall back to__gup_longterm_unlocked(), which takes themmap_semas needed.Cc Jason Gunthorpe <[email protected]>Cc Ira Weiny <[email protected]>
Quoted 44 lines
Signed-off-by John Hubbard <[email protected]>--- drivers/infiniband/core/umem.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-)drivers/infiniband/core/umem.c +6
-11@@ -271,16 +271,13 @@ struct ib_umem *ib_umem_get(struct ib_udata *udata, unsigned long addr, sg = umem->sg_head.sgl;while (npages) { -down_read (&mm->mmap_sem); - ret =get_user_pages (cur_base, - min_t(unsigned long, npages, -PAGE_SIZE /sizeof (struct page *)), - gup_flags |FOLL_LONGTERM , - page_list,NULL ); -if (ret <0 ) { -up_read (&mm->mmap_sem); + ret =get_user_pages_fast (cur_base, + min_t(unsigned long, npages, +PAGE_SIZE / +sizeof (struct page *)), + gup_flags |FOLL_LONGTERM , page_list); +if (ret <0 ) goto umem_release; - } cur_base += ret *PAGE_SIZE ; npages -= ret;@@ -288,8 +285,6 @@ struct ib_umem *ib_umem_get(struct ib_udata *udata, unsigned long addr, sg =ib_umem_add_sg_table (sg, page_list, ret,dma_get_max_seg_size (context->device->dma_device), &umem->sg_nents); - -up_read (&mm->mmap_sem); }sg_mark_end (sg);Signature · 1 line
2.24.0
Quoted 10 lines · Ira Weiny
Quoted 6 lines · John Hubbard
And get rid of the
mmap_semcalls, as part of that. Note thatget_user_pages_fast()will, if necessary, fall back to__gup_longterm_unlocked(), which takes themmap_semas needed.Cc Jason Gunthorpe <[email protected]>Cc Ira Weiny <[email protected]>Reviewed-by Ira Weiny <[email protected]>
Thanks for the review, Ira! This will show up shortly, in the v3 series of "mm/gup: track dma-pinned pages: FOLL_PIN, FOLL_LONGTERM".
thanks,
Signature · 2 lines
John Hubbard NVIDIA
Quoted 45 lines
Quoted 44 lines
Signed-off-by John Hubbard <[email protected]>--- drivers/infiniband/core/umem.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-)drivers/infiniband/core/umem.c +6
-11@@ -271,16 +271,13 @@ struct ib_umem *ib_umem_get(struct ib_udata *udata, unsigned long addr, sg = umem->sg_head.sgl;while (npages) { -down_read (&mm->mmap_sem); - ret =get_user_pages (cur_base, - min_t(unsigned long, npages, -PAGE_SIZE /sizeof (struct page *)), - gup_flags |FOLL_LONGTERM , - page_list,NULL ); -if (ret <0 ) { -up_read (&mm->mmap_sem); + ret =get_user_pages_fast (cur_base, + min_t(unsigned long, npages, +PAGE_SIZE / +sizeof (struct page *)), + gup_flags |FOLL_LONGTERM , page_list); +if (ret <0 ) goto umem_release; - } cur_base += ret *PAGE_SIZE ; npages -= ret;@@ -288,8 +285,6 @@ struct ib_umem *ib_umem_get(struct ib_udata *udata, unsigned long addr, sg =ib_umem_add_sg_table (sg, page_list, ret,dma_get_max_seg_size (context->device->dma_device), &umem->sg_nents); - -up_read (&mm->mmap_sem); }sg_mark_end (sg);Signature · 1 line
2.24.0
Quoted 10 lines · John Hubbard
And get rid of the
mmap_semcalls, as part of that. Note thatget_user_pages_fast()will, if necessary, fall back to__gup_longterm_unlocked(), which takes themmap_semas needed.Cc Jason Gunthorpe <[email protected]>Cc Ira Weiny <[email protected]>Signed-off-by John Hubbard <[email protected]>--- drivers/infiniband/core/umem.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-)
This can go through Andrew's tree if he takes this larger series, otherwise I'll grab it
Thanks,
Jason