Skip to contentSkip to conversation

btrfs: simplify expression in btrfs_csum_bytes_to_leaves()

PATCH Superseded Byongho Lee 2 participants 5 messages Jan 26, 2016 Btrfs file system

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: simplify expression in btrfs_csum_bytes_to_leaves()

Simplify expression in btrfs_csum_bytes_to_leaves().

---
 fs/btrfs/ctree.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/btrfs/ctree.h +1 -2
index a9496644f47d..3ab8026280a2 100644
@@ -3448,8 +3448,7 @@ u64 btrfs_csum_bytes_to_leaves(struct btrfs_root *root, u64 csum_bytes);
 static inline u64 btrfs_calc_trans_metadata_size(struct btrfs_root *root,
 						 unsigned num_items)
 {
-	return (root->nodesize + root->nodesize * (BTRFS_MAX_LEVEL - 1)) *
-		2 * num_items;
+	return root->nodesize * BTRFS_MAX_LEVEL * 2 * num_items;
 }
 
 /*
Signature · 1 line
2.7.0
#1 lore raw

The result of the calculation is different, which doesn't look right.

Quoted 22 lines · Byongho Lee

Simplify expression in btrfs_csum_bytes_to_leaves().

---
 fs/btrfs/ctree.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/btrfs/ctree.h +1 -2
index a9496644f47d..3ab8026280a2 100644
@@ -3448,8 +3448,7 @@ u64 btrfs_csum_bytes_to_leaves(struct btrfs_root *root, u64 csum_bytes);
 static inline u64 btrfs_calc_trans_metadata_size(struct btrfs_root *root,
 						 unsigned num_items)
 {
-	return (root->nodesize + root->nodesize * (BTRFS_MAX_LEVEL - 1)) *
-		2 * num_items;
+	return root->nodesize * BTRFS_MAX_LEVEL * 2 * num_items;
 }
 
 /*
#2 lore raw

Hi Stefan,

Quoted 2 lines · Stefan Behrens

The result of the calculation is different, which doesn't look right.

The expression comes out this way.
(root->nodesize + root->nodesize * (BTRFS_MAX_LEVEL - 1)) * 2 * num_items
->(root->nodesize * (1 + BTRFS_MAX_LEVEL - 1)) * 2 * num_items ->(root->nodesize * (BTRFS_MAX_LEVEL)) * 2 * num_items =>root->nodesize * BTRFS_MAX_LEVEL * 2 * num_items

Am I missing?

Quoted 24 lines · Byongho Lee
Quoted 22 lines

Simplify expression in btrfs_csum_bytes_to_leaves().

---
 fs/btrfs/ctree.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/btrfs/ctree.h +1 -2
index a9496644f47d..3ab8026280a2 100644
@@ -3448,8 +3448,7 @@ u64 btrfs_csum_bytes_to_leaves(struct btrfs_root *root, u64 csum_bytes);
 static inline u64 btrfs_calc_trans_metadata_size(struct btrfs_root *root,
 						 unsigned num_items)
 {
-	return (root->nodesize + root->nodesize * (BTRFS_MAX_LEVEL - 1)) *
-		2 * num_items;
+	return root->nodesize * BTRFS_MAX_LEVEL * 2 * num_items;
 }
 
 /*
Reviewed-by
#3 lore raw

Correction: The result of the calculation is equal, which looks right. Sorry for overlooking the closing bracket.

Quoted 35 lines · Byongho Lee
Quoted 2 lines · Stefan Behrens

The result of the calculation is different, which doesn't look right.

The expression comes out this way.
(root->nodesize + root->nodesize * (BTRFS_MAX_LEVEL - 1)) * 2 * num_items
->(root->nodesize * (1 + BTRFS_MAX_LEVEL - 1)) * 2 * num_items ->(root->nodesize * (BTRFS_MAX_LEVEL)) * 2 * num_items =>root->nodesize * BTRFS_MAX_LEVEL * 2 * num_items

Am I missing?

Quoted 23 lines · Byongho Lee
Quoted 21 lines

Simplify expression in btrfs_csum_bytes_to_leaves().

---
 fs/btrfs/ctree.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/btrfs/ctree.h +1 -2
index a9496644f47d..3ab8026280a2 100644
@@ -3448,8 +3448,7 @@ u64 btrfs_csum_bytes_to_leaves(struct btrfs_root *root, u64 csum_bytes);
 static inline u64 btrfs_calc_trans_metadata_size(struct btrfs_root *root,
 						 unsigned num_items)
 {
-	return (root->nodesize + root->nodesize * (BTRFS_MAX_LEVEL - 1)) *
-		2 * num_items;
+	return root->nodesize * BTRFS_MAX_LEVEL * 2 * num_items;
 }
 
 /*
#4 lore raw
In reply to Byongho Lee

Hi,

Please ignore this patch. Because the function's name is wrong in the subject line. While I was writing the commit log, I copy & pasted the first function's name showing in git diff result. I will prepare V2 soon.

Quoted 21 lines · Byongho Lee

Simplify expression in btrfs_csum_bytes_to_leaves().

---
 fs/btrfs/ctree.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/btrfs/ctree.h +1 -2
index a9496644f47d..3ab8026280a2 100644
@@ -3448,8 +3448,7 @@ u64 btrfs_csum_bytes_to_leaves(struct btrfs_root *root, u64 csum_bytes);
 static inline u64 btrfs_calc_trans_metadata_size(struct btrfs_root *root,
 						 unsigned num_items)
 {
-	return (root->nodesize + root->nodesize * (BTRFS_MAX_LEVEL - 1)) *
-		2 * num_items;
+	return root->nodesize * BTRFS_MAX_LEVEL * 2 * num_items;
 }
 
 /*