Re: is this a bug?

From: Steven Rostedt
Date: Fri Mar 25 2011 - 11:18:18 EST


Strange mail client you have.

On Wed, Mar 23, 2011 at 05:46:56PM -0700, Jay wrote:
> Hi,
>
> Assuming vmscan is doing its job to steal the last page from an
> inode's namespace, so:
>
> shrink_page_list -> remove_mapping -> __remove_from_page_cache:
>
> void __remove_from_page_cache(struct page *page)
>
> {
>
>         ...
>
>         radix_tree_delete(&mapping->page_tree, page->index);
>
>         page->mapping = NULL;
>
> >>> after removing the page from radix tree, it stuck at here.
>
>         mapping->nrpages--;
>
>         ...
>
> }
>
> then another process just calls iput_final to release the inode, so
> iput_final -> evict:
>
> static void evict(struct inode *inode)
>
> {
>
>        ...
>
>         } else {
>
>                 if (inode->i_data.nrpages)
>
> >>> here it finds that nrpage is 1, so go into truncate_inode_pages() but it won't find any page in the page tree.
>
>                         truncate_inode_pages(&inode->i_data, 0);
>
> >>> here nrpages remains 1.
>
>                 end_writeback(inode);
>
> >>> hit  BUG_ON(inode->i_data.nrpages) in end_writeback().


Did you actually hit this bug?

>
>         }
>
>         ...
>
> }
>
> The root cause of this problem is that nrpages is accessed w/o holding
> mapping->page_tree. The fix is also easy, just grab ->tree_lock inside
> truncate_inode_pages_range:
>
> +       spin_lock_irq(&mapping->tree_lock);
>
> -         if (mapping->nrpages == 0)
>
> +        if (mapping->nrpages == 0) {
>
> +               spin_unlock_irq(&mapping->tree_lock);
>
>                 return;
>
> +        }
>
> +        spin_unlock_irq(&mapping->tree_lock);
>
> Am I missed anything?

Perhaps the comment before the __remove_from_page_cache()

/*
* Remove a page from the page cache and free it. Caller has to make
* sure the page is locked and that nobody else uses it - or that usage
* is safe. The caller must hold the mapping's tree_lock.
*/

-- Steve

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/