summaryrefslogtreecommitdiff
path: root/fs/btrfs/transaction.c
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.com>2026-05-07 19:59:32 +0200
committerFilipe Manana <fdmanana@suse.com>2026-06-09 11:49:25 +0100
commit513528a286e0807968fb2baf1db4e6ad5a49e724 (patch)
treec3330c260b33a49cf6ba6ee17e4c7e861b7ff8d7 /fs/btrfs/transaction.c
parente6c249adb7217a20534e0583a82ee28251c65dc4 (diff)
downloadlinux-next-513528a286e0807968fb2baf1db4e6ad5a49e724.tar.gz
linux-next-513528a286e0807968fb2baf1db4e6ad5a49e724.zip
btrfs: simplify how first hit is passed to __btrfs_abort_transaction()
Optimize the btrfs_abort_transaction() for size as it (by our convention) must be put right after the error condition is detected. The exact file:line is reported so there's a portion that must be inlined. As this is cold code it bloats functions. In previous patch "btrfs: move transaction abort message to __btrfs_abort_transaction()" the error message was moved to the common helper, saving like 20KiB of btrfs.ko and several instructions per call site and some stack space. There's little left to be optimized, we need to keep the atomic test_and_set_bit() and to convey that as 'first hit' to __btrfs_abort_transaction(). Right now it's a bool, which takes 8 bytes on stack for each call but it's 1 bit of information. We can encode that to some of the other parameters. For that let's use the 'error' parameter, by convention it's negative errno so we can reliably detect if it's the first hit or a later error. Also the negation is usually implemented by a single instruction (NEG on x86_64) so the resulting object code is kept short. This reduces btrfs.ko by 8K and stack in several functions by 8 bytes. Cumulative effect with the other commit is -30K of btrfs.ko. While the encoding is an implementation detail, it's contained within the API. Making the transaction abort calls very light is desired. Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs/btrfs/transaction.c')
-rw-r--r--fs/btrfs/transaction.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index aef2462b25d8..a289a8fa237c 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -2727,12 +2727,23 @@ int btrfs_clean_one_deleted_snapshot(struct btrfs_fs_info *fs_info)
*
* We'll complete the cleanup in btrfs_end_transaction and
* btrfs_commit_transaction.
+ *
+ * Note: the parameter @error encodes whether the transactin abort was first hit
+ * (setting the FS_ERROR state bit in btrfs_abort_transaction())
+ * - positive number - first hit
+ * - negative number - abort after it was already done
*/
void __cold __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
const char *function,
- unsigned int line, int error, bool first_hit)
+ unsigned int line, int error)
{
struct btrfs_fs_info *fs_info = trans->fs_info;
+ bool first_hit = false;
+
+ if (error > 0) {
+ error = -error;
+ first_hit = true;
+ }
WRITE_ONCE(trans->aborted, error);
WRITE_ONCE(trans->transaction->aborted, error);