Skip to content

Commit 8e184bf

Browse files
Davidlohr Buesobrauner
authored andcommitted
fs/buffer: optimize discard_buffer()
While invalidating, the clearing of the bits in discard_buffer() is done in one fully ordered CAS operation. In the past this was done via individual clear_bit(), until e7470ee (fs: buffer: do not use unnecessary atomic operations when discarding buffers). This implies that there were never strong ordering requirements outside of being serialized by the buffer lock. As such relax the ordering for archs that can benefit. Further, the implied ordering in buffer_unlock() makes current cmpxchg implied barrier redundant due to release semantics. And while in theory the unlock could be part of the bulk clearing, it is best to leave it explicit, but without the double barriers. Signed-off-by: Davidlohr Bueso <[email protected]> Link: https://lore.kernel.org/[email protected] Reviewed-by: Jan Kara <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent d11a249 commit 8e184bf

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

fs/buffer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,8 +1614,8 @@ static void discard_buffer(struct buffer_head * bh)
16141614
bh->b_bdev = NULL;
16151615
b_state = READ_ONCE(bh->b_state);
16161616
do {
1617-
} while (!try_cmpxchg(&bh->b_state, &b_state,
1618-
b_state & ~BUFFER_FLAGS_DISCARD));
1617+
} while (!try_cmpxchg_relaxed(&bh->b_state, &b_state,
1618+
b_state & ~BUFFER_FLAGS_DISCARD));
16191619
unlock_buffer(bh);
16201620
}
16211621

0 commit comments

Comments
 (0)