Skip to content

Commit

Permalink
btrfs: set blocking_writers directly, no increment or decrement
Browse files Browse the repository at this point in the history
The increment and decrement was inherited from previous version that
used atomics, switched in commit 06297d8 ("btrfs: switch
extent_buffer blocking_writers from atomic to int"). The only possible
values are 0 and 1 so we can set them directly.

The generated assembly (gcc 9.x) did the direct value assignment in
btrfs_set_lock_blocking_write (asm diff after change in 06297d8):

     5d:   test   %eax,%eax
     5f:   je     62 <btrfs_set_lock_blocking_write+0x22>
     61:   retq

  -  62:   lock incl 0x44(%rdi)
  -  66:   add    $0x50,%rdi
  -  6a:   jmpq   6f <btrfs_set_lock_blocking_write+0x2f>

  +  62:   movl   $0x1,0x44(%rdi)
  +  69:   add    $0x50,%rdi
  +  6d:   jmpq   72 <btrfs_set_lock_blocking_write+0x32>

The part in btrfs_tree_unlock did a decrement because
BUG_ON(blockers > 1) is probably not a strong hint for the compiler, but
otherwise the output looks safe:

  - lock decl 0x44(%rdi)

  + sub    $0x1,%eax
  + mov    %eax,0x44(%rdi)

Signed-off-by: David Sterba <dsterba@suse.com>
  • Loading branch information
David Sterba committed Nov 18, 2019
1 parent f5c2a52 commit 40d38f5
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions fs/btrfs/locking.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void btrfs_set_lock_blocking_write(struct extent_buffer *eb)
if (eb->blocking_writers == 0) {
btrfs_assert_spinning_writers_put(eb);
btrfs_assert_tree_locked(eb);
eb->blocking_writers++;
eb->blocking_writers = 1;
write_unlock(&eb->lock);
}
}
Expand Down Expand Up @@ -305,7 +305,7 @@ void btrfs_tree_unlock(struct extent_buffer *eb)

if (blockers) {
btrfs_assert_no_spinning_writers(eb);
eb->blocking_writers--;
eb->blocking_writers = 0;
/*
* We need to order modifying blocking_writers above with
* actually waking up the sleepers to ensure they see the
Expand Down

0 comments on commit 40d38f5

Please sign in to comment.