linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Mike Rapoport <rppt@kernel.org>
To: "Matthew Wilcox (Oracle)" <willy@infradead.org>
Cc: linux-mm@kvack.org, Andrew Morton <akpm@linux-foundation.org>,
	Hugh Dickins <hughd@google.com>,
	William Kucharski <william.kucharski@oracle.com>,
	Johannes Weiner <hannes@cmpxchg.org>, Jan Kara <jack@suse.cz>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/7] mm: Rewrite shmem_seek_hole_data
Date: Thu, 20 Aug 2020 19:45:46 +0300	[thread overview]
Message-ID: <20200820164546.GD752365@kernel.org> (raw)
In-Reply-To: <20200819150555.31669-3-willy@infradead.org>

On Wed, Aug 19, 2020 at 04:05:50PM +0100, Matthew Wilcox (Oracle) wrote:
> use the XArray directly instead of using the pagevec abstraction.
> The code is simpler and more efficient.
> 
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> ---
>  mm/shmem.c | 61 +++++++++++++++++++++---------------------------------
>  1 file changed, 24 insertions(+), 37 deletions(-)
> 
> diff --git a/mm/shmem.c b/mm/shmem.c
> index a7bbc4ed9677..0f9f149f4b5e 100644
> --- a/mm/shmem.c
> +++ b/mm/shmem.c
> @@ -2659,53 +2659,40 @@ static ssize_t shmem_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
>  }
>  
>  /*
> - * llseek SEEK_DATA or SEEK_HOLE through the page cache.
> + * llseek SEEK_DATA or SEEK_HOLE through the page cache.  We don't need
> + * to get a reference on the page because this interface is racy anyway.
> + * The page we find will have had the state at some point.

For my non-native ear "will have had" is too complex ;-)

>   */
>  static pgoff_t shmem_seek_hole_data(struct address_space *mapping,
>  				    pgoff_t index, pgoff_t end, int whence)
>  {
> +	XA_STATE(xas, &mapping->i_pages, index);
>  	struct page *page;
> -	struct pagevec pvec;
> -	pgoff_t indices[PAGEVEC_SIZE];
> -	bool done = false;
> -	int i;
>  
> -	pagevec_init(&pvec);
> -	pvec.nr = 1;		/* start small: we may be there already */
> -	while (!done) {
> -		pvec.nr = find_get_entries(mapping, index,
> -					pvec.nr, pvec.pages, indices);
> -		if (!pvec.nr) {
> -			if (whence == SEEK_DATA)
> -				index = end;
> -			break;
> +	rcu_read_lock();
> +	if (whence == SEEK_DATA) {
> +		for (;;) {
> +			page = xas_find(&xas, end);
> +			if (xas_retry(&xas, page))
> +				continue;
> +			if (!page || xa_is_value(page) || PageUptodate(page))
> +				break;
>  		}
> -		for (i = 0; i < pvec.nr; i++, index++) {
> -			if (index < indices[i]) {
> -				if (whence == SEEK_HOLE) {
> -					done = true;
> -					break;
> -				}
> -				index = indices[i];
> -			}
> -			page = pvec.pages[i];
> -			if (page && !xa_is_value(page)) {
> -				if (!PageUptodate(page))
> -					page = NULL;
> -			}
> -			if (index >= end ||
> -			    (page && whence == SEEK_DATA) ||
> -			    (!page && whence == SEEK_HOLE)) {
> -				done = true;
> +	} else /* SEEK_HOLE */ {
> +		for (;;) {
> +			page = xas_next(&xas);
> +			if (xas_retry(&xas, page))
> +				continue;
> +			if (!xa_is_value(page) &&
> +					(!page || !PageUptodate(page)))
> +				break;
> +			if (xas.xa_index >= end)
>  				break;
> -			}
>  		}
> -		pagevec_remove_exceptionals(&pvec);
> -		pagevec_release(&pvec);
> -		pvec.nr = PAGEVEC_SIZE;
> -		cond_resched();
>  	}
> -	return index;
> +	rcu_read_unlock();
> +
> +	return xas.xa_index;
>  }
>  
>  static loff_t shmem_file_llseek(struct file *file, loff_t offset, int whence)
> -- 
> 2.28.0
> 
> 

-- 
Sincerely yours,
Mike.


  reply	other threads:[~2020-08-20 16:45 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-19 15:05 [PATCH 0/7] Overhaul find_get_entries and pagevec_lookup_entries Matthew Wilcox (Oracle)
2020-08-19 15:05 ` [PATCH 1/7] mm: Use pagevec_lookup in shmem_unlock_mapping Matthew Wilcox (Oracle)
2020-08-21 15:53   ` Jan Kara
2020-08-19 15:05 ` [PATCH 2/7] mm: Rewrite shmem_seek_hole_data Matthew Wilcox (Oracle)
2020-08-20 16:45   ` Mike Rapoport [this message]
2020-08-20 19:04     ` Matthew Wilcox
2020-08-19 15:05 ` [PATCH 3/7] mm: Add an 'end' parameter to find_get_entries Matthew Wilcox (Oracle)
2020-08-20 16:47   ` Mike Rapoport
2020-08-21 16:07   ` Jan Kara
2020-08-21 16:33     ` Matthew Wilcox
2020-08-21 18:06       ` Jan Kara
2020-08-19 15:05 ` [PATCH 4/7] mm: Add an 'end' parameter to pagevec_lookup_entries Matthew Wilcox (Oracle)
2020-08-24 16:09   ` Jan Kara
2020-08-19 15:05 ` [PATCH 5/7] mm: Remove nr_entries parameter from pagevec_lookup_entries Matthew Wilcox (Oracle)
2020-08-24 16:10   ` Jan Kara
2020-08-19 15:05 ` [PATCH 6/7] mm: Pass pvec directly to find_get_entries Matthew Wilcox (Oracle)
2020-08-24 16:16   ` Jan Kara
2020-08-24 17:36     ` Matthew Wilcox
2020-08-25 12:33       ` Jan Kara
2020-08-25 13:28         ` Matthew Wilcox
2020-08-25 15:24           ` Jan Kara
2020-08-25 16:23           ` Johannes Weiner
2020-08-19 15:05 ` [PATCH 7/7] mm: Remove pagevec_lookup_entries Matthew Wilcox (Oracle)
2020-08-22  2:34 ` [PATCH 0/7] Overhaul find_get_entries and pagevec_lookup_entries William Kucharski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200820164546.GD752365@kernel.org \
    --to=rppt@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=hannes@cmpxchg.org \
    --cc=hughd@google.com \
    --cc=jack@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=william.kucharski@oracle.com \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).