fs/buffer: optimize discard_buffer()
authorDavidlohr Bueso <dave@stgolabs.net>
Thu, 15 May 2025 17:39:25 +0000 (10:39 -0700)
committerChristian Brauner <brauner@kernel.org>
Wed, 21 May 2025 07:34:29 +0000 (09:34 +0200)
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 e7470ee89f0 (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 <dave@stgolabs.net>
Link: https://lore.kernel.org/20250515173925.147823-5-dave@stgolabs.net
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/buffer.c

index 7621f0c471f7e89a20a8d38209e1586d6634fcf8..dd8709e05225edada21f98d1149831aae44bc157 100644 (file)
@@ -1614,8 +1614,8 @@ static void discard_buffer(struct buffer_head * bh)
        bh->b_bdev = NULL;
        b_state = READ_ONCE(bh->b_state);
        do {
-       } while (!try_cmpxchg(&bh->b_state, &b_state,
-                             b_state & ~BUFFER_FLAGS_DISCARD));
+       } while (!try_cmpxchg_relaxed(&bh->b_state, &b_state,
+                                     b_state & ~BUFFER_FLAGS_DISCARD));
        unlock_buffer(bh);
 }