Re: [PATCH 2/4] mm: introduce put_user_page(), placeholder version
On 10/3/18 9:22 AM, Jan Kara wrote: > On Thu 27-09-18 22:39:48, john.hubb...@gmail.com wrote: >> From: John Hubbard >> >> Introduces put_user_page(), which simply calls put_page(). >> This provides a way to update all get_user_pages*() callers, >> so that they call put_user_page(), instead of put_page(). >> >> Also adds release_user_pages(), a drop-in replacement for >> release_pages(). This is intended to be easily grep-able, >> for later performance improvements, since release_user_pages >> is not batched like release_pages() is, and is significantly >> slower. > > A small nit but can we maybe call this put_user_pages() for symmetry with > put_user_page()? I don't really care too much but it would look natural to > me. > Sure. It started out as "make it a drop-in replacement for release_pages()", but now it's not quite a drop-in replacement anymore. And in any case it's an opportunity to make the name more intuitive, so that seems like a good idea. If anyone hates put_user_pages() and wants to campaign relentlessly for release_pages*(), then now is the time! :) thanks, -- John Hubbard NVIDIA
Re: [PATCH 2/4] mm: introduce put_user_page(), placeholder version
On 10/3/18 9:22 AM, Jan Kara wrote: > On Thu 27-09-18 22:39:48, john.hubb...@gmail.com wrote: >> From: John Hubbard >> >> Introduces put_user_page(), which simply calls put_page(). >> This provides a way to update all get_user_pages*() callers, >> so that they call put_user_page(), instead of put_page(). >> >> Also adds release_user_pages(), a drop-in replacement for >> release_pages(). This is intended to be easily grep-able, >> for later performance improvements, since release_user_pages >> is not batched like release_pages() is, and is significantly >> slower. > > A small nit but can we maybe call this put_user_pages() for symmetry with > put_user_page()? I don't really care too much but it would look natural to > me. > Sure. It started out as "make it a drop-in replacement for release_pages()", but now it's not quite a drop-in replacement anymore. And in any case it's an opportunity to make the name more intuitive, so that seems like a good idea. If anyone hates put_user_pages() and wants to campaign relentlessly for release_pages*(), then now is the time! :) thanks, -- John Hubbard NVIDIA
Re: [PATCH 2/4] mm: introduce put_user_page(), placeholder version
On Thu 27-09-18 22:39:48, john.hubb...@gmail.com wrote: > From: John Hubbard > > Introduces put_user_page(), which simply calls put_page(). > This provides a way to update all get_user_pages*() callers, > so that they call put_user_page(), instead of put_page(). > > Also adds release_user_pages(), a drop-in replacement for > release_pages(). This is intended to be easily grep-able, > for later performance improvements, since release_user_pages > is not batched like release_pages() is, and is significantly > slower. A small nit but can we maybe call this put_user_pages() for symmetry with put_user_page()? I don't really care too much but it would look natural to me. Honza -- Jan Kara SUSE Labs, CR
Re: [PATCH 2/4] mm: introduce put_user_page(), placeholder version
On Thu 27-09-18 22:39:48, john.hubb...@gmail.com wrote: > From: John Hubbard > > Introduces put_user_page(), which simply calls put_page(). > This provides a way to update all get_user_pages*() callers, > so that they call put_user_page(), instead of put_page(). > > Also adds release_user_pages(), a drop-in replacement for > release_pages(). This is intended to be easily grep-able, > for later performance improvements, since release_user_pages > is not batched like release_pages() is, and is significantly > slower. A small nit but can we maybe call this put_user_pages() for symmetry with put_user_page()? I don't really care too much but it would look natural to me. Honza -- Jan Kara SUSE Labs, CR
[PATCH 2/4] mm: introduce put_user_page(), placeholder version
From: John Hubbard Introduces put_user_page(), which simply calls put_page(). This provides a way to update all get_user_pages*() callers, so that they call put_user_page(), instead of put_page(). Also adds release_user_pages(), a drop-in replacement for release_pages(). This is intended to be easily grep-able, for later performance improvements, since release_user_pages is not batched like release_pages() is, and is significantly slower. Also: rename goldfish_pipe.c's release_user_pages(), in order to avoid a naming conflict with the new external function of the same name. This prepares for eventually fixing the problem described in [1], and is following a plan listed in [2]. [1] https://lwn.net/Articles/753027/ : "The Trouble with get_user_pages()" [2] https://lkml.kernel.org/r/20180709080554.21931-1-jhubb...@nvidia.com Proposed steps for fixing get_user_pages() + DMA problems. CC: Matthew Wilcox CC: Michal Hocko CC: Christopher Lameter CC: Jason Gunthorpe CC: Dan Williams CC: Jan Kara CC: Al Viro Signed-off-by: John Hubbard --- drivers/platform/goldfish/goldfish_pipe.c | 4 ++-- include/linux/mm.h| 14 ++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/drivers/platform/goldfish/goldfish_pipe.c b/drivers/platform/goldfish/goldfish_pipe.c index 2da567540c2d..fad0345376e0 100644 --- a/drivers/platform/goldfish/goldfish_pipe.c +++ b/drivers/platform/goldfish/goldfish_pipe.c @@ -332,7 +332,7 @@ static int pin_user_pages(unsigned long first_page, unsigned long last_page, } -static void release_user_pages(struct page **pages, int pages_count, +static void __release_user_pages(struct page **pages, int pages_count, int is_write, s32 consumed_size) { int i; @@ -410,7 +410,7 @@ static int transfer_max_buffers(struct goldfish_pipe *pipe, *consumed_size = pipe->command_buffer->rw_params.consumed_size; - release_user_pages(pages, pages_count, is_write, *consumed_size); + __release_user_pages(pages, pages_count, is_write, *consumed_size); mutex_unlock(>lock); diff --git a/include/linux/mm.h b/include/linux/mm.h index a61ebe8ad4ca..72caf803115f 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -943,6 +943,20 @@ static inline void put_page(struct page *page) __put_page(page); } +/* Placeholder version, until all get_user_pages*() callers are updated. */ +static inline void put_user_page(struct page *page) +{ + put_page(page); +} + +/* A drop-in replacement for release_pages(): */ +static inline void release_user_pages(struct page **pages, + unsigned long npages) +{ + while (npages) + put_user_page(pages[--npages]); +} + #if defined(CONFIG_SPARSEMEM) && !defined(CONFIG_SPARSEMEM_VMEMMAP) #define SECTION_IN_PAGE_FLAGS #endif -- 2.19.0
[PATCH 2/4] mm: introduce put_user_page(), placeholder version
From: John Hubbard Introduces put_user_page(), which simply calls put_page(). This provides a way to update all get_user_pages*() callers, so that they call put_user_page(), instead of put_page(). Also adds release_user_pages(), a drop-in replacement for release_pages(). This is intended to be easily grep-able, for later performance improvements, since release_user_pages is not batched like release_pages() is, and is significantly slower. Also: rename goldfish_pipe.c's release_user_pages(), in order to avoid a naming conflict with the new external function of the same name. This prepares for eventually fixing the problem described in [1], and is following a plan listed in [2]. [1] https://lwn.net/Articles/753027/ : "The Trouble with get_user_pages()" [2] https://lkml.kernel.org/r/20180709080554.21931-1-jhubb...@nvidia.com Proposed steps for fixing get_user_pages() + DMA problems. CC: Matthew Wilcox CC: Michal Hocko CC: Christopher Lameter CC: Jason Gunthorpe CC: Dan Williams CC: Jan Kara CC: Al Viro Signed-off-by: John Hubbard --- drivers/platform/goldfish/goldfish_pipe.c | 4 ++-- include/linux/mm.h| 14 ++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/drivers/platform/goldfish/goldfish_pipe.c b/drivers/platform/goldfish/goldfish_pipe.c index 2da567540c2d..fad0345376e0 100644 --- a/drivers/platform/goldfish/goldfish_pipe.c +++ b/drivers/platform/goldfish/goldfish_pipe.c @@ -332,7 +332,7 @@ static int pin_user_pages(unsigned long first_page, unsigned long last_page, } -static void release_user_pages(struct page **pages, int pages_count, +static void __release_user_pages(struct page **pages, int pages_count, int is_write, s32 consumed_size) { int i; @@ -410,7 +410,7 @@ static int transfer_max_buffers(struct goldfish_pipe *pipe, *consumed_size = pipe->command_buffer->rw_params.consumed_size; - release_user_pages(pages, pages_count, is_write, *consumed_size); + __release_user_pages(pages, pages_count, is_write, *consumed_size); mutex_unlock(>lock); diff --git a/include/linux/mm.h b/include/linux/mm.h index a61ebe8ad4ca..72caf803115f 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -943,6 +943,20 @@ static inline void put_page(struct page *page) __put_page(page); } +/* Placeholder version, until all get_user_pages*() callers are updated. */ +static inline void put_user_page(struct page *page) +{ + put_page(page); +} + +/* A drop-in replacement for release_pages(): */ +static inline void release_user_pages(struct page **pages, + unsigned long npages) +{ + while (npages) + put_user_page(pages[--npages]); +} + #if defined(CONFIG_SPARSEMEM) && !defined(CONFIG_SPARSEMEM_VMEMMAP) #define SECTION_IN_PAGE_FLAGS #endif -- 2.19.0