diff mbox series

btrfs: subpage: dump extra subpage bitmaps for debug

Message ID f9523e59665ae26d569030735c7bf3d7611040ae.1685082765.git.wqu@suse.com (mailing list archive)
State New, archived
Headers show
Series btrfs: subpage: dump extra subpage bitmaps for debug | expand

Commit Message

Qu Wenruo May 26, 2023, 12:30 p.m. UTC
There is a bug report that assert_eb_page_uptodate() get triggered for
free space tree metadata.

Without proper dump for the subpage bitmaps it's much harder to debug.

Thus this patch would dump all the subpage bitmaps (split them into
their own bitmaps) for a much easier debugging.

The output would look like this:
(Dumpped after a tree block got read from disk)

 page:000000006e34bf49 refcount:4 mapcount:0 mapping:0000000067661ac4 index:0x1d1 pfn:0x110e9
 memcg:ffff0000d7d62000
 aops:btree_aops [btrfs] ino:1
 flags: 0x8000000000002002(referenced|private|zone=2)
 page_type: 0xffffffff()
 raw: 8000000000002002 0000000000000000 dead000000000122 ffff00000188bed0
 raw: 00000000000001d1 ffff0000c7992700 00000004ffffffff ffff0000d7d62000
 page dumped because: btrfs subpage dump
 BTRFS warning (device dm-1): start=30490624 len=16384 page=30474240 bitmaps: uptodate=4-7 error= dirty= writeback= ordered= checked=

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 fs/btrfs/extent_io.c |  3 ++-
 fs/btrfs/subpage.c   | 42 ++++++++++++++++++++++++++++++++++++++++++
 fs/btrfs/subpage.h   |  2 ++
 3 files changed, 46 insertions(+), 1 deletion(-)

Comments

Christoph Hellwig May 26, 2023, 1:43 p.m. UTC | #1
Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>
David Sterba May 26, 2023, 2:50 p.m. UTC | #2
On Fri, May 26, 2023 at 08:30:53PM +0800, Qu Wenruo wrote:
> There is a bug report that assert_eb_page_uptodate() get triggered for
> free space tree metadata.
> 
> Without proper dump for the subpage bitmaps it's much harder to debug.
> 
> Thus this patch would dump all the subpage bitmaps (split them into
> their own bitmaps) for a much easier debugging.
> 
> The output would look like this:
> (Dumpped after a tree block got read from disk)
> 
>  page:000000006e34bf49 refcount:4 mapcount:0 mapping:0000000067661ac4 index:0x1d1 pfn:0x110e9
>  memcg:ffff0000d7d62000
>  aops:btree_aops [btrfs] ino:1
>  flags: 0x8000000000002002(referenced|private|zone=2)
>  page_type: 0xffffffff()
>  raw: 8000000000002002 0000000000000000 dead000000000122 ffff00000188bed0
>  raw: 00000000000001d1 ffff0000c7992700 00000004ffffffff ffff0000d7d62000
>  page dumped because: btrfs subpage dump
>  BTRFS warning (device dm-1): start=30490624 len=16384 page=30474240 bitmaps: uptodate=4-7 error= dirty= writeback= ordered= checked=
> 
> Signed-off-by: Qu Wenruo <wqu@suse.com>

Added to misc-next, thanks.

> ---
>  fs/btrfs/extent_io.c |  3 ++-
>  fs/btrfs/subpage.c   | 42 ++++++++++++++++++++++++++++++++++++++++++
>  fs/btrfs/subpage.h   |  2 ++
>  3 files changed, 46 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
> index d8becf1cdbc0..13c43291de04 100644
> --- a/fs/btrfs/extent_io.c
> +++ b/fs/btrfs/extent_io.c
> @@ -4570,7 +4570,8 @@ static void assert_eb_page_uptodate(const struct extent_buffer *eb,
>  		uptodate = btrfs_subpage_test_uptodate(fs_info, page,
>  						       eb->start, eb->len);
>  		error = btrfs_subpage_test_error(fs_info, page, eb->start, eb->len);
> -		WARN_ON(!uptodate && !error);
> +		if (WARN_ON(!uptodate && !error))
> +			btrfs_subpage_dump_bitmap(fs_info, page, eb->start, eb->len);

There was a minor conflict after code removing the PageError bits.

>  	} else {
>  		WARN_ON(!PageUptodate(page) && !PageError(page));
>  	}
> diff --git a/fs/btrfs/subpage.c b/fs/btrfs/subpage.c
> index 045117ca0ddc..f45d62bf2dfb 100644
> --- a/fs/btrfs/subpage.c
> +++ b/fs/btrfs/subpage.c
> @@ -745,3 +745,45 @@ void btrfs_page_unlock_writer(struct btrfs_fs_info *fs_info, struct page *page,
>  	/* Have writers, use proper subpage helper to end it */
>  	btrfs_page_end_writer_lock(fs_info, page, start, len);
>  }
> +
> +#define get_subpage_bitmap(subpage, subpage_info, name, dst)	\

I've upper cased the macro.

> +	bitmap_cut(dst, subpage->bitmaps, 0,			\
> +		   subpage_info->name##_offset, subpage_info->bitmap_nr_bits) \
> +
> +void btrfs_subpage_dump_bitmap(struct btrfs_fs_info *fs_info,

And added 'const' to fs_info. Also as this is a debugging helper I added
the __cold attribute.

> +			       struct page *page, u64 start, u32 len)

Not possible for the page though because e.g. page_offset takes a
non-const pointer.

> +{
> +	struct btrfs_subpage_info *subpage_info = fs_info->subpage_info;
> +	struct btrfs_subpage *subpage;
> +	unsigned long uptodate_bitmap;
> +	unsigned long error_bitmap;
> +	unsigned long dirty_bitmap;
> +	unsigned long writeback_bitmap;
> +	unsigned long ordered_bitmap;
> +	unsigned long checked_bitmap;
> +	unsigned long flags;
> +
> +	ASSERT(PagePrivate(page) && page->private);
> +	ASSERT(subpage_info);
> +	subpage = (struct btrfs_subpage *)page->private;
> +
> +
> +	spin_lock_irqsave(&subpage->lock, flags);
> +	get_subpage_bitmap(subpage, subpage_info, uptodate, &uptodate_bitmap);
> +	get_subpage_bitmap(subpage, subpage_info, error, &error_bitmap);
> +	get_subpage_bitmap(subpage, subpage_info, dirty, &dirty_bitmap);
> +	get_subpage_bitmap(subpage, subpage_info, writeback, &writeback_bitmap);
> +	get_subpage_bitmap(subpage, subpage_info, ordered, &ordered_bitmap);
> +	get_subpage_bitmap(subpage, subpage_info, checked, &checked_bitmap);
> +	spin_unlock_irqrestore(&subpage->lock, flags);
> +
> +	dump_page(page, "btrfs subpage dump");
> +	btrfs_warn(fs_info, "start=%llu len=%u page=%llu, bitmaps uptodate=%*pbl error=%*pbl dirty=%*pbl writeback=%*pbl ordered=%*pbl checked=%*pbl",
> +		    start, len, page_offset(page),
> +		    subpage_info->bitmap_nr_bits, &uptodate_bitmap,
> +		    subpage_info->bitmap_nr_bits, &error_bitmap,
> +		    subpage_info->bitmap_nr_bits, &dirty_bitmap,
> +		    subpage_info->bitmap_nr_bits, &writeback_bitmap,
> +		    subpage_info->bitmap_nr_bits, &ordered_bitmap,
> +		    subpage_info->bitmap_nr_bits, &checked_bitmap);
> +}
diff mbox series

Patch

diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index d8becf1cdbc0..13c43291de04 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -4570,7 +4570,8 @@  static void assert_eb_page_uptodate(const struct extent_buffer *eb,
 		uptodate = btrfs_subpage_test_uptodate(fs_info, page,
 						       eb->start, eb->len);
 		error = btrfs_subpage_test_error(fs_info, page, eb->start, eb->len);
-		WARN_ON(!uptodate && !error);
+		if (WARN_ON(!uptodate && !error))
+			btrfs_subpage_dump_bitmap(fs_info, page, eb->start, eb->len);
 	} else {
 		WARN_ON(!PageUptodate(page) && !PageError(page));
 	}
diff --git a/fs/btrfs/subpage.c b/fs/btrfs/subpage.c
index 045117ca0ddc..f45d62bf2dfb 100644
--- a/fs/btrfs/subpage.c
+++ b/fs/btrfs/subpage.c
@@ -745,3 +745,45 @@  void btrfs_page_unlock_writer(struct btrfs_fs_info *fs_info, struct page *page,
 	/* Have writers, use proper subpage helper to end it */
 	btrfs_page_end_writer_lock(fs_info, page, start, len);
 }
+
+#define get_subpage_bitmap(subpage, subpage_info, name, dst)	\
+	bitmap_cut(dst, subpage->bitmaps, 0,			\
+		   subpage_info->name##_offset, subpage_info->bitmap_nr_bits) \
+
+void btrfs_subpage_dump_bitmap(struct btrfs_fs_info *fs_info,
+			       struct page *page, u64 start, u32 len)
+{
+	struct btrfs_subpage_info *subpage_info = fs_info->subpage_info;
+	struct btrfs_subpage *subpage;
+	unsigned long uptodate_bitmap;
+	unsigned long error_bitmap;
+	unsigned long dirty_bitmap;
+	unsigned long writeback_bitmap;
+	unsigned long ordered_bitmap;
+	unsigned long checked_bitmap;
+	unsigned long flags;
+
+	ASSERT(PagePrivate(page) && page->private);
+	ASSERT(subpage_info);
+	subpage = (struct btrfs_subpage *)page->private;
+
+
+	spin_lock_irqsave(&subpage->lock, flags);
+	get_subpage_bitmap(subpage, subpage_info, uptodate, &uptodate_bitmap);
+	get_subpage_bitmap(subpage, subpage_info, error, &error_bitmap);
+	get_subpage_bitmap(subpage, subpage_info, dirty, &dirty_bitmap);
+	get_subpage_bitmap(subpage, subpage_info, writeback, &writeback_bitmap);
+	get_subpage_bitmap(subpage, subpage_info, ordered, &ordered_bitmap);
+	get_subpage_bitmap(subpage, subpage_info, checked, &checked_bitmap);
+	spin_unlock_irqrestore(&subpage->lock, flags);
+
+	dump_page(page, "btrfs subpage dump");
+	btrfs_warn(fs_info, "start=%llu len=%u page=%llu, bitmaps uptodate=%*pbl error=%*pbl dirty=%*pbl writeback=%*pbl ordered=%*pbl checked=%*pbl",
+		    start, len, page_offset(page),
+		    subpage_info->bitmap_nr_bits, &uptodate_bitmap,
+		    subpage_info->bitmap_nr_bits, &error_bitmap,
+		    subpage_info->bitmap_nr_bits, &dirty_bitmap,
+		    subpage_info->bitmap_nr_bits, &writeback_bitmap,
+		    subpage_info->bitmap_nr_bits, &ordered_bitmap,
+		    subpage_info->bitmap_nr_bits, &checked_bitmap);
+}
diff --git a/fs/btrfs/subpage.h b/fs/btrfs/subpage.h
index 0e80ad336904..cffc59d4ea75 100644
--- a/fs/btrfs/subpage.h
+++ b/fs/btrfs/subpage.h
@@ -154,5 +154,7 @@  void btrfs_page_assert_not_dirty(const struct btrfs_fs_info *fs_info,
 				 struct page *page);
 void btrfs_page_unlock_writer(struct btrfs_fs_info *fs_info, struct page *page,
 			      u64 start, u32 len);
+void btrfs_subpage_dump_bitmap(struct btrfs_fs_info *fs_info,
+			       struct page *page, u64 start, u32 len);
 
 #endif