Commit 1ed73535 authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] writeback livelock fix

If a filesystem's ->writepage implementation repeatedly refuses to write the
page (it keeps on redirtying it instead) (reiserfs seems to do this) then the
writeback logic can get stuck repeately trying to write the same page.

Fix that up by correctly setting wbc->pages_skipped, to tell the writeback
logic that things aren't working out.
parent 8a51beef
......@@ -1826,7 +1826,7 @@ static int __block_write_full_page(struct inode *inode, struct page *page,
if (wbc->sync_mode != WB_SYNC_NONE || !wbc->nonblocking) {
lock_buffer(bh);
} else if (test_set_buffer_locked(bh)) {
__set_page_dirty_nobuffers(page);
redirty_page_for_writepage(wbc, page);
continue;
}
if (test_clear_buffer_dirty(bh)) {
......
......@@ -1393,7 +1393,7 @@ static int ext3_ordered_writepage(struct page *page,
return ret;
out_fail:
__set_page_dirty_nobuffers(page);
redirty_page_for_writepage(wbc, page);
unlock_page(page);
return ret;
}
......@@ -1422,7 +1422,7 @@ static int ext3_writeback_writepage(struct page *page,
return ret;
out_fail:
__set_page_dirty_nobuffers(page);
redirty_page_for_writepage(wbc, page);
unlock_page(page);
return ret;
}
......@@ -1478,7 +1478,7 @@ static int ext3_journalled_writepage(struct page *page,
return ret;
no_write:
__set_page_dirty_nobuffers(page);
redirty_page_for_writepage(wbc, page);
out_unlock:
unlock_page(page);
goto out;
......
......@@ -458,7 +458,7 @@ int ntfs_readpage(struct file *file, struct page *page)
*
* Based on ntfs_read_block() and __block_write_full_page().
*/
static int ntfs_write_block(struct page *page)
static int ntfs_write_block(struct writeback_control *wbc, struct page *page)
{
VCN vcn;
LCN lcn;
......@@ -499,10 +499,7 @@ static int ntfs_write_block(struct page *page)
* Put the page back on mapping->dirty_pages, but leave its
* buffer's dirty state as-is.
*/
// FIXME: Once Andrew's -EAGAIN patch goes in, remove the
// __set_page_dirty_nobuffers(page) and return -EAGAIN instead
// of zero.
__set_page_dirty_nobuffers(page);
redirty_page_for_writepage(wbc, page);
unlock_page(page);
return 0;
}
......@@ -733,10 +730,7 @@ static int ntfs_write_block(struct page *page)
* Put the page back on mapping->dirty_pages, but
* leave its buffer's dirty state as-is.
*/
// FIXME: Once Andrew's -EAGAIN patch goes in, remove
// the __set_page_dirty_nobuffers(page) and set err to
// -EAGAIN instead of zero.
__set_page_dirty_nobuffers(page);
redirty_page_for_writepage(wbc, page);
err = 0;
} else
SetPageError(page);
......@@ -869,7 +863,7 @@ static int ntfs_writepage(struct page *page, struct writeback_control *wbc)
}
/* Normal data stream. */
return ntfs_write_block(page);
return ntfs_write_block(wbc, page);
}
/*
......@@ -986,10 +980,7 @@ static int ntfs_writepage(struct page *page, struct writeback_control *wbc)
* Put the page back on mapping->dirty_pages, but leave its
* buffer's dirty state as-is.
*/
// FIXME: Once Andrew's -EAGAIN patch goes in, remove the
// __set_page_dirty_nobuffers(page) and set err to -EAGAIN
// instead of zero.
__set_page_dirty_nobuffers(page);
redirty_page_for_writepage(wbc, page);
err = 0;
} else {
ntfs_error(vi->i_sb, "Resident attribute write failed with "
......
......@@ -2112,7 +2112,7 @@ static int reiserfs_write_full_page(struct page *page, struct writeback_control
lock_buffer(bh);
} else {
if (test_set_buffer_locked(bh)) {
__set_page_dirty_nobuffers(page);
redirty_page_for_writepage(wbc, page);
continue;
}
}
......
......@@ -486,6 +486,8 @@ int get_user_pages(struct task_struct *tsk, struct mm_struct *mm, unsigned long
int __set_page_dirty_buffers(struct page *page);
int __set_page_dirty_nobuffers(struct page *page);
int redirty_page_for_writepage(struct writeback_control *wbc,
struct page *page);
int FASTCALL(set_page_dirty(struct page *page));
int set_page_dirty_lock(struct page *page);
int clear_page_dirty_for_io(struct page *page);
......
......@@ -579,6 +579,18 @@ int __set_page_dirty_nobuffers(struct page *page)
}
EXPORT_SYMBOL(__set_page_dirty_nobuffers);
/*
* When a writepage implementation decides that it doesn't want to write this
* page for some reason, it should redirty the locked page via
* redirty_page_for_writepage() and it should then unlock the page and return 0
*/
int redirty_page_for_writepage(struct writeback_control *wbc, struct page *page)
{
wbc->pages_skipped++;
return __set_page_dirty_nobuffers(page);
}
EXPORT_SYMBOL(redirty_page_for_writepage);
/*
* If the mapping doesn't provide a set_page_dirty a_op, then
* just fall through and assume that it wants buffer_heads.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment