btrfs: move transaction abort message to __btrfs_abort_transaction()
David Sterba
maintainerPATCH 1/1 btrfs: move transaction abort message to __btrfs_abort_transaction()
The btrfs_abort_transaction() is called at the location where we want to report the abort. It must be a macro so we get the correct line and stack trace. This inlines the necessary code and the rest is pushed to __btrfs_abort_transaction().
There's a possibility to reduce the inlined code if we move the message to the helper function as well, without loss of information. The difference is only that the WARN will not print it inside the stack report but after:
--[ cut here ]--
WARNING: fs/btrfs/transaction.c:2045 at btrfs_commit_transaction+0xa21/0xd30 [btrfs], CPU#11: bonnie++/3377975 ... --[ end trace ] -- BTRFS error (device dm-0 state A): Transaction aborted (error -28)
While previously there would be one more line like:
--[ cut here ]--
BTRFS: Transaction aborted (error -28)
WARNING: fs/btrfs/transaction.c:2045 at btrfs_commit_transaction+0xa21/0xd30 [btrfs], CPU#11: bonnie++/3377975 ... --[ end trace ] --
This removes about 22KiB of btrfs.ko on a release config.
--- fs/btrfs/transaction.c | 3 +++ fs/btrfs/transaction.h | 11 +---------- 2 files changed, 4 insertions(+), 10 deletions(-)
fs/btrfs/transaction.c +3 -0
@@ -2729,6 +2729,9 @@ void __cold __btrfs_abort_transaction(struct btrfs_trans_handle *trans, {struct btrfs_fs_info *fs_info = trans->fs_info; +btrfs_err (trans->fs_info,"Transaction %llu aborted (error %d)" , + trans->transid, error); +WRITE_ONCE (trans->aborted, error);WRITE_ONCE (trans->transaction->aborted, error);if (first_hit && error == -ENOSPC )
fs/btrfs/transaction.h +1 -10
@@ -253,16 +253,7 @@ do { \if (!test_and_set_bit (BTRFS_FS_STATE_TRANS_ABORTED , \ &((trans)->fs_info->fs_state))) { \ __first = true; \ -if (WARN (btrfs_abort_should_print_stack (error), \ -KERN_ERR \ -"BTRFS: Transaction %llu aborted (error %d)\n" , \ - (trans)->transid, (error))) { \ -/* Stack trace printed. */ \ - }else { \ -btrfs_err ((trans)->fs_info, \ -"Transaction %llu aborted (error %d)" , \ - (trans)->transid, (error)); \ - } \ +WARN_ON (btrfs_abort_should_print_stack (error)); \ } \__btrfs_abort_transaction ((trans), __func__, \ __LINE__, (error), __first); \
Signature · 1 line
2.51.0
Quoted 37 lines · David Sterba
The
btrfs_abort_transaction()is called at the location where we want to report the abort. It must be a macro so we get the correct line and stack trace. This inlines the necessary code and the rest is pushed to__btrfs_abort_transaction().There's a possibility to reduce the inlined code if we move the message to the helper function as well, without loss of information. The difference is only that the WARN will not print it inside the stack report but after:
--[ cut here ]-- WARNING: fs/btrfs/transaction.c:2045 at btrfs_commit_transaction+0xa21/0xd30 [btrfs], CPU#11: bonnie++/3377975 ... --[ end trace ] -- BTRFS error (device dm-0 state A): Transaction aborted (error -28)While previously there would be one more line like:
--[ cut here ]-- BTRFS: Transaction aborted (error -28) WARNING: fs/btrfs/transaction.c:2045 at btrfs_commit_transaction+0xa21/0xd30 [btrfs], CPU#11: bonnie++/3377975 ... --[ end trace ] --This removes about 22KiB of btrfs.ko on a release config.
Signed-off-by David Sterba <[email protected]>--- fs/btrfs/transaction.c | 3 +++ fs/btrfs/transaction.h | 11 +---------- 2 files changed, 4 insertions(+), 10 deletions(-)fs/btrfs/transaction.c +0
-0
fs/btrfs/transaction.c void __cold __btrfs_abort_transaction(struct btrfs_trans_handle *trans, · line 2734
Quoted 6 lines
fs/btrfs/transaction.c +3
-0@@ -2729,6 +2729,9 @@ void __cold __btrfs_abort_transaction(struct btrfs_trans_handle *trans, {struct btrfs_fs_info *fs_info = trans->fs_info; +btrfs_err (trans->fs_info,"Transaction %llu aborted (error %d)" , + trans->transid, error); +
This message will be outputted for every btrfs_abort_transaction() call.
Shouldn't we move it behind first_hit check?
Thanks,
Qu
Quoted 43 lines · Qu Wenruo
Quoted 40 lines · David Sterba
The
btrfs_abort_transaction()is called at the location where we want to report the abort. It must be a macro so we get the correct line and stack trace. This inlines the necessary code and the rest is pushed to__btrfs_abort_transaction().There's a possibility to reduce the inlined code if we move the message to the helper function as well, without loss of information. The difference is only that the WARN will not print it inside the stack report but after:
--[ cut here ]-- WARNING: fs/btrfs/transaction.c:2045 at btrfs_commit_transaction+0xa21/0xd30 [btrfs], CPU#11: bonnie++/3377975 ... --[ end trace ] -- BTRFS error (device dm-0 state A): Transaction aborted (error -28)While previously there would be one more line like:
--[ cut here ]-- BTRFS: Transaction aborted (error -28) WARNING: fs/btrfs/transaction.c:2045 at btrfs_commit_transaction+0xa21/0xd30 [btrfs], CPU#11: bonnie++/3377975 ... --[ end trace ] --This removes about 22KiB of btrfs.ko on a release config.
Signed-off-by David Sterba <[email protected]>--- fs/btrfs/transaction.c | 3 +++ fs/btrfs/transaction.h | 11 +---------- 2 files changed, 4 insertions(+), 10 deletions(-)fs/btrfs/transaction.c +0
-0@@ -2729,6 +2729,9 @@ void __cold __btrfs_abort_transaction(struct btrfs_trans_handle *trans, {struct btrfs_fs_info *fs_info = trans->fs_info;
Quoted 7 lines
fs/btrfs/transaction.c void __cold __btrfs_abort_transaction(struct btrfs_trans_handle *trans, · line 2734
Quoted 3 lines
fs/btrfs/transaction.c +3
-0+btrfs_err (trans->fs_info,"Transaction %llu aborted (error %d)" , + trans->transid, error); +This message will be outputted for every
btrfs_abort_transaction()call.Shouldn't we move it behind
first_hitcheck?
Right, we should, to keep the previous behaviour. I'll update it, thanks.
David Sterba
maintainerPATCH v2 1/1 btrfs: move transaction abort message to __btrfs_abort_transaction()
In reply to David SterbaThe btrfs_abort_transaction() is called at the location where we want to report the abort. It must be a macro so we get the correct line and stack trace. This inlines the necessary code and the rest is pushed to __btrfs_abort_transaction().
There's a possibility to reduce the inlined code if we move the message to the helper function as well, without loss of information. The difference is only that the WARN will not print it inside the stack report but after:
--[ cut here ]--
WARNING: fs/btrfs/transaction.c:2045 at btrfs_commit_transaction+0xa21/0xd30 [btrfs], CPU#11: bonnie++/3377975 ... --[ end trace ] -- BTRFS error (device dm-0 state A): Transaction aborted (error -28)
While previously there would be one more line like:
--[ cut here ]--
BTRFS: Transaction aborted (error -28)
WARNING: fs/btrfs/transaction.c:2045 at btrfs_commit_transaction+0xa21/0xd30 [btrfs], CPU#11: bonnie++/3377975 ... --[ end trace ] --
This removes about 20KiB of btrfs.ko on a release config.
---
v2:
- move message in __btrfs_abort_transaction() under 'first_hit', also to make the WRITE_ONCE() assignments immediate
- savings updated to 20K, it depends on the config and compiler, use an average of a few setups
fs/btrfs/transaction.c | 8 ++++++-- fs/btrfs/transaction.h | 11 +---------- 2 files changed, 7 insertions(+), 12 deletions(-)
fs/btrfs/transaction.c +6 -2
@@ -2731,8 +2731,12 @@ void __cold __btrfs_abort_transaction(struct btrfs_trans_handle *trans,WRITE_ONCE (trans->aborted, error);WRITE_ONCE (trans->transaction->aborted, error); -if (first_hit && error == -ENOSPC ) -btrfs_dump_space_info_for_trans_abort (fs_info); +if (first_hit) { +btrfs_err (trans->fs_info,"Transaction %llu aborted (error %d)" , + trans->transid, error); +if (error == -ENOSPC ) +btrfs_dump_space_info_for_trans_abort (fs_info); + }/* Wake up anybody who may be waiting on this transaction */ wake_up (&fs_info->transaction_wait);wake_up (&fs_info->transaction_blocked_wait);
fs/btrfs/transaction.h +1 -10
@@ -253,16 +253,7 @@ do { \if (!test_and_set_bit (BTRFS_FS_STATE_TRANS_ABORTED , \ &((trans)->fs_info->fs_state))) { \ __first = true; \ -if (WARN (btrfs_abort_should_print_stack (error), \ -KERN_ERR \ -"BTRFS: Transaction aborted (error %d)\n" , \ - (error))) { \ -/* Stack trace printed. */ \ - }else { \ -btrfs_err ((trans)->fs_info, \ -"Transaction aborted (error %d)" , \ - (error)); \ - } \ +WARN_ON (btrfs_abort_should_print_stack (error)); \ } \__btrfs_abort_transaction ((trans), __func__, \ __LINE__, (error), __first); \
Signature · 1 line
2.53.0
Quoted 45 lines · David Sterba
The
btrfs_abort_transaction()is called at the location where we want to report the abort. It must be a macro so we get the correct line and stack trace. This inlines the necessary code and the rest is pushed to__btrfs_abort_transaction().There's a possibility to reduce the inlined code if we move the message to the helper function as well, without loss of information. The difference is only that the WARN will not print it inside the stack report but after:
--[ cut here ]--
WARNING: fs/btrfs/transaction.c:2045 at btrfs_commit_transaction+0xa21/0xd30 [btrfs], CPU#11: bonnie++/3377975 ... --[ end trace ] -- BTRFS error (device dm-0 state A): Transaction aborted (error -28)While previously there would be one more line like:
--[ cut here ]--
BTRFS: Transaction aborted (error -28)WARNING: fs/btrfs/transaction.c:2045 at btrfs_commit_transaction+0xa21/0xd30 [btrfs], CPU#11: bonnie++/3377975 ... --[ end trace ] --This removes about 20KiB of btrfs.ko on a release config.
Signed-off-by David Sterba <[email protected]>---
v2:
- move message in__btrfs_abort_transaction()under 'first_hit', also to make theWRITE_ONCE()assignments immediate
- savings updated to 20K, it depends on the config and compiler, use an average of a few setupsfs/btrfs/transaction.c | 8 ++++++-- fs/btrfs/transaction.h | 11 +---------- 2 files changed, 7 insertions(+), 12 deletions(-)fs/btrfs/transaction.c +0
-0
fs/btrfs/transaction.c void __cold __btrfs_abort_transaction(struct btrfs_trans_handle *trans, · line 2735
Quoted 7 lines
fs/btrfs/transaction.c +2
-2@@ -2731,8 +2731,12 @@ void __cold __btrfs_abort_transaction(struct btrfs_trans_handle *trans,WRITE_ONCE (trans->aborted, error);WRITE_ONCE (trans->transaction->aborted, error); -if (first_hit && error == -ENOSPC ) -btrfs_dump_space_info_for_trans_abort (fs_info); +if (first_hit) { + btrfs_err(trans->fs_info, "Transaction %llu aborted (error %d)",
There's already a local fs_info variable, no need to trans->fs_info.
Otherwise:
Filipe Manana <[email protected]>
Quoted 33 lines
fs/btrfs/transaction.c +4
-0+ trans->transid, error); +if (error == -ENOSPC ) +btrfs_dump_space_info_for_trans_abort (fs_info); + }/* Wake up anybody who may be waiting on this transaction */ wake_up (&fs_info->transaction_wait);wake_up (&fs_info->transaction_blocked_wait);fs/btrfs/transaction.h +1
-11@@ -253,16 +253,7 @@ do { \if (!test_and_set_bit (BTRFS_FS_STATE_TRANS_ABORTED , \ &((trans)->fs_info->fs_state))) { \ __first = true; \ -if (WARN (btrfs_abort_should_print_stack (error), \ -KERN_ERR \ -"BTRFS: Transaction aborted (error %d)\n" , \ - (error))) { \ -/* Stack trace printed. */ \ - }else { \ -btrfs_err ((trans)->fs_info, \ -"Transaction aborted (error %d)" , \ - (error)); \ - } \ +WARN_ON (btrfs_abort_should_print_stack (error)); \ } \__btrfs_abort_transaction ((trans), __func__, \ __LINE__, (error), __first); \ --2.53.0
Quoted 47 lines · Filipe Manana
Quoted 46 lines · David Sterba
The
btrfs_abort_transaction()is called at the location where we want to report the abort. It must be a macro so we get the correct line and stack trace. This inlines the necessary code and the rest is pushed to__btrfs_abort_transaction().There's a possibility to reduce the inlined code if we move the message to the helper function as well, without loss of information. The difference is only that the WARN will not print it inside the stack report but after:
--[ cut here ]--
WARNING: fs/btrfs/transaction.c:2045 at btrfs_commit_transaction+0xa21/0xd30 [btrfs], CPU#11: bonnie++/3377975 ... --[ end trace ] -- BTRFS error (device dm-0 state A): Transaction aborted (error -28)While previously there would be one more line like:
--[ cut here ]--
BTRFS: Transaction aborted (error -28)WARNING: fs/btrfs/transaction.c:2045 at btrfs_commit_transaction+0xa21/0xd30 [btrfs], CPU#11: bonnie++/3377975 ... --[ end trace ] --This removes about 20KiB of btrfs.ko on a release config.
Signed-off-by David Sterba <[email protected]>---
v2:
- move message in__btrfs_abort_transaction()under 'first_hit', also to make theWRITE_ONCE()assignments immediate
- savings updated to 20K, it depends on the config and compiler, use an average of a few setupsfs/btrfs/transaction.c | 8 ++++++-- fs/btrfs/transaction.h | 11 +---------- 2 files changed, 7 insertions(+), 12 deletions(-)fs/btrfs/transaction.c +0
-0@@ -2731,8 +2731,12 @@ void __cold __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
Quoted 8 lines
fs/btrfs/transaction.c void __cold __btrfs_abort_transaction(struct btrfs_trans_handle *trans, · line 2735
Quoted 6 lines
fs/btrfs/transaction.c +2
-2WRITE_ONCE (trans->aborted, error);WRITE_ONCE (trans->transaction->aborted, error); -if (first_hit && error == -ENOSPC ) -btrfs_dump_space_info_for_trans_abort (fs_info); +if (first_hit) { + btrfs_err(trans->fs_info, "Transaction %llu aborted (error %d)",There's already a local
fs_infovariable, no need totrans->fs_info.
Ah, copy&paste leftover, I'll fix it in for-next, thanks.