diff options
author | Jeff Mahoney <jeffm@suse.com> | 2012-02-15 10:23:57 -0500 |
---|---|---|
committer | David Sterba <dsterba@suse.cz> | 2012-02-15 10:40:25 -0500 |
commit | 87826df0ec36fc28884b4ddbb3f3af41c4c2008f (patch) | |
tree | 7d95bf1ff03c82805903330a279a67642be68699 /fs | |
parent | a7e221e9002306a753d6f78b4060edabce402033 (diff) |
btrfs: delalloc for page dirtied out-of-band in fixup worker
We encountered an issue that was easily observable on s/390 systems but
could really happen anywhere. The timing just seemed to hit reliably
on s/390 with limited memory.
The gist is that when an unexpected set_page_dirty() happened, we'd
run into the BUG() in btrfs_writepage_fixup_worker since it wasn't
properly set up for delalloc.
This patch does the following:
- Performs the missing delalloc in the fixup worker
- Allow the start hook to return -EBUSY which informs __extent_writepage
that it should mark the page skipped and not to redirty it. This is
required since the fixup worker can fail with -ENOSPC and the page
will have already been redirtied. That causes an Oops in
drop_outstanding_extents later. Retrying the fixup worker could
lead to an infinite loop. Deferring the page redirty also saves us
some cycles since the page would be stuck in a resubmit-redirty loop
until the fixup worker completes. It's not harmful, just wasteful.
- If the fixup worker fails, we mark the page and mapping as errored,
and end the writeback, similar to what we would do had the page
actually been submitted to writeback.
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/btrfs/extent_io.c | 65 | ||||
-rw-r--r-- | fs/btrfs/extent_io.h | 1 | ||||
-rw-r--r-- | fs/btrfs/inode.c | 14 |
3 files changed, 53 insertions, 27 deletions
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index fcf77e1ded40..89ba79fb945c 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c | |||
@@ -2161,6 +2161,38 @@ static int bio_readpage_error(struct bio *failed_bio, struct page *page, | |||
2161 | 2161 | ||
2162 | /* lots and lots of room for performance fixes in the end_bio funcs */ | 2162 | /* lots and lots of room for performance fixes in the end_bio funcs */ |
2163 | 2163 | ||
2164 | int end_extent_writepage(struct page *page, int err, u64 start, u64 end) | ||
2165 | { | ||
2166 | int uptodate = (err == 0); | ||
2167 | struct extent_io_tree *tree; | ||
2168 | int ret; | ||
2169 | |||
2170 | tree = &BTRFS_I(page->mapping->host)->io_tree; | ||
2171 | |||
2172 | if (tree->ops && tree->ops->writepage_end_io_hook) { | ||
2173 | ret = tree->ops->writepage_end_io_hook(page, start, | ||
2174 | end, NULL, uptodate); | ||
2175 | if (ret) | ||
2176 | uptodate = 0; | ||
2177 | } | ||
2178 | |||
2179 | if (!uptodate && tree->ops && | ||
2180 | tree->ops->writepage_io_failed_hook) { | ||
2181 | ret = tree->ops->writepage_io_failed_hook(NULL, page, | ||
2182 | start, end, NULL); | ||
2183 | /* Writeback already completed */ | ||
2184 | if (ret == 0) | ||
2185 | return 1; | ||
2186 | } | ||
2187 | |||
2188 | if (!uptodate) { | ||
2189 | clear_extent_uptodate(tree, start, end, NULL, GFP_NOFS); | ||
2190 | ClearPageUptodate(page); | ||
2191 | SetPageError(page); | ||
2192 | } | ||
2193 | return 0; | ||
2194 | } | ||
2195 | |||
2164 | /* | 2196 | /* |
2165 | * after a writepage IO is done, we need to: | 2197 | * after a writepage IO is done, we need to: |
2166 | * clear the uptodate bits on error | 2198 | * clear the uptodate bits on error |
@@ -2172,13 +2204,11 @@ static int bio_readpage_error(struct bio *failed_bio, struct page *page, | |||
2172 | */ | 2204 | */ |
2173 | static void end_bio_extent_writepage(struct bio *bio, int err) | 2205 | static void end_bio_extent_writepage(struct bio *bio, int err) |
2174 | { | 2206 | { |
2175 | int uptodate = err == 0; | ||
2176 | struct bio_vec *bvec = bio->bi_io_vec + bio->bi_vcnt - 1; | 2207 | struct bio_vec *bvec = bio->bi_io_vec + bio->bi_vcnt - 1; |
2177 | struct extent_io_tree *tree; | 2208 | struct extent_io_tree *tree; |
2178 | u64 start; | 2209 | u64 start; |
2179 | u64 end; | 2210 | u64 end; |
2180 | int whole_page; | 2211 | int whole_page; |
2181 | int ret; | ||
2182 | 2212 | ||
2183 | do { | 2213 | do { |
2184 | struct page *page = bvec->bv_page; | 2214 | struct page *page = bvec->bv_page; |
@@ -2195,28 +2225,9 @@ static void end_bio_extent_writepage(struct bio *bio, int err) | |||
2195 | 2225 | ||
2196 | if (--bvec >= bio->bi_io_vec) | 2226 | if (--bvec >= bio->bi_io_vec) |
2197 | prefetchw(&bvec->bv_page->flags); | 2227 | prefetchw(&bvec->bv_page->flags); |
2198 | if (tree->ops && tree->ops->writepage_end_io_hook) { | ||
2199 | ret = tree->ops->writepage_end_io_hook(page, start, | ||
2200 | end, NULL, uptodate); | ||
2201 | if (ret) | ||
2202 | uptodate = 0; | ||
2203 | } | ||
2204 | |||
2205 | if (!uptodate && tree->ops && | ||
2206 | tree->ops->writepage_io_failed_hook) { | ||
2207 | ret = tree->ops->writepage_io_failed_hook(bio, page, | ||
2208 | start, end, NULL); | ||
2209 | if (ret == 0) { | ||
2210 | uptodate = (err == 0); | ||
2211 | continue; | ||
2212 | } | ||
2213 | } | ||
2214 | 2228 | ||
2215 | if (!uptodate) { | 2229 | if (end_extent_writepage(page, err, start, end)) |
2216 | clear_extent_uptodate(tree, start, end, NULL, GFP_NOFS); | 2230 | continue; |
2217 | ClearPageUptodate(page); | ||
2218 | SetPageError(page); | ||
2219 | } | ||
2220 | 2231 | ||
2221 | if (whole_page) | 2232 | if (whole_page) |
2222 | end_page_writeback(page); | 2233 | end_page_writeback(page); |
@@ -2818,8 +2829,12 @@ static int __extent_writepage(struct page *page, struct writeback_control *wbc, | |||
2818 | if (tree->ops && tree->ops->writepage_start_hook) { | 2829 | if (tree->ops && tree->ops->writepage_start_hook) { |
2819 | ret = tree->ops->writepage_start_hook(page, start, | 2830 | ret = tree->ops->writepage_start_hook(page, start, |
2820 | page_end); | 2831 | page_end); |
2821 | if (ret == -EAGAIN) { | 2832 | if (ret) { |
2822 | redirty_page_for_writepage(wbc, page); | 2833 | /* Fixup worker will requeue */ |
2834 | if (ret == -EBUSY) | ||
2835 | wbc->pages_skipped++; | ||
2836 | else | ||
2837 | redirty_page_for_writepage(wbc, page); | ||
2823 | update_nr_written(page, wbc, nr_written); | 2838 | update_nr_written(page, wbc, nr_written); |
2824 | unlock_page(page); | 2839 | unlock_page(page); |
2825 | ret = 0; | 2840 | ret = 0; |
diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h index bc6a042cb6fc..cecc3518c121 100644 --- a/fs/btrfs/extent_io.h +++ b/fs/btrfs/extent_io.h | |||
@@ -319,4 +319,5 @@ struct btrfs_mapping_tree; | |||
319 | int repair_io_failure(struct btrfs_mapping_tree *map_tree, u64 start, | 319 | int repair_io_failure(struct btrfs_mapping_tree *map_tree, u64 start, |
320 | u64 length, u64 logical, struct page *page, | 320 | u64 length, u64 logical, struct page *page, |
321 | int mirror_num); | 321 | int mirror_num); |
322 | int end_extent_writepage(struct page *page, int err, u64 start, u64 end); | ||
322 | #endif | 323 | #endif |
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 7405753ec5d7..bf392e532617 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c | |||
@@ -1555,6 +1555,7 @@ static void btrfs_writepage_fixup_worker(struct btrfs_work *work) | |||
1555 | struct inode *inode; | 1555 | struct inode *inode; |
1556 | u64 page_start; | 1556 | u64 page_start; |
1557 | u64 page_end; | 1557 | u64 page_end; |
1558 | int ret; | ||
1558 | 1559 | ||
1559 | fixup = container_of(work, struct btrfs_writepage_fixup, work); | 1560 | fixup = container_of(work, struct btrfs_writepage_fixup, work); |
1560 | page = fixup->page; | 1561 | page = fixup->page; |
@@ -1582,12 +1583,21 @@ again: | |||
1582 | page_end, &cached_state, GFP_NOFS); | 1583 | page_end, &cached_state, GFP_NOFS); |
1583 | unlock_page(page); | 1584 | unlock_page(page); |
1584 | btrfs_start_ordered_extent(inode, ordered, 1); | 1585 | btrfs_start_ordered_extent(inode, ordered, 1); |
1586 | btrfs_put_ordered_extent(ordered); | ||
1585 | goto again; | 1587 | goto again; |
1586 | } | 1588 | } |
1587 | 1589 | ||
1588 | BUG(); | 1590 | ret = btrfs_delalloc_reserve_space(inode, PAGE_CACHE_SIZE); |
1591 | if (ret) { | ||
1592 | mapping_set_error(page->mapping, ret); | ||
1593 | end_extent_writepage(page, ret, page_start, page_end); | ||
1594 | ClearPageChecked(page); | ||
1595 | goto out; | ||
1596 | } | ||
1597 | |||
1589 | btrfs_set_extent_delalloc(inode, page_start, page_end, &cached_state); | 1598 | btrfs_set_extent_delalloc(inode, page_start, page_end, &cached_state); |
1590 | ClearPageChecked(page); | 1599 | ClearPageChecked(page); |
1600 | set_page_dirty(page); | ||
1591 | out: | 1601 | out: |
1592 | unlock_extent_cached(&BTRFS_I(inode)->io_tree, page_start, page_end, | 1602 | unlock_extent_cached(&BTRFS_I(inode)->io_tree, page_start, page_end, |
1593 | &cached_state, GFP_NOFS); | 1603 | &cached_state, GFP_NOFS); |
@@ -1630,7 +1640,7 @@ static int btrfs_writepage_start_hook(struct page *page, u64 start, u64 end) | |||
1630 | fixup->work.func = btrfs_writepage_fixup_worker; | 1640 | fixup->work.func = btrfs_writepage_fixup_worker; |
1631 | fixup->page = page; | 1641 | fixup->page = page; |
1632 | btrfs_queue_worker(&root->fs_info->fixup_workers, &fixup->work); | 1642 | btrfs_queue_worker(&root->fs_info->fixup_workers, &fixup->work); |
1633 | return -EAGAIN; | 1643 | return -EBUSY; |
1634 | } | 1644 | } |
1635 | 1645 | ||
1636 | static int insert_reserved_file_extent(struct btrfs_trans_handle *trans, | 1646 | static int insert_reserved_file_extent(struct btrfs_trans_handle *trans, |