Skip to contentSkip to conversation

fs: Small refactoring of the code in ext4 2.6.37-rc1

PATCH NAK André Luis Pereira dos Santos - BSRSoft 3 participants 3 messages Nov 4, 2010 ext4 file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs: Small refactoring of the code in ext4 2.6.37-rc1

From: Andre Luis Pereira dos Santos <[email protected]>

Hi.
Small refactoring of the code in order to make minor enhancements to critical areas. The notation x + 1 has been replaced by more efficient notation x + +.

---

fs/ext4/extents.c +3 -3
@@ -555,9 +555,9 @@ ext4_ext_binsearch(struct inode *inode,
 	while (l <= r) {
 		m = l + (r - l) / 2;
 		if (block < le32_to_cpu(m->ee_block))
-			r = m - 1;
+			r = m--;
 		else
-			l = m + 1;
+			l = m++;
 		ext_debug("%p(%u):%p(%u):%p(%u) ", l, le32_to_cpu(l->ee_block),
 				m, le32_to_cpu(m->ee_block),
 				r, le32_to_cpu(r->ee_block));
@@ -1557,7 +1557,7 @@ static int ext4_ext_try_to_merge(struct
 		if (ext4_ext_is_uninitialized(ex))
 			uninitialized = 1;
 		ex->ee_len = cpu_to_le16(ext4_ext_get_actual_len(ex)
-				+ ext4_ext_get_actual_len(ex + 1));
+				+ ext4_ext_get_actual_len(ex++));
 		if (uninitialized)
 			ext4_ext_mark_uninitialized(ex);
 
#1 lore raw
Quoted 12 lines · André Luis Pereira dos Santos - BSRSoft

From: Andre Luis Pereira dos Santos <[email protected]>

Hi.
Small refactoring of the code in order to make minor enhancements to critical areas. The notation x + 1 has been replaced by more efficient notation x + +.

---

fs/ext4/extents.c ext4_ext_binsearch(struct inode *inode, · line 560

Quoted 8 lines
fs/ext4/extents.c +2 -2
@@ -555,9 +555,9 @@ ext4_ext_binsearch(struct inode *inode,
 	while (l <= r) {
 		m = l + (r - l) / 2;
 		if (block < le32_to_cpu(m->ee_block))
-			r = m - 1;
+			r = m--;
 		else
-			l = m + 1;
+			l = m++;

These do not give identical results.

foo = bar + 1; assigns (bar + 1) to foo.
foo = bar--; assigns bar to foo then decrements bar. foo = --bar; decrements bar then assigns bar to foo.

So your change both change the value that will be assigned to 'r' and 'l' and also modify 'm' which was not previously modified.

fs/ext4/extents.c static int ext4_ext_try_to_merge(struct · line 1560

Quoted 9 lines
fs/ext4/extents.c +1 -1
 		ext_debug("%p(%u):%p(%u):%p(%u) ", l, le32_to_cpu(l->ee_block),
 				m, le32_to_cpu(m->ee_block),
 				r, le32_to_cpu(r->ee_block));
@@ -1557,7 +1557,7 @@ static int ext4_ext_try_to_merge(struct
 		if (ext4_ext_is_uninitialized(ex))
 			uninitialized = 1;
 		ex->ee_len = cpu_to_le16(ext4_ext_get_actual_len(ex)
-				+ ext4_ext_get_actual_len(ex + 1));
+				+ ext4_ext_get_actual_len(ex++));

After your change gcc complains:

fs/ext4/extents.c:1559:16: warning: operation on ‘ex’ may be undefined fs/ext4/extents.c:1559:16: warning: operation on ‘ex’ may be undefined

which it is correct in doing since you are now modifying the value of the pointer which is dereferenced in the assignment. Previously the value of (ex+1) was simply passed to ext4_ext_get_actual_len(), but now you are passing the value of (ex) to ext4_ext_get_actual_len() and then subsequently incrementing 'ex' itself.

fs/ext4/extents.c static int ext4_ext_try_to_merge(struct · line 1563

Quoted 4 lines
fs/ext4/extents.c +0 -0
 		if (uninitialized)
 			ext4_ext_mark_uninitialized(ex);
 

Was this patch even compile tested?

Signature · 3 lines
Jesper Juhl <[email protected]>             http://www.chaosbits.net/
Plain text mails only, please      http://www.expita.com/nomime.html
Don't top-post  http://www.catb.org/~esr/jargon/html/T/top-post.html
#2 lore raw
In reply to André Luis Pereira dos Santos - BSRSoft

2010/11/4 André Luis Pereira dos Santos - BSRSoft <[email protected]>:

Quoted 24 lines

From: Andre Luis Pereira dos Santos <[email protected]>

Hi.
Small refactoring of the code in order to make minor enhancements to critical areas. The notation x + 1 has been replaced by more efficient notation x + +.

---

fs/ext4/extents.c  2010-11-04 19:54:26.000000000 -0200 renamed from fs/ext4/extents.c  2010-11-01 09:54:12.000000000 -0200 +1 -1
@@ -555,9 +555,9 @@ ext4_ext_binsearch(struct inode *inode,
        while (l <= r) {
                m = l + (r - l) / 2;
                if (block < le32_to_cpu(m->ee_block))
-                       r = m - 1;
+                       r = m--;

               else
-                       l = m + 1;
+                       l = m++;
               ext_debug("%p(%u):%p(%u):%p(%u) ", l, le32_to_cpu(l->ee_block), m, le32_to_cpu(m->ee_block),
                               r, le32_to_cpu(r->ee_block));

fs/ext4/extents.c  2010-11-04 19:54:26.000000000 -0200 static int ext4_ext_try_to_merge(struct · line 1562

Quoted 7 lines
fs/ext4/extents.c  2010-11-04 19:54:26.000000000 -0200 renamed from fs/ext4/extents.c  2010-11-01 09:54:12.000000000 -0200 +1 -1
@@ -1557,7 +1557,7 @@ static int ext4_ext_try_to_merge(struct
                if (ext4_ext_is_uninitialized(ex))
                        uninitialized = 1;
                ex->ee_len = cpu_to_le16(ext4_ext_get_actual_len(ex)
-                               + ext4_ext_get_actual_len(ex + 1));
+                               + ext4_ext_get_actual_len(ex++));
                if (uninitialized)
                        ext4_ext_mark_uninitialized(ex);

But

                   r = m - 1;
is not equivalent to
                   r = m--;

At a minimum your code no longer passes the same value to of m to ext_debug.

NAK

Greg
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html