linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Kirill A. Shutemov" <kirill@shutemov.name>
To: Matthew Wilcox <willy@infradead.org>
Cc: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org, Hugh Dickins <hughd@google.com>,
	William Kucharski <william.kucharski@oracle.com>
Subject: Re: [PATCH v2] page cache: Store only head pages in i_pages
Date: Fri, 15 Feb 2019 01:03:44 +0300	[thread overview]
Message-ID: <20190214220344.2ovvzwcfuxxehzzt@kshutemo-mobl1> (raw)
In-Reply-To: <20190214205331.GD12668@bombadil.infradead.org>

On Thu, Feb 14, 2019 at 12:53:31PM -0800, Matthew Wilcox wrote:
> On Thu, Feb 14, 2019 at 04:30:04PM +0300, Kirill A. Shutemov wrote:
> >  - page_cache_delete_batch() will blow up on
> > 
> > 			VM_BUG_ON_PAGE(page->index + HPAGE_PMD_NR - tail_pages
> > 					!= pvec->pages[i]->index, page);
> 
> Quite right.  I decided to rewrite page_cache_delete_batch.  What do you
> (and Jan!) think to this?  Compile-tested only.
> 
> diff --git a/mm/filemap.c b/mm/filemap.c
> index 0d71b1acf811..facaa6913ffa 100644
> --- a/mm/filemap.c
> +++ b/mm/filemap.c
> @@ -279,11 +279,11 @@ EXPORT_SYMBOL(delete_from_page_cache);
>   * @pvec: pagevec with pages to delete
>   *
>   * The function walks over mapping->i_pages and removes pages passed in @pvec
> - * from the mapping. The function expects @pvec to be sorted by page index.
> + * from the mapping. The function expects @pvec to be sorted by page index
> + * and is optimised for it to be dense.
>   * It tolerates holes in @pvec (mapping entries at those indices are not
>   * modified). The function expects only THP head pages to be present in the
> - * @pvec and takes care to delete all corresponding tail pages from the
> - * mapping as well.
> + * @pvec.
>   *
>   * The function expects the i_pages lock to be held.
>   */
> @@ -292,40 +292,36 @@ static void page_cache_delete_batch(struct address_space *mapping,
>  {
>  	XA_STATE(xas, &mapping->i_pages, pvec->pages[0]->index);
>  	int total_pages = 0;
> -	int i = 0, tail_pages = 0;
> +	int i = 0;
>  	struct page *page;
>  
>  	mapping_set_update(&xas, mapping);
>  	xas_for_each(&xas, page, ULONG_MAX) {
> -		if (i >= pagevec_count(pvec) && !tail_pages)
> +		if (i >= pagevec_count(pvec))
>  			break;
> +
> +		/* A swap/dax/shadow entry got inserted? Skip it. */
>  		if (xa_is_value(page))
>  			continue;
> -		if (!tail_pages) {
> -			/*
> -			 * Some page got inserted in our range? Skip it. We
> -			 * have our pages locked so they are protected from
> -			 * being removed.
> -			 */
> -			if (page != pvec->pages[i]) {
> -				VM_BUG_ON_PAGE(page->index >
> -						pvec->pages[i]->index, page);
> -				continue;
> -			}
> -			WARN_ON_ONCE(!PageLocked(page));
> -			if (PageTransHuge(page) && !PageHuge(page))
> -				tail_pages = HPAGE_PMD_NR - 1;
> +		/*
> +		 * A page got inserted in our range? Skip it. We have our
> +		 * pages locked so they are protected from being removed.
> +		 */
> +		if (page != pvec->pages[i]) {

Maybe a comment for the VM_BUG while you're there?

> +			VM_BUG_ON_PAGE(page->index > pvec->pages[i]->index,
> +					page);
> +			continue;
> +		}
> +
> +		WARN_ON_ONCE(!PageLocked(page));
> +
> +		if (page->index == xas.xa_index)
>  			page->mapping = NULL;
> -			/*
> -			 * Leave page->index set: truncation lookup relies
> -			 * upon it
> -			 */
> +		/* Leave page->index set: truncation lookup relies on it */
> +
> +		if (page->index + (1UL << compound_order(page)) - 1 ==
> +				xas.xa_index)

It's 1am here and I'm slow, but it took me few minutes to understand how
it works. Please add a comment.

>  			i++;
> -		} else {
> -			VM_BUG_ON_PAGE(page->index + HPAGE_PMD_NR - tail_pages
> -					!= pvec->pages[i]->index, page);
> -			tail_pages--;
> -		}
>  		xas_store(&xas, NULL);
>  		total_pages++;
>  	}

-- 
 Kirill A. Shutemov

  reply	other threads:[~2019-02-14 22:03 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-12 18:34 [PATCH v2] page cache: Store only head pages in i_pages Matthew Wilcox
2019-02-13 14:41 ` Jan Kara
2019-02-13 20:17   ` Matthew Wilcox
2019-02-14 16:27     ` Jan Kara
2019-02-14 13:30 ` Kirill A. Shutemov
2019-02-14 20:53   ` Matthew Wilcox
2019-02-14 22:03     ` Kirill A. Shutemov [this message]
2019-02-14 22:25       ` Matthew Wilcox
2019-02-14 21:17   ` Matthew Wilcox
2019-02-14 22:08     ` Kirill A. Shutemov
2019-02-14 22:11       ` Matthew Wilcox
2019-02-14 22:29         ` Kirill A. Shutemov
2019-02-14 22:29   ` Kirill A. Shutemov
2019-02-15 20:28     ` Matthew Wilcox
2019-02-14 22:41   ` Kirill A. Shutemov
2019-02-15 20:20     ` Matthew Wilcox
2019-02-15 21:17       ` Kirill A. Shutemov

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=20190214220344.2ovvzwcfuxxehzzt@kshutemo-mobl1 \
    --to=kirill@shutemov.name \
    --cc=hughd@google.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --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).