Skip to contentSkip to conversation

fs/buffer.c: change buffer_busy() to use logical-OR expression

PATCH In review Namhyung Kim 2 participants 3 messages Oct 23, 2010 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs/buffer.c: change buffer_busy() to use logical-OR expression

Convert bitwise-OR operator to logical-OR in favor of short-circuit evaluation. The end result would be same.

---
 fs/buffer.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
fs/buffer.c +1 -1
index f5755f7..4362e77 100644
@@ -3069,7 +3069,7 @@ EXPORT_SYMBOL(sync_dirty_buffer);
  */
 static inline int buffer_busy(struct buffer_head *bh)
 {
-	return atomic_read(&bh->b_count) |
+	return atomic_read(&bh->b_count) ||
 		(bh->b_state & ((1 << BH_Dirty) | (1 << BH_Lock)));
 }
 
Signature · 1 line
1.7.0.4
maintainer
#1 lore raw
Quoted 2 lines · Namhyung Kim

Convert bitwise-OR operator to logical-OR in favor of short-circuit evaluation. The end result would be same.

It'll cost _more_.

Think of it:

	v = atomic_read(...)
	w = bh->b_state
	w &= constant
	v |= w
	return v

vs.
v = atomic_read()
branch to l if not equal to 0
w = bh->b_state
if w & constant is not 0, branch to l
v = 0
return v
l: v = 1
return v

That short-circuit won't win anything here.

#2 lore raw

2010-10-23 (토), 18:21 +0100, Al Viro:

Quoted 22 lines · Namhyung Kim
Quoted 2 lines

Convert bitwise-OR operator to logical-OR in favor of short-circuit evaluation. The end result would be same.

It'll cost _more_.

Think of it:

	v = atomic_read(...)
	w = bh->b_state
	w &= constant
	v |= w
	return v

vs.
v = atomic_read()
branch to l if not equal to 0
w = bh->b_state
if w & constant is not 0, branch to l
v = 0
return v
l: v = 1
return v

Quoted 1 line

That short-circuit won't win anything here.

I see. It adds expensive branch insns. I just checked that patched code generated longer code, Cool. But what if I exchange the order of evaluation, check the bitmask before atomic_read()? Isn't it helpful either?

Thanks.

Signature · 2 lines
Regards,
Namhyung Kim