fs: refactor code to use clear_and_wake_up_bit()
Subsystems (2)
cover fs: refactor code to use clear_and_wake_up_bit()
Refactor code to use clear_and_wake_up_bit() instead of manual calls to:
clear_bit_unlock(); smp_mb__after_atomic(); wake_up_bit();
The helper function clear_and_wake_up_bit() was introduced in 'commit 8236b0ae31c83 ("bdi: wake up concurrent wb_shutdown() callers.")' as a generic way of doing the same sequence of operations, but several pieces of code still remain.
Replace manual calls to the operations by a single call to clear_and_wake_up_bit() to deduplicate code and standardize pathways.
TESTING
=======
Boot-tested on an x86_64 QEMU virtual machine. Basic filesystem operations (create, delete, sync) were performed on an ext4 filesystem with data=journal modes. No issues were observed.
---
Agatha Isabelle Moreira (2):
fs: buffer: use clear_and_wake_up_bit() in unlock_buffer()
fs: jbd2: use clear_and_wake_up_bit() in journal_end_buffer_io_sync()
fs/buffer.c | 4 +--- fs/jbd2/commit.c | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-)
Signature · 1 line
2.53.0
PATCH 1/2 fs: buffer: use clear_and_wake_up_bit() in unlock_buffer()
Use clear_and_wake_up_bit() in unlock_buffer(), since the helper was introduced in 'commit 8236b0ae31c83 ("bdi: wake up concurrent wb_shutdown() callers.")' as a generic way of doing the same sequence of operations:
clear_bit_unlock(); smp_mb__after_atomic(); wake_up_bit();
The helper was implemented to avoid bugs caused by forgetting to call wake_up_bit() after clear_bit_unlock().
Since unlock_buffer() predates git and was last modified in 'commit 4e857c58efeb9 ("arch: Mass conversion of smp_mb__*()")', years before clear_and_wake_up_bit(), it still uses the open-coded sequence.
Replace the open-coded sequence with the helper to avoid duplicate code and reduce code paths to maintain.
--- fs/buffer.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
fs/buffer.c +1 -3
@@ -74,9 +74,7 @@ EXPORT_SYMBOL(__lock_buffer);void unlock_buffer (struct buffer_head *bh) { -clear_bit_unlock (BH_Lock, &bh->b_state); -smp_mb__after_atomic (); -wake_up_bit (&bh->b_state, BH_Lock); +clear_and_wake_up_bit (BH_Lock, &bh->b_state); }EXPORT_SYMBOL (unlock_buffer);
Signature · 1 line
2.53.0
PATCH 2/2 fs: jbd2: use clear_and_wake_up_bit() in journal_end_buffer_io_sync()
In reply to Agatha Isabelle MoreiraUse clear_and_wake_up_bit() in journal_end_buffer_io_sync(), since the helper was introduced in 'commit 8236b0ae31c83 ("bdi: wake up concurrent wb_shutdown() callers.")' as a generic way of doing the same sequence of operations:
clear_bit_unlock(); smp_mb__after_atomic(); wake_up_bit();
The helper was first implemented to avoid bugs caused by forgetting to call wake_up_bit() after clear_bit_unlock().
Since journal_end_buffer_io_sync() was first introduced by 'commit 470decc613ab2 ("jbd2: initial copy of files from jbd")' and last modified in this operation by 'commit 4e857c58efeb9 ("arch: Mass conversion of smp_mb__*()")', years before clear_and_wake_up_bit(), it still uses the open-coded sequence.
Replace the open-coded sequence with the helper to avoid duplicate code and reduce code paths to maintain.
--- fs/jbd2/commit.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
fs/jbd2/commit.c +1 -3
@@ -39,9 +39,7 @@ static void journal_end_buffer_io_sync(struct buffer_head *bh, int uptodate)else clear_buffer_uptodate (bh);if (orig_bh) { -clear_bit_unlock (BH_Shadow, &orig_bh->b_state); -smp_mb__after_atomic (); -wake_up_bit (&orig_bh->b_state, BH_Shadow); +clear_and_wake_up_bit (BH_Shadow, &orig_bh->b_state); }unlock_buffer (bh); }
Signature · 1 line
2.53.0
Quoted 6 lines · Agatha Isabelle Moreira
Refactor code to use
clear_and_wake_up_bit()instead of manual calls to:clear_bit_unlock(); smp_mb__after_atomic(); wake_up_bit();
Quoted 6 lines
The helper function
clear_and_wake_up_bit()was introduced in 'commit8236b0ae31c83("bdi: wake up concurrentwb_shutdown()callers.")' as a generic way of doing the same sequence of operations, but several pieces of code still remain.[...]
Applied to the vfs-7.2.misc branch of the vfs/vfs.git tree. Patches in the vfs-7.2.misc branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs-7.2.misc
[1/2] fs: buffer: use clear_and_wake_up_bit() in unlock_buffer()
https://git.kernel.org/vfs/vfs/c/89aafbd6d52b [2/2] fs: jbd2: use clear_and_wake_up_bit() in journal_end_buffer_io_sync() https://git.kernel.org/vfs/vfs/c/d7a7e95e5f50
Re: [PATCH 1/2] fs: buffer: use clear_and_wake_up_bit() in unlock_buffer()
In reply to Agatha Isabelle MoreiraQuoted 15 lines · Agatha Isabelle Moreira
Use
clear_and_wake_up_bit()inunlock_buffer(), since the helper was introduced in 'commit8236b0ae31c83("bdi: wake up concurrentwb_shutdown()callers.")' as a generic way of doing the same sequence of operations:clear_bit_unlock(); smp_mb__after_atomic(); wake_up_bit();The helper was implemented to avoid bugs caused by forgetting to call
wake_up_bit()afterclear_bit_unlock().Since
unlock_buffer()predates git and was last modified in 'commit4e857c58efeb9("arch: Mass conversion of smp_mb__*()")', years beforeclear_and_wake_up_bit(), it still uses the open-coded sequence.
Quoted 6 lines
Replace the open-coded sequence with the helper to avoid duplicate code and reduce code paths to maintain.
Looks good. Feel free to add:
Honza
Quoted 22 lines
--- fs/buffer.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)fs/buffer.c +1
-3@@ -74,9 +74,7 @@ EXPORT_SYMBOL(__lock_buffer);void unlock_buffer (struct buffer_head *bh) { -clear_bit_unlock (BH_Lock, &bh->b_state); -smp_mb__after_atomic (); -wake_up_bit (&bh->b_state, BH_Lock); +clear_and_wake_up_bit (BH_Lock, &bh->b_state); }EXPORT_SYMBOL (unlock_buffer);Signature · 1 line
2.53.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH 2/2] fs: jbd2: use clear_and_wake_up_bit() in journal_end_buffer_io_sync()
In reply to Agatha Isabelle MoreiraQuoted 17 lines · Agatha Isabelle Moreira
Use
clear_and_wake_up_bit()injournal_end_buffer_io_sync(), since the helper was introduced in 'commit8236b0ae31c83("bdi: wake up concurrentwb_shutdown()callers.")' as a generic way of doing the same sequence of operations:clear_bit_unlock(); smp_mb__after_atomic(); wake_up_bit();The helper was first implemented to avoid bugs caused by forgetting to call
wake_up_bit()afterclear_bit_unlock().Since
journal_end_buffer_io_sync()was first introduced by 'commit470decc613ab2("jbd2: initial copy of files from jbd")' and last modified in this operation by 'commit4e857c58efeb9("arch: Mass conversion of smp_mb__*()")', years beforeclear_and_wake_up_bit(), it still uses the open-coded sequence.
Quoted 6 lines
Replace the open-coded sequence with the helper to avoid duplicate code and reduce code paths to maintain.
Looks good. Feel free to add:
Honza
Quoted 22 lines
--- fs/jbd2/commit.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)fs/jbd2/commit.c +1
-3@@ -39,9 +39,7 @@ static void journal_end_buffer_io_sync(struct buffer_head *bh, int uptodate)else clear_buffer_uptodate (bh);if (orig_bh) { -clear_bit_unlock (BH_Shadow, &orig_bh->b_state); -smp_mb__after_atomic (); -wake_up_bit (&orig_bh->b_state, BH_Shadow); +clear_and_wake_up_bit (BH_Shadow, &orig_bh->b_state); }unlock_buffer (bh); }Signature · 1 line
2.53.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 9 lines · Agatha Isabelle Moreira
fs: refactor code to use
clear_and_wake_up_bit()Refactor code to use
clear_and_wake_up_bit()instead of manual calls to:clear_bit_unlock(); smp_mb__after_atomic(); wake_up_bit();[...]
Applied to the vfs-7.3.misc branch of the vfs/vfs.git tree. Patches in the vfs-7.3.misc branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs-7.3.misc
[1/2] fs: buffer: use clear_and_wake_up_bit() in unlock_buffer()
https://git.kernel.org/vfs/vfs/c/1a6e4692deca [2/2] fs: jbd2: use clear_and_wake_up_bit() in journal_end_buffer_io_sync() https://git.kernel.org/vfs/vfs/c/8efd38683c81