Linux EXT4 FS development
 help / color / mirror / Atom feed
* [PATCH 0/2] fs: refactor code to use clear_and_wake_up_bit()
@ 2026-05-20 19:45 Agatha Isabelle Moreira
  2026-05-20 19:58 ` [PATCH 1/2] fs: buffer: use clear_and_wake_up_bit() in unlock_buffer() Agatha Isabelle Moreira
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Agatha Isabelle Moreira @ 2026-05-20 19:45 UTC (permalink / raw)
  To: linux-fsdevel, linux-ext4, linux-kernel, Christian Brauner,
	Jan Kara, shuo chen, Theodore Ts'o, linux-kernel-mentees,
	shuah, patch-reply

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.

Suggested-by: shuo chen <1289151713@qq.com>
Link: https://lore.kernel.org/kernelnewbies/agzoqV835-co4kAN@guidai/T/#t
Signed-off-by: Agatha Isabelle Moreira <code@agatha.dev>
---

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(-)

-- 
2.53.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] fs: buffer: use clear_and_wake_up_bit() in unlock_buffer()
  2026-05-20 19:45 [PATCH 0/2] fs: refactor code to use clear_and_wake_up_bit() Agatha Isabelle Moreira
@ 2026-05-20 19:58 ` Agatha Isabelle Moreira
  2026-05-20 20:05 ` [PATCH 2/2] fs: jbd2: use clear_and_wake_up_bit() in journal_end_buffer_io_sync() Agatha Isabelle Moreira
  2026-05-22 13:14 ` [PATCH 0/2] fs: refactor code to use clear_and_wake_up_bit() Christian Brauner
  2 siblings, 0 replies; 4+ messages in thread
From: Agatha Isabelle Moreira @ 2026-05-20 19:58 UTC (permalink / raw)
  To: linux-fsdevel, linux-ext4, linux-kernel, Alexander Viro,
	Christian Brauner, Jan Kara, shuo chen, linux-kernel-mentees,
	shuah, patch-reply

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.

Suggested-by: shuo chen <1289151713@qq.com>
Link: https://lore.kernel.org/kernelnewbies/agzoqV835-co4kAN@guidai/T/#t
Signed-off-by: Agatha Isabelle Moreira <code@agatha.dev>
---
 fs/buffer.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/fs/buffer.c b/fs/buffer.c
index b0b3792b1496..4348b240bd97 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -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);
 
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] fs: jbd2: use clear_and_wake_up_bit() in journal_end_buffer_io_sync()
  2026-05-20 19:45 [PATCH 0/2] fs: refactor code to use clear_and_wake_up_bit() Agatha Isabelle Moreira
  2026-05-20 19:58 ` [PATCH 1/2] fs: buffer: use clear_and_wake_up_bit() in unlock_buffer() Agatha Isabelle Moreira
@ 2026-05-20 20:05 ` Agatha Isabelle Moreira
  2026-05-22 13:14 ` [PATCH 0/2] fs: refactor code to use clear_and_wake_up_bit() Christian Brauner
  2 siblings, 0 replies; 4+ messages in thread
From: Agatha Isabelle Moreira @ 2026-05-20 20:05 UTC (permalink / raw)
  To: linux-ext4, linux-kernel, linux-fsdevel, Theodore Ts'o,
	Jan Kara, shuo chen, linux-kernel-mentees, shuah, patch-reply

Use `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.

Suggested-by: shuo chen <1289151713@qq.com>
Link: https://lore.kernel.org/kernelnewbies/agzoqV835-co4kAN@guidai/T/#t
Signed-off-by: Agatha Isabelle Moreira <code@agatha.dev>
---
 fs/jbd2/commit.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/fs/jbd2/commit.c b/fs/jbd2/commit.c
index 8cf61e7185c4..b647fde76e49 100644
--- a/fs/jbd2/commit.c
+++ b/fs/jbd2/commit.c
@@ -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);
 }
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] fs: refactor code to use clear_and_wake_up_bit()
  2026-05-20 19:45 [PATCH 0/2] fs: refactor code to use clear_and_wake_up_bit() Agatha Isabelle Moreira
  2026-05-20 19:58 ` [PATCH 1/2] fs: buffer: use clear_and_wake_up_bit() in unlock_buffer() Agatha Isabelle Moreira
  2026-05-20 20:05 ` [PATCH 2/2] fs: jbd2: use clear_and_wake_up_bit() in journal_end_buffer_io_sync() Agatha Isabelle Moreira
@ 2026-05-22 13:14 ` Christian Brauner
  2 siblings, 0 replies; 4+ messages in thread
From: Christian Brauner @ 2026-05-22 13:14 UTC (permalink / raw)
  To: linux-fsdevel, linux-ext4, linux-kernel, Jan Kara, shuo chen,
	Theodore Ts'o, linux-kernel-mentees, shuah, patch-reply,
	Agatha Isabelle Moreira
  Cc: Christian Brauner

On Wed, 20 May 2026 16:45:35 -0300, Agatha Isabelle Moreira wrote:
> 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.
> 
> [...]

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-05-22 13:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-20 19:45 [PATCH 0/2] fs: refactor code to use clear_and_wake_up_bit() Agatha Isabelle Moreira
2026-05-20 19:58 ` [PATCH 1/2] fs: buffer: use clear_and_wake_up_bit() in unlock_buffer() Agatha Isabelle Moreira
2026-05-20 20:05 ` [PATCH 2/2] fs: jbd2: use clear_and_wake_up_bit() in journal_end_buffer_io_sync() Agatha Isabelle Moreira
2026-05-22 13:14 ` [PATCH 0/2] fs: refactor code to use clear_and_wake_up_bit() Christian Brauner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox