All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Btrfs: add another missing end_page_writeback on submit_extent_page failure
@ 2016-12-16  6:41 Takafumi Kubota
  2016-12-22  6:20 ` Liu Bo
  0 siblings, 1 reply; 18+ messages in thread
From: Takafumi Kubota @ 2016-12-16  6:41 UTC (permalink / raw)
  To: linux-btrfs
  Cc: clm, jbacik, dsterba, linux-kernel, fdmanana, naota, Takafumi Kubota

This is actually inspired by Filipe's patch(55e3bd2e0c2e1).

When submit_extent_page() in __extent_writepage_io() fails,
Btrfs misses clearing a writeback bit of the failed page.
This causes the false under-writeback page.
Then, another sync task hangs in filemap_fdatawait_range(),
because it waits the false under-writeback page.

CPU0                            CPU1

__extent_writepage_io()
  ret = submit_extent_page() // fail

  if (ret)
    SetPageError(page)
    // miss clearing the writeback bit

                                sync()
                                  ...
                                  filemap_fdatawait_range()
                                    wait_on_page_writeback(page);
                                    // wait the false under-writeback page

Signed-off-by: Takafumi Kubota <takafumi.kubota1012@sslab.ics.keio.ac.jp>
---
 fs/btrfs/extent_io.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 1e67723..ef9793b 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -3443,8 +3443,10 @@ static noinline_for_stack int __extent_writepage_io(struct inode *inode,
 					 bdev, &epd->bio, max_nr,
 					 end_bio_extent_writepage,
 					 0, 0, 0, false);
-		if (ret)
+		if (ret) {
 			SetPageError(page);
+			end_page_writeback(page);
+		}
 
 		cur = cur + iosize;
 		pg_offset += iosize;
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 18+ messages in thread
* [PATCH v2] Btrfs: add another missing end_page_writeback on submit_extent_page failure
  2017-02-08 18:30                         ` David Sterba
@ 2017-02-09  8:24 ` Takafumi Kubota
  -1 siblings, 0 replies; 18+ messages in thread
From: Takafumi Kubota @ 2017-02-09  8:24 UTC (permalink / raw)
  To: linux-btrfs
  Cc: clm, jbacik, dsterba, linux-kernel, bo.li.liu, naota,
	Takafumi Kubota, David Sterba

If btrfs_bio_alloc fails in submit_extent_page, submit_extent_page returns
without clearing the writeback bit of the failed page.

__extent_writepage_io, that is a caller of submit_extent_page,
does not clear the remaining writeback bit anywhere.
As a result, this will cause the hang at filemap_fdatawait_range,
because it waits the writeback bit to be cleared from the failed page.
So, we have to call end_page_writeback to clear the writeback bit.

For reproducing the hang, we inject a fault like

   if (should_failtest()) { // I define should_failtest()
        bio = NULL;
   }
   else {
        bio = btrfs_bio_alloc(...);
   }

in submit_extent_page.

We should also check whether page has the bit before end_page_writeback,
to avoid the conflict against the other end_page_writeback in bio_endio.
Thus, we add PageWriteback checks not only in __extent_writepage_io,
but also in write_one_eb too, because it misses the check.

Signed-off-by: Takafumi Kubota <takafumi.kubota1012@sslab.ics.keio.ac.jp>
Reviewed-by: Liu Bo <bo.li.liu@oracle.com>
Cc: David Sterba <dsterba@suse.cz>
---
 fs/btrfs/extent_io.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 4ac383a..aa1908a 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -3445,8 +3445,11 @@ static noinline_for_stack int __extent_writepage_io(struct inode *inode,
 					 bdev, &epd->bio, max_nr,
 					 end_bio_extent_writepage,
 					 0, 0, 0, false);
-		if (ret)
+		if (ret) {
 			SetPageError(page);
+			if (PageWriteback(page))
+				end_page_writeback(page);
+		}
 
 		cur = cur + iosize;
 		pg_offset += iosize;
@@ -3767,7 +3770,8 @@ static noinline_for_stack int write_one_eb(struct extent_buffer *eb,
 		epd->bio_flags = bio_flags;
 		if (ret) {
 			set_btree_ioerr(p);
-			end_page_writeback(p);
+			if (PageWriteback(p))
+				end_page_writeback(p);
 			if (atomic_sub_and_test(num_pages - i, &eb->io_pages))
 				end_extent_buffer_writeback(eb);
 			ret = -EIO;
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2017-02-10 16:04 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-16  6:41 [PATCH] Btrfs: add another missing end_page_writeback on submit_extent_page failure Takafumi Kubota
2016-12-22  6:20 ` Liu Bo
2017-01-13  6:12   ` takafumi-sslab
2017-01-30 20:09     ` Liu Bo
2017-02-01  3:27       ` takafumi-sslab
2017-02-01 16:19         ` Liu Bo
2017-02-04 12:42           ` takafumi-sslab
2017-02-06  3:35             ` Liu Bo
2017-02-06  5:50               ` takafumi-sslab
2017-02-06 16:26                 ` Liu Bo
2017-02-06 16:34                   ` Liu Bo
2017-02-07 11:09                     ` takafumi-sslab
2017-02-07 20:14                       ` Liu Bo
2017-02-08 18:30                         ` David Sterba
2017-02-06  9:36               ` takafumi-sslab
2017-02-09  8:24 [PATCH v2] " Takafumi Kubota
2017-02-09  8:24 ` Takafumi Kubota
2017-02-10 16:02 ` David Sterba

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.