diff mbox series

[06/17] mm/filemap: Don't call ->readpage if IOCB_WAITQ is set

Message ID 20201102184312.25926-7-willy@infradead.org (mailing list archive)
State New, archived
Headers show
Series Refactor generic_file_buffered_read | expand

Commit Message

Matthew Wilcox Nov. 2, 2020, 6:43 p.m. UTC
The readpage operation can block in many (most?) filesystems, so we
should punt to a work queue instead of calling it.  This was the last
caller of lock_page_async(), so remove it.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 mm/filemap.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)

Comments

Kent Overstreet Nov. 2, 2020, 7:17 p.m. UTC | #1
On Mon, Nov 02, 2020 at 06:43:01PM +0000, Matthew Wilcox (Oracle) wrote:
> The readpage operation can block in many (most?) filesystems, so we
> should punt to a work queue instead of calling it.  This was the last
> caller of lock_page_async(), so remove it.
> 
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>

Reviewed-by: Kent Overstreet <kent.overstreet@gmail.com>
Christoph Hellwig Nov. 3, 2020, 7:31 a.m. UTC | #2
On Mon, Nov 02, 2020 at 06:43:01PM +0000, Matthew Wilcox (Oracle) wrote:
> The readpage operation can block in many (most?) filesystems, so we
> should punt to a work queue instead of calling it.  This was the last
> caller of lock_page_async(), so remove it.
> 
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>
Nikolay Borisov Nov. 5, 2020, 7:22 a.m. UTC | #3
On 2.11.20 г. 20:43 ч., Matthew Wilcox (Oracle) wrote:
> The readpage operation can block in many (most?) filesystems, so we
> should punt to a work queue instead of calling it.  This was the last
> caller of lock_page_async(), so remove it.

You mention lock_page_async, yet you remove lock_page_for_iocb.

> 
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> ---
>  mm/filemap.c | 14 ++------------
>  1 file changed, 2 insertions(+), 12 deletions(-)
> 
> diff --git a/mm/filemap.c b/mm/filemap.c
> index 7a4101ceb106..5bafd2dc830c 100644
> --- a/mm/filemap.c
> +++ b/mm/filemap.c
> @@ -2152,16 +2152,6 @@ static void shrink_readahead_size_eio(struct file_ra_state *ra)
>  	ra->ra_pages /= 4;
>  }
>  
> -static int lock_page_for_iocb(struct kiocb *iocb, struct page *page)
> -{
> -	if (iocb->ki_flags & IOCB_WAITQ)
> -		return lock_page_async(page, iocb->ki_waitq);
> -	else if (iocb->ki_flags & IOCB_NOWAIT)
> -		return trylock_page(page) ? 0 : -EAGAIN;
> -	else
> -		return lock_page_killable(page);
> -}
> -
>  static unsigned mapping_get_read_thps(struct address_space *mapping,
>  		pgoff_t index, unsigned int nr_pages, struct page **pages)
>  {
> @@ -2210,7 +2200,7 @@ static struct page *filemap_read_page(struct kiocb *iocb, struct file *filp,
>  	struct file_ra_state *ra = &filp->f_ra;
>  	int error;
>  
> -	if (iocb->ki_flags & (IOCB_NOIO | IOCB_NOWAIT)) {
> +	if (iocb->ki_flags & (IOCB_NOIO | IOCB_NOWAIT | IOCB_WAITQ)) {
>  		unlock_page(page);
>  		put_page(page);
>  		return ERR_PTR(-EAGAIN);
> @@ -2231,7 +2221,7 @@ static struct page *filemap_read_page(struct kiocb *iocb, struct file *filp,
>  	}
>  
>  	if (!PageUptodate(page)) {
> -		error = lock_page_for_iocb(iocb, page);
> +		error = lock_page_killable(page);
>  		if (unlikely(error)) {
>  			put_page(page);
>  			return ERR_PTR(error);
>
diff mbox series

Patch

diff --git a/mm/filemap.c b/mm/filemap.c
index 7a4101ceb106..5bafd2dc830c 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -2152,16 +2152,6 @@  static void shrink_readahead_size_eio(struct file_ra_state *ra)
 	ra->ra_pages /= 4;
 }
 
-static int lock_page_for_iocb(struct kiocb *iocb, struct page *page)
-{
-	if (iocb->ki_flags & IOCB_WAITQ)
-		return lock_page_async(page, iocb->ki_waitq);
-	else if (iocb->ki_flags & IOCB_NOWAIT)
-		return trylock_page(page) ? 0 : -EAGAIN;
-	else
-		return lock_page_killable(page);
-}
-
 static unsigned mapping_get_read_thps(struct address_space *mapping,
 		pgoff_t index, unsigned int nr_pages, struct page **pages)
 {
@@ -2210,7 +2200,7 @@  static struct page *filemap_read_page(struct kiocb *iocb, struct file *filp,
 	struct file_ra_state *ra = &filp->f_ra;
 	int error;
 
-	if (iocb->ki_flags & (IOCB_NOIO | IOCB_NOWAIT)) {
+	if (iocb->ki_flags & (IOCB_NOIO | IOCB_NOWAIT | IOCB_WAITQ)) {
 		unlock_page(page);
 		put_page(page);
 		return ERR_PTR(-EAGAIN);
@@ -2231,7 +2221,7 @@  static struct page *filemap_read_page(struct kiocb *iocb, struct file *filp,
 	}
 
 	if (!PageUptodate(page)) {
-		error = lock_page_for_iocb(iocb, page);
+		error = lock_page_killable(page);
 		if (unlikely(error)) {
 			put_page(page);
 			return ERR_PTR(error);