linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Jan Kara <jack@suse.cz>
Cc: linux-mm@kvack.org, Miklos Szeredi <mszeredi@suse.cz>,
	Jay <jinshan.xiong@whamcloud.com>,
	Miklos Szeredi <mszeredi@suse.de>
Subject: Re: [PATCH v2] mm: Fix assertion mapping->nrpages == 0 in end_writeback()
Date: Mon, 20 Jun 2011 17:18:33 -0700	[thread overview]
Message-ID: <20110620171833.411c96e0.akpm@linux-foundation.org> (raw)
In-Reply-To: <1308152233-16919-1-git-send-email-jack@suse.cz>

On Wed, 15 Jun 2011 17:37:13 +0200
Jan Kara <jack@suse.cz> wrote:

> Under heavy memory and filesystem load, users observe the assertion
> mapping->nrpages == 0 in end_writeback() trigger. This can be caused
> by page reclaim reclaiming the last page from a mapping in the following
> race:
> 	CPU0				CPU1
>   ...
>   shrink_page_list()
>     __remove_mapping()
>       __delete_from_page_cache()
>         radix_tree_delete()
> 					evict_inode()
> 					  truncate_inode_pages()
> 					    truncate_inode_pages_range()
> 					      pagevec_lookup() - finds nothing
> 					  end_writeback()
> 					    mapping->nrpages != 0 -> BUG
>         page->mapping = NULL
>         mapping->nrpages--
> 
> Fix the problem by doing a reliable check of mapping->nrpages under
> mapping->tree_lock in end_writeback().
> 
> Analyzed by Jay <jinshan.xiong@whamcloud.com>, lost in LKML, and dug
> out by Miklos Szeredi <mszeredi@suse.de>.
> 
> CC: Jay <jinshan.xiong@whamcloud.com>
> CC: Miklos Szeredi <mszeredi@suse.de>
> Signed-off-by: Jan Kara <jack@suse.cz>
> ---
>  fs/inode.c         |    7 +++++++
>  include/linux/fs.h |    1 +
>  mm/truncate.c      |    5 +++++
>  3 files changed, 13 insertions(+), 0 deletions(-)
> 
>   Andrew, does this look better?

spose so.

> diff --git a/fs/inode.c b/fs/inode.c
> index 33c963d..1133cb0 100644
> --- a/fs/inode.c
> +++ b/fs/inode.c
> @@ -467,7 +467,14 @@ EXPORT_SYMBOL(remove_inode_hash);
>  void end_writeback(struct inode *inode)
>  {
>  	might_sleep();
> +	/*
> +	 * We have to cycle tree_lock here because reclaim can be still in the
> +	 * process of removing the last page (in __delete_from_page_cache())
> +	 * and we must not free mapping under it.
> +	 */
> +	spin_lock(&inode->i_data.tree_lock);
>  	BUG_ON(inode->i_data.nrpages);
> +	spin_unlock(&inode->i_data.tree_lock);

That's an expensive assertion.  We might want to wrap all this in
CONFIG_DEBUG_VM.

Or we could do

	if (unlikely(inode->i_data.nrpages)) {
		/* comment goes here */
		spin_lock(&inode->i_data.tree_lock);
		BUG_ON(inode->i_data.nrpages);
		spin_unlock(&inode->i_data.tree_lock);
	}

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2011-06-21  0:19 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-15 15:37 [PATCH v2] mm: Fix assertion mapping->nrpages == 0 in end_writeback() Jan Kara
2011-06-21  0:18 ` Andrew Morton [this message]
2011-06-21  6:47   ` Miklos Szeredi
2011-06-21 19:23     ` Jan Kara

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=20110620171833.411c96e0.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=jack@suse.cz \
    --cc=jinshan.xiong@whamcloud.com \
    --cc=linux-mm@kvack.org \
    --cc=mszeredi@suse.cz \
    --cc=mszeredi@suse.de \
    /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).