Skip to contentSkip to conversation

btrfs: improve sibling keys check failure report

PATCH In review [email protected] 4 participants 15 messages Apr 26, 2023 – Apr 27, 2023 Btrfs file system

lore
Share & tools
lore
#0 lore raw

cover btrfs: improve sibling keys check failure report

From: Filipe Manana <[email protected]>

This makes reporting of sibling key check failures more useful, by printing more exact stack traces in case the extent buffers are leaves and dumping the extent buffers. This is motivated by a recent report [1]. More details on the changelogs of each patch.

[1] https://lore.kernel.org/linux-btrfs/[email protected]/

Filipe Manana (3):
btrfs: abort transaction when sibling keys check fails for leaves
btrfs: print extent buffers when sibling keys check fails
btrfs: tag as unlikely the key comparison when checking sibling keys

 fs/btrfs/ctree.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/3 btrfs: abort transaction when sibling keys check fails for leaves

From: Filipe Manana <[email protected]>

If the sibling keys check fails before we move keys from one sibling leaf to another, we are not aborting the transaction - we leave that to some higher level caller of btrfs_search_slot() (or anything else that uses it to insert items into a b+tree).

This means that the transaction abort will provide a stack trace that omits the b+tree modification call chain. So change this to immediately abort the transaction and therefore get a more useful stack trace that shows us the call chain in the bt+tree modification code.

It's also important to immediately abort the transaction just in case some higher level caller is not doing it, as this indicates a very serious corruption and we should stop the possibility of doing further damage.

---
 fs/btrfs/ctree.c | 2 ++
 1 file changed, 2 insertions(+)
fs/btrfs/ctree.c +2 -0
index d94429e0f16a..a0b97a6d075a 100644
@@ -3296,6 +3296,7 @@ static int push_leaf_right(struct btrfs_trans_handle *trans, struct btrfs_root
 
 	if (check_sibling_keys(left, right)) {
 		ret = -EUCLEAN;
+		btrfs_abort_transaction(trans, ret);
 		btrfs_tree_unlock(right);
 		free_extent_buffer(right);
 		return ret;
@@ -3514,6 +3515,7 @@ static int push_leaf_left(struct btrfs_trans_handle *trans, struct btrfs_root
 
 	if (check_sibling_keys(left, right)) {
 		ret = -EUCLEAN;
+		btrfs_abort_transaction(trans, ret);
 		goto out;
 	}
 	return __push_leaf_left(trans, path, min_data_size, empty, left,
Signature · 1 line
2.34.1
Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] btrfs: abort transaction when sibling keys check fails for leaves

Quoted 12 lines · On 2023/4/26 18:51, [email protected] wrote:

From: Filipe Manana <[email protected]>

If the sibling keys check fails before we move keys from one sibling leaf to another, we are not aborting the transaction - we leave that to some higher level caller of btrfs_search_slot() (or anything else that uses it to insert items into a b+tree).

This means that the transaction abort will provide a stack trace that omits the b+tree modification call chain. So change this to immediately abort the transaction and therefore get a more useful stack trace that shows us the call chain in the bt+tree modification code.

Quoted 6 lines

It's also important to immediately abort the transaction just in case some higher level caller is not doing it, as this indicates a very serious corruption and we should stop the possibility of doing further damage.

Thanks,
Qu

Quoted 24 lines
---
  fs/btrfs/ctree.c | 2 ++
  1 file changed, 2 insertions(+)
fs/btrfs/ctree.c +2 -0
index d94429e0f16a..a0b97a6d075a 100644
@@ -3296,6 +3296,7 @@ static int push_leaf_right(struct btrfs_trans_handle *trans, struct btrfs_root
 
  	if (check_sibling_keys(left, right)) {
  		ret = -EUCLEAN;
+		btrfs_abort_transaction(trans, ret);
  		btrfs_tree_unlock(right);
  		free_extent_buffer(right);
  		return ret;
@@ -3514,6 +3515,7 @@ static int push_leaf_left(struct btrfs_trans_handle *trans, struct btrfs_root
 
  	if (check_sibling_keys(left, right)) {
  		ret = -EUCLEAN;
+		btrfs_abort_transaction(trans, ret);
  		goto out;
  	}
  	return __push_leaf_left(trans, path, min_data_size, empty, left,
#3 lore raw

PATCH 2/3 btrfs: print extent buffers when sibling keys check fails

In reply to [email protected]

From: Filipe Manana <[email protected]>

When trying to move keys from one node/leaf to another sibling node/leaf, if the sibling keys check fails we just print an error message with the last key of the left sibling and the first key of the right sibling. However it's also useful to print all the keys of each sibling, as it may provide some clues to what went wrong, which code path may be inserting keys in an incorrect order. So just do that, print the siblings with btrfs_print_tree(), as it works for both leaves and nodes.

---
 fs/btrfs/ctree.c | 4 ++++
 1 file changed, 4 insertions(+)
fs/btrfs/ctree.c +4 -0
index a0b97a6d075a..a061d7092369 100644
@@ -2708,6 +2708,10 @@ static bool check_sibling_keys(struct extent_buffer *left,
 	}
 
 	if (btrfs_comp_cpu_keys(&left_last, &right_first) >= 0) {
+		btrfs_crit(left->fs_info, "left extent buffer:");
+		btrfs_print_tree(left, false);
+		btrfs_crit(left->fs_info, "right extent buffer:");
+		btrfs_print_tree(right, false);
 		btrfs_crit(left->fs_info,
 "bad key order, sibling blocks, left last (%llu %u %llu) right first (%llu %u %llu)",
 			   left_last.objectid, left_last.type,
Signature · 1 line
2.34.1
Reviewed-by on v1 2/3
#4 lore raw

Re: [PATCH 2/3] btrfs: print extent buffers when sibling keys check fails

Quoted 11 lines · On 2023/4/26 18:51, [email protected] wrote:

From: Filipe Manana <[email protected]>

When trying to move keys from one node/leaf to another sibling node/leaf, if the sibling keys check fails we just print an error message with the last key of the left sibling and the first key of the right sibling. However it's also useful to print all the keys of each sibling, as it may provide some clues to what went wrong, which code path may be inserting keys in an incorrect order. So just do that, print the siblings with btrfs_print_tree(), as it works for both leaves and nodes.

However my concern is, printing two tree blocks may be a little too large. Definitely not something can be capture by one screen.

Although dumping single tree block is already too large for a single screen, I don't have any better way...

Thanks,
Qu

Quoted 19 lines
---
  fs/btrfs/ctree.c | 4 ++++
  1 file changed, 4 insertions(+)
fs/btrfs/ctree.c +4 -0
index a0b97a6d075a..a061d7092369 100644
@@ -2708,6 +2708,10 @@ static bool check_sibling_keys(struct extent_buffer *left,
  	}
 
  	if (btrfs_comp_cpu_keys(&left_last, &right_first) >= 0) {
+		btrfs_crit(left->fs_info, "left extent buffer:");
+		btrfs_print_tree(left, false);
+		btrfs_crit(left->fs_info, "right extent buffer:");
+		btrfs_print_tree(right, false);
  		btrfs_crit(left->fs_info,
  "bad key order, sibling blocks, left last (%llu %u %llu) right first (%llu %u %llu)",
  			   left_last.objectid, left_last.type,
#5 lore raw

Re: [PATCH 2/3] btrfs: print extent buffers when sibling keys check fails

Quoted 14 lines · Qu Wenruo
Quoted 10 lines · On 2023/4/26 18:51, [email protected] wrote:

From: Filipe Manana <[email protected]>

When trying to move keys from one node/leaf to another sibling node/leaf, if the sibling keys check fails we just print an error message with the last key of the left sibling and the first key of the right sibling. However it's also useful to print all the keys of each sibling, as it may provide some clues to what went wrong, which code path may be inserting keys in an incorrect order. So just do that, print the siblings with btrfs_print_tree(), as it works for both leaves and nodes.

Quoted 6 lines
Quoted 1 line

However my concern is, printing two tree blocks may be a little too large. Definitely not something can be capture by one screen.

What?
If I check syslog/dmesg, I can certainly access hundreds, thousands of lines...

I suppose by "capture by one screen" you mean a screenshot?

Quoted 25 lines

Although dumping single tree block is already too large for a single screen, I don't have any better way...

Thanks,
Qu

Quoted 19 lines
---
  fs/btrfs/ctree.c | 4 ++++
  1 file changed, 4 insertions(+)
fs/btrfs/ctree.c +4 -0
index a0b97a6d075a..a061d7092369 100644
@@ -2708,6 +2708,10 @@ static bool check_sibling_keys(struct extent_buffer *left,
      }
 
      if (btrfs_comp_cpu_keys(&left_last, &right_first) >= 0) {
+             btrfs_crit(left->fs_info, "left extent buffer:");
+             btrfs_print_tree(left, false);
+             btrfs_crit(left->fs_info, "right extent buffer:");
+             btrfs_print_tree(right, false);
              btrfs_crit(left->fs_info,
  "bad key order, sibling blocks, left last (%llu %u %llu) right first (%llu %u %llu)",
                         left_last.objectid, left_last.type,
#6 lore raw

Re: [PATCH 2/3] btrfs: print extent buffers when sibling keys check fails

Quoted 19 lines · Filipe Manana
Quoted 18 lines · Qu Wenruo
Quoted 11 lines · On 2023/4/26 18:51, [email protected] wrote:

From: Filipe Manana <[email protected]>

When trying to move keys from one node/leaf to another sibling node/leaf, if the sibling keys check fails we just print an error message with the last key of the left sibling and the first key of the right sibling. However it's also useful to print all the keys of each sibling, as it may provide some clues to what went wrong, which code path may be inserting keys in an incorrect order. So just do that, print the siblings with btrfs_print_tree(), as it works for both leaves and nodes.

Quoted 7 lines
Quoted 2 lines

However my concern is, printing two tree blocks may be a little too large. Definitely not something can be capture by one screen.

What?
If I check syslog/dmesg, I can certainly access hundreds, thousands of lines...

I suppose by "capture by one screen" you mean a screenshot?

Yep, mostly a phone shot of a physical monitor, which a lot of end users choose to use to report their initial trans abort.

E.g. https://lore.kernel.org/linux-btrfs/[email protected]/

I guess the reason is, if the trans abort happens on the root fs, there will be no persistent log files anyway. (Although it's still possible to pass the dmesg to another machine or go netconsole, but not everyone has such setup ready).

Thanks,
Qu

Quoted 26 lines
Quoted 26 lines

Although dumping single tree block is already too large for a single screen, I don't have any better way...

Thanks,
Qu

Quoted 19 lines
---
   fs/btrfs/ctree.c | 4 ++++
   1 file changed, 4 insertions(+)
fs/btrfs/ctree.c +4 -0
index a0b97a6d075a..a061d7092369 100644
@@ -2708,6 +2708,10 @@ static bool check_sibling_keys(struct extent_buffer *left,
       }
 
       if (btrfs_comp_cpu_keys(&left_last, &right_first) >= 0) {
+             btrfs_crit(left->fs_info, "left extent buffer:");
+             btrfs_print_tree(left, false);
+             btrfs_crit(left->fs_info, "right extent buffer:");
+             btrfs_print_tree(right, false);
               btrfs_crit(left->fs_info,
   "bad key order, sibling blocks, left last (%llu %u %llu) right first (%llu %u %llu)",
                          left_last.objectid, left_last.type,
#7 lore raw

Re: [PATCH 2/3] btrfs: print extent buffers when sibling keys check fails

Quoted 34 lines · Qu Wenruo
Quoted 19 lines · Filipe Manana
Quoted 18 lines · Qu Wenruo
Quoted 11 lines · On 2023/4/26 18:51, [email protected] wrote:

From: Filipe Manana <[email protected]>

When trying to move keys from one node/leaf to another sibling node/leaf, if the sibling keys check fails we just print an error message with the last key of the left sibling and the first key of the right sibling. However it's also useful to print all the keys of each sibling, as it may provide some clues to what went wrong, which code path may be inserting keys in an incorrect order. So just do that, print the siblings with btrfs_print_tree(), as it works for both leaves and nodes.

Quoted 7 lines
Quoted 2 lines

However my concern is, printing two tree blocks may be a little too large. Definitely not something can be capture by one screen.

What?
If I check syslog/dmesg, I can certainly access hundreds, thousands of lines...

I suppose by "capture by one screen" you mean a screenshot?

Yep, mostly a phone shot of a physical monitor, which a lot of end users choose to use to report their initial trans abort.

Quoted 7 lines

E.g.
https://lore.kernel.org/linux-btrfs/[email protected]/

I guess the reason is, if the trans abort happens on the root fs, there will be no persistent log files anyway.
(Although it's still possible to pass the dmesg to another machine or go netconsole, but not everyone has such setup ready).

So what?
I don't see how that invalidates printing extent buffers... Many users are able to access dmesg/syslog
and paste what they get there... It's also useful for development where we can certainly access everything...

Quoted 29 lines

Thanks,
Qu

Quoted 26 lines
Quoted 26 lines

Although dumping single tree block is already too large for a single screen, I don't have any better way...

Thanks,
Qu

Quoted 19 lines
---
   fs/btrfs/ctree.c | 4 ++++
   1 file changed, 4 insertions(+)
fs/btrfs/ctree.c +4 -0
index a0b97a6d075a..a061d7092369 100644
@@ -2708,6 +2708,10 @@ static bool check_sibling_keys(struct extent_buffer *left,
       }
 
       if (btrfs_comp_cpu_keys(&left_last, &right_first) >= 0) {
+             btrfs_crit(left->fs_info, "left extent buffer:");
+             btrfs_print_tree(left, false);
+             btrfs_crit(left->fs_info, "right extent buffer:");
+             btrfs_print_tree(right, false);
               btrfs_crit(left->fs_info,
   "bad key order, sibling blocks, left last (%llu %u %llu) right first (%llu %u %llu)",
                          left_last.objectid, left_last.type,
#8 lore raw

Re: [PATCH 2/3] btrfs: print extent buffers when sibling keys check fails

Quoted 43 lines · Filipe Manana
Quoted 34 lines · Qu Wenruo
Quoted 19 lines · Filipe Manana
Quoted 18 lines · Qu Wenruo
Quoted 11 lines · On 2023/4/26 18:51, [email protected] wrote:

From: Filipe Manana <[email protected]>

When trying to move keys from one node/leaf to another sibling node/leaf, if the sibling keys check fails we just print an error message with the last key of the left sibling and the first key of the right sibling. However it's also useful to print all the keys of each sibling, as it may provide some clues to what went wrong, which code path may be inserting keys in an incorrect order. So just do that, print the siblings with btrfs_print_tree(), as it works for both leaves and nodes.

Quoted 7 lines
Quoted 2 lines

However my concern is, printing two tree blocks may be a little too large. Definitely not something can be capture by one screen.

What?
If I check syslog/dmesg, I can certainly access hundreds, thousands of lines...

I suppose by "capture by one screen" you mean a screenshot?

Yep, mostly a phone shot of a physical monitor, which a lot of end users choose to use to report their initial trans abort.

Quoted 7 lines

E.g.
https://lore.kernel.org/linux-btrfs/[email protected]/

I guess the reason is, if the trans abort happens on the root fs, there will be no persistent log files anyway.
(Although it's still possible to pass the dmesg to another machine or go netconsole, but not everyone has such setup ready).

Quoted 5 lines

So what?
I don't see how that invalidates printing extent buffers... Many users are able to access dmesg/syslog
and paste what they get there... It's also useful for development where we can certainly access everything...

That's why I gave the reviewed-by tag.

Maybe we can shrink the output to the first several and last several items in the future.

But for now since it's just a trans abort, it should be mostly fine for the end uesrs to access the full dump.

Thanks,
Qu

Quoted 31 lines
Quoted 31 lines

Thanks,
Qu

Quoted 26 lines
Quoted 26 lines

Although dumping single tree block is already too large for a single screen, I don't have any better way...

Thanks,
Qu

Quoted 19 lines
---
    fs/btrfs/ctree.c | 4 ++++
    1 file changed, 4 insertions(+)
fs/btrfs/ctree.c +4 -0
index a0b97a6d075a..a061d7092369 100644
@@ -2708,6 +2708,10 @@ static bool check_sibling_keys(struct extent_buffer *left,
        }
 
        if (btrfs_comp_cpu_keys(&left_last, &right_first) >= 0) {
+             btrfs_crit(left->fs_info, "left extent buffer:");
+             btrfs_print_tree(left, false);
+             btrfs_crit(left->fs_info, "right extent buffer:");
+             btrfs_print_tree(right, false);
                btrfs_crit(left->fs_info,
    "bad key order, sibling blocks, left last (%llu %u %llu) right first (%llu %u %llu)",
                           left_last.objectid, left_last.type,
#9 lore raw

Re: [PATCH 2/3] btrfs: print extent buffers when sibling keys check fails

Quoted 53 lines · Qu Wenruo
Quoted 43 lines · Filipe Manana
Quoted 34 lines · Qu Wenruo
Quoted 19 lines · Filipe Manana
Quoted 18 lines · Qu Wenruo
Quoted 11 lines · On 2023/4/26 18:51, [email protected] wrote:

From: Filipe Manana <[email protected]>

When trying to move keys from one node/leaf to another sibling node/leaf, if the sibling keys check fails we just print an error message with the last key of the left sibling and the first key of the right sibling. However it's also useful to print all the keys of each sibling, as it may provide some clues to what went wrong, which code path may be inserting keys in an incorrect order. So just do that, print the siblings with btrfs_print_tree(), as it works for both leaves and nodes.

Quoted 7 lines
Quoted 2 lines

However my concern is, printing two tree blocks may be a little too large. Definitely not something can be capture by one screen.

What?
If I check syslog/dmesg, I can certainly access hundreds, thousands of lines...

I suppose by "capture by one screen" you mean a screenshot?

Yep, mostly a phone shot of a physical monitor, which a lot of end users choose to use to report their initial trans abort.

Quoted 7 lines

E.g.
https://lore.kernel.org/linux-btrfs/[email protected]/

I guess the reason is, if the trans abort happens on the root fs, there will be no persistent log files anyway.
(Although it's still possible to pass the dmesg to another machine or go netconsole, but not everyone has such setup ready).

Quoted 5 lines

So what?
I don't see how that invalidates printing extent buffers... Many users are able to access dmesg/syslog
and paste what they get there... It's also useful for development where we can certainly access everything...

Quoted 4 lines

That's why I gave the reviewed-by tag.

Maybe we can shrink the output to the first several and last several items in the future.

That's not really useful for most cases, and I've certainly run into key ordering bugs in the past where having an entire leaf printed made the problem easier to debug,
sometimes it made it immediately obvious where the bug happened and why.

We are avoiding printing useful stuff just because we assume people will take a photo from their phone... For those with access to dmesg/syslog, we lose useful
information.

Quoted 37 lines

But for now since it's just a trans abort, it should be mostly fine for the end uesrs to access the full dump.

Thanks,
Qu

Quoted 31 lines
Quoted 31 lines

Thanks,
Qu

Quoted 26 lines
Quoted 26 lines

Although dumping single tree block is already too large for a single screen, I don't have any better way...

Thanks,
Qu

Quoted 19 lines
---
    fs/btrfs/ctree.c | 4 ++++
    1 file changed, 4 insertions(+)
fs/btrfs/ctree.c +4 -0
index a0b97a6d075a..a061d7092369 100644
@@ -2708,6 +2708,10 @@ static bool check_sibling_keys(struct extent_buffer *left,
        }
 
        if (btrfs_comp_cpu_keys(&left_last, &right_first) >= 0) {
+             btrfs_crit(left->fs_info, "left extent buffer:");
+             btrfs_print_tree(left, false);
+             btrfs_crit(left->fs_info, "right extent buffer:");
+             btrfs_print_tree(right, false);
                btrfs_crit(left->fs_info,
    "bad key order, sibling blocks, left last (%llu %u %llu) right first (%llu %u %llu)",
                           left_last.objectid, left_last.type,
#10 lore raw

Re: [PATCH 2/3] btrfs: print extent buffers when sibling keys check fails

In reply to Qu Wenruo
Quoted 13 lines · Qu Wenruo
Quoted 11 lines · On 2023/4/26 18:51, [email protected] wrote:

From: Filipe Manana <[email protected]>

When trying to move keys from one node/leaf to another sibling node/leaf, if the sibling keys check fails we just print an error message with the last key of the left sibling and the first key of the right sibling. However it's also useful to print all the keys of each sibling, as it may provide some clues to what went wrong, which code path may be inserting keys in an incorrect order. So just do that, print the siblings with btrfs_print_tree(), as it works for both leaves and nodes.

Quoted 7 lines

However my concern is, printing two tree blocks may be a little too large. Definitely not something can be capture by one screen.

Although dumping single tree block is already too large for a single screen, I don't have any better way...

For debugging with full logging we can add what we think would be useful but for the screenshot debugging we can only choose the last piece of information which I think is the stack trace.

#11 lore raw

PATCH 3/3 btrfs: tag as unlikely the key comparison when checking sibling keys

In reply to [email protected]

From: Filipe Manana <[email protected]>

When checking siblings keys, before moving keys from one node/leaf to a sibling node/leaf, it's very unexpected to have the last key of the left sibling greater than or equals to the first key of the right sibling, as that means we have a (serious) corruption that breaks the key ordering properties of a b+tree. Since this is unexpected, surround the comparison with the unlikely macro, which helps the compiler generate better code for the most expected case (no existing b+tree corruption). This is also what we do for other unexpected cases of invalid key ordering (like at btrfs_set_item_key_safe()).

---
 fs/btrfs/ctree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/ctree.c +1 -1
index a061d7092369..c315fb793b30 100644
@@ -2707,7 +2707,7 @@ static bool check_sibling_keys(struct extent_buffer *left,
 		btrfs_item_key_to_cpu(right, &right_first, 0);
 	}
 
-	if (btrfs_comp_cpu_keys(&left_last, &right_first) >= 0) {
+	if (unlikely(btrfs_comp_cpu_keys(&left_last, &right_first) >= 0)) {
 		btrfs_crit(left->fs_info, "left extent buffer:");
 		btrfs_print_tree(left, false);
 		btrfs_crit(left->fs_info, "right extent buffer:");
Signature · 1 line
2.34.1
Reviewed-by on v1 3/3
#12 lore raw

Re: [PATCH 3/3] btrfs: tag as unlikely the key comparison when checking sibling keys

Quoted 12 lines · On 2023/4/26 18:51, [email protected] wrote:

From: Filipe Manana <[email protected]>

When checking siblings keys, before moving keys from one node/leaf to a sibling node/leaf, it's very unexpected to have the last key of the left sibling greater than or equals to the first key of the right sibling, as that means we have a (serious) corruption that breaks the key ordering properties of a b+tree. Since this is unexpected, surround the comparison with the unlikely macro, which helps the compiler generate better code for the most expected case (no existing b+tree corruption). This is also what we do for other unexpected cases of invalid key ordering (like at btrfs_set_item_key_safe()).

Quoted 1 line

Thanks,
Qu

Quoted 17 lines
---
  fs/btrfs/ctree.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/ctree.c +1 -1
index a061d7092369..c315fb793b30 100644
@@ -2707,7 +2707,7 @@ static bool check_sibling_keys(struct extent_buffer *left,
  		btrfs_item_key_to_cpu(right, &right_first, 0);
  	}
 
-	if (btrfs_comp_cpu_keys(&left_last, &right_first) >= 0) {
+	if (unlikely(btrfs_comp_cpu_keys(&left_last, &right_first) >= 0)) {
  		btrfs_crit(left->fs_info, "left extent buffer:");
  		btrfs_print_tree(left, false);
  		btrfs_crit(left->fs_info, "right extent buffer:");
#13 lore raw

Re: [PATCH 3/3] btrfs: tag as unlikely the key comparison when checking sibling keys

In reply to [email protected]
Quoted 22 lines · On Wed, Apr 26, 2023 at 11:51:37AM +0100, [email protected] wrote:

From: Filipe Manana <[email protected]>

When checking siblings keys, before moving keys from one node/leaf to a sibling node/leaf, it's very unexpected to have the last key of the left sibling greater than or equals to the first key of the right sibling, as that means we have a (serious) corruption that breaks the key ordering properties of a b+tree. Since this is unexpected, surround the comparison with the unlikely macro, which helps the compiler generate better code for the most expected case (no existing b+tree corruption). This is also what we do for other unexpected cases of invalid key ordering (like at btrfs_set_item_key_safe()).

---
 fs/btrfs/ctree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/ctree.c +0 -0
index a061d7092369..c315fb793b30 100644

fs/btrfs/ctree.c static bool check_sibling_keys(struct extent_buffer *left, · line 2713

Quoted 8 lines
fs/btrfs/ctree.c +1 -1
@@ -2707,7 +2707,7 @@ static bool check_sibling_keys(struct extent_buffer *left,
 		btrfs_item_key_to_cpu(right, &right_first, 0);
 	}
 
-	if (btrfs_comp_cpu_keys(&left_last, &right_first) >= 0) {
+	if (unlikely(btrfs_comp_cpu_keys(&left_last, &right_first) >= 0)) {
 		btrfs_crit(left->fs_info, "left extent buffer:");
 		btrfs_print_tree(left, false);
 		btrfs_crit(left->fs_info, "right extent buffer:");

Yeah, this is the pattern for unlikely(), compiler unfortunately does not recognize the cold functions like printk in the statement block so the manual annotations are needed. There's a minor effect on assembly, some of the instructions are reordered.

#14 lore raw
In reply to [email protected]
Quoted 7 lines · On Wed, Apr 26, 2023 at 11:51:34AM +0100, [email protected] wrote:

From: Filipe Manana <[email protected]>

This makes reporting of sibling key check failures more useful, by printing more exact stack traces in case the extent buffers are leaves and dumping the extent buffers. This is motivated by a recent report [1]. More details on the changelogs of each patch.

Quoted 6 lines

[1] https://lore.kernel.org/linux-btrfs/[email protected]/

Filipe Manana (3):
btrfs: abort transaction when sibling keys check fails for leaves
btrfs: print extent buffers when sibling keys check fails
btrfs: tag as unlikely the key comparison when checking sibling keys

Added to misc-next, thanks.